User:Dantman/Title Customization Hack

Title Customization Hack is a Hack for the Page Title which allows for sysops to edit the way the title is displayed at the top of the page.

Why would you want this?

Some people like being able to selectively remove titles, or remove namespaces from displaying in the titlebar, using this hack it gives that ability without needing to edit the code all the time.

Process

edit

It's quite a quick and simple thing to do.

  • Go to MediaWiki:Title on your wiki and create it with the default text {{FULLPAGENAME}}. (This will make the title display normaly when we finish the hack.)
  • Open /includes/SkinTemplate.php
  • Under the outputPage function, We look for this line: $tpl->set( 'title', $wgOut->getPageTitle() );
  • And we replace it with: $tpl->set( 'title', wfMsg('title') );

Now when you go back to your wiki the title will display normaly (If you skiped the first step and did it last before you create that page the title would show as <Title>).

What Now?

edit

Currently your wiki looks the exact same because the {{FULLPAGENAME}} we used displays the same title as normal. But if we add somthing to MediaWiki:Title such as a "- " at the start that would show up so now "Title" would show as "- Title", or if you erased the {{FULLPAGENAME}} from the page the title would dissapear and only the horizontal line would show.

For the best functionality you might want to install ParserFunctions. That way using if, ifeq, or switch statements you could edit the title with say, selective namespace removal.

Selective Namespace Removal

edit

Use this code inside of MediaWiki:Title:

{{#switch:{{NAMESPACE}}|Namespace1=|Namespace2=|...|NamespaceN=|=|{{NAMESPACE}}:}}{{PAGENAME}}

Where Namespace1, Namespace2, NamespaceN, etc... are the namespaces you wish to make dissapear. Now when inside of Main, or any of the namespaces listed there will be no : and the namespace will not display. So if I listed Help inside of the namespaces "Help:Contents" would show as "Contents".

Selective Namespace Style

edit

Using this code inside of MediaWiki:Title:

<span style="color: {{#switch:{{NAMESPACE}}|Namespace1=color1|Namespace2=|Namespace3=color2/3|defaultColor}};">
{{#switch:{{NAMESPACE}}|CNamespace1=extratext|HiddenNamespace1=|HiddenNamespace2=|=|{{NAMESPACE}}:}}{{PAGENAME}}
</span>

Doing some changes with that code can do multiple things for your site. In the first switch statement you can specify a namespace then specify a color, that color will be used when the title is displayed for that namespace. In the second namespace we can do the same thing as with the previous code, and like there we can also add things to the start of the Title. So if we had a site about characters, we could replace the NPC: prefix with a [NPC] and if we wanted and extra space between them we would use <nowiki>[NPC] </nowiki>

Changes

edit
  • 14/09/2006 - Code edits have been changed from MonoBook.php to SkinTemplate.php so the hack works on all skins. Dantman