Snippets/MySandbox
Appearance
< Snippets
MySandbox | |
---|---|
Language(s): | JavaScript |
Compatible with: | MediaWiki 1.20+ (Vector; Monobook) |
Description
[edit]Add a "Sandbox" link to the personal portlet menu. You can also use the SandboxLink extension which improves the user experience by loading the link together with the rest of the page, and does not require JavaScript. On the other hand, when the extension is installed on a wiki, there is no way for a user to opt out of the sandbox link appearing on the personal toolbar.
Code
[edit]/**
* Add a "My sandbox" link to the personal portlet menu.
*
* Required modules: mediawiki.util, mediawiki.Title, mediawiki.Uri
*
* @source https://www.mediawiki.org/wiki/Snippets/MySandbox
* @version 2014-07-16
*/
( function ( mw, $ ) {
$( function () {
var conf, title, url;
// Customize/Translate this to your needs
conf = {
subpageName: 'sandbox',
portletLabel: 'Sandbox',
portletTooltip: 'Go to your sandbox',
editintroPagename: 'Template:User_sandbox',
preloadPagename: 'Template:User_sandbox/preload'
};
// Don't alter the code below
// Use Special:MyPage (as opposed to mw.user.getName()) so that it
// works for logged-out users as well.
title = new mw.Title( 'Special:MyPage/' + conf.subpageName );
url = new mw.Uri( title.getUrl() );
url.extend( {
action: 'edit',
redlink: 1,
editintro: new mw.Title( conf.editintroPagename ),
preload: new mw.Title( conf.preloadPagename )
} );
mw.util.addPortletLink(
'p-personal',
url,
conf.portletLabel,
'pt-sandbox',
conf.portletTooltip,
null,
'#pt-preferences'
);
} );
}( mediaWiki, jQuery ) );