Changing the title on MediaWiki’s main page

November 19th, 2009

MediaWiki is the free software that powers Wikipedia, as well as several lesser-known wikis. I downloaded it yesterday, and I found changing its appearance more challenging than I had anticipated.

By default, a page is titled with a big headline stating the name of the entry, such as propylene glycol alginate on this page. Accordingly, the main page has a big “Main Page” headline. There doesn’t seem to be an easy way to change that to a more relevant string, but I was able to do so using the following steps: Assuming you’re using the default theme Monobook, open the file skins/MonoBook.php. In version 1.15.1 (and probably other recent versions) the relevant line is on 118:
<h1 id="firstHeading" class="firstHeading"><?php $this->data['displaytitle']!=''?$this->html('title'):$this->text('title') ?></h1>

data[‘displaytitle’] will be blank on the main page, but I don’t know if it’s blank on other contexts also, so in order to be certain, I added a second condition to check against and linebreaks for increased readability:
<h1 id="firstHeading" class="firstHeading">
if ($this->data['displaytitle'] != '') {

// It's the main page; put desired
// welcome message here.
} elseif ($this->data['title'] == 'Main Page') {
echo 'Welcome to this wiki!';

// displaytitle is blank but it's not the
// main page; I have no idea if this
// condition will ever be met.
} else {

Tags: ,

Comments are closed.