Published on MacDevCenter (
 See this if you're having trouble printing code examples

Web Apps with Tiger: MediaWiki

by Kevin Hemenway

It's not prom night. It's not graduation. It's not time to pop the question. No raise, no bonus, no Ed McMahon, no free song from iTunes. Instead, we're going to install our first web application. Now, I know, I know: installing software versus a lifetime of acceptances from your partner is a teensy bit of a skewed comparison. And if I had something to tie the two together, to suggest that they're equivalent coming-of-ages where you evolve from beastdom or innocence into civilized society, I'd probably have stated it by now. But I don't, so I won't. Let's just start this crazy thing, eh? (If you're behind, catch up with Web Apps with Tiger: Getting Started and Web Apps with Tiger: Security and MySQL.)

Choosing the Right Software

In our previous articles, there hasn't been much of a chance to make choices: to decide if we really want PHP, or if MySQL was the best outcome we could've reached regarding databases. PHP and MySQL are such entrenched expectations that you simply can't go wrong with them (calm the flames, you muckrakers!). Now that those are outta the way, we're entering a familiar world where you or the person you're asking are right, and all others are wrong, and laughably so.

What's your favorite text editor on OS X? What about image manipulation? Is AppleScript worth learning? The Dock is great! No, it's not! I love the Dashboard! You're an idiot! Et cetera, et cetera, et cetera. The same software decisions you've made regarding your local OS X applications apply equally to web software.

With web applications, however, there's a big difference: instead of just one person, you, fiddling with a text or image editor, every one of your web site's visitors is going to be messing with, innocently or maliciously, the software you make available on your server. That's quite a different dynamic than what you're probably used to.

Mentally, I have a fluctuating set of things I look for when I'm choosing a web app. They're not hard and fast rules, merely "be awares" that help me decide if a particular software is even worth investigating. Making the right choice up front is abnormally important with web applications: if you make the wrong one, you're going to be looking at possible site downtime, custom scripts to import old data into a replacement system, and the constant harassment of users who preferred whatever you had installed before. My list of concerns include (currently... once this article has been posted, I'll be all, "ArgGHh! I forget Aloofness!"):

Related Reading

Apache Cookbook
By Ken Coar, Rich Bowen

These are all questions that run through my head when I'm researching a particular web program. Naturally, they've all been asked for the pieces of software we'll be exploring within this series. Be aware, however, that there are very few projects that satisfy every little quibble; the final decision often devolves into a listing of pros and cons and how much a particular negative outweighs a specific positive.

Installing MediaWiki

The first piece of software we're going to install is from a breed called a wiki. Wikis are a relatively ("relatively") new type of software that some folks absolutely hate, some absolutely love, and some think'll be good enough in a few years. According to Wikipedia, the quite popular community created encyclopedia:

A wiki is a web application that allows users to add content . . . but also allows anyone to edit the content. The term Wiki also refers to the collaborative software used to create such a website . . .
Not only is a gargantuan wiki itself (the most well-known today, certainly), it also runs the software we'll be installing. Thus, MediaWiki satisfies our dependence and reputation concerns immediately. The development community can be found on IRC, mailing lists, or their own specific wiki--there's really no easily accessible "end user" friendly place. The readability of the code doesn't make me smile, but that's a subjective opinion anyway, and expandability is possible via extensions. For resources, I've not personally been able to create disastrous loads or heavy memory usage, but your mileage, traffic, and server skills will vary.

At the time of this writing, 1.4.9 is the latest version of the MediaWiki software. 1.5 is currently in release candidate testing, but you should only consider installing that if you're self-sufficient enough to not really need this series of articles. The following assumes an installation of 1.4.9. It also, for the sake of readability, instructs you to install MediaWiki into a subdirectory called wiki. In real life, however, you'd want to name this something that describes purpose, not implementation (see Cool URIs Don't Change). Download MediaWiki to your Desktop, and then run the following commands to create /Library/WebServer/Documents/wiki:

morbus@:~ > cd /Library/WebServer/Documents
morbus@:~ > tar xvzf ~/Desktop/mediawiki-1.4.9.tar.gz
morbus@:~ > mv mediawiki-1.4.9 wiki

Before we move on with the installation, we'll have to create a MySQL database for MediaWiki to use for all our content. Running the following commands (which assume you've set up your environment and root password as instructed in the previous article) will do that for us. Replace the italicized text with your own unique decisions. The middle two commands are word-wrapped, but should each be typed as all one line.

