This page is a translated version of the page Manual:Interface/Sidebar and the translation is 27% complete.
Outdated translations are marked like this.
See also: Manual:Remove Tabs

MediaWiki:Sidebar 允许用户修改导航栏。 The navigation bar which provides links to the most important locations in the wiki and supplies site administrators with a place to add an important collection of links. For instance, most wikis will link to their community discussion page and some useful tool pages.

Monobook 和 Vector 皮肤将导航栏与搜索栏和工具箱一起放在左上角(从右到左的语言为右上角),但是该位置可能在其他皮肤上有所不同。 此侧边栏不向 Mobile 站点的用户显示(即由 Extension:MobileFrontend / Skin:MinervaNeue 生成的站点版本 ) - 使用 MobileMenu 钩子)。


要在 wiki 上自定义 MediaWiki:Sidebar,您首先需要使用具有“editinterface”权限的用户登录。 对于管理员,这是默认启用的。[1]

You can access to MediaWiki:Sidebar by either:

  • Going to http://yourdomain/wiki/index.php?title=MediaWiki:Sidebar&action=edit in your browser.
  • Typing MediaWiki:Sidebar in search bar, and validating with Enter.
  • From Special:AllMessages, searching for "side".

以下是在 MediaWiki:Sidebar 中为侧边栏添加的示例代码:

* navigation
** mainpage|Accueil
** Special:RecentChanges|Recent changes
* new heading
** portal-url|Forums
** https://www.mediawiki.org|MediaWiki home




导航栏可以分成几个部分,每个部分都有自己的新标题。 这是通过添加一个星号来完成的。

每个部分的标题取自第一级列表元素(上例中的“导航”和“新标题”)。 如果此文本与接口消息的名称(MediaWiki名称空间中该标题的现有页面)相对应,则该页面的文本用作标签; 否则,标题标题按原样使用。 Please note the {{int:}} magic word does not work since it is useless: MediaWiki automatically looks for a translation to display before to fallback to the default message.

In the example above, * navigation and * new heading are section headings.

Creating links in the sidebar

Links are created with 2 asterisks (called Second-level list elements). For example:

** <span lang="en" dir="ltr" class="mw-content-ltr">target</span>|<span lang="en" dir="ltr" class="mw-content-ltr">link text</span>

:链接目标可以是界面消息(MediaWiki 命名空间中的页面)或维基页面的名称,也可以是外部链接。 在任一情况下,link 可以是内部的、跨维基的或外部的。[2]

