/**
* Extra toollinks for MediaWiki's interface.
* Written for Wikimedia Commons, may be useful on other wikis as well.
* Originally written by Arnomane in 2006, rewritten in 2011 by Krinkle.
*
* @rev 6 (2011-12-28)
* @author Duesentrieb, 2006
* @author Avatar, 2006
* @author Arnomane, 2006 - 2007
* @author Dbenbenn, 2006
* @author Timo Tijhof (Krinkle), 2010 - 2011
*/
/*global jQuery:false, mediaWiki:false, importScript:false*/
// Disable the old version, just in case it's also loaded
window.load_extratabs = false;
( function ( $, mw ) {
"use strict";
var title, username, userLang, nsMain, nsTemplate, extraTabs;
// Quick reference to these
title = mw.config.get( 'wgTitle' );
username = title.split('/')[0];
userLang = mw.config.get( 'wgUserLanguage' );
// Namespace ids
nsMain = 0;
nsTemplate = 10;
extraTabs = {
doInjectGroup: function ( group ){
$.each( group, function( i, l ) {
// 'label' can be a key or the message itself
var msg = mw.message( 'extratabs-' + l.label + '-label' );
msg = msg.exists() ? msg.toString() : l.label;
mw.util.addPortletLink( l.portlet, l.target, msg, l.id );
} );
},
/**
* Ge interface links to be added.
* Grouped by category, containing an array of objects with
* keys for target, label, id and portlet.
*
* After MediaWiki 1.19 is deployed, the wikiGetlink() calls should be replaces,
* to avoid namespace-redirects on non-English wikis for the links, with:
* <code>new mw.Title( 'User:Foo' ).getUrl()</code> (which returns the link
* *with* the localized namespace prefix).
*/
getLinks: function( key ) {
switch ( key ) {
default:
return [];
}
},
/**
* Initialization
*/
init: function() {
/**
* Localization
*
* To be moved into the MediaWiki-namespace once ResourceLoader 2.0
* is ready and Gadgets supports msgs. That'll make translating a lot easier
* and removes the need to importScript() another JS-page in init().
*/
// (undented for easier copy/pasting to translations)
mw.messages.set({
"extratabs-wplangcode": "en",
"extratabs-wppage-label": "$1wikibooks"
});
// Import another set of messages, which either
// does nothing (if the subpage doesn't exist)
// or re-sets one or more messages into the user language
if ( userLang !== 'en' ) {
// Since this is asynchronous there is a small change the localization
// is not used. This happends if the import takes until after dom-ready,
// in which case startInjection() is already called.
importScript( 'MediaWiki:Gadget-ExtraTabs2.js/' + userLang );
}
},
/**
* Injection of interface links.
* Shouldn't be called until the document is ready.
*/
startInjection: function() {
switch ( mw.config.get( 'wgNamespaceNumber' ) ) {
case nsTemplate:
extraTabs.doInjectGroup([{
target: 'http://' + mw.msg( 'extratabs-wplangcode' ) + '.wikibooks.org/wiki/Template:' + title,
label: mw.msg( 'extratabs-wppage-label', mw.msg( 'extratabs-wplangcode' ) ), portlet: 'p-cactions', id: 'ca-wppage'
}]);
break;
}
}
};
// Initialize right away
extraTabs.init();
// Explose publically
mw.commonsExtraTabs = extraTabs;
// Fire off the rest as soon as the dom is ready
$( document ).ready( extraTabs.startInjection );
}( jQuery, mediaWiki ));