Extension:AddPersonalUrls

Purpose
This extension adds some items to the personal URLs bar. It can be seen as a demo for using the PersonalUrls hook. You're likely to customize it for your needs.

The current version adds the following items:


 * A link to the Extension:DynamicPageList Special Page which displays all subpages of the user's page.


 * A link to a subpage "Favorites" of the current user's page.


 * A link to a subpage "Sandbox" of the current user's page.


 * A link to a subpage "Notes" of the current user's page.

Except the first item, all of these are blank pages at the beginning which belong to your personal space. You can store any kind of wikitext in it, the names are just suggestions.

Installation
Even though this extension has been tested on MediaWiki 1.9, it is likely to work on earlier versions as well.


 * Save the to a file extensions/AddPersonalUrls/AddPersonalUrls.php.

require_once( "extensions/AddPersonalUrls/AddPersonalUrls.php" );
 * Add the following line to your LocalSettings.php:


 * Create system messages that will be used as titles. The needed pages and suggested contents are:
 * MediaWiki:Mypages – my pages
 * MediaWiki:Favorites – my favorites
 * MediaWiki:Sandbox – my sandbox
 * MediaWiki:Mynotes – my notes


 * The new URLs are defined in the static class member ExtAddPersonalUrls::$mTable. You may customize this in your LocalSettings.php. The string '$username' will be replaced with the current username (you need to write this within single quotes to avoid that PHP already interprets this while processing LocalSettings.php, in which case it would evaluate to an empty string).


 * You need to have the Extension:DynamicPageList installed, otherwise the first item does not work. If you can't or don't want to do that, put the following in your LocalSettings.php:

unset( ExtAddPersonalUrls::$mTable[0] );

Source
 'AddPersonalUrls',  'version' => ExtAddPersonalUrls::VERSION,  'author' => 'RV1971',  'url' => 'http://www.mediawiki.org/wiki/Extension:AddPersonalUrls',  'description' => 'add some items to the personal URLs' );

$wgExtAddPersonalUrls = new ExtAddPersonalUrls;

$wgHooks['PersonalUrls'][] = array( &$wgExtAddPersonalUrls,                                    'onAddPersonalUrls' ); class ExtAddPersonalUrls { const VERSION = '0.3';

public static $mTable = array ( array( 'page' => 'Special:DynamicPageListSP', 'name' => 'mypages', 'args' => '/namespace%3DUser&&titlematch%3D$username%25' ),	   array( 'page' => 'User:$username/Favorites', 'name' => 'favorites', 'args' => null ),	   array( 'page' => 'User:$username/Sandbox', 'name' => 'sandbox', 'args' => null ),	   array( 'page' => 'User:$username/Notes', 'name' => 'mynotes', 'args' => null ) ); function onAddPersonalUrls( &$personal_urls, &$wgTitle ) {     global $wgUser;

$username = $wgUser->getName; if( $wgUser->getID ) {         $pageurl = $wgTitle->getLocalURL;

$urls[] = array_shift( $personal_urls );

foreach( self::$mTable as $item ) {             $urldetails = Skin::makeUrlDetails( str_replace( '$username', $username, $item['page'] ) );

$args = str_replace( '$username', $username, $item['args'] ); $urls[] = array( 'text' => wfMsg( $item['name'] ),                              'href' => $urldetails['href'] . $args,                               'class' => $args ? false			       : ($urldetails['exists'] ? false : 'new'),                              'active' => $args ? false 			       : ($urldetails['href'] == $pageurl) ); }         $personal_urls = $urls + $personal_urls; }     return true; } } ?>

Change Log

 * 0.3 :
 * Configuration parameter is now a class member.


 * 0.21 :
 * Bugfix in mypages.


 * 0.2 :
 * Configure items via a customizable array.


 * 0.1 :
 * First version published.