Extension:ExpandAfter
From MediaWiki.org
|
Expand After Release status: unknown |
|
|---|---|
| Implementation | Parser functions |
| Description | Allows to expand content in <tags> in templates. |
| Author(s) | User:Vitas |
| Version | 0.0.1 |
| MediaWiki | created on 1.8.2. |
| Download | no link |
Contents |
[edit] Usage
{{#expandafter:tag|a1="val" a2="val"|content}}
Gives <tag a1="val" a2="val">content</tag>.
This converts an XML-style extension to a parser function which allows the values of a1 and a2 and the content to depend on template parameters (but not on variables and templates), which is not directly possible within the XML-style tags.
[edit] Example: math
For example in template {{half}}:
{{#expandafter:math||{ {{{1}}} \over 2 } }}
Using {{half|a+b}} gives
(<math>{ a+b \over 2}</math>).
However, {{#expandafter:math||{{#expr:3-1}} \over 3 }} and {{#expandafter:math||18 \over 3 }} do not work.
[edit] Example: nowiki
Template:Demo containing
- {{#expandafter:nowiki||{{{1}}}}} gives {{{1}}}
is convenient for demonstrating wikitext syntax. For example:
{{demo|a[[b]]c ''d'' '''e'''}} gives:
- a[[b]]c ''d'' '''e''' gives abc d e
However, this does not work for demonstrating the expansion of variables and templates, because variables and templates in the expression for the value of a parameter of a template or parser function are expanded before the parameter is used.
See also m:Help:Template documentation#Templates for documentation.
[edit] Installation
require_once( "$IP/extensions/ExpandAfter.php");
ExpandAfter.php:
<?php
function expandAfterInit() {
global $wgParser;
$wgParser->setFunctionHook( 'expandafter', 'expandAfterHook' );
$wgParser->setFunctionHook( 'ea', 'expandAfterHook' );
}
function expandAfterHook($parser) {
$args = func_get_args();
array_shift($args);
$tag = array_shift($args);
$attrs = array_shift($args);
$content = implode('|',$args);
return "<$tag $attrs>$content</$tag>";
}
function expandAfterLanguageGetMagicHook( &$magicWords, $langCode = 'en' ) {
$magicWords['ea'] = array( 0, 'ea');
$magicWords['expandafter'] = array( 0, 'expandafter');
return true;
}
$wgExtensionFunctions[] = 'expandAfterInit';
$wgHooks['LanguageGetMagic'][] = 'expandAfterLanguageGetMagicHook';
?>

