Manual:Developing extensions

▪ Extensions ▪ Tag Extensions ▪ Parser Function ▪ Hooks ▪ Special Pages ▪ Skins ▪ Magic Words

Each extension consists of three parts:

1. setup,

2. execution, and

3. internationalization.

A minimal extension will consist of three files, one for each part:


Stores the setup instructions.


Stores the execution code for the extension. For complex extensions, requiring multiple PHP files, the implementation code may instead be placed in a subdirectory, MyExtension/includes. For an example, see the Semantic MediaWiki extension.


stores internationalization information for the extension.

Note:''''' Originally, extensions were single files, and you may still find some examples of this deprecated style. When writing an extension, you should replace MyExtension above with the name of your extension. Files should be named in UpperCamelCase', which is the general file naming convention.[1]


1 Setup

1.1 Registering features with MediaWiki

1.2 Making your extension user configurable

1.3 Preparing classes for autoloading

1.4 Deferring setup

1.5 Defining additional hooks

1.6 Adding database tables

1.7 Set up internationalization

2 Execution

3 Internationalization

4 Extension types

5 Support other core versions

6 Publishing

7 See also

8 references


Your goal in writing the setup portion is to consolidate set up so that users installing your extension need do nothing more than include the setup file in their LocalSettings.php file, like this:

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

If you want to make your extension user configurable, you need to define and document some configuration parameters and your users setup should look something like this:

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

$wgMyExtensionConfigThis = 1;

$wgMyExtensionConfigThat = false;

To reach this simplicity, your setup file will need to accomplish a number of tasks (described in detail in the following sections):

· register any media handler, parser function, special page, custom XML tag, and variable used by your extension.

· define and/or validate any configuration variables you have defined for your extension.

· prepare the classes used by your extension for autoloading

· determine what parts of your setup should be done immediately and what needs to be deferred until the MediaWiki core has been initialized and configured

· define any additional hooks needed by your extension

· create or check any new database tables required by your extension.

· setup internationalization and localization for your extension

Registering features with MediaWiki

MediaWiki lists all the extensions that have been installed on its Special:Version page. For example, you can see all the extensions installed on this wiki at Special:Version. It is good form to make sure that your extension is also listed on this page. To do this, you will need to add an entry to $wgExtensionCredits for each media handler, parser function, special page, custom XML tag, and variable used by your extension. The entry will look something like this:

$wgExtensionCredits['validextensionclass'][] = array(

'path' => __FILE__,

'name' => 'Example',

'author' =>'John Doe',

'url' => '',

'description' '=>' 'This extension is an example and performs no discernible function',

'version' => 1.5,


See Manual:$wgExtensionCredits for full details on what these fields do. Many of the fields are optional, but it's still good practise to fill them out.

In addition to the above registration, you must also "hook" your feature into MediaWiki. The above only sets up the Special:Version page. The way you do this depends on the type of your extension. For details, please see the documentation for each type of extension:


Making your extension user configurable

If you want your user to be able to configure your extension, you'll need to provide one or more configuration variables. It is a good idea to give those variables a unique name. They should also follow MediaWiki naming conventions (e.g. global variables should begin with $wg).

For example, if your extension is named "Very silly extension that does nothing", you might want to name all your configuration variables to begin $wgVsetdn or $wgVSETDN. It doesn't really matter what you choose so long as none of the MediaWiki core begins its variables this way and you have done a reasonable job of checking to see that none of the published extensions begin their variables this way. Users won't take kindly to having to choose between your extension and some other extensions because you chose overlapping variable names.

It is also a good idea to include extensive documentation of any configuration variables in your installation notes.

Warning: To avoid register_globals vulnerabilities, ALWAYS explicitly set all your extension's configuration variables in extension setup file. Constructs like if ( !isset( $wgMyLeetOption ) ) $wgMyLeetOption = somevalue; do not safeguard against register_globals!

Here is a rather complex example from the CategoryTree extension, showing the full range of possibilities here:


* Constants for use with the mode,

* defining what should be shown in the tree


define( 'CT_MODE_CATEGORIES', 0 );

define( 'CT_MODE_PAGES', 10 );

define( 'CT_MODE_ALL', 20 );

define( 'CT_MODE_PARENTS', 100 );


* Options:


* $wgCategoryTreeMaxChildren

* - maximum number of children shown in a tree

* node. Default is 200

* $wgCategoryTreeAllowTag

* - enable

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on FANDOM

Random Wiki