Mediawiki site building tips

From

Jump to: navigation, search

Contents

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:

sudo wget http://upload.wikimedia.org/ext-dist/ConfirmEdit-MW1.16-r62678.tar.gz
sudo tar -xzf ConfirmEdit-MW1.16-r62678.tar.gz -C /var/lib/mediawiki/extensions
sudo rm ConfirmEdit-MW1.16-r62678.tar.gz
  • Add the following line near the end of LocalSettings.php:
require_once( "$IP/extensions/ConfirmEdit/ConfirmEdit.php" );
  • 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.

  • Download and install:
cd /var/lib/mediawiki/extensions
sudo wget -O currentrecaptcha.zip http://recaptcha.googlecode.com/files/recaptcha-mediawiki-1.7.zip
sudo unzip currentrecaptcha.zip
sudo rm currentrecaptcha.zip
  • Edit the Mediawiki LocalSettings.php file (assuming you put it in /etc/mediwiki). (Use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu.):
sudo kate /etc/mediawiki/LocalSettings.php
and add the following lines:
#For ReCaptcha
require_once( "$IP/extensions/recaptcha/ReCaptcha.php" );
# Sign up for these at http://recaptcha.net/api/getkey
$recaptcha_public_key = ' xyxyxyxyxyxyxyxyx ';
$recaptcha_private_key = ' ababababababababa ';
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:

// Fix the default captcha behaviour
$wgGroupPermissions['*'            ]['skipcaptcha'] = false;
$wgGroupPermissions['user'         ]['skipcaptcha'] = true;
$wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;
$wgGroupPermissions['bot'          ]['skipcaptcha'] = true; // registered bots
$wgGroupPermissions['sysop'        ]['skipcaptcha'] = true;
#
$wgCaptchaTriggers['edit']          = true;
$wgCaptchaTriggers['create']        = true;
$wgCaptchaTriggers['createaccount'] = true;

Spam blacklist

SpamBlacklist is an extension that prevents edits that include one of the URLs in a spam list. The default blacklist is the one used by Wikimedia. Install:

sudo mkdir /var/lib/mediawiki/extensions/SpamBlacklist
cd /var/lib/mediawiki/extensions/SpamBlacklist
sudo wget http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SpamBlacklist/SpamBlacklist.php
sudo wget http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SpamBlacklist/SpamBlacklist_body.php
sudo wget http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SpamBlacklist/SpamBlacklist.i18n.php
sudo wget http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SpamBlacklist/cleanup.php
sudo wget http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SpamBlacklist/README
  • Add to the end of your LocalSettings.php file:
#
# This is the SpamBlacklist from Wikimedia:
require_once( "$IP/extensions/SpamBlacklist/SpamBlacklist.php" );
#
$wgSpamBlacklistFiles = array("http://meta.wikimedia.org/wiki/Spam_blacklist");
#
  • 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:
$wgSpamBlacklistFiles = array("$IP/extensions/SpamBlacklist/wikimedia_blacklist");
  • Add specific websites (or rules) to the pages:
  • MediaWiki:Spam-blacklist
and
  • MediaWiki:Spam-whitelist

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:

sudo mkdir /var/lib/mediawiki/extensions/CheckSpambots
cd /var/lib/mediawiki/extensions/CheckSpambots
  • 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):
sudo kate /var/lib/mediawiki/extensions/CheckSpambots/CheckSpambots.php

Also download and save into the /var/lib/mediawiki/extensions/CheckSpambots folder the files (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu):

sudo kate /var/lib/mediawiki/extensions/CheckSpambots/check_spammers_plain.php
sudo kate /var/lib/mediawiki/extensions/CheckSpambots/en.php
sudo kate /var/lib/mediawiki/extensions/CheckSpambots/functions.php
sudo kate /var/lib/mediawiki/extensions/CheckSpambots/config.php

Edit the config.php to choose which databases to check, where to log results, and other variables.

  • Add to the end of your LocalSettings.php file these lines:
#
# CheckSpambots 
#
require_once("extensions/CheckSpambots/CheckSpambots.php");
#
$wgEnableSorbs = false;
#

Note: The $wgEnableSorbs variable is not required with/after MediaWiki 1.16.

Bad Behavior

Bad Behavior is an extension (created for Wordpress blogs) which blocks e-mail harvesters, spambots, and other malicious intent. See the configuration settings. Install:

cd /var/lib/mediawiki/extensions
sudo wget http://downloads.wordpress.org/plugin/bad-behavior.2.0.41.zip
sudo unzip bad-behavior.2.0.41.zip
sudo rm bad-behavior.2.0.41.zip
  • Towards the end of your LocalSettings.php file add the lines:
