User:MusikAnimal/responseHelper.js

This is an old revision of this page, as edited by MusikAnimal (talk | contribs) at 22:34, 18 January 2015 (rename). 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.
// <pre><nowiki>
(function() {
	mw.util.addPortletLink('p-navigation', wgServer + '/wiki/Wikipedia:Requests for page protection', "WP:RFPP");
	mw.util.addPortletLink('p-navigation', wgServer + '/wiki/Wikipedia:Administrator intervention against vandalism', "WP:AIV");
	mw.util.addPortletLink('p-navigation', wgServer + '/wiki/Wikipedia:Requests for permissions', "WP:PERM");
	
	var responses = {}, inline = false, indentation = ":", templateName = "", defaultPrompt = "";
	
	if(document.title.indexOf("Editing Wikipedia:Requests for page protection (section)") !== -1) {
		templateName = "RFPP";
		defaultPrompt = "Duration?";
		responses = {
			"Checking" : {
				code : "ch",
				summary : "checking"
			},
			"Semi-protected" : {
				code : "s|X",
				summary : "semi-protected "
			},
			"Pending protected" : {
				code : "pd|X",
				summary : "pending-change protected "
			},
			"Fully protected" : {
				code : "p|X",
				summary : "fully protected "
			},
			"Move protected" : {
				code : "m|X",
				summary : "move protected "
			},
			"Creation protected" : {
				code : "t|X",
				summary : "creation protected "
			},
			"Template protected" : {
				code : "tp|X",
				summary : "template protected "
			},
			"Done" : {
				code : "do",
				summary : "done"
			},
			"Not done" : {
				code : "no",
				summary : "not done"
			},
			"Declined" : {
				code : "d",
				summary : "Declined. ",
				prompt : "Reason?"
			},
			"Declined nea" : {
				code : "nea",
				summary : "declined – not enough recent disruptive activity"
			},
			"Declined aiv" : {
				code : "aiv",
				summary : "declined – warn user and report to AIV"
			},
			"Declined np" : {
				code : "np",
				summary : "declined – pages are not protected preemptively"
			},
			"Declined nhr" : {
				code : "nhr",
				summary : "declined – not a high-risk template"
			},
			"Declined dr" : {
				code : "dr",
				summary : "declined – consider dispute resolution"
			},
			"Declined ut" : {
				code : "ut",
				summary : "declined – user talk pages not subject to severe vandalism"
			},
			"Declined her" : {
				code : "her",
				summary : "declined – edit rate too high for pending changes"
			},
			"Users blocked" : {
				code : "b",
				summary : "user(s) blocked"
			},
			"Users reblocked" : {
				code : "tb",
				summary : "user(s) re-blocked with talk page editing disallowed"
			},
			"Unprotected" : {
				code : "u",
				summary : "unprotected"
			},
			"Not unprotected" : {
				code : "nu",
				summary : "not unprotected"
			},
			"Already unprot'd" : {
				code : "au|X",
				summary : "already unprotected ",
				prompt : "Admin's name?"
			},
			"Already prot'd" : {
				code : "ap|X",
				summary : "already protected ",
				prompt : "Admin's name?"
			},
			"Already done" : {
				code : "ad|X",
				summary : "already done",
				prompt : "Admin's name?"
			},
			"Question" : {
				code : "q",
				summary : "question ",
				prompt : "Question:"
			},
			"Note" : {
				code : "n",
				summary : "note ",
				prompt : "Note:"
			},
			"Archive" : {
				code : "ar",
				summary : "request immediate archiving"
			},
			"Withdrawn" : {
				code : "w",
				summary : "withdrawn by requestor"
			},
			"Edit warring" : {
				code : "ew",
				summary : "consider the edit warring noticeboard"
			}
		};
	} else if(document.title.indexOf("Editing Wikipedia:Requests for permissions/Rollback (section)") !== -1) {
		indentation = "::";
		templateName = "subst:RFPR";
		defaultPrompt = "Admin's name?";
		responses = {
			"Done" : {
				code : "d",
				summary : "done"
			},
			"Already done" : {
				code : "ad|X",
				summary : "already done "
			},
			"Not done" : {
				code : "nd",
				summary : "not done ",
				prompt : "Reason?"
			},
			"Not done (exp)" : {
				code : "exp|X",
				summary : "not done: edit count too low ",
				prompt : "Number of mainsapce edits?"
			},
			"Not done (rvw)" : {
				code : "rvw",
				summary : "not done: recently requested reviewer"
			},
			"Not done (nrb)" : {
				code : "nrb",
				summary : "not done: not what rollback is for"
			}
		};
	} else if(document.title.indexOf("Editing Wikipedia:Administrator intervention against vandalism") !== -1) {
		indentation = "::";
		templateName = "AIV";
		inline = true;
		responses = {
			"Checking" : {
				code : "chk",
				summary : "checking"
			},
			"Warned user" : {
				code : "w",
				summary : "warned user"
			},
			"Insufficient activity" : {
				code : "i",
				summary : "insufficient recent activity to warrant a block"
			},
			"No vand since final" : {
				code : "f",
				summary : "no vandalism since final warning"
			},
			"No edits since warn" : {
				code : "nesw",
				summary : "no edits since being warned"
			},
			"Stale warning" : {
				code : "ow|X",
				summary : "Stale warning. ",
				prompt : "The last warning issued how long ago?"
			},
			"Monitoring" : {
				code : "m",
				summary : "actively monitoring user"
			},
			"Question" : {
				code : "q",
				summary : "Question. ",
				prompt : "Question:"
			},
			"WP:ANEW" : {
				code : "3rr",
				summary : "consider reporting to [[WP:ANEW]]"
			},
			"WP:AN/I" : {
				code : "a",
				summary : "consider reporting to [[WP:AN/I]]"
			},
			"WP:UAA" : {
				code : "u",
				summary : "consider reporting to [[WP:UAA]]"
			},
			"WP:RFPP" : {
				code : "r",
				summary : "consider reporting to [[WP:RFPP]]"
			},
			"WP:SPI" : {
				code : "sp",
				summary : "consider reporting to [[WP:SPI]]"
			},
			"Note" : {
				code : "n",
				summary : "Note. ",
				prompt : "Note:"
			},
			"IP not indef'd" : {
				code : "in",
				summary : "IPs are generally not blocked indefinitely"
			},
			"Shared IP" : {
				code : "s",
				summary : "Appears to be a shared IP"
			},
			"Declined" : {
				code : "dc",
				summary : "Declined. ",
				prompt : "Reason?"
			},
			"4im inappropriate" : {
				code : "4im",
				summary : "user inappropriate warned with 4im"
			},
			"Content dispute" : {
				code : "c",
				summary : "content dispute"
			},
			"Insufficient warn." : {
				code : "ns",
				summary : "User has been insufficiently warned"
			},
			"Not punitive" : {
				code : "np",
				summary : "blocks are preventive, not punitive"
			},
			"Not vandalism" : {
				code : "nv",
				summary : "edits are not vandalism"
			},
			"False postivie" : {
				code : "fp",
				summary : "false positive"
			},
			"Page deleted" : {
				code : "d",
				summary : "page deleted"
			},
			"Stale report" : {
				code : "e|X",
				summary : "Stale report. ",
				prompt : "How long since the user last edited?"
			},
			"Stale (was good)" : {
				code : "sn|X",
				summary : "Report was good but is now stale. ",
				prompt : "How long since the user last edited?"
			}
		};
	}
	
	var respondFn = function(e) {
		var response = e.data.response;
		var code = response.code, comment = "", value = "";
		
		if(code.indexOf("|X") !== -1) {
			value = prompt((response.prompt ? response.prompt : defaultPrompt) + " (optional, hit OK to omit)");
			if(value === null) return false;
			code = code.slice(0,(value.length ? -1 : -2)) + value;
		} else if(response.prompt) {
			value = prompt(response.prompt + " (optional, hit OK to omit)");
			if(value === null) return false;
			if(value.length) comment = " "+value;
		}
		
		var $textarea = $("#wpTextbox1");
		var currentText = $textarea.val();
		var responseStr = indentation + "{{"+templateName+"|" + code + "}}"+comment+" ~~~~";
		
		if(inline) {
			var caretPos = $textarea[0].selectionStart;
			$textarea.val(currentText.substring(0, caretPos) + responseStr + currentText.substring(caretPos));
		} else {
			$textarea.val(currentText + responseStr);
		}
		
		$("#wpSummary").val($("#wpSummary").val() + response.summary + value + " (using [[User:MusikAnimal/responseHelper|responseHelper]])");
	};
	
	for(var response in responses) {
		var id = responses[response].code.replace(/\W/g, '');
		mw.util.addPortletLink('p-navigation', 'javascript:', "("+response+")", "rh-"+id, responses[response].summary);
		$("#rh-"+id).click({
		  	response : responses[response]
		}, respondFn);
	}
}());
// </nowiki></pre>