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 13:34, 18 June 2024 (fix). 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.
// Work in progress, report bugs as [[User talk:CanonNi]]
// <nowiki>

$(function (){
    //Check if the config is defined
    if (typeof(alertHelperConfig) == 'undefined') {
      alertHelperConfig = {};
    }
   
    if (typeof(alertHelperConfig.topicList) == 'undefined') {
        alertHelperConfig.topicList = {
        	'a-a' : [ 'Armenia, Azerbaijan, or related conflicts' ],
        	'a-i' : [ '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' ],
        	'r-i' : [ 'the intersection of race/ethnicity and human abilities and behaviour' ],
        	'sl'  : [ 'Sri Lanka' ],
        	'tt'  : [ 'The Troubles' ]
        };
    }
      
    mw.util.addPortletLink(
        'p-tb', //target tab - personal links
        '#', //link URL
        'CT Alert', //link text
        'pt-alert', //id of new button
        'Alert about contentious topics', //hover text
	);
   
    $('#pt-status').click(function (){
        var Window = new Morebits.simpleWindow(600, 500);
        Window.setTitle('Alert about contentious topics');
        Window.setScriptName('alertHelper');
        Window.display();
        var form = new Morebits.quickForm(publish);
        var categories = form.append({
            type: 'select',
            name: 'topic',
            label: 'Select topic:'
        });
        for (var key in alertHelperConfig.topicList) {
    		if (alertHelperConfig.topicList.hasOwnProperty(key)) {
				categories.append({
            		type: 'option',
            		label: alertHelperConfig.topicList[key][0],
            		value: key
        		});
    		}
		}
        form.append({ type: 'submit' });
        var result = form.render();
        Window.setContent(result);
        Window.display();

        function publish(e){
            var form = e.target;
            var status = form.status.value;
            var text = pageobj.getPageText();
            
            text += '\n' + '{{subst:alert|' + topic + '}} ~~~~';
            
            Morebits.simpleWindow.setButtonsEnabled(false);
            Morebits.status.init(form);
			Morebits.wiki.actionCompleted.notice = 'Alerted!';
            
            var statusPage = new Morebits.wiki.page(alertHelperConfig.statusPage, 'Processing');
            statusPage.setFollowRedirect(true);
            statusPage.load(function() {
                statusPage.getStatusElement().status('Setting status');
                statusPage.setEditSummary('Contentious topic alert: ' + topic + ' (using [[User:CanonNi/Scripts/AlertHelper|AlertHelper]])');
                statusPage.setPageText(status);
                statusPage.save();
            });
        }
    });
});

// </nowiki>
// [[Category:Wikipedia scripts]]