Jump to content

User:Technical 13/Scripts/Enhanced "What links here".js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/******************************************************************************************************************/
/*                                         Enhanced "What links here" script                                      */
/*                                                                                                                */
/*   author:        User:Technical_13                                                                             */
/*   source:        http://en.wikipedia.org/wiki/User:Technical_13/Scripts/Enhanced_"What_links_here".js          */
/*   documentation: http://en.wikipedia.org/wiki/User:Technical_13/Scripts/Enhanced_"What_links_here"  (redlink)  */
/*   contact:       http://en.wikipedia.org/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 //});
}