Extension:HTML Tags/Implementing LRMI

HTML Tags was designed to support LRMI, or the Learning Resource Metadata Initiative, a metadata standard for open educational resources developed by Creative Commons. The full specification for LRMI can be found here. HTML Tags can also support the use of schema.org parameters with no additional work (except for adding schema.org parameters to the necessary templates,) and should be able to support most other metadata schemas with some tinkering.

Implementing LRMI with HTML Tags requires enabling two HTML tags, <meta> and <span>, since both of those tags are necessary to create LRMI metadata that verifies against Google’s rich text snippet testing tool. Although there are many ways to implement LRMI once these tags are enabled, we’ve written a series of templates that can be used for this purpose.

If you’d like to use LRMI on your wiki, you should be able to directly copy over these templates and successfully use them. If you try to implement this template structure and run in to any problems, please drop a note on the talk page here or email Max at isalix@gmail.com - we'd be more than happy to get you up and running with LRMI and HTML Tags.

LocalSettings.php

edit

Add these lines to your LocalSettings.php file to set up HTML_Tags for LRMI:

$wgHTMLTagsAttributes['meta'] = array( 'itemprop', 'content' );
$wgHTMLTagsAttributes['span'] = array( 'itemprop', 'itemscope', 'itemtype' );

Templates

edit

{{LRMI}}

edit

{{LRMI}} is a template that can be used to tag a page with multiple LRMI properties at once. For most purposes, this is probably the template you will want to use to add LRMI data to your page. The template by default contains all LRMI properties, if any do not apply to your page you can simply leave them blank. This template is especially useful when used in conjunction with adding a button to the standard editing window with WikiEditor. It should be called in the following format:

{{LRMI
|itemprop=
|itemtype=
|contents=
|educationalAlignment=
|intendedEndUserRole=
|educationalUse=
|timeRequired=
|typicalAgeRange=
|interactivityType=
|learningResourceType=
|useRightsUrl=
|isBasedOnUrl=
|name=
|About=
|dateCreated=
|author=
|publisher=
|inLanguage=
|mediaType=
}}

Here’s the code for the template itself. It should work on any standard Mediawiki installation that has HTML Tags installed, meta and span tags enabled, and the dependent templates present.