#
# the Bad Behavior extension
#
include_once( "$IP/includes/DatabaseFunctions.php" );
include( "$IP/extensions/bad-behavior/bad-behavior-mediawiki.php" );
#
  • Bad-behavior logs to a database, which doesn't work for me. Turn this off by editing the bad-behavior-mediawiki.php file (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu):
sudo kate /var/lib/mediawiki/extensions/bad-behavior/bad-behavior-mediawiki.php

and change the line:

'logging' => true,
to
'logging' => false,

AkismetKlik

AkismetKlik uses the Akismet engine (created for Wordpress blogs) to filter comment spammers.

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.

SideBar Donate

This SideBarDonateBox extension adds a PayPal donate button to the Sidebar. (Sign up with PayPal donate and generate the code for a Donate button first.) Install:

sudo mkdir /var/lib/mediawiki/extensions/SidebarDonateBox
cd /var/lib/mediawiki/extensions/SidebarDonateBox
sudo wget http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SidebarDonateBox/SidebarDonateBox.php
  • Add to the LocalSettings.php file code similar to this:
# This is for the Sidebar PayPal button
#
require_once("$IP/extensions/SidebarDonateBox/SidebarDonateBox.php");
#
#$egSidebarDonateBoxContent = 'PayPal code';
#
$egSidebarDonateBoxContent = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="12345678">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>';
#
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.)
 <?php
 if(!strstr($_SERVER['REQUEST_URI'], "Special:") &&
 !strstr($_SERVER['REQUEST_URI'], "User:") &&
 !strstr($_SERVER['REQUEST_URI'], "User_talk:") &&
 !strstr($_SERVER['REQUEST_URI'], "Image:") &&
 !strstr($_SERVER['REQUEST_URI'], "action=submit") &&
 !strstr($_SERVER['REQUEST_URI'], "action=edit") &&
 !strstr($_SERVER['REQUEST_URI'], "Template:")) {
 include("adsense/adsense_horizontal.php");
 }
 ?>   

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.

  • Download and install :
sudo wget http://upload.wikimedia.org/ext-dist/GoogleAdSense-MW1.16-r61946.tar.gz
sudo tar -xzf GoogleAdSense-MW1.16-r61946.tar.gz -C /var/lib/mediawiki/extensions
  • Using the settings found in the generated code, edit your LocalSettings.php file, adding the lines:
#
# This section is for Google AdSense
#
require_once( "$IP/extensions/GoogleAdSense/GoogleAdSense.php" );
$wgGoogleAdSenseClient = 'replace this with the client name';
$wgGoogleAdSenseSlot = 'replace this with the slot name';
$wgGoogleAdSenseID = 'replace this with your ID';
// Width of the AdSense box, specified in your AdSense account
$wgGoogleAdSenseWidth  = 120;
// Height of the AdSense box, specified in your AdSense account
$wgGoogleAdSenseHeight = 240;
// Source URL of the AdSense script
$wgGoogleAdSenseSrc    = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
// Show the AdSense box only for anonymous users
$wgGoogleAdSenseAnonOnly = false;
#
  • While logged into your MediaWiki site as an administrator, edit the page Mediawiki:Common.css and add the lines:
/* Pad Google AdSense box in portlet in sidebar */
#p-googleadsense .pBody {
 padding-top: 5px;
 text-align:  center;
}
  • 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).

  • Download and extract:
sudo wget -O GoogleAdSense.zip http://www.paulgu.com/files/getfile/getfile.php?id=10
sudo unzip GoogleAdSense.zip
sudo rm GoogleAdSense.zip
  • This will give you a folder named GoogleAdSense. However, this is the same folder name as the folder for Google AdSense2, so rename the folder while moving it to the extensions folder:
sudo mv GoogleAdSense /var/lib/mediawiki/extensions/GoogleAdSense30
  • Generate a content ad unit in the Google AdSense account. Long horizontal ads can be created as 728 x 90. Copy the generated code into a file and save it for reference.
  • Edit the GoogleAdSense.php file (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu):
sudo kate /var/lib/mediawiki/extensions/GoogleAdSense30/GoogleAdSense.php
  • Find the line:
$PUBLISHER_ID = "pub-xxxxxxxxxxxxxxxx";

and replace pub-xxxxxxxxxxxxxxxx with the publisher ID (aka google_ad_client) that was generated during your ad unit code generation.

  • Find the line:
'C01' => array('unitID' => 'xxx', 'width' => '728', 'height' => '90', 'position' => 'none'),

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.

  • Edit your LocalSettings.php file and add the lines:
#
# Google Adsense. Edit /var/lib/mediawiki/extensions/GoogleAdSense30/GoogleAdSense.php.
# Use tags such as <google uid="C01" position="none"></google>
#
include_once( "$IP/extensions/GoogleAdSense30/GoogleAdSense.php" );
#
  • Then you can place your ad on any page by placing a tag such as
