* set eol-style:native where missing
[T119942Repr.git] / Parser_function.php
blobe73b714e21865f47ae9555d94d40ac4b487c83fe
1 <?php
3 # Guard against direct invocation from the web, print a friendly help message
5 if ( !defined( 'MEDIAWIKI' ) ) {
6 echo <<<EOT
7 <html><body>
8 <p>This is the Parser_function example extension. To enable it, put the
9 following in your LocalSettings.php:</p>
10 <pre>
11 require_once( "\$IP/extensions/examples/Parser_function.php" );
12 </pre></body></html>
13 EOT;
14 exit( 1 );
17 # Define a setup function
18 $wgExtensionFunctions[] = 'wfExampleParserFunction_Setup';
19 # Add a hook to initialise the magic word
20 $wgHooks['LanguageGetMagic'][] = 'wfExampleParserFunction_Magic';
22 function wfExampleParserFunction_Setup() {
23 global $wgParser;
24 # Set a function hook associating the "example" magic word with our function
25 $wgParser->setFunctionHook( 'example', 'wfExampleParserFunction_Render' );
28 function wfExampleParserFunction_Magic( &$magicWords, $langCode ) {
29 # Add the magic word
30 # The first array element is case sensitivity, in this case it is not case sensitive
31 # All remaining elements are synonyms for our parser function
32 $magicWords['example'] = array( 0, 'example' );
33 return true;
36 function wfExampleParserFunction_Render( &$parser, $param1 = '', $param2 = '' ) {
37 # The parser function itself
38 # The input parameters are wikitext with templates expanded
39 # The output should be wikitext too
40 return "param1 is $param1 and param2 is $param2";