For a couple of years now I’ve been maintaining an invite-only-access family history wiki site using the MediaWiki engine (the system built for Wikipedia). It was the last thing left on my creaking old RedHat 7 box, until recently when I finally sat down and figured out how to move it to my VMWare Server based Debian virtual server farm.
This being my second time at setting up MediaWiki, I decided to try to do it a bit better this time. Setting up on RedHat was a long drawn out process of getting the various dependencies set up and configured properly. Thanks to apt-get, setting MediaWiki up on Debian is much easier.
Here, I’m going to walk through setting the latest stable version of MediaWiki up on Debian Etch, and also show you how easy it is to borrow templates and styles from Wikipedia to use in your own MediaWiki deployment.
So here we’re aiming to set up a very minimal Debian Etch deployment, with the packages required to run MediaWiki added in. In my case my MediaWiki box is actually a virtual host running under VMWare server. I created a new VM and ran a preseeded deployment using my preseed_base.cfg file as described in my previous post on proper virtual machine setup on Debian.
Once the deployment was done, I commented out the CD line from /etc/apt/sources.list. I do my installs into the VM with the ISO mounted as a CD ROM drive. Once the install is done, I unmount the ISO and then do additional installs from the network. You can leave the CD in there if you like though.
After doing an apt-get update and an apt-get upgrade, I installed other packages needed for a basic MediaWiki installation. What I’ll probably do later is create a customized version of preseed_base.cfg which includes these packages.
apt-get install mysql-server php5 php5-mysql apache2 \ libapache2-mod-php5 imagemagick subversion
By the way, subversion is in there so we can install the MediaWiki ParserFunctions extension later. If you’d prefer not to have subversion on your server, you can apt-get remove it after the extension is installed. Alternatively you can leave it out and install the extension another way (see below).
Now we have a few config bits to fix up. As described in this post
Set an admin password for your mysql database:
sudo mysqladmin -u root password 'default admin password'
Open up the PHP config (in vi, naturally)
sudo vi /etc/php5/apache2/php.ini
Set the memory limit to 20 meg:
memory_limit = 20M
Make sure the following lines are uncommented:
And bounce Apache to pick up those PHP config changes:
sudo /etc/init.d/apache2 restart
Note that we’re not installing MediaWiki through apt-get. Thats because the package for Etch is version 1.7 which is pretty old and doesn’t work with many of the templates that we’re going to import from Wikipedia later.
The up and coming Debian release (called lenny) has a package for version 1.12 (the current stable version of MediaWiki) so if you wanted to do this entirely through apt-get you could probably temporarily hack your sources.list and get the package from the lenny release set. MediaWiki itself is all PHP code, so there’s no compilation involved. That means it’s dead easy to install even without apt-get as follows:
cd /var/www sudo wget http://download.wikimedia.org/mediawiki /1.12/mediawiki-1.12.0.tar.gz sudo tar vxfz mediawiki-1.12.0.tar.gz sudo mv mediawiki-1.12.0 wiki cd /var/www/wiki sudo chmod a+w config
By the way those commands are adapted from this post. Also as described in that post we now hit http://hostname/wiki/ and go through the wiki config page. When that’s done then do this:
sudo mv config/LocalSettings.php . sudo rm -Rf config
I also reset the ownership on all the files in the wiki as follows:
sudo chown -R root:root * sudo chown -R www-data:www-data images sudo chown www-data:www-data LocalSettings.php
It’s entirely possible that those chown’s are doing something bad, so check before you blindly follow me.
Finally to turn on file uploads open LocalSettings.php up in vi (or another editor I guess would be ok) and look for the line
$wgEnableUploads = false;
Change that to true. Also check that the following lines are present and not commented out:
$wgUseImageMagick = true; $wgImageMagickConvertCommand = "/usr/bin/convert";
If they are commented out it means that the MediaWiki config page could not find the ImageMagick binaries used for creating thumbnails. If that happens check your install of ImageMagick (it was part of our main apt-get install before), and once you have it installed properly make sure those two lines are set properly in LocalSettings.php.
Now at this point we have a working basic MediaWiki install. We can create pages, edit content, upload images and so on. The next thing we want to do is install the ParserFunctions extension.
The ParserFunctions extension contains a bunch of basic conditional and expression functions which are used by the more interesting templates in Wikipedia. Actually you may not need to install these functions depending on what templates you want to pull across, but you might as well as it’s quick and easy.
How to do this is well described in this post. I’m reproducing it here to save you clicking through, and also because I’ve changed the version references to 1.12. If you want to install the extension without using subversion, check out that article.
cd /var/www/wiki/extensions sudo svn co http://svn.wikimedia.org/svnroot /mediawiki/branches/REL1_12/extensions /ParserFunctions/
Note: you’ll have to take my line breaks out of that URL for it to work
Then edit LocalSettings.php (in the root of your wiki) and add the following line:
I usually put that straight after the existing require_once() for DefaultSettings.php
You can check that the extension is properly installed by going to your wiki’s Special:Version page. For example: http://localhost/wiki/index.php/Special:Version. Under the Installed Extensions heading you should see an entry for ParserFunctions.
Pulling Templates From Wikipedia
MediaWiki supports a pretty insane domain-specific language for doing templating. Templates can be used to replicate structures or pieces of content across many pages in a MediaWiki deployment. It’s very easy to get started building your own templates as they are just created as pages in the wiki in the special Template: namespace. Wikipedia has many rich templates that include functionality that would take a lot of work to re-create, so as long as we’re respecting the stipulations of the GPL, you can use those templates in your own wiki.
As I’m doing a family history wiki, I was interested in finding out if Wikipedia had any templates that would help to standardize genealogical data: names, birth dates, places of birth, parents, children etc. The best one I found is the Infobox Person template. In Wikipedia speak, infoboxes are the boxes you see floating at the right-hand side of many articles that contain some information conforming to some agreed defacto standard of information for some domain.
So the Infobox Person template looks ok. In my Family History wiki, I have a page for each person, and on the person pages, I’ll use the Infobox Person template to hold a standard set of details about the person. It’s not a perfect fit for genealogical record keeping, but it’s a start and I’ll probably adapt it as time goes on.
To pull that template into our MediaWiki deployment, we could just create our own page called Template:Infobox Person and copy and paste the source from the Wikipedia template into our own. The problem is that template embeds other templates, so to move the Infobox Person template across by hand, we’d have to walk the dependency tree and copy all the dependencies across by hand too.
Of course there’s an easier way to do this. We can export whatever we want from Wikipedia and import it into our own MediaWiki installation. Go to the export page in Wikipedia:
And there enter the name of the page or pages you want to export. In my case I put Template:Infobox_Person. Then, check the Include templates checkbox. This will make the export automatically walk the dependency tree of templates and also export the required templates. Click export and you’ll be prompted to save a XML file containing the exported content.
Now flip back to your own MediaWiki install. Login with your Wiki Sysop account, and go to the Special:Import page of your wiki. You can just type that into the address bar, or look near the bottom of the Special page, which is linked from the left navbar.
Browse for the export file you got from Wikipedia, and click upload. MediaWiki will load the content in and list out what it has loaded as confirmation.
Now you should be able to view the imported content. In my case, I confirmed that it had loaded the Infobox Person template by pointing my browser at http://fhwiki/wiki/index/php/Template:Infobox_Person
Once you start pulling templates in from Wikipedia, you’ll probably also want to pull the main stylesheets across as well. Infobox templates for example won’t render as floating boxes unless you get the styles from Wikipedia.
To bring the stylesheets across from Wikipedia, you use the same export / import functions we used to pull the templates across. There are two pages to bring across:
Your default MediaWiki installation does have these stylesheets, but they don’t define any styles.
So with that, you should now be able to easily run up a MediaWiki deployment, and pre-populate it with some useful templates so that you can launch right into creating a professional Wiki.
สุขสันต์วันแม่! Happy (Thai) Mothers day.