Jump to content

User:Cleared as filed/wikipageAfd.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.
// User:Quarl/wikipageAfd.js - extra afd-related wikipage functionality

// requires: wikipage.js, datetime.js

// <pre><nowiki>

// return log page for given date (default today)
function afdLogPage(d) {
    d = d || new Date();
    return new WikiPage(null,'Wikipedia:Articles for deletion/Log/' + datestampYYYYMonthD(d));
}

WikiPage.prototype.afdPage = function() {
    // AFD only applies to main (ignoring Talk)
    if (!this.nsMainP) return null;

    return new WikiPage(null, 'Wikipedia:Articles for deletion/' + this.article);
}

WikiPage.prototype.afdPageX = function() {
    // already an AFD page?
    if (this.afdTargetPage()) return this;
    return this.afdPage();
}

WikiPage.prototype.afdTargetPage = function() {
    if (!this.page.match(/^Wikipedia:Articles for deletion\/(.*?)(?: \([0-9]+|2nd nomination|3rd nomination|4th nomination\))?$/)) return null;

    var p = RegExp.$1;
    if (p.match(/^Log\//)) return null;

    return new WikiPage(null, p);
}

WikiPage.prototype.afdLogDate = function() {
    if (!this.page.match(/^Wikipedia:Articles for deletion\/Log\/(.*?)?$/)) return null;
    var d = RegExp.$1;
    return new Date(Date.parse(d));
}

function wikipageAfd_load() {
    window.wpAfdTarget = wikiPage.afdTargetPage();
    window.wpAfd = wikiPage.afdPageX();
    window.wpAfdLogDate = wikiPage.afdLogDate();

    window.afdP = Boolean(wpAfdTarget);
    window.afdLogP = Boolean(wpAfdLogDate);
}

$(wikipageAfd_load);

// </nowiki></pre>