MediaWiki:Gadget-topIcons.js: Difference between revisions

no edit summary
No edit summary
Tag: Manual revert
No edit summary
Line 1:
"use strict";
 
/**
* Moves icons from [[Template:External]] to the top bar, next to "Article" and "Talk" tabs;
Line 4 ⟶ 6:
*/
(function ($, mw) {
let var namespace = mw.config.get('wgNamespaceNumber');
 
// automatically show externals on Special and MediaWiki namespaces
if (namespace === -1 || namespace === 8) {
let page = mw.config.get('wgPageName');
 
addLink('the RuneScape Wiki', 'rsw', page);
addLink('the RuneScape Classic Wiki', 'classicrsw', page);
addLink('the Meta Weird Gloop Wiki', 'meta', page);
}
else {
// make this work when "Show preview without reloading the page" is checked
mw.hook('wikipage.content').add(function ($content) {
if (!$content.has('.rs-external-header-links').length) return;
 
// clear existing externals first so previewing doesn't add an infinite amount
$('.gadget-external-icon').remove();
 
// automatically show externals on Special and MediaWiki namespaces
// convert whatever [[Template:External]] gives us
if (namespace === -1 || namespace === 8) {
$('.rs-header-icon').each(function (index, icon) {
let var page = mw.config.get('wgPageName');
addLink(icon.dataset.wikiname, icon.dataset.interwiki, icon.dataset.page);
addLink('the RuneScape Wiki', 'rsw', page);
});
addLink('the RuneScape Classic Wiki', 'classicrsw', page);
addLink('the Meta Weird Gloop Wiki', 'meta', page);
} else {
// make this work when "Show preview without reloading the page" is checked
mw.hook('wikipage.content').add(function ($content) {
if (!$content.has('.rs-external-header-links').length) return;
 
// clear existing externals first so previewing doesn't add an infinite amount
// clean up
$('.rsgadget-external-header-linksicon').remove();
});
}
 
// convert whatever [[Template:External]] gives us
function addLink(wikiname, interwiki, page) {
$('.rs-header-icon').each(function (index, icon) {
let url = mw.util.getUrl(interwiki + ':' + page);
addLink(icon.dataset.wikiname, icon.dataset.interwiki, icon.dataset.page);
let title = wikiname + ' also has an article on ' + page + '.';
});
 
// clean up
// wikipedia links aren't forwarded - see [[Special:Interwiki]]
$('.gadgetrs-external-iconheader-links').remove();
if (interwiki === 'wikipedia') {
});
url = '//en.wikipedia.org/wiki/' + encodeURIComponent(page);
}
function addLink(wikiname, interwiki, page) {
let var url = mw.util.getUrl(interwiki + ':' + page);
let var title = wikiname + ' also has an article on ' + page + '.';
 
// wikipedia links aren't forwarded - see [[Special:Interwiki]]
// Special and MediaWiki namespaces
if (namespace === -1 ||if namespace(interwiki === 8'wikipedia') {
url = '//en.wikipedia.org/wiki/' + encodeURIComponent(page);
url += window.location.search; // include url parameters
}
title = 'Open this page on ' + wikiname + '.';
}
 
// Special and MediaWiki namespaces
let link = mw.util.addPortletLink(
if (namespace === -1 || namespace === 8) {
'p-namespaces',
url += window.location.search; // include url parameters
url,
title = 'Open this page on ' + wikiname + '.';
'', // no text - use background-image instead
}
'gadget-external-' + interwiki, // button id
let var link = mw.util.addPortletLink('p-namespaces', url, '',
title // title text shown on hover
'', // no text - use background-image instead
);
'gadget-external-' + interwiki, // button id
// button id
title // title text shown on hover
);
 
// for styling all links at once - addPortletLink only sets an id
$(link).addClass('gadget-external-icon');
}
})(jQuery, mediaWiki);