Do the following to determine the target:
  1. 获取目标文本。
  2. 如果存在具有该名称的现有或默认界面消息,请使用该消息的内容而不是目标文本。
  3. 如果上一步的输出是有效的 URL(以 http:// 或其他 URL 协议 开头),则链接将指向该 URL。
  4. 否则,它会将其视为 wikilink 的链接目标(链接到该页面名称或 interwiki)。
  5. 如果它最终会链接到“-”,则整个条目将从侧边栏中删除。 (这对于通过更改包含链接的消息来删除所有语言的条目很有用)。
  • "** portal-url|portal" 使用 MediaWiki:Portal-url 的文本(其中包含“Project:Community portal
  • "** https://www.mediawiki.org|MediaWiki home" links to https://www.mediawiki.org since this is a valid URL.
  • "** Special:RecentChanges|Recent changes" 链接到 Special:RecentChanges,因为没有该名称的界面消息。
  • "** w:Foo|Some interwiki page" 出于同样的原因,链接到 w:Foo
link text
链接文本可以是界面消息的名称(MediaWiki 命名空间中的页面)或纯文本。
  • 如果链接文本是现有或默认界面消息的名称,则将使用该消息的内容。 MediaWiki 将检查本地化版本; 例如,如果当前语言是fr(法语),并且链接文本是界面消息“forum”,则在使用“forum”之前会检查“forum/fr”。
  • 否则,链接文本按原样用作目标。
  • 请注意,链接文本是“非”可选的,就像在普通的 wiki 链接中一样。 如果链接文本丢失,该项目将被忽略
  • ** Homepage|mainpage uses MediaWiki:Mainpage (which contains "MediaWiki").
  • ** Special:Recentchanges|Recent changes uses "Recent changes", since there is no interface message of that name.


Some skins allow customizing the order of some special elements, like the search bar, toolbox, and languages. That can be done by adding the special keywords SEARCH, TOOLBOX and LANGUAGES respectively, to MediaWiki:Sidebar using the heading syntax.

However, some skins like MonoBook no longer support defining the position of the search element, and the search element is placed right after the first section of the sidebar instead. In that case, to move the search element at the top, the workaround is to define an empty leading section. For example:

* empty section
* navigation
** mainpage|mainpage
** Special:Recentchanges|Recent changed
* new heading
** portal-url|portal
** https://www.mediawiki.org|MediaWiki home

Note that some skins may display the first section differently, or place some element between the first and the second section (if any).

Tooltips and Accesskey

A tooltip is a message which appears when a cursor is positioned over an icon, image, hyperlink, or other element in a graphical user interface.

If you add an item to the sidebar, it will have no "tooltip". But you can create a tooltip by doing the following:[3]

  • create a wiki page named "MediaWiki:Tooltip-n-<id of the item>"
  • and put the tooltip in that page.

An access key or accesskey allows a computer user to immediately jump to a specific part of a web page via the keyboard.

Accesskeys can also be created by doing the following:

  • create a wiki page named "MediaWiki:Accesskey-n-<id of the item>"
  • and put the accesskey in that page.



You can translate the strings, which you use, by editing the according pages in the MediaWiki namespace.

Example: The string, which will replace the item named "mainpage", is taken from MediaWiki:Mainpage. To set/change this text for users, who display your wiki in German, you can put the according text on the page MediaWiki:Mainpage/de.

That way you can easily translate these texts through the MediaWiki interface.

Please note that MediaWiki will by default use the content of the Sidebar page in that language, which corresponds to the default language of your wiki. So, if your wiki e.g. uses French as its default language, edit MediaWiki:Mainpage/fr in order to show a modified sidebar to all users, who have not changed their language setting and to all anonymous users.

For more advanced translation, see 帮助:扩展:翻译/未结构化元素翻译 .

Advanced customization

The sidebar can be fully customized by implementing JavaScript or Cascading Style Sheets, or by editing the PHP files directly. Before using these methods, note that:

  • JavaScript is fragile: it will not work for users with JavaScript disabled, and scripts frequently fail in different browsers or skins.
  • Editing the PHP files can easily cause unexpected errors, and your changes will be lost in the next update unless you manually change the new files.

Remove the Sidebar and main logo at MediaWiki:Sidebar

To completely remove the sidebar and logo:

Blank the MediaWiki:Sidebar page and save.

Then add:

#column-content { margin: 0 0 1em 0; }
#content { margin: 0 0 0 0; }
#p-cactions { left: .1em; }

This moves the main text of your wiki to the left.

Completely remove the sidebar, tabs and search bar

See also: Manual:Remove Tabs

Deletes the logo, and the entire sidebar:

#p-logo, .generated-sidebar, #p-lang, #p-tb  { display:none; }

Deletes the search bar:

#p-search { display:none; }

Deletes the talk tab:

#ca-talk { display:none!important; }

Deletes the Page tab:

#ca-nstab-main { display:none!important; }

Force UI-messages to follow content

Some pages should sometimes follow the content language, especially for multilingual sites. This can be controlled with the setting $wgForceUIMsgAsContentMsg . Each message overridden in this way must be explicitly given, for example to let the sidebar link to versions given by the content language for the main page and the portal page add the following to


$wgForceUIMsgAsContentMsg = [ 'mainpage', 'portal-url' ];

用 JavaScript 添加或移除工具部分

The toolbox appears on the left under MediaWiki:Sidebar. The toolbox is a dynamic element requiring programmatic methods such as skin extensions, PHP (see skins/MonoBook.php and creating a new skin) or JavaScript.

The JavaScript solution uses User:{username}/common.js / MediaWiki:Common.js, available for MediaWiki 1.9+.

Now simply configure which link should appear in which section. You also can remove some links if you want to.


function ModifySidebar( action, section, name, link ) {
	try {
		switch ( section ) {
			case 'languages':
				var target = 'p-lang';
			case 'toolbox':
				var target = 'p-tb';
			case 'navigation':
				var target = 'p-navigation';
				var target = 'p-' + section;

		if ( action == 'add' ) {
			var node = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var aNode = document.createElement( 'a' );
			var liNode = document.createElement( 'li' );

			aNode.appendChild( document.createTextNode( name ) );
			aNode.setAttribute( 'href', link );
			liNode.appendChild( aNode );
			liNode.className = 'plainlinks';
			node.appendChild( liNode );

		if ( action == 'remove' ) {
			var list = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var listelements = list.getElementsByTagName( 'li' );

			for ( var i = 0; i < listelements.length; i++ ) {
				if (
					listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
					listelements[i].getElementsByTagName( 'a' )[0].href == link
					list.removeChild( listelements[i] );

	} catch( e ) {
		// let's just ignore what's happened

function CustomizeModificationsOfSidebar() {
	// adds [[Special:CategoryTree|Special:CategoryTree]] to toolbox
	ModifySidebar( 'add', 'toolbox', 'CategoryTree', 'https://en.wikipedia.org/wiki/Special:CategoryTree' );
	// removes [[Special:Upload|Special:Upload]] from toolbox
	ModifySidebar( 'remove', 'toolbox', 'Upload file', 'https://en.wikipedia.org/wiki/Special:Upload' );

jQuery( CustomizeModificationsOfSidebar );
function CustomizeModificationsOfSidebar() has to be customized for adding or removing links in specific sections:
ModifySidebar( "action", "section", "name", "link" );
action add to add a link; remove to remove a link
section navigation, toolbox, languages but also any other existing customized section; the given link will be added to or removed from this section
name contains the text of the link
link contains the URL of the link

Restricting modifications to specific usergroups

If you want to restrict the modification of the links to a specific user group (e.g. bureaucrat), change:

jQuery( CustomizeModificationsOfSidebar );


if ( mw.config.get( 'wgUserGroups', [] ).indexOf( 'bureaucrat' ) !== -1 ) {
	jQuery( CustomizeModificationsOfSidebar );

For restricting the modifications to IPs instead of a specific user group, use

if ( mw.config.get( 'wgUserGroups', [] ).indexOf( 'user' ) === -1 ) {
	jQuery( CustomizeModificationsOfSidebar );

Add or remove toolbox sections (PHP)

You can add in your file LocalSettings.php the hook described on this page. With this, you can modify via MediaWiki:Sidebar the links in the toolbox panel (remove some links, change their name) and add custom links (e.g. add the "Recent changes" link there instead of the navigation panel.

Make expanding/collapsing sidebar for all users (Monobook skin only)

If you use the Monobook skin and don't want to miss the expandable menu bar from e.g. Vector skin, paste the following code into MediaWiki:Monobook.js of your wiki.

// Code snippet to make your sidebar items expandable. 
// Use this code ONLY for the Monobook skin. 

$( document ).ready( function() {
	// Set the default expanded items by their headline
	var defaultExpandItems = ['Navigation', 'Orga'];
	// Set the basic-name for the cookies, which save the current state of expanding
	var expandCookieName = 'disdance_project_wiki_nav_expanded_';

var maxHeights = [];
	var expandeds = [];
	var labels = [];

function initNav() {
	$( '#p-logo' ).css({'position': 'relative', 'display': 'block'});
	$( '.generated-sidebar h5,#p-tb h5 ').each( function( i ) {
		var id = $( this ).parent().attr( 'id' );
		maxHeights[id] = $( this ).next( 'div' ).height();
		var str = $( this ).html();
		labels[id] = str;

if ( $.cookie( expandCookieName + id ) == 'false' ) {
			expandeds[id] = false;
			minimize( $( this ) );
		} else if ( $.cookie( expandCookieName + id ) == 'true' ) {
			expandeds[id] = true;
			maximize( $( this ) );
		} else if ( defaultExpandItems.indexOf( str ) == -1 ) {
			expandeds[id] = false;
			minimize( $( this ) );
		} else {
			expandeds[id] = true;
			maximize( $( this ) );
		$( this ).css({'cursor': 'pointer'});
		$( this ).click( toggleNav );
	} );

function minimize( target ) {
	var id = $( target ).parent().attr( 'id' );
	// You can change the expires parameter to save the cookie longer/shorter than 7 days like in this code
	$.cookie( expandCookieName + id, 'false', { expires: 7} );
	var str = labels[id] + '  ►';
	$( target ).next( 'div' ).animate({'height': '0px'});
	$( target ).html( str );

function maximize( target ) {
	var id = $( target ).parent().attr( 'id' );
	// You can change the expires parameter to save the cookie longer/shorter than 7 days like in this code
	$.cookie( expandCookieName + id, 'true', { expires: 7} );
	var str = labels[id] + '  ▼';
	var newHeight = maxHeights[id];
	$( target ).next( 'div' ).animate({'height': newHeight + 'px'});
	$( target ).html( str );

function toggleNav( e ) {
	var id = $(e.target ).parent().attr( 'id' );
	expandeds[id] = !expandeds[id];
	if( expandeds[id] == true ) {
		maximize( e.target );
	} else {
		minimize( e.target );


Sidebar width in Monobook skin (CSS)

You can change the width of your sidebar by adding the following CSS rules to your MediaWiki:Monobook.css

note that this is an article, not a file. This changes the width to 15em, the actions position and portlet width should be an em or so less, so I've set them to 14em in this example.

/* increase sidebar width */
#column-content { margin-left: -15em; }
#column-content #content { margin-left: 15em; }
#p-logo a, #p-logo a:hover { width: 15em; }
#p-cactions { left: 14.5em; }
.portlet { width: 14em; }
#column-content { margin-left: -14em; }
#content.mw-body { margin-left: 14em; }

Change sidebar content when logged in (PHP)

Install and configure the DynamicSidebar extension.

Parser functions in sidebar

Although it is not exactly recommended, the sidebar does support parser functions (such as ParserFunctions), provided the ** is outside the parser function, and the parser function does not span multiple lines. For example:


works. However the following would not work since the parser function spans multiple lines:



Changes not showing up

MediaWiki aggressively caches content if possible, which often causes the navigation bar to persist after changes. Purging the cache of affected pages should correct the situation. To perform a mass-purge of all caches at once, touch the LocalSettings.php file or truncate the objectcache table in your database (you may have to do both).

You also need to have $wgUseDatabaseMessages set to true. Also, if your links don't have a | in them, they will not show up because of this line of code in Skin.php: if ( strpos( $line, '|' ) !== false ) {

If you are a user or average wiki admin, you will not be able to do the advanced stuff above to get changes to show up. If purging does not work either, you can sometimes still see CSS changes right away in preview (especially when changing your personal CSS). For example; changing the sidebar width, padding, or margins. Changes can take awhile to show up after saving though. If nothing shows up after awhile you may need to contact the overall wiki, or wiki farm, sysop.

Lowercase link labels

If your links are not being capitalized as intended, try adding spaces around the bar character; for example:

** http://www.example.com/download.php?file=44555 | Download

Sections disappear or show unexpected content

If a section does not display or displays unexpected content, check that the header text isn't the name of an interface message by searching Special:AllMessages. If it is, use a different header text, or create a new interface message and use it.

For example, if you want to use "Sidebar" as header text, create the interface message "MediaWiki:Sidebar-header" containing only "Sidebar". Then, use * sidebar-header as header.

Sections are not displayed if there are no links of the form ** target | link text (e.g. when the target was forgotten).

Broken links after updating Special:Version

This will happen e.g., each time there are newer translations for your site language's sidebar items. One could add new redirect pages each time, but a better solution would be to use one's own sidebar item names instead of trying to keep track of the current MediaWiki translations.



  1. (有关为组或用户分配权限的信息,请参阅 手册:用户权限 。) 然后,使用你的 wiki 上的一个页面链接,但是要把地址栏/URL里你的 wiki 页面标题替换成 MediaWiki:Sidebar(如 首页)然后加载那个页面 - 现在你应该看得到侧边栏当前的内容。(如果你使用长 URL,可能需要使用语法 //yourdomain/yourwiki/index.php?title=MediaWiki:Sidebar&action=edit) 如果侧边栏的内容已被修改,只需点击“编辑”或“编辑源代码”链接,否则你可能需要通过点击“创建”或“创建源代码”链接先创建页面。
  2. 在某些情况下(例如带有“&”字符的链接)需要一个接口消息。链接目标不能依赖于首选项中设置的界面语言。
  3. http://www.kaarebmikkelsen.dk/?p=174