WikiToLearn

From mediawiki.org
(Redirected from Extension Tutorial)

WikiToLearn uses mediawiki, which is a massive framework for making wikis written in PHP. It is designed to be very flexible, allowing many different kinds of extensions.

MediaWiki supports two different types of flexibility: skins and extensions. Here we will discuss the steps you need to go through to make extensions.

How MediaWiki works[edit]

MediaWiki is driven by a text format called wikitext--it contains all the content, formatting, images, and everything else for a page. This is stored in a database, along with other metadata like title.

Most extensions extend MediaWiki by utilizing what are called hooks, which define a place to register a callback to an event. (Think signal/slots). A full list of basic hooks lives here.

Different languages[edit]

There are many ways to separate content for different languages in a wiki, but WikiToLearn just has an entirely different wiki for each language (except for meta and pool)

The LocalSettings.php file[edit]

The LocalSettings.php defines the extensions that should be loaded for a wiki, and the settings for each extension. You can look at WikiToLearn's here. Every wiki must have this file.

Loading an extension[edit]

There are two different "types" of extensions: ones that use the new extension format and those who don't. We will explain the difference in the files later.

Loading an extension with the old format[edit]

The old format for extensions just uses a simple `require_once` for loading the extension:

require_once( "$IP/extensions/{extension name}/{extension name}.php" );

For example:

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

Loading an extension with the new format[edit]

Loading an extension with the new format is much easier:

wfLoadExtension("{extension name}");

For example:

wfLoadExtension("SyntaxHighlight_GeSHi");

Checking if an extension is loaded[edit]

Many extensions aren't obvious when they are enabled, so it is often helpful to check if you extension is loaded. To do this, go to {your wiki URL}/Special:Version so in the case of a local instance, it would be en.tuttorotto.biz/Special:Version. This page has a list of the extensions, the authors, copyright information, etc for each extension.

The extension file structure[edit]

Extensions need only a few files to work:

This is only for the new extension format.

WikiToLearn

extensions
{extension_name}
extension.json
{other php files}
i18n
{language code}.json
...
COPYING (optional)

The {extension_name} directory[edit]

This is in the extensions directory of the root WikiToLearn folder. At WikiToLearn, we put all of our extensions in different repositories, and then link then into the extensions using a git submodule. Extension are almost always not necessarily specific for WikiToLearn, so there is no reason not to be modular when it is so easy.

If you move the repository and update that in the .gitmodules file, then make sure to run git submodule sync after to make sure that git updates the submodule correctly

The extension.json file[edit]

This file defines all of the data that MediaWiki needs to load the extension. This includes the authors, copyright, hooks, classes to load, and many more things.

Making a extension.json file[edit]

The first thing you are going to want to do when you make an extension is to make the extension.json file, without it you cannot load your extension!

The following section defines some of the things that you will want to put in your extension.json file. For more information see this page.

Start with the opening { that every JSON file must start with:

{

Now let's add the extension name:

"name": "{extension name}",

Now a list of authors:

"author": [
    "{author 1}",
    "{author 2}",
    ...
],

Then the licence file. In order to get a working link to your license in the Special:Version page, you need to have the COPYING file. In the extension.json file you will only define the name of the license, it will be linked to the COPYING automatically.

"license-name": "{license name}",

Next, you can provide an (optional) url to a homepage for your extension. This will often be mediawiki.org/wiki/Extension:{extension name}.

"url": "{extension website}",