Extensions FAQ

How do I enable an extension?
Copy the extension PHP file to your extensions folder and add a require_once( "extensions/FILENAME" ); statement to your LocalSettings.php, with FILENAME being the filename of your extension, such as Extension.php.

How do I write my own extension?
See Extending wiki markup.

How do I disable caching for pages using my extension?
The extension purgePage can also be used to perform the steps listed below, it works for MediaWiki 1.3 - 1.5. For MediaWiki 1.3, include the following code in your extension:

For MediaWiki 1.4, use this (won't necessarily work in all cases):

Note: The above doesn't work in all cases. Using the same logic but with different code the following lines work much better. $ts = mktime; $now = gmdate("YmdHis", $ts + 120); $ns = $wgTitle->getNamespace; $ti = wfStrencode($wgTitle->getDBkey); $sql = "UPDATE cur SET cur_touched='$now' WHERE cur_namespace=$ns AND cur_title='$ti'"; wfQuery($sql, DB_WRITE, ""); For MediaWiki 1.4 the following also works (possibly better than the above method):

In MediaWiki 1.5beta5, a more reliable interface was introduced. Your parser hook function may take a parser object as a third parameter, by reference. Use the following code: Note: on MediaWiki version 1.5.8 any of the above didn't work. You can see the following code functioning properly here. I had to use the following code in the second function of the extension (not the "setHook" function):

WARNING: In version 1.6 and many early versions of 1.7, it is impossible for extensions to prevent pages from being cached when edits are submitted. This is not expected behavior, see 5683. There are a number of ways to work around this issue:
 * Install the DisableCache hack. This is the most elegant solution, but has not been thoroughly tested.
 * Run action=purge after submitting edits. This is the safest choice, but may not be feasible in large wikis.
 * Disable caching site-wide. This will sharply increase the amount of work that your server will have to perform.  To disable all caching, put the following code in LocalSettings.php:

Recent versions
In MediaWiki 1.7.0 and upwards, the following should be sufficient:



where  is the reference to the parent parser that is passed as a third parameter to parser hook extensions.

Special pages
When rendering output that will not be subject to parser cache, such as on a special page

where $text is the wikitext to be parsed.

Parser hooks
Parser hook functions are passed a reference to the parser object and should use this to parse wikitext.

Parser::recursiveTagParse has been around since version 1.8. Its advantages include simplicity (it takes just one argument and returns a string) and the fact that it parses extension tags in $text, so you can nest extension tags. An approach that does not have these advantages would be:

The fourth and fifth parameters to Parser::parse are $lineStart and $clearState</tt>; these dictate how the parser behaves. $lineStart</tt>, when true, indicates that the wikitext is to be treated as starting on a new line (use this when dealing with blocks, or handling lists, etc.). $clearState</tt>, when true, indicates that the parser should clear internal state information; in most cases, this should be false.

Note that Parser::parse</tt> returns a ParserOutput object, not raw HTML, as in the example above.

In cases where this does not work (often due to order of operations, nesting or other hook confusion), use a cloned copy of the parser object:

How can I avoid modification of my extension's HTML output?
This will probably require moving some code around in the parser. The current extension code assumes extensions will produce inline material and they are inserted before the final block-level rendering stages.

How can I pass XML-style parameters in my extension tag?
This is supported from MediaWiki 1.5. Accept a second parameter on your hook function, which will be an associative array of attribute => value pairs.

The value strings have already had HTML character entities decoded for you, so if you emit them back to HTML don't forget to use
 * In version 1.4x you can use a div element with a class name of your extension to be invisible and contain the attributes. The extension code can then match them from the article content. This example will extract and loop through all the attributes from a specified div class:


 * Addition/alternative to the 1.4x approach

As the above script didn't worked out a 100%, I developed something on me own, based on the above solution. I put the div inside of the tags of my extension, so a different set of arguments can be passed to the extension on every use in one article. The var $input is the text between the extension tags, passed to the extension function.

Example:

name="Andreas" Other stuff, for the extension to process

Code:

I've installed an extension, but I get NaodW... output
MediaWiki 1.5(.1) has problems with some PHP versions which causes that output. You should upgrade to MediaWiki 1.5.2 or later.

Templates with extension tags
There is also similar problem when using template parameters inside extension tags (in template definition). It does occur only when an extension perform parsing of input string (between extension tags). When template is present, and such a template or extension tag appears somewhere else on the page, strange NaodW... strings are generated in result (seems as error of wiki parser).

''Note: In earlier versions of MediaWiki "NaodW..." is observed, and in later ones similar "UNIQ..." string appears.''

Additionally, if symbol of parameter is used inside extension tags (e.g.

What permissions do I apply to the extensions folder?
All the scripts in the /wiki structure need to be readable and executable by the user that PHP runs as. All perms are usually 755 and owner/group being that user. The LocalSettings.php file is created by the script on setup and so will be an example to set the rest by.

How do I get my extension to show up on Special:Version?
In order for your extension to be displayed on the Special:Version page in MediaWiki, you must assign extension credits within your PHP code.

To do this, add a $wgExtensionCredits variable as the first executable line of code before your hook line or function definition

An example extension credit is:

Replace 'validextensionclass' with one of the following:
 * 'specialpage' -- reserved for additions to Mediawiki Special Pages;
 * 'parserhook' -- used if your extension modifies, complements, or replaces the parser functions in MediaWiki;
 * 'variable' -- extension that add multiple functionality to MediaWiki;
 * 'other' -- all other extensions.