MediaWiki
From blog.UsToBe.com
| You are here: Home > Technology > MediaWiki
MediaWiki is a free software wiki package originally written for Wikipedia. It is now used by several other projects of the non-profit Wikimedia Foundation and by many other wikis, including the MediaWiki website itself.
Our experience with MediaWiki
We have setup, configured, used and customized MediaWiki many times. Also this site - blog.UsToBe.com - is powered by MediaWiki. We created a new skin and did some extension and customization work to support our IT Contractors applications, as well as some security and privacy configurations.
This site was originally running on:
Click here for actual version information.
Frequently Asked Questions
How to change the default skin and disable other skins
For this site we created a new skin called "wiki" and we configured it as default skin by editing LocalSettings.php:
## Default skin: you can change the default skin. Use the internal symbolic ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook': $wgDefaultSkin = 'wiki';
To disable registered users from selecting another skin as preferred skin, we added the following configuration to LocalSettings.php.
# To remove various skins from the User Preferences choices
$wgSkipSkins = array("chick", "classic", "cologneblue", "monobook",
"myskin", "nostalgia", "simple", "standard");
How to restrict access to the User List
By default the special page listusers (SpecialPage:listusers) allows everyone to view the list of users. In some cases it is preferred to restrict access to this page to certain groups.
A simple customization of MediaWiki does the trick.
- Step #1 - Make the listusers page a restricted special page
Edit the following file: includes/SpecialPage.php
Find the following line:
'Listusers' => array( 'SpecialPage', 'Listusers' ),
Replace this code by the following:
'Listusers' => array( 'SpecialPage', 'Listusers', 'listusers' ),
By doing this MediaWiki will no longer consider this special page as a regular special page. It will be considered as a restricted special page.
- Step #2 - Assign rights to the groups you want
Change LocalSettings.php to assign the rights you want.
The following e.g. allows member of the sysop group to view the listusers page.
# Allow sysops to view the user list $wgGroupPermissions['sysop']['listusers'] = true;
How to create an extension
MediaWiki Extensions are compilations of PHP code that add new features or enhance functionality of the main MediaWiki core. Extensions are one of the main advantages of MediaWiki. They give wiki administrators and wiki end-users the ability to adapt MediaWiki to their requirements.
A simple extension consists of 3 files, this example is taken from the Contractors application on this website.
- Contractors.php - the setup script for the extension
- Contractors.i18n.php - the execution code for the extension
- Contractors_body.php - the internationalization information for the extension.
The following sample code just adds an English translation for the new message 'applications'.
Contractors.php
<?php
$dir = dirname(__FILE__) . '/';
$wgExtensionMessagesFiles['Contractors'] = $dir . 'Contractors.i18n.php';
$wgExtensionFunctions[] = 'wfSetupContractors';
$wgAutoloadClasses['Contractors'] = $dir . 'Contractors_body.php';
$wgExtensionCredits['parserhook']['Contractors'] = array(
'name' => 'Contractors',
'version' => preg_replace('/^.* (\d\d\d\d-\d\d-\d\d) .*$/', '\1', '$LastChangedDate$'),
'author' => "Rudy D'hauwe",
'url' => 'http://blog.ustobe.com/index.php/Contractors',
'description' => 'Implements the Contractors application.',
'descriptionmsg' => 'contractors_desc',
);
function wfSetupContractors() {
global $wgMessageCache;
require( dirname( __FILE__ ) . '/Contractors.i18n.php' );
foreach ( $messages as $lang => $langMessages ) {
$wgMessageCache->addMessages( $langMessages, $lang );
}
}
Contractors.i18n.php
The translations can be edited by means of the Special:Allmessages page.
<?php
$messages = array();
$messages['en'] = array(
'applications' => 'applications',
);
Contractors_body.php
<?php
/**
* Contractors extension.
*
*/
class Contractors {
# here comes the body
}
How to register a custom made extension
Home made extensions e.g. the Contractors extension can be registered by adding the following to LocalSettings.php.
require_once( "$IP/extensions/Contractors/Contractors.php" );
How to parse and output WikiText from within an extension class
This page describes the primary source files (classes) / objects of the MediaWiki code.
global $wgOut;
$html = $wgOut->parse("This is some ''lovely'' [[MediaWiki]] text.");
echo($html);
How to tell the MediaWiki to display things as you typed them
The nowiki tag ignores [[Wiki]] ''markup''. It reformats text by removing newlines and multiple spaces. It still interprets special characters: →
What we typed to get the previous line:
<nowiki>
The nowiki tag ignores [[Wiki]] ''markup''.
It reformats text by removing
newlines and multiple spaces.
It still interprets special characters: →
</nowiki>
More information here.
How to clearly show the SQL query in the event of a database error
Clearly showing the SQL will aid in debugging in the event of a database error, however...
- Showing SQL to all users, will give crackers some clues about the database structure of your website, and might help them find security weaknesses.
- SQL Database errors are not supposed to occur during any normal MediaWiki operation, and so with luck you will never need to improve the error information
If you do see an error including "(SQL query hidden)", it can be useful to set this to $wgShowSQLErrors=true; temporarily. More information here.
$wgShowSQLErrors=true;


