Template:New MediaWiki parser extension

InfoDabble > Tech Notes > MediaWiki > New MediaWiki parser extension
Jump to: navigation, search
Use this template for creating a new MediaWiki parser extension called NAME. See Manual:Manual:Parser functions

***Use subst: for Template:New MediaWiki extension below***

This is a MediaWiki Extension
NAME

Release status: beta

Type: Parser extension
Description: .
Author: Eric Hartwell
Version: 0.5
MediaWiki: Tested on
Download: Code (this article)

Contents

[edit] What can this extension do?

This project is still under development.

[edit] Usage

[edit] Installation

[edit] Parameters

[edit] Changes to LocalSettings.php

require_once("$IP/extensions/NAME/NAME.php");

[edit] Code

<?php
/**
 * NAME.php
 * This Extension does .......
 * written by Eric Hartwell  http://www.ehartwell.com/about
 * To activate the functionality of this extension include the following in your
 * LocalSettings.php file:
 * require_once('$IP/extensions/NAME/NAME.php');
 */
if(! defined( 'MEDIAWIKI' ) ) {
   echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
   die( -1 );
} else {
 
// Replace validextensionclass with: specialpage, parserhook, variable (multiple functionality), other
$wgExtensionCredits['validextensionclass'][] = array(
     'name' => 'NAME',
     'author' =>'Eric Hartwell', 
     'url' => 'http://www.ehartwell.com',
     'description' => 'This Extension is an example and performs no discernable function',
    );
 
# Define a setup function
$wgExtensionFunctions[] = 'wfNAME_Setup';
# Add a hook to initialise the magic word
$wgHooks['LanguageGetMagic'][]       = 'wfNAME_Magic';
 
function wfNAME_Setup() {
        global $wgParser;
        # Set a function hook associating the "name" magic word with our function
        $wgParser->setFunctionHook( 'name', 'wfNAME_Render' );
}
 
function wfNAME_Magic( &$magicWords, $langCode ) {
        # Add the magic word
        # The first array element is case sensitive, in this case it is not case sensitive
        # All remaining elements are synonyms for our parser function
        $magicWords['name'] = array( 0, 'name');
        # unless we return true, other parser functions extensions won't get loaded.
        return true;
}
 
function wfNAME_Render( &$parser, $param1 = '', $param2 = '' ) {
        # The parser function itself
        # The input parameters are wikitext with templates expanded
        # The output should be wikitext too
        return "param1 is $param1 and param2 is $param2";
}
 
?>


[edit] See also