Revision as of 12:00, 5 March 2015 by Seb35 (talk | contribs) (+demo)

A small code snippet to allow administrators to modify the toolbox through MediaWiki:Sidebar. For example, move the "Recent changes" from the navigation to the toolbox:

* navigation
** mainpage|mainpage-description
** randompage-url|randompage
** helppage|help
** WHATLINKSHERE|whatlinkshere
** RECENTCHANGESLINKED|recentchangeslinked-toolbox
** recentchanges-url|recentchanges
** FEEDS|feeds
** CONTRIBUTIONS|contributions
** LOG|log
** BLOCKIP|blockip
** EMAILUSER|emailuser
** USERRIGHTS|userrights
** UPLOAD|upload
** SPECIALPAGES|specialpages
** PRINT|printableversion
** PERMALINK|permalink
** INFO|pageinfo-toolboxlink

All possible keywords are written here, but this means they could be displayed on appropriate pages (e.g. BLOCKIP only on user pages) and they are always displayed. It is exactly the current behaviour.

A demo is (currently) available on (you can walk on other pages to see how the items change).


For now, this is only a code snippet. Perhaps it could evolve as an extension.

Note this code is not really beautiful, particularly the inner foreach, but I didn’t find another way to retrieve the exact content of "MediaWiki:Sidebar" (without reparsing it obviously), since only the URL is given in the $toolbox array. Possibly it would be possible to "invert" the URL function to get the title, but this is also a bit hacky. Another solution would be to modify the core (Skin::addToSidebarPlain()) to add this information in the array, but this a very bad solution to locally change MW core (without changing the official codebase itself).

// Licence WTFPL 2.0
$wgHooks['BaseTemplateToolbox'][] = 'modifyToolbox';

function modifyToolbox( BaseTemplate $baseTemplate, array &$toolbox ) {


	$modifiedToolbox = array();

	// Walk in the MediaWiki:Sidebar message, section toolbox
	foreach ( $baseTemplate->data['sidebar']['TOOLBOX'] as $value ) {
		$specialLink = false;

		// Search if the keyword exists
		foreach ( $keywords as $key ) {
			if ( $value['href'] == Title::newFromText($key)->fixSpecialName()->getLinkURL() ) {
				$specialLink = true;

				// This is a keyword, hence add this special link
				if ( array_key_exists( strtolower($key), $toolbox ) ) {
					$modifiedToolbox[strtolower($key)] = $toolbox[strtolower($key)];

		// This is a normal link
		if ( !$specialLink ) {
			$modifiedToolbox[] = $value;

	$toolbox = $modifiedToolbox;

	return true;