YK: Chapter 2: Setting up MediaWiki

From Blik
Jump to: navigation, search


The MediaWiki environment
[edit]

MediaWiki is a program written in PHP , a very popular language for web applications. It can run on any operating system that PHP can run on, which is all the major ones. Similarly, it can run on any major web server. MediaWiki requires a database, which can be almost any of the major database systems: MySQL, PostgreSQL, SQLServer, Oracle and SQLite (Sybase is one major database system that is not supported). In practice, though, there are sometimes issues with running MediaWiki with database systems other than MySQL, since they get significantly less usage and attention. (Core MediaWiki, at least, seems to work fine with PostgreSQL as well.)

LAMP[edit]

By far the most popular setup for MediaWiki is what’s known as the “LAMP stack”: Linux, Apache, MySQL and PHP. Only the last of these is required, but the other three are strongly encouraged.

You can see the following page to see what versions of PHP, and of the different database systems, each version of MediaWiki is compatible with: https://www.mediawiki.org/wiki/Compatibility


Download
[edit]


There are essentially two ways to download MediaWiki:

  • as a “tarball”, or a single archive file,
  • and via Git, a version-control system.

Using Git is the recommended method, because it’s easier to install, and it lets you upgrade your code much more easily later on. But if you don’t have Git, you can get the code from here: https://www.mediawiki.org/wiki/Download_from_Git#Download

When MediaWiki is downloaded as a tarball, it comes pre-bundled with some number of extensions, contained in the /extensions directory: The exact set depends on the version of MediaWiki: from versions 1.18 to 1.20, the bundled extensions were ConfirmEdit, Gadgets, Nuke, ParserFunctions, Renameuser, Vector and WikiEditor. Since version 1.21, the set of extensions additionally includes Cite, ImageMap, Interwiki, Title Blacklist, SpamBlacklist, Poem, InputBox, LocalisationUpdate and SyntaxHighlight GeSHi; while the Vector extension has been removed, because its functionality is now part of core MediaWiki.

Most of these extensions will be discussed in some detail later in the book.

If you have Git installed (and it’s at least version 1.7), you can download MediaWiki with the following call:

git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git 

This will create a directory named “core”, which you can (and should) then rename.


Installing
[edit]


Once you’ve downloaded the main MediaWiki code, go to the URL for that code in a browser. At that point, assuming you have PHP, a database system and a web server running, the MediaWiki code should get executed correctly, and it will then look for a file called LocalSettings.php, the initialization file for MediaWiki, holding all the user-modifiable settings for the wiki; we’ll get to many of them over the course of this book.

By default, if it’s not there, its absence tells MediaWiki that this is a new installation. MediaWiki will then guide you on the browser through a series of steps where you have to specify the wiki’s name, the name of the database to be created, and other settings, including the username and password for the wiki’s first user (by default, the username is “WikiSysop”). This user is important even if you plan to create a different one for yourself later, because it has administrator privileges, so if you want to give yourself administrator privileges (and you will), you’ll have to do it via that user.

Once you’ve completed all the steps, a LocalSettings.php file will be created automatically, and a new database should be created as well on your database system.

[edit]


Most, though not all, of MediaWiki’s skins include a spot for a logo, at the top left-hand corner of the screen (or top right-hand, if the wiki is in a right-to-left language).

In MediaWiki, the logo is the customary way to individualize one’s wiki ­ for better or worse, most skins don’t display the name of the wiki anywhere on the page (other than indirectly at the bottom, in the “About ___” link). So the logo should show the name of the wiki, and ideally some representative graphic though that part is strictly optional; it’s much better to have a logo that just states the wiki name than no logo at all.

MediaWiki wikis do have a default logo, which is a grayed-out MediaWiki sunflower logo with the words “Set $wgLogo to the URL path to your own logo image” over it. As the instructions say, all you need to do is set a new value for $wgLogo in your LocalSettings.php file. The logo image can be located either within the MediaWiki directory, or at some arbitrary URL. By default, it’s located at /skins/common/images/wiki.png :

  • ­ you shouldn’t replace that file with your logo image, because then you run the risk of it being overwritten when you update the MediaWiki code.


Changing the URL structure
[edit]

By default, MediaWiki URLs appear in a format like:

mywiki.com/mediawiki/index.php?title=Main_Page 

However, the preferred format is something more like:

mywiki.com/wiki/Main_Page 

This is the format that Wikipedia and other Wikimedia sites use. The “wiki” directory can have any name, though “wiki” makes sense for obvious reasons.

There are various approaches to changing the URL format, based primarily on whether you have root access on the server on which the wiki resides. You can see all the steps required for the various approaches here: https://www.mediawiki.org/wiki/Manual:Short_URL

We’ll just note that there are some cases when users want to have a URL structure that looks simply like:

mywiki.com/Main_Page 

It’s certainly a clean-looking URL, but this is not recommended, because, among other reasons, it means that your server can’t have helper files like robots.txt and favicon.ico. You can see a longer discussion of this approach here: https://www.mediawiki.org/wiki/Manual:Wiki_in_site_root_directory

Finally, you can also change the name of the start page, which by default is (in English) “Main Page”, by changing the contents of the page “MediaWiki:mainpage”. This is an example of interface text editable via the wiki, of which there are hundreds of examples ­ see here for a complete description.


Updating MediaWiki
[edit]


As new versions of MediaWiki come out, you’re generally advised to keep updating to the latest version ­ there are always bug fixes, interface improvements, and interesting new features. It’s generally pretty easy to update, though it depends on whether you’re using Git or not.

If you are using Git, you can just

  • run a “git pull” in the directory housing your MediaWiki code.
  • Then, you’ll need to call the script “update.php”, located in MediaWiki’s /maintenance directory ­ it goes through the database and adds or modifies database tables to fit the new DB schema for this version. update.php tends to work very well. It even works when upgrading from extremely old versions.

If you’re downloading the new MediaWiki version as a package, instead of via Git, then you’ll need to move the /images directory, the /extensions directory (or at least parts of it), and LocalSettings.php into this new directory, and rename both it and the old MediaWiki directory so that the wiki URL will now point to this one. As before, you’ll need to call update.php.

And if you’re using any extensions besides the ones that come pre-bundled with MediaWiki, then you might have to get the latest versions of those as well. Extensions that don’t work with a certain MediaWiki version tend to break pretty easily when you try them out, so it should be fairly straightforward to see if any extensions need updating.