MediaWiki:Gadget-allLangs.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
mw.loader.using('site',function(){
'use strict';
const config = mw.config.get([
'wgScriptPath',
'wgNamespaceNumber',
'wgCanonicalNamespace',
'wgCanonicalSpecialPageName',
'wgTitle',
'wgUserLanguage'
]);
if ( window.iosp_loaded || (config.wgNamespaceNumber == -1 && !config.wgCanonicalSpecialPageName)) return;
window.iosp_loaded = true;
var pagename = '';
if ( [8, 9].includes(config.wgNamespaceNumber)) { // MediaWiki, Discussion
pagename = config.wgCanonicalNamespace + ':' + config.wgTitle;
} else if ( config.wgNamespaceNumber == -1 ) { // Special pages
pagename = config.wgCanonicalNamespace + ':' + config.wgCanonicalSpecialPageName;
var subpageIdx = config.wgTitle.indexOf( '/' );
if ( subpageIdx >= 0 )
pagename = pagename + config.wgTitle.substr( subpageIdx );
}
var langs = [];
if ( pagename.length && $( '#p-lang' ).length === 0 ) {
$.get(config.wgScriptPath + '/api.php', {
action: 'query',
format: 'json',
meta: 'allmessages|siteinfo',
formatversion: 2,
ammessages: 'otherlanguages',
amlang: config.wgUserLanguage,
siprop: 'interwikimap',
sifilteriw: 'local'
}).done(function (d) {
d.query.interwikimap.forEach(function(entry){
if (entry.language !== undefined) {
var l = entry.language;
l = l.charAt(0).toUpperCase() + l.slice(1);
langs.push({ url: entry.url, language: l, prefix: entry.prefix });
}
});
if ( langs.length > 0 ) {
// Header
document.getElementById('mw-panel').innerHTML += '<div id="p-lang" class="mw-portlet mw-portlet-lang vector-menu vector-menu-portal portal" aria-labelledby="p-lang-label" role="navigation">' +
'<h3 id="p-lang-label" class="vector-menu-heading">' +
'<span>' + d.query.allmessages[0].content + '</span>' +
'</h3>' +
'<div class="vector-menu-content body">' +
'<ul class="vector-menu-content-list menu"></ul>' +
'</div>' +
'</div>';
// Adding language-entries
var langList = document.querySelector('#p-lang .menu');
for ( var lang in langs ) {
langList.innerHTML += '<li>' +
'<a href="' + langs[lang].url.replace( '$1', pagename) +
'" title="' + pagename.replace( '_', ' ' ) + ' - ' + langs[lang].language +
'">' + langs[lang].language +
'</a>' +
'</li>';
}
if (mw.user.options.get('gadget-collapsibleSidebar') === 1) mw.loader.using('ext.gadget.collapsibleSidebar',function(){$(document).trigger('addSidebarPanel')});
}
});
}
} );