PersonalisedHomepage

From TestWiki

Jump to: navigation, search
This extension is currently installed on this wiki. Feel free to experiment with it!
MediaWiki logo.png
This extension is also documented at
Extension:PersonalisedHomepage
on MediaWiki.org.

If the pages are not in sync. then this version on my test wiki is always the most up-to-date.

This extension allows users to personalise the home page by creating a new page in their user space that will be used instead.

[edit] How to customise

Create a sub-page of your user page which has the same name as the main page of your wiki. By default this is Main Page, but this is configurable on a per-wiki basis so it may differ in your case. You can find the correct name by checking the contents of MediaWiki:Mainpage for the wiki in question. "Main Page" should be replaced by the appropriate value for your wiki throughout the remainder of these instructions.

If your username was "Sir Dennis" you would therefore create your personalised home page at "User:Sir Dennis/Main Page". You can edit the page to contain whatever you want. If you want to include the contents of the non-customised main page then add {{:Main Page}} at the point you want it to appear.

[edit] Source

Copy the source code to a file called PersonalisedHomepage.php in your extensions directory, and add the following line to the bottom of your LocalSettings.php file:

include_once("extensions/PersonalisedHomepage.php");

<debug_file_header>
<debug_last_modified>

<?php
if (!defined('MEDIAWIKI')) die("MediaWiki extensions cannot be run directly.");
/**
 * An extension to allow users to have their own customised main page.
 *
 * THIS EXTENSION WAS DEVELOPED AND TESTED ON MEDIAWIKI 1.6.10
 * OTHER VERSIONS ARE UNTESTED, BUT SHOULD BE OK
 *
 * @package MediaWiki
 * @subpackage Extensions
 *
 * @author Mark Clements <mclements at kennel17 dot co dot uk>
 * @copyright copyright © 2007-2013, Mark Clements
 * @license http://creativecommons.org/licenses/by-sa/2.5/ cc-by-sa 2.5 or later
 * @version $Rev: 792 $
 */
 
// Setup version number
	$pMCExt_Version = '$Rev: 792 $';
	$pMCExt_Version = substr($pMCExt_Version, 6, -2);
// Setup extension credits
	$wgExtensionCredits['other'][] = array(
		'name' => "Personal Homepage",
		'version' => "r" . $pMCExt_Version,
		'author' => "Mark Clements",
		'description' => "an extension to allow users to customise the Main Page",
		'url' => "http://www.kennel17.co.uk/testwiki/PersonalisedHomepage",
	);
// Tidy up
	unset($pMCExt_Version);
 
	$wgExtensionFunctions[] = "wfPersonalHomepage";
 
/////////////////////////////////////////////////
 
	function wfPersonalHomepage() {
		global $wgHooks;
 
	// Setup parser hooks
		$wgHooks['ParserBeforeStrip'][] = "wfPERSHOM_DoIt";
	}
 
	function wfPERSHOM_DoIt(&$Parser, &$Text, &$StripState) {
		global $wgOut, $wgUser, $wgContLang, $wgRequest;
 
		if (isset($wgOut) && isset($wgUser) && isset($wgRequest)) {
			if ($wgRequest->getVal('action', 'view') == "view") {
				$MainPage = wfMsg("mainpage");
				$Title = $Parser->getTitle();
				if ($Title->getNamespace() == NS_MAIN && $Title->getText() == $MainPage) {
					$ToPage = $wgContLang->getNsText(NS_USER) . ":" . $wgUser->getName() . "/" . $MainPage;
					$NewTitle = Title::newFromText($ToPage);
					if ($NewTitle->exists())
						$wgOut->redirect($NewTitle->getFullURL());
				}
			}
		}
 
		return true;
	}
Personal tools