Jump to content

User:Quarl/autowarn.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.
// THIS SCRIPT IS OBSOLETE -- SEE [[User:Quarl/userwarn.js]]




// [[User:Quarl/autowarn.js]] - warn user using templates.  Adds a "warn"
// menu.  (formerly [[User:Quarl/auto_testn.js]])

// Prompts for relevant pages; e.g. enter "foo && bar && baz", and outputs
// "This message concerns the pages [[foo]], [[bar]], and [[baz]].  Thanks for
// experimenting..."

// depends: wikipage.js, wikiedit.js, wikitabs.js
// enhanced by: advanced_sig.js

// <pre><nowiki>

if(typeof window.makeSignature=='undefined')makeSignature=function(){return "~~~~"};

autowarn = new Object();

autowarn.warn = function(template) {
    var pagenames = prompt("Vandalism to which article(s) (separate using &&)?");
    if (typeof pagenames != 'string') return;

    wikiPage.getEditorAsync(autowarn._edit, template, pagenames);
}

autowarn._englishJoin = function(words) {
    if (words.length == 0) {
        return '';
    } else if (words.length == 1) {
        return words[0];
    } else if (words.length == 2) {
        return words[0] + ' and ' + words[1];
    } else {
        words[words.length-1] = 'and ' + words[words.length-1];
        return words.join(', ');
    }
}

autowarn._splitPageNames = function(s) {
    var words = s.split('&&');
    var pages = [];
    for (var i in words) {
        var word = trimspaces(words[i]);
        if (!word) continue;
        word = word.replace(/^\[\[/, '');
        word = word.replace(/\]\]$/, '');
        pages.push('[[' + word + ']]');
    }
    return pages;
}

autowarn._edit = function(editor, template, pagenames) {
    if (typeof(template) != 'string') { alert("autowarn Internal error 5f95d195-b1c8-4f7e-b751-740230b1926a"); return; }

    var pagesw = autowarn._splitPageNames(pagenames);
    var pages = autowarn._englishJoin(pagesw);

    var text = '{{subst:' + template + '}} ' + makeSignature() + '\n';

    if (pages) {
        text = ('This message concerns the ' + (pagesw.length==1?'page':'pages') + ' ' +
                pages + '.  ' + text);
    }
    text = '\n\n' + text;

    var summary = "Warning {{" + template + "}}";
    if (pages) {
        summary += ", concerning " + pages;
    }

    // if (editor.refuseCreate()) return;
    editor.wpTextbox1 = trim_lines(editor.wpTextbox1) + text;
    editor.wpSummary = summary;
    editor.submit();
}

autowarn._load = function() {
    // Only add tab to User talk pages (but not subpages)

    if (wikiPage.sandboxP ||
        wikiPage.namespace == 'User talk' && !wikiPage.subarticle)
    {
        autowarn._addTabs();
    }
}

autowarn._addTabs = function()
{
    var menu = wikitabs.addTabMenu('Warn', 'mn-warn');

    var qt = function(s) { return s ? '"'+s+'"' : 'null'; }

    var warning = function(template /*, alttemplate */, title) {
        title = "Warn user using template {{"+template+"}}: " + title;
        wikitabs.addLiLink(menu, 'javascript:autowarn.warn(' + qt(template) /* + ', ' + qt(alttemplate)*/ + ')',
                           template, 'ca-autowarn-'+template,
                           title);
    }

    warning('nn-test', 'Non-notable additions');
    // warning('test0', 'Before making controversial edits, please discuss');
    warning('selftest', 'Thanks for reverting yourself');
    warning('test1', 'Your test worked, and has been reverted');
    warning('test2', 'Stop adding nonsense ');
    warning('test2a', 'Vandalism level 2 (blanking)');
    warning('test3', 'Stop vandalizing, or face block');
    warning('test4', 'Last warning before block');
    warning('test4im', 'This is your ONLY WARNING before block');
    warning('test5', 'You have been temporarily BLOCKED');
    warning('test6', 'You have been BLOCKED for repeated vandalism');
    warning('bv', 'Blatant vandal');

    // warning('spam1',);
    // warning('spam2',);


}

$(autowarn._load);

//

// </nowiki></pre>