Manual:Interface/Sidebar - MediaWiki
Jump to content
From mediawiki.org
Manual:Interface
Translate this page
Languages:
Nederlands
Taqbaylit
Yorùbá
italiano
polski
português
português do Brasil
svenska
čeština
русский
саха тыла
עברית
العربية
अवधी
বাংলা
ဖၠုံလိက်
中文
한국어
This page documents a
system message
, a wiki page that defines part of the
MediaWiki interface
See also the
default documentation
Sidebar example
See also:
Manual:Remove Tabs
MediaWiki:Sidebar
allows a user to modify the navigation bar.
The navigation bar 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.
The Monobook and Vector
skins
place the navigation bar on the top-left (top-right for right-to-left languages) along with the search bar and toolbox, but the placement may be different in other skins.
This sidebar is
not shown to users of the
Mobile
site
(i.e. the version of the site produced by
Extension:MobileFrontend
Skin:MinervaNeue
- use the
MobileMenu
hook for that).
Customize the sidebar
edit
To customize the
MediaWiki:Sidebar
on a wiki, you need first to be logged in with a user that has the
editinterface
permission. For administrators this is enabled by default.
You can access MediaWiki:Sidebar by either:
Going to http://yourdomain/w/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".
Here is example code added in
MediaWiki:Sidebar
for a sidebar:
* navigation
** mainpage|Accueil
** Special:RecentChanges|Recent changes
* new heading
** portal-url|Forums
** https://www.mediawiki.org|MediaWiki home
* TOOLBOX
** page-info-url|Information about this page.
This example will result in the following sidebar:
Sidebar example
If you have to create a new page, you will be presented with the default content for the sidebar in the editor. In order to successfully create a
MediaWiki:Sidebar
page, you need to change the content before saving.
Extending the TOOLBOX
edit
Extending the toolbox is not recommended, and when done via MediaWiki:Sidebar will likely also require associated JavaScript/CSS site changes.
Note the TOOLBOX keyword is handled differently by different skins and extension should be carefully considered as the expectation with links in the TOOLBOX menu is that
they relate to the existing page
Adding links that do not relate directly to the current page breaks expectations of the contract set in.
Please refer to the associated note at
Manual:Hooks/SidebarBeforeOutput#Note about extending TOOLBOX
Splitting the navigation bar into new sections
edit
The navigation bar can be split into sections, each with a new heading of its own.
This is done by adding one asterisk.
The heading for each section is taken from the first-level list element ("navigation" and "new heading" in the example above).
If this text corresponds to the name of an interface message (an existing page of that title in the MediaWiki namespace), then the text of that page is used as a label; otherwise, the header title is used as-is.
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
edit
Links are created with 2 asterisks (called Second-level list elements).
For example:
** target|link text
target
The link target can be the name of an interface message (page in the MediaWiki namespace) or wiki page, or an external link. In either case, the
link
can be internal, interwiki, or external.
Do the following to determine the target:
Get the target text.
If there is an existing or default interface message with that name, use the content of that message instead of the target text.
If the output from the previous step is a valid URL (beginning with
or other
URL protocol
), the link will point to that URL.
Otherwise, it will treat it as the link target of a wikilink (linking to that page name or interwiki).
In case it would end up linking to
, the whole entry is removed from the sidebar. (This is useful for removing an entry on all languages by changing the message holding the link).
Examples:
**
portal-url
|portal
" – Uses the text of
MediaWiki:Portal-url
(which contains "Project:Community portal").
**
|MediaWiki home
" – Links to
since this is a valid URL.
**
Special:RecentChanges
|Recent changes
" – Links to Special:RecentChanges, since there is no interface message of that name and that is not a valid URL.
**
w:Foo
|Some interwiki page
" – Links to
w:Foo
for the same reason.
link text
The link text can be the name of an interface message (page in the MediaWiki namespace) or plain text.
If the link text is the name of an existing or default interface message, the content of that message will be used. MediaWiki will check for localized versions; for example, if the current language is fr (French) and the link text is the interface message "forum", it will check for "forum/fr" before using "forum".
Otherwise, the link text is used as the target as-is.
Notice that the link text is
not
optional as in normal wiki links. If the link text is missing,
the item is ignored
Examples:
** Homepage|
mainpage
– Uses
MediaWiki:Mainpage
(which contains "MediaWiki").
** Special:Recentchanges|
Recent changes
– Uses "Recent changes", since there is no interface message of that name.
Target link
w:Foo
is the english version interwiki article. For another language version must be used language code before the target article name. For example to polish version
w:pl:Foo
or shortly
pl:Foo
. But for the multilanguage wiki target as this, is better use
Special:MyLanguage
You can try for example link to
Help:Links
article.
Special:MyLanguage/Help:Links#Interlanguage_links | helplinks
String
helplinks
is translatable message from MediaWiki namespace, similary as
portal
above, but target URL is result of the special page. Not generated from content of the translatable message as
MediaWiki:portal-url
. If the translated content of target page exists, is directly opened. If not, is opened default language version of it.
Section order (elements)
edit
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, 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
edit
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:
create a wiki page named
MediaWiki:Tooltip-n-
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-
and put the accesskey in that page.
Example:
* Homepage|mainpage-description
- Uses
MediaWiki:Tooltip-n-mainpage-description
and
MediaWiki:Accesskey-n-mainpage-description
Translations
edit
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
Help:Extension:Translate/Unstructured element translation
Advanced customization
edit
The sidebar can be fully customized by implementing
JavaScript
or
CSS
, 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
edit
To completely remove the sidebar and logo:
Blank the
MediaWiki:Sidebar
page and save.
Then add:
column-content
margin
em
content
margin
p-cactions
left
.1
em
This moves the main text of your wiki to the left.
Completely remove the sidebar, tabs and search bar
edit
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
edit
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
LocalSettings.php
code
$wgForceUIMsgAsContentMsg
'mainpage'
'portal-url'
];
Add or remove toolbox sections
edit
The
toolbox
appears on the left under
MediaWiki:Sidebar
in certain skins. On Vector 2022 it appears on the right of the screen (in LTR languages).
As of MediaWiki 1.43 you can append links to the toolbox using MediaWiki:Sidebar via
MediaWiki:Sidebar
* empty section
* navigation
* TOOLBOX
** portal-url|Forum
Adding toolbox items prior to 1.43 via JavaScript
edit
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+.
Entire MediaWiki website: copy the script below into
MediaWiki:Common.js
One specific user: copy the script below into
Special:MyPage/common.js
(or the JS page for the user's current
skin
, such as
Special:MyPage/monobook.js
).
Now simply configure which link should appear in which section. You also can remove some links if you want to.
Code
edit
function
ModifySidebar
action
section
name
link
try
switch
section
case
'languages'
var
target
'p-lang'
break
case
'toolbox'
var
target
'p-tb'
break
case
'navigation'
var
target
'p-navigation'
break
default
var
target
'p-'
section
break
if
action
==
'add'
var
node
document
getElementById
target
getElementsByTagName
'div'
)[
getElementsByTagName
'ul'
)[
];
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'
)[
getElementsByTagName
'ul'
)[
];
var
listelements
list
getElementsByTagName
'li'
);
for
var
listelements
length
++
if
listelements
].
getElementsByTagName
'a'
)[
].
innerHTML
==
name
||
listelements
].
getElementsByTagName
'a'
)[
].
href
==
link
list
removeChild
listelements
);
catch
// let's just ignore what's happened
return
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
);
Usage
function CustomizeModificationsOfSidebar()
- Has to be customized for adding or removing links in specific sections:
ModifySidebar( "
action
", "
section
", "
name
", "
link
" );
parameter
value
action
add
to add a link;
remove
to remove a link
section
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
edit
If you want to restrict the modification of the links to a specific user group (e.g.
bureaucrat
), change
jQuery
CustomizeModificationsOfSidebar
);
to
if
mw
config
get
'wgUserGroups'
[]
).
indexOf
'bureaucrat'
!==
jQuery
CustomizeModificationsOfSidebar
);
For restricting the modifications to IPs instead of a specific user group, use
if
mw
config
get
'wgUserGroups'
[]
).
indexOf
'user'
===
jQuery
CustomizeModificationsOfSidebar
);
Add or remove toolbox sections (PHP)
edit
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)
edit
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
[];
initNav
();
});
function
initNav
()
'#p-logo'
).
css
({
'position'
'relative'
'display'
'block'
});
'.generated-sidebar h5,#p-tb h5 '
).
each
function
var
id
this
).
parent
().
attr
'id'
);
maxHeights
id
this
).
next
'div'
).
height
();
var
str
this
).
html
();
labels
id
str
if
expandCookieName
id
==
'false'
expandeds
id
false
minimize
this
);
else
if
expandCookieName
id
==
'true'
expandeds
id
true
maximize
this
);
else
if
defaultExpandItems
indexOf
str
==
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
expandCookieName
id
'false'
expires
);
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
expandCookieName
id
'true'
expires
);
var
str
labels
id
' ▼'
var
newHeight
maxHeights
id
];
target
).
next
'div'
).
animate
({
'height'
newHeight
'px'
});
target
).
html
str
);
function
toggleNav
var
id
target
).
parent
().
attr
'id'
);
expandeds
id
expandeds
id
];
if
expandeds
id
==
true
maximize
target
);
else
minimize
target
);
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
Sidebar width in Monobook skin (CSS)
edit
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
-15
em
column-content
content
margin-left
15
em
p-logo
p-logo
hover
width
15
em
p-cactions
left
14.5
em
portlet
width
14
em
column-content
margin-left
-14
em
content
mw-body
margin-left
14
em
Change sidebar content when logged in (PHP)
edit
Install and configure the
DynamicSidebar
extension.
Parser functions in sidebar
edit
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:
*Heading
**{{#ifeq:{{NAMESPACE}}|User|Page-to-link-to{{!}}text-to-show-on-user-page}}
**{{#ifeq:{{NAMESPACE}}|Talk|Another-Page-to-link-to{{!}}text-to-show-on-talk-page}}
works. However the following would
not
work since the parser function spans multiple lines:
*Heading
{{#ifeq:1|1|
**foo{{!}}
bar
**baz{{!}}fred
}}
Troubleshooting
edit
Changes not showing up
edit
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
edit
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
edit
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
edit
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.
Deprecation warning for Skin::appendSpecialPagesLinkIfAbsent()
edit
MediaWiki version:
1.44
In MediaWiki 1.44, the link to Special:SpecialPages was removed from the toolbox and added to the default version for
MediaWiki:Sidebar
To support the transition, for interface admins who have already customized MediaWiki:Sidebar, the special pages link will be automatically added, as otherwise it would simply disappear.
This automatic addition will emit a deprecation warning for Skin::appendSpecialPagesLinkIfAbsent().
To modify this behavior, follow the guidance in
T385346
See also
edit
Sidebar
Manual:Interface/Sidebar/Hacks
– Unsupported PHP modifying hacks that used to be on this page
Manual:$wgEnableSidebarCache
Category:Menu extensions
Manual:Remove Tabs
– Remove MediaWiki tabs
References
edit
(For information on assigning a permission to groups or users, see
Manual:User rights
.)

Then, use a link to a page on your wiki, but replace your wiki page's title (e.g.
Main_Page
) in the URL/Address bar with
MediaWiki:Sidebar
and load that page - you should now see the current content of the sidebar. (You may need to use the syntax
//yourdomain/yourwiki/index.php?title=MediaWiki:Sidebar&action=edit
if you use long URLs.)

If the content of the sidebar has already been modified, you can click on the
Edit
or
Edit source
link, otherwise you may need to create the page first by clicking on
Create
or
Create source
In some cases (such as links with the
character), an interface message is necessary. The link target cannot be made dependent on the interface language set in the preferences.
Kaare Mikkelsen (25.1.2012):
Adding tooltips to sidebar items in MediaWiki
Wayback Machine
30.10.2022)
Retrieved from "
Categories
Interface messages
MediaWiki administration
Manual
Interface/Sidebar
Add topic