MediaWiki:Markfordeletion.js

/* Mark for (Speedy) Deletion Adapted to use Template:Delete */ /* Customization */ window.MarkForDeletion = { promptedDeleteReason: "Out of project scope" }; /* Source: http://dev.wikia.com/wiki/MarkForDeletion, used revision 47639 */ $(function {   "use strict";    if(mw.config.get("wgAction") !== "view" || mw.config.get("wgNamespaceNumber") === -1 || mw.config.get("wgUserName") === null) {        return;    }    var i18n = {        /* English */        en: {            buttonTitle: "Mark for speedy deletion",            spam: "spam",            prompt: "Enter delete reason to quickly mark this page for speedy deletion",            error: "An error occurred while marking the page for speedy deletion"        }    };    function setDeleteNotice(deleteReason) {        $.ajax({ type: "POST", url: mw.util.wikiScript('api'), data: { action: "edit", title: mw.config.get("wgPageName"), summary: "Marked for speedy deletion because: " + deleteReason, token: mw.user.tokens.get("editToken"), prependtext: "{" + "{SpeedyDelete|" + deleteReason + "}}\n", format: "json" },           success: function(d) { if(d && d.error && d.error.code) { alert(i18n.error + ": " + d.error.code, 'error'); } else { window.location.reload; }           },            error: function { alert(i18n.error + ": " + d.error.code, 'error'); }       });    }    function initializeI18N {        var lang = mw.config.get("wgUserLanguage"),            base = lang.split("-")[0];        if(i18n[lang]) {            i18n = i18n[lang];        } else if(i18n[base]) {            i18n = i18n[base];        } else {            i18n = i18n.en;        }    }    function initDeleteNoticeButton {        // don't create duplicate buttons        if ($("#mark-for-deletion-link").length > 0) {            return;        }        var $button = $(mw.html.element("a", {            id: "mark-for-deletion-link",            style: "cursor: pointer;"        }, i18n.buttonTitle)), $toolbar, $insertLinkHere;        // create button        $button.click(function { var promptedDeleteReason = i18n.spam; if (window.MarkForDeletion && typeof window.MarkForDeletion.promptedDeleteReason === "string") { promptedDeleteReason = window.MarkForDeletion.promptedDeleteReason; }           var deleteReason = window.prompt(i18n.prompt, promptedDeleteReason); if (typeof deleteReason === "string" && deleteReason.length > 0) { setDeleteNotice(deleteReason); }       });        // add button to toolbar        $toolbar = $("#p-tb");        if ($toolbar.length > 0) {            $toolbar.find("ul").append($button);        }        $("#mark-for-deletion-link").wrap("");    }    initializeI18N;    initDeleteNoticeButton; });