{{LRMI-span|itemprop={{{itemprop|}}}|itemtype={{#if:{{{itemtype|}}}|{{{itemtype|}}}|{{#switch:{{{itemprop|}}}|educationalAlignment=http://schema.org/AlignmentObject |intendedEndUserRole=http://schema.org/Text|educationalUse=http://schema.org/Text |timeRequired=http://schema.org/Duration|typicalAgeRange=http://schema.org/Text |interactivityType=http://schema.org/Text|learningResourceType=http://schema.org/Text |useRightsUrl=http://schema.org/URL|isBasedOnUrl=http://schema.org/URL |name=http://schema.org/Text|About=http://schema.org/Text|dateCreated=http://schema.org/Date |author=http://schema.org/Person|publisher=http://schema.org/Organization |inLanguage=http://schema.org/Language|mediaType=http://schema.org/Text}}}}|contents={{{contents|}}} {{#if:{{{educationalAlignment|}}}|{{LRMI-meta|itemprop=educationalAlignment|content={{{educationalAlignment|}}}}} }}{{#if:{{{intendedEndUserRole|}}}|{{LRMI-meta|itemprop=intendedEndUserRole|content={{{intendedEndUserRole|}}}}} }}{{#if:{{{educationalUse|}}}|{{LRMI-meta|itemprop=educationalUse|content={{{educationalUse|}}}}}{{#if:{{{timeRequired|}}}|{{LRMI-meta|itemprop=timeRequired|content={{{timeRequired|}}}}} }}{{#if:{{{typicalAgeRange|}}}|{{LRMI-meta|itemprop=typicalAgeRange|content={{{typicalAgeRange|}}}}} }}{{#if:{{{interactivityType|}}}|{{LRMI-meta|itemprop=interactivityType|content={{{interactivityType|}}}}} }}{{#if:{{{learningResourceType|}}}|{{LRMI-meta|itemprop=learningResourceType|content={{{learningResourceType|}}}}} }}{{#if:{{{useRightsUrl|}}}|{{LRMI-meta|itemprop=useRightsUrl|content={{{useRightsUrl|}}}}} }}{{#if:{{{isBasedOnUrl|}}}|{{LRMI-meta|itemprop=isBasedOnUrl|content={{{isBasedOnUrl|}}}}} }}{{#if:{{{name|}}}|{{LRMI-meta|itemprop=name|content={{{name|}}}}} }}{{#if:{{{About|}}}|{{LRMI-meta|itemprop=About|content={{{About|}}}}} }}{{#if:{{{dateCreated|}}}|{{LRMI-meta|itemprop=dateCreated|content={{{dateCreated|}}}}} }}{{#if:{{{author|}}}|{{LRMI-meta|itemprop=author|content={{{author|}}}}} }}{{#if:{{{publisher|}}}|{{LRMI-meta|itemprop=publisher|content={{{publisher|}}}}} }}{{#if:{{{inLanguage|}}}|{{LRMI-meta|itemprop=inLanguage|content={{{inLanguage|}}}}} }}{{#if:{{{mediaType|}}}|{{LRMI-meta|itemprop=mediaType|content={{{mediaType|}}}}} }} }} }}

{{LRMI-single}}

edit

{{LRMI-single}} is a template that can be used to tag a page with one specific LRMI property. In most situations it is desirable to use {{LRMI-object}} in place of this template, but we’ve included it anyway for comprehensiveness. It should be called in the following format:

{{LRMI-single
|property=
|expectedtype=
|description=
|content=
|value=
}}

Here’s the code for the template, which should work on any standard MediaWiki installation that has HTML Tags installed, the meta and span tags enabled, and the dependent templates present:

<htmltag tagname="span" itemprop="{{{property|}}}" itemscope itemtype="{{{expectedtype|}}}"><htmltag tagname="meta" itemprop="{{{description|}}}" content="{{{content|}}}" />{{{value|}}}</htmltag>

{{LRMI-meta}}

edit

{{LRMI-meta}} is a template called by {{LRMI}} and {{LRMI-object}}. It should be called in the following fashion:

{{LRMI-meta
|itemprop=can be one of the following: educationalAlignment, intendedEndUserRole,
educationalUse, timeRequired, typicalAgeRange, interactivityType, learningResourceType,
useRightsUrl, isBasedOnUrl, [and from Schema.org] name, About, dateCreated, author,
publisher, inLanguage, mediaType
|content=
}}

Here’s the code for the template, which should work on any standard MediaWiki installation that has HTML Tags installed and the meta tag enabled:

<htmltag tagname="meta" itemprop="{{{itemprop|}}}" content="{{{content|}}}" />

{{LRMI-span}}

edit

{{LRMI-span}} is a template called by {{LRMI}} and {{LRMI-object}}. It should be called in the following fashion:

{{LRMI-span
|itemprop=
|itemtype=
|contents=
}}

Here’s the code for the template, which should work on any standard MediaWiki installation that has HTML Tags installed and the meta tag enabled:

<htmltag tagname="span" itemprop="{{{itemprop|}}}" itemscope itemtype="{{{itemtype|}}}">{{{contents|}}}</htmltag>

WikiEditor changes

edit

Once you have implemented the LRMI template, you can add a button to the toolbar provided by the WikiEditor extension, so that users can easily add a stub call to this template on pages where they want to embed LRMI data. The easiest way to do this (though possibly not the ideal one) is to make changes directly to the WikiEditor code. Here is how you can do it; these changes work with at least WikiEditor version 0.3.1.

WikiEditor.php

edit

Add the following lines, around line 140:

                        'wikieditor-toolbar-tool-file-insert',
                        'wikieditor-toolbar-tool-file-cancel',
+                       'wikieditor-toolbar-tool-lrmi-insert',
+                       'wikieditor-toolbar-tool-lrmi-insert-example',
                 ),
         ),

WikiEditor.i18n.php

edit

Around line 274, add the following lines:

        'wikieditor-toolbar-help-content-indent-syntax' => 'Normal text<br />:Indented text<br />::Indented text',
        'wikieditor-toolbar-help-content-indent-result' => 'Normal text<dl><dd>Indented text<dl><dd>Indented text</dd></dl></
+       'wikieditor-toolbar-tool-lrmi-insert' => 'Insert Learning Resource Metadata (LRMI) template',
+       'wikieditor-toolbar-tool-lrmi-insert-example' => 'YY-YY',
  );

modules/jquery.wikiEditor.toolbar.config.js

edit

Add the following lines around line 182:

                                                                'options': {
                                                                         'pre': "--~~~~"
                                                                 }
                                                         }
                                                 },
+'lrmi-insert': {
+'labelMsg': 'wikieditor-toolbar-tool-lrmi-insert',
+        'type': 'button',
+        'icon': {
+                'default':'lrmi.png'
+        },
+        'action': {
+                'type': 'encapsulate',
+                'options': {
+                        'pre': "{{LRMI-object\n|itemprop=educationalAlignment\n|educationalAlignment=Independent study\n|intendedEndUserRole=Student\n|educationalUse=Reading\n|timeRequired=P30M\n|typicalAgeRange=",
+                        'periMsg':'wikieditor-toolbar-tool-lrmi-insert-example',
+                        'post': "\n|interactivityType=non-interactive\n|learningResourceType=single page\n|useRightsUrl=http://creativecommons.org/licenses/by/3.0/\n|isBasedOnUrl=\n|name={{PAGENAME}}\n|About=\n|dateCreated=YYYY-MM-DD\n|author=Wikibooks contributors\n|publisher=Wikimedia Foundation\n|inLanguage=English\n|mediaType=Wiki article\n}}"
+                }
+        }
+},
                                         }
                                 }

lrmi.png

edit

Finally, download the image LRMI WikiEditor button.png, and save it as the file lrmi.png in the directory /modules/images/toolbar.