MediaWiki:Gadget-countWLH.js
Saltar para a navegação
Saltar para a pesquisa
Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
- Opera: Pressione Ctrl-F5.
// Add the total numbers of links and transclusions to WhatLinksHere pages
// Authors: RheingoldRiver, Rye Greenwood
$(document).ready(function() {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Whatlinkshere') return;
// get WLH page title and namespace from the form input fields
var title = $('#mw-whatlinkshere-target').val();
var ns = $('#namespace').val();
title = title ? title : mw.config.get('wgTitle').replace('WhatLinksHere/', ''); // if failed, get title from URL
// fetch data
return new mw.Api().get({
action : 'query',
prop : 'linkshere|transcludedin',
titles : title,
lhlimit : 'max',
tilimit : 'max',
lhnamespace : ns === '' ? '*' : ns,
tinamespace : ns === '' ? '*' : ns,
}).then(function(data) {
var linkshereCount, transcludedinCount = 0;
// extract information from the API result
for (var p in data.query.pages) {
var page = data.query.pages[p];
linkshereCount = page.linkshere ? page.linkshere.length : 0;
transcludedinCount = page.transcludedin ? page.transcludedin.length : 0;
}
// i18n: load localized pipes and parentheses
new mw.Api().loadMessagesIfMissing( [ 'pipe-separator', 'parentheses' ] )
.then(function() {
var pipe = mw.msg("pipe-separator");
// prepare injection into HTML
var fieldset = $("#mw-content-text > fieldset"); // element that holds the "Hide transclusions | ..." string
var fieldsetText = fieldset.html(); // get raw HTML text of its contents
var firstPipe = fieldsetText.indexOf(pipe);
var secondPipe = fieldsetText.indexOf(pipe, firstPipe + 1);
// inject
var newText = ''.concat(
fieldsetText.substring(0, firstPipe), " ",
mw.msg('parentheses', transcludedinCount),
fieldsetText.substring(firstPipe, secondPipe), " ",
mw.msg('parentheses', linkshereCount),
fieldsetText.substring(secondPipe)
);
fieldset.html(newText); // replace HTML text with new text
});
});
});