User:Technical 13/Scripts/Enhanced "What links here".js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Technical 13/Scripts/Enhanced "What links here". |
/******************************************************************************************************************/
/* Enhanced "What links here" script */
/* */
/* author: User:Technical_13 */
/* source: http://wiki.riteme.site/wiki/User:Technical_13/Scripts/Enhanced_"What_links_here".js */
/* documentation: http://wiki.riteme.site/wiki/User:Technical_13/Scripts/Enhanced_"What_links_here" (redlink) */
/* contact: http://wiki.riteme.site/wiki/User_talk:Technical_13 */
/* license: CC-BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/) */
/******************************************************************************************************************/
// Look for "What links here" in the toolbox
if (mw.config.get('wgNamespaceNumber') >= 0 && $('#t-whatlinkshere').length === 0) {
alert('Missing "What links here" in the side menu! Contact script creator for assistance.');
// return;
} else {
/*/ Start process
$('#t-whatlinkshere').load(function () {
*/
// Build arrays
$.ajax({
url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&meta=siteinfo&siprop=namespaces&format=json',
dataType: 'json',
async: false,
success: function (siResponse) {
var i = 0;
for (var ns in siResponse.query.namespaces) {
if (siResponse.query.namespaces[ns].id > -1) {
// Define namespace number
nsPos[i][0] = siResponse.query.namespaces[ns].id;
// Define namespace displayed name
nsPos[i][1] = siResponse.query.namespaces[ns].nodeValue;
// Pull number of links for current namespace up to 500
$.ajax({
url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&list=backlinks&bllimit=500&blnamespace=' + nsNum + '&bltitle=' + mw.config.get('wgPageName') + '&format=json',
dataType: 'json',
async: false,
success: function (blResponse) {
// Define number of links for current namespace up to 500
bl = blResponse.query.backlinks.length;
if (isNaN(bl) ){
bl = 0;
}
if(typeof nsPos !== 'undefined') {
nsPos[i][2] = bl;
}
}
});
// TRON
if(typeof nsPos !== 'undefined') {
alert(i + ' => [' + nsPos[i][0] + ', ' + nsPos[i][1] + ', ' + nsPos[i][2] + ']');
}
// TROFF
i++;
}
}
}
});
// for now //});
}