<google uid="C01" position="none"></google>

ShareThis

The ShareThis extension provides links to popular social bookmarking and news sources. It works without modification for the Monobook skin.

  • Install:
sudo mkdir /var/lib/mediawiki/extensions/ShareThis
cd /var/lib/mediawiki/extensions/ShareThis
sudo kate /var/lib/mediawiki/extensions/ShareThis/ShareThis.php
This is a PHP script, so make sure the first line is:
<?php
  • Install the associated icons:
cd /usr/share/mediawiki/skins/common/images
sudo wget http://jimbojw.com/download/sharethis-icons.zip
sudo unzip sharethis-icons.zip
sudo rm sharethis-icons.zip
  • Edit your LocalSettings.php file and add the lines:
#
# Add ShareThis to the sidebar
require_once( "$IP/extensions/ShareThis/ShareThis.php" );
$wgShowShareThisSidebar = true;
#

Batch Upload Local files

The UploadLocal extension provides a method to upload multiple files (that are placed in its "data" upload directory) into the wiki.

  • Install:
sudo mkdir /var/lib/mediawiki/extensions/UploadLocal
cd /var/lib/mediawiki/extensions/UploadLocal
sudo wget https://git.wikimedia.org/zip/?r=mediawiki/extensions/UploadLocal&h=refs/heads/master&format=gz
sudo tar -xzf UploadLocal-refs_heads_master.tar.gz
sudo rm UploadLocal-refs_heads_master.tar.gz
  • Add the following line near the end of LocalSettings.php:
require_once( "$IP/extensions/UploadLocal/UploadLocal.php" );
  • Copy the files you wish to batch upload into the /var/lib/mediawiki/extensions/UploadLocal/data directory.
  • Change the ownership of the files in the directory to www-data to be safe.
sudo cd /var/lib/mediawiki/extensions/UploadLocal/data
sudo chown www-data:root *
  • 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):
# For the Bashfr quotations module
#
require_once("$IP/extensions/bashfr/bashfr.php");
#
  • 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.
My reality comes from http://ubuntuguide.org
%
When I wonder "What the hell I am doing?" I go to Kubuntuguide at http://ubuntuguide.org/wiki/Kubuntuguide
%
MediaWiki is the premier wiki. Visit their website: http://www.mediawiki.org/wiki/MediaWiki
  • 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).
# This clears the cache daily, which I use to change rotating content (pictures, fortunes, etc.) daily.
#
require("includes/GlobalFunctions.php");
$wgCacheEpoch = wfTimestamp( TS_MW, time() - 86400 ); # 60*60*24 = 1 day

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");
#
  • An example use of this tag would resemble:
 <random>
 <format>Visit our sponsor: [%ITEM%]</format>
 <item>http://ubuntuguide.org UbuntuGuide</item>
 <item>http://ubuntuguide.org/wiki/KubuntuGuide Kubuntuguide</item>
 <item>http://www.mediawiki.org MediaWiki</item>
 </random>

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:

