Mediawiki site building tips

Introduction

MediaWiki is one of the most widely used wiki servers in the world. It is the software used by Wikipedia. It is free and open source and can be customised to many different uses by installing additional modules. This page is a cookbook of how I set up a MediaWiki site and may be helpful for getting an initial site customized. I am assuming you have one (or multiple) MediaWiki installations running using these instructions.

If you are interested in the list of Mediawiki extensions used by Wikipedia then see this list.

Choose the Main Page

Edit the page " Mediawiki:Mainpage " from within your wiki and as content enter the name of the page you wish to designate as your main page. For more info, see this section of the Mediawiki FAQ.

Add Spam filters

See this article for several effective methods for stopping MediaWiki spam.

Captcha

ConfirmEdit

The ConfirmEdit extension is a way to combat automated (spam) edits using a simple text, pictorial, math, or question-based Captcha mechanism. Install:

There are several modules available for ConfirmEdit that allow different types of Captchas. For example, QuestyCaptcha allows custom questions/answers to be presented as the challenge.

ReCaptcha

ReCaptcha is a webservice Captcha module to present a text challenge for user-input that is unreadable by computer bots, lessening the chance of automated input (spam and vandalism). This can be used for wikis and for other uses. A ReCaptcha extension for MediaWiki is available.

where xyxyxyxyxyxyxyxyx is the public key obtained in the previous step and ababababababababa is the private key.

Now ReCaptcha should appear automatically for new user sign-ups, anonymous edits that contain new external links, and brute-force password cracking attempts. Captcha behavior can be modified by adding lines to LocalSettings.php:

Alternatively, you could download the Wikimedia blacklist from http://meta.wikimedia.org/wiki/Spam_blacklist into a file named wikimedia_blacklist that is stored in the /var/lib/mediawiki/extensions/SpamBlacklist folder. Then in LocalSettings.php use the variable:

Note: I advise putting an administrator lock on MediaWiki:Spam-whitelist.

Check Spambots

Check Spambots is an automated script that may be configured to query the one of several spambot or open-proxy-IP-address databases prior to allowing a user to perform a function. (APIs are required for several of these databases.) Install:

Copy the CheckSpambots.php script from this location and save it as /var/lib/mediawiki/extensions/CheckSpambots/CheckSpambots.php (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu):

AkismetKlik

ConfirmAccount

The Confirm Account extension disables direct account creation and requires the approval of new accounts by a bureaucrat. (As spam becomes increasingly prevalent, this maneuver often becomes necessary).

Nuke multiple pages

The Nuke extension allows the removal of multiple additions by a single user or IP address. It is included in all version of Mediawiki after 1.18.

Replace the value 12345678 with the value for the PayPal Donate button generated for your account.

There are other alternative Donation / Fundraising interfaces which are more comprehensive (and complex). See this section.

Google AdSense

Few websites make money from placing ads, anymore, simply because there are so many websites. (Over the course of several years I have made only a few dollars.) Still, Google AdSense is one of the few ways to easily place ads on your site. (Google is selective about its partners these days, so make sure your website is mature and fully functional before signing up with Google AdSense.)

Sign up for Google AdSense and wait for a confirmation e-mail (usually takes 2 days).

Create an ad unit as instructed in the confirmation e-mail.

Google AdSense -> AdSense Setup -> AdSense for Content

-> Ad unit - Choose if you just want images, text or both -> Continue

-> Format: 124 x 240 Vertical Banner

-> Colors: Graphite (or your preference)

-> Other desired settings -> Submit and get code

Save the generated code to a text file.

Use either the Google Adsense2 or Google Adsense Mediawiki extension (below) for maximum flexibility.

A direct method of using the code in the Monobook skin (of Mediawiki) can be accomplished using this advice (which is the method this wiki uses):

Create an adsense subfolder in your Mediawiki directory.

Create a file (e.g. adsense_horizontal.php and/or adsense_vertical.php) in the adsense folder that contains the code generated when signing up for Google Adsense.

