User:Quarl/autowarn.js
Appearance
(Redirected from User:Quarl/autowarn basic.js)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Quarl/autowarn. |
// 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>