Jump to content

User:CanonNi/Scripts/AlertAssistant.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by CanonNi (talk | contribs) at 11:44, 9 November 2024 (partial rewrite). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
$.when($.ready).then(() => {
    const topicList = {
        aa: "Armenia, Azerbaijan, or related conflicts",
        ai: "the Arab–Israeli conflict",
        ab: "abortion",
        acu: "complementary and alternative medicine",
        ap: "post-1992 politics of the United States and closely related people",
        at: "the English Wikipedia article titles policy and Manual of Style",
        b: "the Balkans or Eastern Europe ",
        blp: "articles about living or recently deceased people, and edits relating to the subject (living or recently deceased) of such biographical articles",
        cc: "climate change",
        cid: " discussions about infoboxes and to edits adding, deleting, collapsing, or removing verifiable information from infoboxes",
        covid: "COVID-19, broadly construed",
        fg: "Falun Gong",
        gc: "governmental regulation of firearm ownership; the social, historical and political context of such regulation; and the people and organizations associated with these issues",
        gg: "gender-related disputes or controversies or people associated with them",
        gmo: "genetically modified organisms, commercially produced agricultural chemicals and the companies that produce them, broadly construed",
        horn: "the Horn of Africa (defined as including Ethiopia, Somalia, Eritrea, Djibouti, and adjoining areas if involved in related disputes)",
        ipa: "India, Pakistan, and Afghanistan",
        irp: "post-1978 Iranian politics",
        kurd: "the topics of Kurds and Kurdistan, broadly construed",
        ps: "pseudoscience and fringe science",
        ri: "the intersection of race/ethnicity and human abilities and behaviour",
        sl: "Sri Lanka",
        tt: "The Troubles",
    };

    if (mw.config.get("wgNamespaceNumber") === 3) {
        mw.util.addPortletLink(
            "p-cactions",
            "#",
            "AlertAssistant",
            "ca-alert",
            "Alert about contentious topics"
        );
    }

    $("#ca-alert").click(() => {
        let Window = new Morebits.simpleWindow(600, 500);
        Window.setTitle("Alert about contentious topics");
        Window.setScriptName("AlertAssistant");
        Window.display();
        let form = new Morebits.quickForm(publish);
        form.append({
            type: "radio",
            name: "first",
            list: [
                { label: "First", value: "true" },
                { label: "Regular", value: "false" },
            ],
        });
        let categories = form.append({
            type: "select",
            name: "topic",
            label: "Select topic:",
        });
        for (const key in topicList) {
            categories.append({
                type: "option",
                label: topicList.topicList[key][0],
                value: key,
            });
        }
        form.append({ type: "submit" });
        const result = form.render();
        Window.setContent(result);
        Window.display();

        function publish(e) {
            const form = e.target;
            const topic = form.topic.value;
            const first = form.first.value === "true";

            Morebits.simpleWindow.setButtonsEnabled(false);
            Morebits.status.init(form);
            Morebits.wiki.actionCompleted.notice = "Alerted!";

            const alertPage = new Morebits.wiki.page(
                mw.config.get("wgPageName"),
                "Processing"
            );
            alertPage.setFollowRedirect(true);
            alertPage.load(function () {
                let text = alertPage.getPageText(); //<nowiki>
                if (first) {
                    text += `\n\n{{subst:alert/first|${topic}}} ~~~~`;
                } else {
                    text += `\n\n== Contentious topic alert ==\n
                    {{subst:alert|${topic}}} ~~~~`;
                } //</nowiki>
                alertPage.setEditSummary(
                    `Contentious topic alert: ${topic} ([[User:CanonNi/Scripts/AlertAssistant|AA]])`
                );
                alertPage.setPageText(text);
                alertPage.save();
                alertPage.save();
            });
        }
    });
});