Extension:TagParser
From MediaWiki.org
This extension is obsolete!
It has been replaced by core functionality in the MediaWiki software (which was added in version 1.12).
This extension is no longer needed since MediaWiki 1.12, which supports the {{#tag}} notation natively. Note however that the syntax used by the new native parser function is slightly different! See help:magic words for the built-in version.
|
Release status: unknown |
|||
|---|---|---|---|
| Implementation | Parser function | ||
| Description | Making expressions in <tags> available by parser function |
||
| Author(s) | René Kijewski | ||
| Last Version | 0.1.2 (2007-12-04) | ||
| MediaWiki | 1.8 to 1.11 (not needed in 1.12) | ||
| License | zlib License | ||
| Download | →Source code | ||
|
|||
|
check usage (experimental) |
|||
Contents |
[edit] Purpose
There are several cases where it could be wanted that expressions like {{{1}}} would be evaluated in <tags> like imagemap or math.
This extension makes this available by the parser function {{#tag}}.
[edit] Usage
There are more or less 3 similar ways to use #tag:
| general | example | |
|---|---|---|
| 1st | {{#tag:name}}
|
{{#tag:br}}
|
| 2nd | {{#tag:name|content}}
|
{{#tag:imagemap|
|
| 3rd | {{#tag:name|attribute1|..|attributeN|content}}
|
{{#tag:source|lang="js"| {{MediaWiki:Common.js}} }}
|
| 4th | {{#tag:|some content}}
empty result |
[edit] Example
If Template:Imagemap contains
{{#tag:imagemap| Image:{{{1|}}}{{!}}{{{width|50px}}}{{!}}{{{alt|}}} default [[{{{2|Main Page}}}|{{{caption|{{{target|Go to the Main Page}}}}}}]] desc {{{description|bottom-left}}} }}
you may write {{Imagemap|Test.png|{{FULLPAGENAME}}|width=100px|alt= |caption=This Page}} and you would get
| as source code: | rendered: |
<imagemap> Image:example.png|100px| default [[Extension:TagParser|This Page]] desc none </imagemap> |
[edit] Download instructions
Please cut and paste the code found below and place it in $IP/extensions/TagParser/TagParser.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
[edit] Installation
To install this extension, add the following line to LocalSettings.php:
require_once( $IP.'/extensions/TagParser/TagParser.php' );
before
require_once( $IP.'/extensions/ParserFunctions/ParserFunctions.php' );
[edit] Code
<?php /* * Extension: TagParser * Copyright (C) 2007 [[de:User:Revolus]] * * Provided under the terms of the zlib/libpng License: * http://www.opensource.org/licenses/zlib-license.php */ $wgExtensionFunctions[] = 'wfTagParser_Setup'; $wgHooks['LanguageGetMagic'][] = 'wfTagParser_Magic'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'TagParser', 'description' => 'Providing <tt><nowiki>{{#tag}}</nowiki></tt> to enable parser functions in XML-tags', 'author' => 'René Kijewski', 'url' => 'http://www.mediawiki.org/wiki/Extension:TagParser', ); function wfTagParser_Setup() { global $wgParser; $wgParser->setFunctionHook('tag', 'wfTagParser_Render'); } function wfTagParser_Magic(&$magicWords, $langCode) { $magicWords['tag'] = array(0, 'tag'); return true; } function wfTagParser_Render( &$parser ) { $attributes = func_get_args(); array_shift($attributes); // 0th parameter is the $parser $tag = array_shift($attributes); // the $tag is always given, but it may be empty $content = array_pop($attributes); // $content may be NULL if($tag === '') { $output = ''; } else { if($content === NULL) { $output = '<'. $tag .' />'; } else { $output = '<' .$tag. ((count($attributes) === 0) ? '' : ' '.implode(' ', $attributes)) .'>'. $content .'</'. $tag .'>'; } } return array($output, 'noparse' => false, 'isHTML' => false); }
