_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

User:XXN/massrestore.js

In this article, the topic of User:XXN/massrestore.js will be addressed from various angles and perspectives in order to offer the reader a complete and detailed vision of it. Different aspects related to User:XXN/massrestore.js will be explored, its implications in different contexts will be analyzed and varied opinions and points of view will be presented. From its emergence to its impact on current society, this article aims to deepen the understanding of User:XXN/massrestore.js and offer the reader a broad and objective overview of this topic.
/*global $, mw */
///An updated version of ] (adapted from ])

if (mw.config.get("wgNamespaceNumber") == -1
        && mw.config.get("wgTitle").toLowerCase() == "massrestore"
        && /sysop/.test(mw.config.get("wgUserGroups"))) {
    /**
     * Mediawiki takes WAY too long for the document ready to load; this will
     * listen for the actual body being loaded before that.
     */
    new Promise(resolve => {
        $(resolve);
        var interval = window.setInterval(function () {
            if ($("#footer") && $("#mw-navigation")) {
                resolve();
                window.clearInterval(interval);
            }
        }, 100);
    }).then(function () {
        $("h1").html("Mass-restoration tool");
        document.title = "Tim's mass-restoration tool - Wikipedia, the free encyclopedia";
        $(mw.config.get("skin") == "cologneblue" ? "#article" : "#bodyContent").html(
                "<h3 id=\"siteSub\">From Wikipedia, the free encyclopedia</h3><br /><br />"
                + "<form id=\"wpMassRestore\" name=\"wpMassRestore\">"
                + "<b>If you abuse this tool, it's <i>your</i> fault, not mine.</b>"
                + "<div id=\"wpMassRestoreFailedContainer\"></div>"
                + "<br /><br />"
                + "Pages to restore(one on each line, please):<br />"
                + "<textarea tabindex=\"1\" accesskey=\",\" name=\"wpMassRestorePages\" "
                + "id=\"wpMassRestorePages\" rows=\"10\" cols=\"80\"></textarea>"
                + "<br /><br /><table style=\"background-color:transparent\">"
                + "<tr><td>Reason:</td>"
                + "<td><input type=\"text\" id=\"wpMassRestoreReason\" name=\"wpMassRestoreReason\""
                + " maxlength=\"255\" /></td></tr>"
                + "<tr><td><input type=\"button\" id=\"wpMassRestoreSubmit\" name=\"wpMassRestoreSubmit\""
                + " value=\"Restore\"/></td>" + "</form>");
        $("#wpMassRestoreSubmit").click(function () {
            $("#wpMassRestoreSubmit").attr("disabled", true);
            var wpMassRestoreReason = $("#wpMassRestoreReason").val();
            var restored = 0;
            var errors = {};
            $.ajax({
                url: mw.config.get("wgScriptPath") + "/api.php",
                data: {
                    format: "json",
                    action: "query",
                    prop: "info",
                    intoken: "edit",
                    titles: $("#wpMassRestorePages").val().split("\n").join("|")
                }
            }).then(function (data) {
                Promise.all($.map(data.query.pages, function (info) {
                    function fail(e) {
                        errors = e;
                    }
                    return $.ajax({
                        method: "post",
                        url: mw.config.get("wgScriptPath") + "/api.php",
                        data: {
                            format:"json",
                            action: "undelete",
                            reason: wpMassRestoreReason,
                            token: info.edittoken,
                            title: info.title
                        }
                    }).then(function (subdata) {
                        // If restored, update the restored count and the button.
                        if (subdata.undelete) {
                            $("#wpMassRestoreSubmit").val(++restored);
                        } else {
                            fail(subdata.error.info);
                        }
                    }, fail);
                })).then($.noop, $.noop).then(function () {
                    $("#wpMassRestoreSubmit").val("Done (" + restored + ")");

                    if (!$.isEmptyObject(errors)) {
                        var ul = $("<ul></ul>");
                        $.each(errors, function (title, e) {
                            ul.append("<li><a href=\"" + mw.config.get("wgScript") + "?title=" +
                                    encodeURIComponent(title) + "\">" + title + "</a>: " + e + "</li>");
                        });
                        $("#wpMassRestoreFailedContainer").html(
                        		"<br /><strong>Failed restorations:</strong>").append(ul);
                    }
                });
            });
        });
    });
}