Place an "include" within the /skins/Monobook.php file that refers to the /adsense/adsense_horizontal.php file. The position of these "include" lines in Monobook.php will determine the position of the ad on the page. (Note that in these lines are exclusions for pages that are "administrative" pages, on which the Google Adsense rules do not allow ads to be placed.)

Google AdSense2

The MediaWiki Google AdSense 2 extension places an AdSense box in the MediaWiki sidebar. This has the advantage of being visible on every page. You must create a 124 x 240 Vertical Banner ad unit to use with it.

Google AdSense will now appear in the sidebar. Obviously, users who block scripts (using NoScript, for example) or block ads (using Adblock Plus, for example) will not be able to view the ads. To test whether the ads display correctly, make sure your own script and ad blockers (if any) are turned off, as well.

Google AdSense

The original Google AdSense Mediawiki extension uses tags to place ads. Both this extension and the AdSense2 extension (for the sidebar) can be used simultaneously (as long as they are stored in differently-named extensions folders).

and replace xxx with the google_ad_slot number (such as 1234567890) that corresponds to the ad unit you wish to use. Note the C01. This will be the uid that corresponds to this ad unit. The width and height should correspond to those of the ad unit being used.

Then login to the wiki as a privileged user and find the Upload local files option:

MyWiki -> Special pages -> Upload local files

Facilitate printing to an eBook

Collections

The Collection extension facilitates grouping pages for export to PDF or other format. (See Wikieducator for an example). This is the system Wikipedia uses to create eBooks. It can be used with MediaWiki 1.14 or later. For more information see this article.

PdfBook

Some wiki users like to print out part or all of the wiki into an ebook (PDF format). This can be facilitated with the PdfBook extension. For more information see this article.

Add Quotations

Bashfr is an extension that uses a text file in the Fortune format and displays one random quote from that file.

Create a folder named bashfr in the extensions folder of your site. In a multi-site wiki, this will be at /etc/mediawiki/sites/subsite_x/extensions. Otherwise the default location is at /var/lib/mediawiki/extensions.

sudo mkdir /var/lib/mediawiki/extensions/bashfr

Create a text file named bashfr.php in this directory into which you will copy the PHP code found here (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu).

sudo kate /var/lib/mediawiki/extensions/bashfr/bashfr.php

Edit the LocalSettings.php file for your wiki and add these lines (towards the end of the file):

Copy (or create) a text file in the Fortune format with a list of the quotations in it. It should look like:

I reject your reality and substitute my own...
%
This is one of those "What the hell am I doing?" moments, over!
%
We got a robot in the water, he's stuffed with tuna and it's just another day here at Mythbusters.

It is possible to include a URL as the text in a quotation. (Most browsers will then automatically change the text into an actual link.) In this way, a list of random URL links can also be displayed through the Fortune display.

