Extension:AddPersonalUrls
From MediaWiki.org
|
AddPersonalUrls Release status: stable |
|
|---|---|
| Implementation | MyWiki |
| Description | add some items to the personal URLs |
| Author(s) | RV1971 Talk |
| Version | 0.31 (2007-10-01) |
| MediaWiki | >=1.10 |
| Download | #Source #Change Log |
| Parameters | ExtAddPersonalUrls::$mTable |
| Hooks used | |
Contents |
[edit] 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 a special page based on Extension:DynamicPageList 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.
[edit] Installation
Even though this extension has been tested on MediaWiki 1.10, it is likely to work on earlier versions as well.
- Save the #Source to a file extensions/AddPersonalUrls/AddPersonalUrls.php.
- Add the following line to your LocalSettings.php:
require_once( "extensions/AddPersonalUrls/AddPersonalUrls.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).
- If you want to sue the first item, you need to install Extension:DynamicPageList (version >= 1.4) and the Call Extension (which is contained in the same bundle). Furthermore, you need to create a page Template:My_Pages containing
{{#dpl: namespace=User|titlematch={{{1}}}/%}}
- Alternatively, you can do without the first item, by putting the following in your LocalSettings.php:
unset( ExtAddPersonalUrls::$mTable[0] );
[edit] Source
<?php $wgExtensionCredits['other'][] = array( 'name' => 'AddPersonalUrls', 'version' => ExtAddPersonalUrls::VERSION, 'author' => '[http://www.mediawiki.org/wiki/User:RV1971 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.31'; public static $mTable = array ( array( 'page' => 'Special:Call', 'name' => 'mypages', 'args' => '/My_Pages,$username' ), 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; } } ?>
[edit] Change Log
- 0.31
- Adapted to the new version of Extension:DynamicPageList which does not have a dedicated special page any more.
- 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.