Visit our sponsor: UbuntuGuide
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):
<center>
<random>
<format>Visit our sponsor:<br>[[%ITEM%]]</format>
<item>File:Tech_tux.png|48px|center|link=http://ubuntuguide.org UbuntuGuide|Visit our sponsor: UbuntuGuide</item>
<item>File:ExampleAdPic2.png|55px|center|link=http://ubuntuguide.org/wiki/Kubuntuguide|Visit our sponsor: KubuntuGuide</item>
<item>File:ExampleAdPic3.jpg|center|link=http://exampleexternaldomain.info|caption</item>
</random>
</center>

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:
Visit our sponsor: UbuntuGuide
  • 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:
 <random>
 <format>{{%ITEM%}}</format>
 <item>AdTemplate1</item>
 <item>AdTemplate2</item>
 <item>AdTemplate3</item>
 </random>

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:

 [[File:Tech_tux.png|48px|center|link=http://ubuntuguide.org|Visit our sponsor: UbuntuGuide]]
 <center>Visit our sponsor: [http://ubuntuguide.org UbuntuGuide]</center>

then the Random extension would yield {{AdTemplate1}} which (in versions prior to MediaWiki 1.17) would appear on a wiki page:

Visit our sponsor: UbuntuGuide
Visit our sponsor: UbuntuGuide
  • 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).
# This clears the cache daily, which I use to change rotating content (pictures, fortunes, etc.) daily.
#
require("includes/GlobalFunctions.php");
$wgCacheEpoch = wfTimestamp( TS_MW, time() - 86400 ); # 60*60*24 = 1 day

Customise the Sidebar

Normally, minor changes to the default Sidebar can be made by editing the wiki page " MediaWiki:Sidebar ". However, greater customisation can be achieved using extensions.

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).
sudo kate /var/lib/mediawiki/extensions/CustomNavBlocks/CustomNavBlocks.php
  • Alternatively, download and install the code directly into the extension folder (recommended):
sudo mkdir /var/lib/mediawiki/extensions/CustomNavBlocks
cd /var/lib/mediawiki/extensions/CustomNavBlocks
sudo wget http://git.fsinf.at/mediawiki/customnavblocks/blobs/raw/master/CustomNavBlocks.php
  • Edit the LocalSettings.php file for your wiki and add these lines (toward the end of the file):
# Installs the CustomNavBlocks extension, used to customise the MediaWiki Sidebar
#
require_once( "$IP/extensions/CustomNavBlocks/CustomNavBlocks.php" );
$wgCustomNavBlocksEnable = true;
#
  • Create a wiki page named MediaWiki:CustomNavBlocks. This stores the names of the individual wiki pages, each of which will comprise a custom Sidebar block. Edit the content to resemble:
CustomBlockUbuntu|Ubuntu
CustomBlockKubuntu|Kubuntu
SEARCH
CustomBlockRecLinks|Recommended Links
CustomBlockSidebarAd|Sponsor
CustomBlock5|Title of Block 5
DONATE

Note that several special reserved words such as SEARCH and DONATE (if using the Sidebar Donate extension) can be used by themselves.

  • Create the individual wiki pages MediaWiki:CustomBlockUbuntu, MediaWiki:CustomBlockKubuntu, MediaWiki:CustomBlockRecLinks, MediaWiki:CustomBlockSidebarAd, MediaWiki:CustomBlock5, etc.

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:

body {
font: x-small sans-serif;
background: #f9f9f9 url(headbg.jpg) 0 0 no-repeat;
color: black;
margin: 0;
padding: 0;
}
or the content background colour set:
#content {
background: white;
color: black;
border: 1px solid #aaa;
border-right: none;
line-height: 1.5em;
}

Add icons

A wide variety of GPL (and some LGPL) icons are available at Wikimedia Commons. There is also a large number of icons available in the OpenClipArt Library.

  • 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:

[[File:Prefapp1.png|center|link=http://ubuntuguide.org|16 px|Preferred app 1]]

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:
$wgFileExtensions = array('pdf', 'png', 'gif', 'jpg', 'flv', 'swf', 'mp3');
  • Media files can be used as a link for any text using this type of tag:
[[Media:MyMediaFile.mp3|any text you wish]]

As an example, this text has an audio file linked to it:

You Haven't ?

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.

  • Create a folder for the extension:
sudo mkdir /var/lib/mediawiki/extensions/screenplay
  • Download and extract the extension:
wget -O ScreenPlay.zip http://siege.org/pub/mwspe/ScreenPlay-0.5.php.zip
sudo unzip ScreenPlay.zip
sudo rm ScreenPlay.zip
  • Move the script into the extensions folder:
sudo mv ScreenPlay*.php /var/lib/mediawiki/extensions/screenplay/ScreenPlay.php
  • 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):

sudo wget http://upload.wikimedia.org/ext-dist/Cite-MW1.15-48711.tar.gz
sudo tar -xzf Cite-MW1.15-48711.tar.gz -C /var/lib/mediawiki/extensions
sudo rm Cite-MW1.15-48711.tar.gz
  • Add the following line near the end of LocalSettings.php:
#
# This Cite extension is for citations/references/footnotes
#
require_once( "$IP/extensions/Cite/Cite.php" );
#$wgCiteEnablePopups = true;
  • 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:
# Set $wgRawHtml = true; to allow raw HTML code on wiki pages between <html> </html> tags
# Otherwise, leave this line commented out (or set to false)
#
$wgRawHtml = true;
#

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:

<html>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="12345678">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</html>

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):
<addhtml>
<html>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="12345678">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</html>
</addhtml>

Import (K)Ubuntuguide into your site

  • How do I import a copy of (K)Ubuntuguide into my own wiki?
See this page for Ubuntuguide or this page for Kubuntuguide.

Troubleshooting

Mediawiki 1.15 on Firefox and Google tablet browsers

MediaWiki 1.15 does not display correctly in Google and Firefox browsers on tablets and mobile devices. To correct this, use the solution found here:

  • Edit /skins/common/wikibits.js with your text editor.
  • Comment (using // at the beginning of the relevant lines):
var is_khtml = navigator.vendor == 'KDE' || 	
( document.childNodes && !document.all && !navigator.taintEnabled );
and
} else if (is_khtml) { 	 
importStylesheetURI(stylepath+'/'+skin+'/KHTMLFixes.css');

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:
# for all external links, turn off nofollow tag
$wgNoFollowLinks=false;
#
  • 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.
Personal tools
Sponsor