Last modified on 31 July 2012, at 12:00

MediaWiki Developer's Handbook/Adding new tags

To create a parser extension for a new tag just requires a few lines of code:

if( !defined( 'MEDIAWIKI' ) ) {
  die( "This file is part of MediaWiki and is not a valid entry point\n" );
  }

$wgExtensionFunctions[] = 'myNewTagInit';
$wgExtensionCredits['myNewTag'][]= array(
  'name'         => 'myNewTag Extension', 
  'version'      => '1.0.0', 
  'author'       => 'Your Name', 
  'url'          => 'http://www.your.com/mynewtag/', 
  'description'  => 'This extension is for demonstration only.');

function myNewTagInit() {
  global $wgParser;
  $wgParser->setHook( "myNewTag", "myNewTagParse" );
  }
function myNewTagParse($content, $params, $parser ) {
  return "My ''''fancy'''' output";
  }

For testing create a subdirectory mediawikipath/extensions/mynewtag. Save the coding there as myNewTag.php. Add the following line to LocalSettings.php:

require_once "$IP/extensions/mynewtag/myNewTag.php";

Now create a new mediawiki page

<mynewtag />

and save it.

The output will look like this:
My 'fancy' output