FANDOM

2,054,058 Pages

//
// RecentChangesChecker by Bobogoobo
// On Special:RecentChanges, crosses out non-latest revisions
//   (especially useful when viewing anons only, for example)
// Wishlist: don't cross out if Lwt was latest edit
//   without requiring double the calls...
$(function() {
    if (mw.config.get('wgPageName') !== 'Special:RecentChanges') {
        return;
    }
    var pending = $('.rc-conntent table').length;
 
    $('#recentchanges-options').find('hr').prev().after(
        ' | <span id="rc-checker">Checking for non-latest revisions...</span>'
    );
 
    function checkDone() {
        if (pending === 0) {
            $('#rc-checker').text('All non-latest revisions crossed out.');
        }
    }
 
    $('.rc-conntent table').each(function() {
        var $this = $(this), revision, title, pageId, $link, isNew = false;
        if ($this.attr('class').indexOf(' mw-changeslist-log-') !== -1) {
            // Skip log entries
            pending -= 1;
            checkDone();
            return true;
        } else if ($this.hasClass('mw-collapsible')) {
            // Group of revisions
            revision = $this.find('tr').eq(1).find('td').eq(2).find('a').eq(2);
            $link = $this.find('tr').eq(0).find('td').eq(2).find('a').eq(0);
        } else if (! $this.find('abbr.newpage').length) {
            // Single revision
            revision = $this.find('td').eq(1).find('a').eq(1);
            $link = $this.find('td').eq(1).find('a').eq(0);
        } else {
            // New page, only one revision shown - have to check revcount
            isNew = true;
            revision = $this.find('td').eq(1).find('a').eq(1);
            // Just to make this a little more concise
            revision.attr('href', revision.attr('href').replace(
                '&action=history',
                '&diff=0&action=history'
            ));
            $link = $this.find('td').eq(1).find('a').eq(0);
        }
        revision = revision.attr('href').match(
            /\/wiki\/(.+)\?curid\=(\d+)&diff\=(\d+)&/
        );
        title = revision[1];
        pageId = revision[2];
        revision = revision[3];
        (function ($elem, rev, pageTitle, pid, checkCount) {
            $.getJSON(
                '/api.php?action=query&prop=info&format=json&titles=' +
                    pageTitle.replace(/_/g, ' ') +
                    (checkCount ? '&inprop=revcount' : ''),
                function(data) {
                    data = data.query.pages[pid];
                    // If page ID doesn't match, page was moved, so not latest
                    if (!data) {
                        $elem.wrapInner('<s></s>');
                    } else {
                        if (checkCount) {
                            if (data.revcount > 1) {
                                $elem.wrapInner('<s></s>');
                            }
                        } else {
                            if (data.lastrevid.toString() !== rev) {
                                $elem.wrapInner('<s></s>');
                            }
                        }
                    }
                    pending -= 1;
                    checkDone();
                }
            );
        })($link, revision, title, pageId, isNew);
    });
});
//
Community content is available under Copyright unless otherwise noted.