Contents

Beskrivelse

Whereas a Tag extension is expected to take unprocessed text and return HTML to the browser, a parser function can 'interact' with other wiki elements in the page. For example, the output of a parser function could be used as a template parameter or in the construction of a link.

Den typiske syntaks for en parserfunktion er:

{{ #functionname: param1 | param2 | param3 }}

For more information, see the documentation for Parser::setFunctionHook ( $id, $callback, $flags = 0 ). This documentation states:

<?phpclassExampleExtension{// Register any render callbacks with the parserpublicstaticfunctiononParserSetup(&$parser){// Create a function hook associating the "example" magic word with renderExample()$parser->setFunctionHook('example','ExampleExtension::renderExample');}// Render the output of {{#example:}}.publicstaticfunctionrenderExample($parser,$param1='',$param2='',$param3=''){// The input parameters are wikitext with templates expanded.// The output should be wikitext too.$output="param1 is $param1 and param2 is $param2 and param3 is $param3";return$output;}}

Be aware that entries for $wgExtensionMessagesFiles will be ignored if there exists an entry in $wgMessagesDirs with the same key. To be on the safe side you could use the following:

// Allow translation of the parser function name and avoid conflicts with localisation$wgExtensionMessagesFiles['ExampleExtensionMagic']=__DIR__.'/ExampleExtension.i18n.magic.php';$wgMessagesDirs['ExampleExtension']=__DIR__.'/i18n';