Copy this file to the /var/lib/mediawiki/extensions/bashfr folder (or to your subsite's particular extensions folder) and rename it to bashfr_fortunes .

Wherever you want to place a random quotation from this file, place this tag on your MediaWiki page:

<bashfr />

Add or edit quotations merely by editing the bashfr_fortunes text file. Be sure to maintain the format of a Fortune file (i.e. with a % symbol between each quotation).

Add these lines to the LocalSettings.php file so that a new quote appears every day (or more frequently by using a number smaller than 86400, which is the interval in seconds in which to clear the cache).

Add Random elements as advertisements

Random is an extension that allows one (or more) of a selection of items (or wiki elements) in a list to be presented randomly. This extension allows wiki tags (and elements) so that a combination of images, text, and URL links can be presented together (which together would constitute a typical ad). This is useful for displaying advertisements specific to (and stored within) the wiki.

Create a folder named Random in the extensions folder of your site. In a multi-site wiki, this will be at /etc/mediawiki/sites/subsite_x/extensions. Otherwise the default location is at /var/lib/mediawiki/extensions.

sudo mkdir /var/lib/mediawiki/extensions/Random

Create a text file named Random.php in this directory into which you will copy the PHP code found here (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu).

sudo kate /var/lib/mediawiki/extensions/Random/Random.php

Edit the LocalSettings.php file for your wiki and add these lines (towards the end of the file):

# For the Random extension, used to randomly select an item from a list
#
require_once("$IP/extensions/Random/Random.php");
#

In this example, one of the three items in the list would be randomly selected to replace %ITEM%, yielding an external wiki link in this format: [http://ubuntuguide.org UbuntuGuide], which would appear on a wiki page:

Tip: If it is desirable for an item to appear more often in the rotation, then include the item in the list more than once.

To create ads with images (that can be the size, shape, and format of an ad banner, for example), use this type of tag (note that the caption portion of the tag is only functional in MediaWiki 1.17 or later):

yielding an external wiki link in this format: [[File:Tech_tux.png|48px|center|link=http://ubuntuguide.org|Visit our sponsor: UbuntuGuide]] which would appear (in versions prior to MediaWiki 1.17) on the wiki page:

Visit our sponsor:

The most robust method of creating ads would be to create a series of templates (each with an ad contained within the template). The Random extension would then be used to rotate the ad templates:

where AdTemplate1 would represent the wiki page at Template:AdTemplate1, AdTemplate2 would represent the wiki page at Template:AdTemplate2, and AdTemplate3 would represent the wiki page at Template:AdTemplate3. (In general it is best that an administator protect the Template:AdTemplateX pages.) If Template:AdTemplate1 were to contain code such as:

If desired, the tag code (with the list to be randomly rotated) can be placed in a template (e.g. Template:MyWikiSponsors ) and then just the corresponding template tag (e.g. {{MyWikiSponsors}} ) could be placed within a wiki page. (It is then highly recommended that a wiki administrator protect the template so it cannot be changed by casual wiki users.)

The {{MyWikiSponsors}} tag could then also be placed in a custom block in the Sidebar to enable a rotation of random "ad" presentations in the sidebar.

Add these lines to the LocalSettings.php file so that a new ad appears every day (or more frequently by using a number smaller than 86400, which is the interval in seconds in which to clear the cache).

Customise the Sidebar

CustomNavBlocks is an extension that allows regular MediaWiki wiki pages to be used in the Sidebar. This allows extensive customisation of the sidebar, including the addition of any kind of element such as images, numbered lists, and nested lists.

Create a folder named CustomNavBlocks in the extensions folder of your site. In a multi-site wiki, this will be at /etc/mediawiki/sites/subsite_x/extensions. Otherwise the default location is at /var/lib/mediawiki/extensions.

sudo mkdir /var/lib/mediawiki/extensions/CustomNavBlocks

Create a text file named CustomNavBlocks.php in this directory into which you will copy the PHP code found here (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu).

Edit each page to reflect the content you wish to appear in each block. It is possible to use regular wiki tags in these pages. Adjust the content and formatting of each page so that it appears in the Sidebar as desired.

Randomised content (including images) using the Random extension (as described above) can also be placed in a MediaWiki:CustomBlock page as a type of Sidebar Ad (with random ad rotation).

Each wiki page (used for the sidebar) should be protected by an administrator to prevent a casual wiki user from changing it. (Note: All wiki pages with the Mediawiki: prefix are automatically protected already, and can only be edited by administrators anyway (and therefore do not require additional protection.))

Change skins

Skins in MediaWiki are stored in /usr/share/mediawiki/skins and are particular to the version of MediaWiki in use. In MediaWiki 1.16, the 'vector' skin (the new default for Wikimedia and for MediaWiki 1.17 or later) can be chosen by editing the LocalSettings.php file and changing:

$wgDefaultSkin = 'monobook';

to

$wgDefaultSkin = 'vector';

Change background colours

The background colours are set in the CSS code for the skin being used. For example, if the Monobook skin is being used, the variables are found in /skins/monobook/main.css. There are background colours for many different areas of the wiki; each must be changed separately. Background colours are specified using certain words (such as white, grey, red, blue, green, yellow) or using hex-codes, examples of which are shown here. For example, the main body background colour is set to #f9f9f9 in /skins/monobook/main.css:

Add icons

Icons on a page are best displayed at a size of 48 px. Small icons in a regular line of text are often displayed at 16 px. Icon files that have been saved as an image File in the wiki can then be displayed (see the MediaWiki Help:Images section for more info) using a tag in the generic format:

[[File:filename.extension|options|altlabel|caption]]

where the |options|, |altlabel|, and |caption| sections are optional. (Note: the |caption| option only works in MediaWiki 1.17 and later, and then only displays if an |altlabel| is also designated.)
For example:

where the |link=http://ubuntuguide.org| is an optional link for the icon, and can be the name of another internal wiki page (but without [[ ]] tags) or an external link (when preceded by http://). An "alt" label (which is displayed when the mouse is rolled over the icon) is included in this example but no caption. The |center| option is also optional, as is the display size |16px|.

Embed media into a document

If media files (such as .mp3 audio files) are to be uploaded directly into the wiki, make sure the upload of the media filetype is allowed by editing the $wgFileExtensions variable in LocalSettings.php so that it includes it. For example, to allow .mp3 files:

Embed a PDF document

If PDF files are to be uploaded directly into the wiki, make sure the upload of PDF files are allowed by editing the $wgFileExtensions variable in LocalSettings.php so that it includes pdf. For example:

$wgFileExtensions = array('pdf', 'png', 'gif', 'jpg', 'flv', 'swf');

Use an external PDF viewer

This method is the easiest and most universal.

A PDF document is uploaded as a file into MediaWiki. A link placed in a wiki page of this format:

[[Media:uploadedpdffile.pdf|Description of this PDF File]]

will access the uploaded file for display in an external PDF viewer (such as Okular, Evince, or Acrobat Reader).

Use Browser plugins

A PDF file can be displayed on a wiki page (using tags), but each user must have their browser configured to handle PDF files (with an appropriate plugin or a setting that directs the browser to an external viewer). An advantage of this method is that a PDF file can be viewed on the wiki page at the same time as additional text on the wiki page (that is not part of the PDF file). Not all browsers have a PDF-viewing plugin (such as this one for Firefox) available, however, so the desired result may not be displayed in every browser.

To display the PDF files within wiki pages, install the EmbedPDF plugin:

Create a folder for the extension:

sudo mkdir /var/lib/mediawiki/extensions/embedpdf

Copy the EmbedPDF.php script from this location and save it as /var/lib/mediawiki/extensions/embedpdf/EmbedPDF.php (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu):

sudo kate /var/lib/mediawiki/extensions/embedpdf/EmbedPDF.php

Edit the LocalSettings.php file for your wiki and add these lines (towards the end of the file):

#
# This section is for EmbedPDF tags
require_once("$IP/extensions/embedpdf/EmbedPDF.php");
#

Display an uploaded PDF file by using the tags on a wiki page similar to:

<pdf>http://some.site.com/with/a/document.pdf</pdf>

or

<pdf>Your_uploaded_document.pdf</pdf>

Use templates

This took me a long time to appreciate. I have now converted my wiki(s) so that all content is stored in templates, not on the actual wiki pages themselves. When content is stored in templates in this manner, the display of any wiki page can be changed merely by re-arranging the order of the templates (which contain the actual content) within it.

A template is designated by tags similar to {{MycontentTemplate1}} and {{MycontentTemplate2}} and content is then entered directly into the wiki pages that correspond to them: Template:MycontentTemplate1 and Template:MycontentTemplate2.

A wiki page that displays one way can then be created using

{{MycontentTemplate1}}
{{MycontentTemplate2}}

or can be re-arranged to display differently merely by changing the order of the template tags:

{{MycontentTemplate2}}
{{MycontentTemplate1}}

While this method of wiki creation takes extra steps to implement, in the long run it provides the greatest flexibility. If you intend to create a complex wiki, a plan that includes the liberal usage of templates (from the outset) will save a lot of time later on.

Add WebDAV storage

WebDAV is a method for online storage and versioning of documents with access control. It is sometimes useful to use WebDAV in conjunction with MediaWiki in order to store documents with different levels of security. WebDAV server functions are provided by the WebDAV module of the Apache2 server (on which MediaWiki also runs). See these WebDAV instructions,

Write a screenplay

Ok, this is a pretty esoteric use. I happen to use MediaWiki to write books and screenplays. The ScreenPlay extension allows me to format the text in the format required for screenplays.

Edit the LocalSettings.php file for your wiki and add these lines (towards the end of the file):

#
# This section is for ScreenPlay tags
require_once("$IP/extensions/screenplay/ScreenPlay.php");
#

An example of the usage of this extension is at this Congo Kitabu screenplay site.

Add citations / footnotes

Cite is the Mediawiki extension used by Wikipedia to create citations and footnotes (references) using the <ref> and </ref> tags. Install (choose the version appropriate for your version of Mediawiki):

If you are using a newer version of the Cite extension and wish to enable citation popups, uncomment the $wgCiteEnablePopups option.

At the bottom of the wiki page should be placed the <references /> tag (i.e. wherever the <references /> tag is placed is where the footnotes will be displayed).

Each reference should be placed between the <ref> and </ref> tags within the text of the wiki page, for example: <ref>text of footnote for reference 1</ref>. A reference that is to be used more than once can be named, for example: <ref name="refname2">text of footnote for reference 2</ref> and each subsequent usage of that reference can merely be tagged: <ref name="refname2" />. For more complex uses, see the Cite extension instructions.

Donation / Fundraising Interfaces

The DonationInterface extension provides mechanisms for collecting and tracking payments through various payment gateways. It is the extension used by the Wikimedia foundation.

The InputBox extension can serve as a frontend for the PayPal Donate code (or other donation mechanism code -- in fact, for any HTML code, for that matter).

The Sidebar Donate method for adding a PayPal Donate button is one of the easiest methods.

It is possible to add HTML code (such as the code generated for a PayPal Donate button) directly on a wiki page. However, this also allows HTML code to be added to every page throughout the wiki and therefore entails a certain amount of risk (as malicious HTML code could then be added to any wiki page that is not protected). To enable direct HTML code on all wiki pages, add to the LocalSettings.php file:

Then add to the desired wiki page the code for the PayPal Donate button between <html> </html> tags. (Obviously, replace the value 12345678 with the value for the PayPal Donate button generated for your account.) For example:

It is very important to protect the wiki page with the code on it, so that a casual wiki user won't be able to edit the page and substitute the hosted_button_id value of someone else's PayPal button!

A somewhat safer method is to leave $wgRawHtml = false; and to install the addHTML extension according to the instructions listed. This extension only allows HTML code to be executed from protected pages (and not from unprotected pages). To such a protected page, add the code (for example):

Adding extra white spaces

MediaWiki is set up to remove extraneous white space. However, sometimes it is desirable to insert extra spaces (for formatting or other purposes). For each extra desired (non-breaking) space, insert &nbsp;. To insert three spaces, for example, insert &nbsp;&nbsp;&nbsp;.

Allow search engines to "follow" links

By default, MediaWiki sites add a "nofollow" tag to links contained within the wiki. This is done to limit the usefulness of a wiki in promoting spam links, and to protect internal links from being listed on search engines (such as Google) when a wiki is meant only for the internal use of a private organization. In general it is best to leave the default settings in place.

However, for a fully cross-referenced, publicly available wiki, it may be desirable to make the links within a wiki able to be "followed" by a search engine's indexing spider. To enable this, in the MediaWiki LocalSettings.php add the following lines:

It is possible to allow only certain links (or domain names) to be "followed," retaining the "nofollow" tag for all other links. For this type of fine-grained control, see the summary and the MediaWiki manual.