Manual:Tag extensions

MediaWiki, the software that runs the various Wikimedia projects, allows developers to write their own extensions to the wiki markup. An extension defines an XML-style tag which can be used in the wiki editor like this:

some text

The text between the tags gets passed on to a PHP function you implement. This function can then return a HTML string that gets inserted into the output in place of the tags and text. Note that the return string should be HTML, not wiki markup.

How to get started
MediaWiki extensions live in the  subdirectory in the MediaWiki installation. To create your own extension, first create a new file called  in this directory containing the following template code:

 some text  # the function registered by the extension gets the text between the # tags as input and can transform it into arbitrary HTML code. # Note: The output is not interpreted as WikiText but directly #      included in the HTML output. So Wiki markup is not supported. # To activate the extension, include it from your LocalSettings.php # with: include("extensions/ExampleExt.php"); $wgExtensionFunctions[] = "wfExampleExtension"; function wfExampleExtension { global $wgParser; # register the extension with the WikiText parser # the first parameter is the name of the new tag. In this case it defines the tag ...      # the second parameter is the callback function for processing the text between the tags $wgParser->setHook( "example", "renderExample" ); } # The callback function for converting the input text to HTML output function renderExample( $input ) { $output = "&lt;pre&gt;Text passed into example extension: &lt;br /&gt;". $input. "&lt;/pre&gt;"; return $output; } ?>

Now change the tag name, the function names and of course the functionality of the callback to your liking. Note that it might be better to first install and test the example extension (see next section) and only then start customizing it.

Installing the extension
All it takes is adding a single line to the end of your  file:

include("extensions/YourExtensionName.php");

and you are ready to go. Go to the sandbox and see if it works.