Introduction to MediaWiki Extensions

Explore our blog for insightful guides, tips, and updates on the latest MediaWiki extensions. Discover how to enhance your wiki experience with tools that improve functionality, collaboration, and content management.

...
Daniel Scherzer
Share:
Introduction to Wiki Extensions

MediaWiki Content Types

The most common type of page on a wiki uses “wikitext”, which supports headings, links, images, templates, and all the other features that make up a normal page. This is the default content model. Other types of content supported by MediaWiki core include JavaScript and CSS (for scripts and styles), JSON (for storing data), and “plain text”, which is just displayed as plain text. 

Sometimes, a new feature requires a new type of content storage. For example, the Scribunto extension is used to allow embedding scripts in Lua. These scripts can then be run on pages directly, or via reusable templates. To store the scripts, Scribunto adds the aptly-named Scribunto content model. 

Scribunto example

Scribunto example

If the above snippet was saved with the title “Module:Test”, then writing {{#invoke:Test|demo}} would result in the text Hello, world! being shown.

Another popular extension that adds a content type is TemplateStyles. Template Styles was designed to allow adding custom CSS styles to the output of individual templates, without needing to use the site-wide style sheets that get loaded on every page. To support custom validation of the styles, as well as restrictions such as rejecting background images from unknown sources, it uses a new sanitized-css content model.

MediaWiki Actions

Every request to a wiki includes a specific action to perform, even if the action is implicit. For example, the “view” action is assumed by default. Other actions that MediaWiki core provides allow for viewing page history, editing, and deleting a page or protecting it to restrict editing.

A key characteristic of an action type is the focus on a single page. For features dealing with multiple pages, see special pages below. 

Actions can be used to both add new functionality and improve the defaults. For example, the PageForms extension, which is described in our prior blog post on the best extensions, adds a new way to edit pages. Another extension, AuthorProtect, allows page creators to protect their pages via the authorprotect action:


AuthorProtect Example

AuthorProtect Example


MediaWiki Special Pages

Unlike actions, special pages are primarily useful for features that deal with either multiple pages (like searching for pages with specific properties) or no page (like interacting with a user). MediaWiki core provides multiple pages for monitoring new changes. Special pages that do not deal with a page on the wiki include managing user rights or blocking accounts, version information for the code running on the wiki, and account creation/login.

A common anti-vandalism extension, Nuke, adds a special page to allow the deletion of multiple pages created by a single user. This comes bundled with MediaWiki.


Mass deletion of MediaWiki pages using Nuke

Mass deletion of MediaWiki pages using Nuke


Parser Tags and Functions

Sometimes, a new action, special page, or content type is simply overkill or not the right approach. Consider the case of adding new features to wikitext pages – instead of reimplementing the content type, MediaWiki’s parser allows extensions to register new tags (like from the Cite extension) or parser functions (such as the logical expressions in the ParserFunctions extension).

A fun new tag from the ImageMap extension, which comes bundled with MediaWiki core, is . This tag allows for custom hover text and link targets in different parts of the same image.

Look at a copy of XKCD comic #285, depicting the character Cueball talking to a crowd, one of whom is holding a “citation needed” sign.

A copy of XKCD comic #285, linked to the general explanation of the comic

Links to the general explanation of the comic

Using the ImageMap extension and the wikitext snippet shown below, the overall image links to a general explanation of the comic, the drawing of Cueball links to an explanation of the character, and the “citation needed” sign links to the template on the English Wikipedia being referenced.

A copy of XKCD comic #285, linked to the explanation of the character

Links to the explanation of the character

A copy of XKCD comic #285, linked to the template

Links to the template

Wikitext used (assuming the file is named “XKCD 285.png”)

Wikitext used (assuming the file is named “XKCD 285.png”)

The file being displayed is used under the Creative Commons Attribution 2.5 Generic license and was retrieved from https://commons.wikimedia.org/wiki/File:Webcomic_xkcd_-_Wikipedian_protester.png. 

Conclusion

In short, adding new page actions, types of content, or wikitext features is common and fairly simple. The MediaWiki software is specifically designed to be extensible, and in addition to the extensions that come with the core software, mediawiki.org lists over 1500 extensions at the moment. And, if the extension you are looking for isn’t available, WikiTeq can also create extensions for you!

Latest Stories

Here’s what we've been up to recently.


Stay informed!

Get our latest blogs and news delivered straight to your inbox.