User:Juliancolton/closerfa2.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.
// Adapted from [[User:Animum/rfaclose.js]].

importScript("User:Animum/urlparameters.js");

function closeRFA_init(outcome) {
    window.open(wgScript + "?title=" + wgPageName + "&action=edit&outcome=" + outcome, "_blank", ""); //Open in a new tab
}

$(function() {
    if(wgTitle.indexOf("Requests for adminship/") != -1) {
        mw.util.addPortletLink("p-cactions", "javascript:closeRFA_init(\"pass\")", "pass", "ca-rfapass");
        mw.util.addPortletLink("p-cactions", "javascript:closeRFA_init(\"fail\")", "fail2", "ca-rfafail");
    }
});

$(function() {
    if((UrlParameters["outcome"] == "pass" || UrlParameters["outcome"] == "fail") && wgTitle.indexOf("Requests for adminship/") != -1) {
        if(document.editform.wpTextbox1.value.indexOf("boilerplate metadata rfa") != -1) return;
        var user = wgTitle.split("/")[1];
        document.editform.wpTextbox1.value = "\{\{subst:rfa" + (UrlParameters["outcome"] == "pass" ? "p" : "f") + "\}\}\n" + document.editform.wpTextbox1.value;
        var lines = document.editform.wpTextbox1.value.split("\n");
        lines[2] = "\n'''Final tally: \{\{subst:rfatally\|" + user + "\}\}; withdrawn by nominator, closed by \[\[User:" + wgUserName + "\|" + wgUserName + "\]\] at \~\~\~\~\~'''<!--";
        lines[3] = "";
        lines[4] = "-->";
        document.editform.wpTextbox1.value = lines.join("\n") + "\n\{\{subst:rfab\}\}";
        document.editform.wpSummary.value = "Closing RfA: " + (UrlParameters["outcome"] == "pass" ? "Successful" : "Unsuccessful");
        document.editform.wpMinoredit.checked = true;
        document.editform.wpSave.click();
        window.setTimeout(function() { window.close(); }, 1000);
    }
});