You are here Home > Know-how > MediaWiki - CMS > Advanced Features in MediaWiki > Own MediaWiki Extension
MediaWiki - CMS
 

8.1 Own MediaWiki Extension

15.06.2007
8 Advanced Features in MediaWiki [  up  ] - [ A - Z ] - [ top ] 8.2 Caching

MediaWiki 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:

<tagname> some text </tagname>

An example extension

<?php
# Example WikiMedia extension
# with WikiMedia's extension mechanism it is possible to define
# new tags of the form
# <TAGNAME> some text </TAGNAME>
# 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/YourExtensionName.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 <example> ... </example>
    # 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, $argv ) {
    # $argv is an array containing any arguments passed to the
    # extension like <example argument="foo" bar>..
    # Old: $output = "Text passed into example extension: <br/>$input";
    #
    # As of MediaWiki 1.5:
    $output = "Your text passed into <example> extension: " . $argv["arg1"] . " / " . $argv["fooarg"];
    return $output;
}
?>

Save this code as extensions/mySampleExtension.php

Then, add the statement require("extensions/mySampleExtension.php"); at the bottom of your LocalSettings.php, before the ‹?>›

Extension code in the related Wiki Page

<example arg1="one" fooarg="abc"> </example>

Related Links




See also:


8 Advanced Features in MediaWiki       A - Z Index       Top       Disclaimer       8.2 Caching


$Id: extensions.html,v 1.109 2007/06/15 11:49:14 webcms Exp $
copyright © 2005-2007 by reto