MediaWiki:Gadget-countWLH.js
Перейти до навігації
Перейти до пошуку
Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.
- Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
- Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
- Internet Explorer / Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5
- Opera: натисніть Ctrl-F5
// Add the total numbers of links and transclusions to WhatLinksHere pages
// Authors: RheingoldRiver, Rye Greenwood, Volodyslav
$(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 input').val();
var ns = $('#namespace > select').val();
var invert = $('input[name="invert"]').attr('checked') == undefined ? false : true;
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|redirects',
titles : title,
lhlimit : 'max',
tilimit : 'max',
lhnamespace : invert ? '*' : (ns === '' ? '*' : ns),
tinamespace : invert ? '*' : (ns === '' ? '*' : ns),
rdnamespace : invert ? '*' : (ns === '' ? '*' : ns),
}).then(function(data) {
var Count = {links:0,redirs:0,trans:0};
var terms = {links:'linkshere',redirs:'redirects',trans:'transcludedin'};
// extract information from the API result
for (var p in data.query.pages) {
var page = data.query.pages[p];
for ( var t in terms ) {
for ( var i in page[terms[t]] ) {
if ( invert ) {
Count[t] += page[terms[t]][i].ns != ns ? 1 : 0;
} else {
Count[t] ++;
}
}
}
}
// inject
for ( var i in Count ){
var label = $('#mw-input-hide'+i).parent().parent().find('label');
label.text( label.text() + ' (' + Count[i] + ')' );
}
});
});