User:Barrylb/Special pages outside Special namespace

MediaWiki extensions manual
Special pages outside Special namespace
Release status: unknown
Implementation Special page
Description here is a hack to make special pages integrate better within the site structure. Instead of a special page appearing as http://www.mysite.com/wiki/Special:Events/2006/07/21/Meeting you can make it appear as http://www.mysite.com/wiki/Events/2006/07/21/Meeting.
Author(s) Barrylb
MediaWiki 1.6.7
License No license specified
Download No link
$wgIntegratedSpecialPages
Translate the Barrylb/Special pages outside Special namespace extension if it is available at translatewiki.net


If you have some features on your site that are not suitable for wiki content then quite often one of your only choices is to implement a special page but it doesn't look good having Special: appear in the URL.

So here is a hack to make special pages integrate better within the site structure. Instead of a special page appearing as http://www.mysite.com/wiki/Special:Events/2006/07/21/Meeting you can make it appear as http://www.mysite.com/wiki/Events/2006/07/21/Meeting.

This should work on 1.6.7 and 1.7.1. Do the following:

  • Modify includes/Wiki.php. Insert the following before function initializeSpecialCases :
function checkCustomSpecialpages(&$title, &$output) {
  global $wgTitle, $wgIntegratedSpecialPages;

  foreach ($wgIntegratedSpecialPages as $name => $specialname) {
	if ((strpos($title->getText(), $name.'/') === 0) || ($title->getText() == $name)) {
		if ($title->getText() == $name) {
			$par = NULL;
                        $name = $title->getDBkey();
		}
		else {
			$bits = split( "/", $title->getDBkey(), 2 );
			$name = $bits[0];
			if( !isset( $bits[1] ) ) {
				$par = NULL;
			} else {
				$par = $bits[1];
			}
		}					

		$page = SpecialPage::getPage( $name );
		if (!is_null( $page ) ) {
			$wgTitle = Title::makeTitle( NS_SPECIAL, $name );
			if (!is_null( $wgTitle )) {
				if (!$wgTitle->userCanRead()) {
					$output->loginToUse();
					$output->output();
					exit;
				}
				else {
					$page->execute( $par );
					return true;
				}
			}
		}

	}
  }
  return false;
}
  • In function initializeSpecialCases change this:
 else {
   /* No match to special cases */

to this:

else if (!$this->checkCustomSpecialPages($title, $output)) {
   /* No match to special cases */
  • Then in LocalSettings.php define which paths map to which special pages; usually they will be the same name. eg:
 $wgIntegratedSpecialPages = array ('Events' => 'Events', 'Reports' => 'Reports');