morbus@:~ > mysqladmin -u root -p create wiki_dbname
morbus@:~ >
   mysql -u root -p -e "GRANT ALL PRIVILEGES ON wiki_dbname.*
   TO wiki_user IDENTIFIED BY 'wiki_password'"
morbus@:~ > 
   mysql -u root -p -e "SET PASSWORD FOR
   wiki_user = OLD_PASSWORD('wiki_password')"
morbus@:~ > mysql -u root -p -e "FLUSH PRIVILEGES"

Next, open the wiki/INSTALL file in a text editor, and follow the instructions under "In-place web install." MediaWiki will then be available at The installation wizard is simple enough to not warrant further hand holding; for the "Database config," you'll want to use the database name, user, and password you chose and created in the MySQL commands above. If you don't know what a particular option means, leave it as the default setting.

With the wizard completed, go to the main page of your wiki and create your user by clicking the "create an account or log in" menu item in the upper right. Usernames can contain spaces if you'd like. Alternatively, you can login using the "Sysop" account you created as part of the installation wizard. Once logged in, you'll be returned to the front, and suitably boring, page of your new installation.

As is typical with new software, there's that inevitable, "What next?" If you've never used a wiki before, the most important maxim to take to heart is, you can't screw up, fixes are an edit away. Go ahead and click on that "edit" tab at the top of your main page, and be greeted with a text area with which you can modify the contents, preview, and eventually, save. Every time you change and save a wiki page, a backup is made. Did you screw up or accidentally delete something? You can view the "history" of a page to recover (or re-edit) that missing data, or "rollback" a page to a previous version. A list of recent content changes, as well as specific differences, are accessible from the "Recent changes" link in the "navigation" box on the left.

Most wiki software is shipped with its own Markup: shorthand for the various HTML elements you'd normally use to design your content. Instead of typing <i>eh oh!</i> for italicized text, MediaWiki allows you to use two single quotes instead: ''eh oh!'' (a full list of shorthand possibilities is available). The syntax you'll use the most, [[Some Words]], makes links to other wiki pages. For example, [[Deltab Pains Me]] will automatically create a link to the wiki page named "Deltab Pains Me," whether it exists yet or not. If it exists, clicking the link will show you the article; otherwise, you'll be given a chance to fill it with relevant content.

Every wiki software has a different shorthand, and very few are capable of supporting other formats. This shorthand can actually contribute to a negative mindset: this wiki is hard to use because it doesn't support what I've come to expect elsewhere. MediaWiki is no different: out of the box, it only supports its internal house format. Typing this shorthand is entirely optional; if you prefer using HTML, go right ahead, or use the buttons above the text area to click your way through.

If there's one piece of shorthand you should grow fond of, however, it's --~~~~. This odd looking creature forms a signature that will automatically link your name, user page, and timestamp of your edit, in the form of "--Morbus Iff 02:33, 13 Sep 2005 (EDT)." This becomes very helpful to keep track of who's who during conversation, or simply to keep tabs on the age of the content without running through the page's "history" trying to find the point of origin.

Exploring MediaWiki's Features

While I certainly can't run you through every feature of MediaWiki in my remaining word count, I can give you a taste of some of my favorites. You can read more about these, as well as everything else possible, over at

And more. If there's one document that should be treasured like a million-dollar lifeline, then it's the MediaWiki FAQ, which includes answers to such common concerns as changing the links in the sidebar, that blasted logo, allowing edits for authenticated users only, messing with the various bits of text sprinkled through the interface, et cetera, et cetera.

Final Thoughts

This article was finished whilst listening to Bernard Herrmann's North by Northwest soundtrack. (Yes, that revelation had even less meaning or import than the bungling comparison I made in the introduction.) In my next article, I'll backpedal a bit to explore some further helper monkeys for our server. As always, wax poetic in the comments below. Particularly, some folks desire an Apache/PHP compiling tutorial--to that, I ask, what needs are you missing with the various precompiled OS X versions available?

Kevin Hemenway is the coauthor of Mac OS X Hacks, author of Spidering Hacks, and the alter ego of the pervasively strange Morbus Iff, creator of, which bills itself as "content for the discontented."

Return to the Mac DevCenter

Copyright © 2009 O'Reilly Media, Inc.