MediaWiki:OldFilePages/code.js

// ');   $('#mw_metadata').appendTo('#c_metadata td');    $('#c_metadata').makeCollapsible;    //$('tr.mw-metadata-show-hide-extended a').click; //not working    var html = ' File usage  ';    $('[data-tab-body="history"]').append(html); } function AddLinks {    var runNoTrans = false, noTransHTML;

//First stop: what links here var pagelist = [], html; $.getJSON('/api.php?action=query&list=imageusage&iutitle=' +      encodeURIComponent(wgPageName) + '&iulimit=max&format=json', function(data) {        var usage = data.query.imageusage;        fullSort(usage);        for (var page in usage) {            var title = usage[page].title;            var temp = 'href="/wiki/';            if (usage[page].redirect == "") {                temp = 'class="allpagesredirect" ' + temp;            }            pagelist.push('' + title + '');        }    }).done(function {        var numlinks = pagelist.length;        if (numlinks == 0) {             html = 'There are no pages that transclude this file. ';            noTransHTML = html; runNoTrans = true;        } else if (numlinks <= 100) {            var numString = '';            if (numlinks > 1) { numString = numlinks + ' pages use'; } else { numString = 'page uses'; }           html = 'The following ' + numString + ' this file: ' + pagelist.join('') + ''; } else { pagelist = pagelist.slice(0, 100); html = 'More than 100 pages ' + 'use this file. The following list shows the first 100 pages. ' +              'A full list can be found here.' + ' ' + pagelist.join('') + ''; }   }).fail(function { html = 'There was an error fetching the transclusions list. ';       }).always(function { $('.TransclusionsLoading').remove; $('[data-tab-body="history"]').append(html); if (runNoTrans) { NoTrans(noTransHTML); } //find out if I could avoid this... });

//If no transclusions, list regular links, if any function NoTrans(html) { //todo: fix lulz variable name $.getJSON('/api.php?action=query&list=backlinks&bltitle=' +          encodeURIComponent(wgPageName) + '&bllimit=max&format=json', function(data) {            var links = data.query.backlinks, pagelist = [];            fullSort(links);            for (var page in links) {                var title = links[page].title;                pagelist.push('<a href="/wiki/' + encodeURIComponent(title) +                   '">' + title + '</a></li>');            }            if (pagelist.length) {                var grammar = 'page links';                if (pagelist.length > 1) {                    grammar = 'pages link';                }                html = $(html).html($(html).html + ' However, the following ' + grammar + ' to it:')[0].outerHTML;               html += '' +                   pagelist.join('') + '</ul>';            } else {                html = $(html).html($(html).html + ' No pages link to it either.')[0].outerHTML;           }            $('p.FileTransclusions').replaceWith(html);        }); }

//List duplicate files, if any $.getJSON('/api.php?action=query&titles=' + encodeURIComponent(wgPageName) +      '&prop=duplicatefiles&dflimit=max&format=json', function(data) {        var dupefiles = data.query.pages[wgArticleId.toString].duplicatefiles;        if (dupefiles) {            var pagelist = [], html, grammar = ' file is a duplicate ';            dupefiles.sort(function(a, b) { return mySort(a, b, 'name'); });            for (var DF in dupefiles) {                var filename = dupefiles[DF].name.replace(/_/g, " ");                pagelist.push('<a href="/wiki/File:' + encodeURIComponent(filename) +                   '">' + 'File:' + filename + '</a></li>');            }            if (pagelist.length > 1) {                grammar = ' ' + pagelist.length + ' files are duplicates ';            }            html = '<p class="FileDuplicates">The following' + grammar +               'of this file (<a href="/wiki/Special:FileDuplicateSearch/' + encodeURIComponent(wgPageName.substring(5)) + '">more details</a>): ' + pagelist.join('') + '</ul>';           $('p.FileTransclusions').before(html);        }    }); }

function mySort(a, b, param) { if (a[param] < b[param]) { return -1; } else if (a[param] > b[param]) { return 1; } else { return 0; } }

function fullSort(lst) { lst.sort(function(a, b) { return mySort(a, b, 'title'); }); lst.sort(function(a, b) { return mySort(a, b, 'ns'); }); }

if (wgCanonicalNamespace == 'File' && !$('.diff-article-content').length) { $(document).ready(function {       ChangeLayout;        AddLinks;    }); } //