Extension:TagContent

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
TagContent
Release status: unmaintained
Implementation Parser function
Description Tags content for higher readabillity
Author(s) John Erling Blad (jebladtalk)
Latest version 0.2 (2010-02-21)
License GPL
Download
Translate the TagContent extension if it is available at translatewiki.net
Check usage and version matrix.

TagContent is an extension to define tags that wrap some content in a predefined template, usually for higher readabillity or to ease further processing of the text.

Installation[edit]

  1. Download TagContent from SVN-repository and create the extensions/TagContent directory on your wiki.
  2. Insert this line in the LocalSettings.php file:
    include_once('extensions/TagContent/TagContent.php');
    
  3. Adapt $wgTagContentDefinition and $wgTagContentBlacklist

On Wikipedia or a similar wiki the following additions will be useful for a blacklist

$wgTagContentBlacklist[ 'categorytree' ] = true;
$wgTagContentBlacklist[ 'charinsert' ] = true;
$wgTagContentBlacklist[ 'hiero' ] = true;
$wgTagContentBlacklist[ 'imagemap' ] = true;
$wgTagContentBlacklist[ 'inputbox' ] = true;
$wgTagContentBlacklist[ 'poem' ] = true;
$wgTagContentBlacklist[ 'pre' ] = true;
$wgTagContentBlacklist[ 'ref' ] = true;
$wgTagContentBlacklist[ 'references' ] = true;
$wgTagContentBlacklist[ 'source' ] = true;
$wgTagContentBlacklist[ 'syntaxhighlight' ] = true;
$wgTagContentBlacklist[ 'timeline' ] = true;

A large wiki should unset blacklist and have explicit tag definitions or have very strict rules for who is allowed to edit Mediawiki:Tags-definition

$wgTagContentBlacklist = null;

Usage[edit]

Several new tags can be defined and each one of them maps to a predefined page acting like an ordinary template with the tag content as the first anonymous parameter and the attributes as named parameters. All ordinary wikisyntax are valid for the messages.

Tags can be defined in LocalSettings.php or on a tags definition page in the message namespace if enabled. A tag on the tags definition page must not be predefined or be blacklisted. If a tag isn't predefined or defined on the tags definition page it will act as an usual tag and will possibly be stripped in the cleanup phase. If the blacklist is undefined no tag definitions will be accepted except those defined in LocalSettings.php. The reason behind this is that no blacklist is simply dangerous.

Use of "Mediawiki:Tags-definition" impose a serious load during update of this page and should be avoided if possible.

The definition for a mapping can also include defaults for the named parameters. These will override the defaults given in the template as those will newer be used in this case. Multiple tags can map to the same template but with different parameters.

Example for LocalSettings.php
$wgTagContentDefinition{ 'test-tag' } = array( 'test-template', 'foo' => 'bar' );
Example for "Mediawiki:Tags-definition"
* test-tag|test-template|foo=bar

According to the previous two examples the tag "test-tag" will be transformed according to the definition. The following wikicode will then be rewritten from

lorem ipsum dolor sit amet, <test-tag>consectetur adipisicing elit</test-tag>, sed do eiusmod tempor...

into the following form

lorem ipsum dolor sit amet, {{test-template|consectetur adipisicing elit|foo=bar}}, sed do eiusmod tempor...

An other example may be to use a tag for "new" content and one for "old" content, both may be the same template. First the examples for the necessary definitions, then what this will look like as wikitext in an article and finally what this will look like when rendered.

Example for "Mediawiki:Tags-definition"
*new|template:delimit|type=new
*old|template:delimit|type=old
Example for "Template:Delimit"
<nowiki>&lt;div style="{{#switch:{{{type|}}}|new=color:black|old=color:#999;}}"&gt;{{{1}}}&lt;/div&gt;</nowiki>

When the tags "old" and "new" are used in a wikitext this will look like

<new>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.</new>
 <old>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.</old>

And when rendered this will be like the following

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

The tag form can be more readable than the parser function form when marking large chuncks of text, and it is a lot easier to parse with a quick and dirty regexp expression.

Nesting of tags are always difficult, and as this extension makes no attempt to verify that the placement of tags are legal compared to other tags on the page, the only real help in correcting such errors are "tidy" in various incarnations. This may although give somewhat strange errors sometimes. Typically the root cause for such errors are constructs like

lorem ipsum dolor sit amet, <foo>consectetur <bar>adipisicing elit</foo>, sed do eiusmod<bar> tempor...

Because parts of the wikimarkup is generated by a rather dumb parser the most common error will come from opening a tag in one paragraph and closing it in another.

Note that this extension might push evaluation from first parser pass to second parser pass and this might create run time errors.

Alternatives[edit]

Not known


Use the discussion page for feedback, questions, feature requests and bug reports.