User:MusikAnimal/responseHelper.js

This is an old revision of this page, as edited by MusikAnimal (talk | contribs) at 17:37, 2 August 2015 (add handling for all WP:PERM pages). 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() {
	var responses = {}, inline = false, indentation = ":", templateName = "", defaultPrompt = "", anew = false, unresolved;
	
	// base responses for permission pages
	if(/Editing Wikipedia:Requests for permissions\/(?!Rollback|Confirmed).*\(section\)/.test(document.title)) {
		indentation = "::";
		templateName = "";
		defaultPrompt = "Reason?";
		responses = {
			"Done" : {
				code : "done",
				summary : "done"
			},
			"Not done" : {
				code : "not done",
				summary : "Not done. ",
				prompt : "Reason?"
			},
			"Comment" : {
				code : "comment",
				summary : "Comment. ",
				prompt : "Comment:"
			},
			"Admin note" : {
				code : "administrator note",
				summary : "Admin note. ",
				prompt : "Administrator note:"
			}
		};
	} 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: mainspace edit count too low ",
				prompt : "Number of mainspace edits?"
			},
			"Not done (rvw)" : {
				code : "rvw",
				summary : "not done: recently requested pending changes reviewer"
			},
			"Not done (nrb)" : {
				code : "nrb",
				summary : "not done: not what rollback is for"
			}
		};
	} else if(document.title.indexOf("Editing Wikipedia:Requests for permissions/Confirmed (section)") !== -1) {
		indentation = "::";
		templateName = "subst:RFPC";
		responses = {
			"Done" : {
				code : "d",
				summary : "done"
			},
			"Already done" : {
				code : "ad",
				summary : "already done"
			},
			"Not done" : {
				code : "nd",
				summary : "not done ",
				prompt : "Reason?"
			},
			"Not done (file)" : {
				code : "ndf",
				summary : "not done: you should upload to commons or request at [[WP:FFU]]"
			},
			"Not done (promoblock)" : {
				code : "ndpromou",
				summary : "not done: blocked for having a promotional username"
			},
			"Not done (no reply)" : {
				code : "ndnr",
				summary : "not done: no response to inquiry"
			},
			"Not done (per above)" : {
				code : "ndpa",
				summary : "not done: as explained by others"
			},
			"Not done (IP)" : {
				code : "ip",
				summary : "not done: anonymous users cannot be granted additional rights"
			},
			"Question - why?" : {
				code : "why",
				summary : "question: why do you think you are not confirmed?"
			}
		};
	} else 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: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 protected" : {
				code : "p",
				summary : "page protected"
			},
			"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?"
			}
		};
	} else if(document.title.indexOf("Editing Wikipedia:Administrators' noticeboard/Edit warring (section)") !== -1) {
		anew = true;
		indentation = "*";
		templateName = "AN3";
		defaultPrompt = "Duration?";
		responses = {
			"Blocked" : {
				code : "b|X",
				summary : "blocked "
			},
			"Nom. blocked" : {
				code : "nb|X",
				summary : "nominator blocked "
			},
			"Both blocked" : {
				code : "bb|X",
				summary : "both blocked "
			},
			"Already blocked" : {
				code : "ab",
				summary : "already blocked"
			},
			"No violation" : {
				code : "nv",
				summary : "no violation"
			},
			"No 3RR vio" : {
				code : "nve",
				summary : "three-revert rule not applicable"
			},
			"Stale" : {
				code : "s",
				summary : "stale"
			},
			"Declined" : {
				code : "d",
				summary : "declined ",
				prompt : "Reason?"
			},
			"Malformed report" : {
				code : "mr",
				summary : "declined – malformed report"
			},
			"Not blocked" : {
				code : "not",
				summary : "not blocked"
			},
			"Page protected" : {
				code : "p",
				summary : "page protected"
			},
			"Page prot'd dr" : {
				code : "pe",
				summary : "page protected – consider dispute resolution"
			},
			"Warned" : {
				code : "w",
				summary : "warned user(s)"
			},
			"Note" : {
				code : "n",
				summary : "Note. ",
				prompt : "Note:",
				unresolved : true
			},
			"Comment" : {
				code : "c",
				summary : "Comment. ",
				prompt : "Comment:",
				unresolved : true
			}
		};
	} else if(document.title.indexOf("Editing Wikipedia:Usernames for administrator attention") !== -1) {
		indentation = "::";
		templateName = "UAA";
		defaultPrompt = "Reason?";
		inline = true;
		responses = {
			"Note" : {
			  code : "n",
			  summary : "Note. ",
			  prompt : "Note:"
			},
			"Question" : {
			  code : "q",
			  summary : "Question. ",
			  prompt : "Question: "
			},
			"Comment" : {
			  code : "c",
			  summary : "Comment. ",
			  prompt : "Comment:"
			},
			"Wait" : {
			  code : "w",
			  summary : "Wait until the user edits"
			},
			"Monitor" : {
			  code : "m",
			  summary : "Keep monitoring the user, until their username is more clear."
			},
			"Being discussed" : {
			  code : "d",
			  summary : "Being discussed with the user"
			},
			"Discussed, const. edits" : {
			  code : "dc",
			  summary : "Being discussed with the user, since they have edited constructively."
			},
			"AfC-only edits" : {
			  code : "a",
			  summary : "Only edits are to AfC submission. Please discuss this with the user first and re-report if necessary."
			},
			"Requested change" : {
			  code : "rc",
			  summary : "User has requested a username change."
			},
			"Problem" : {
			  code : "p",
			  summary : "Problem: This account does not exist or may be hidden"
			},
			"Stale" : {
			  code : "s",
			  summary : "Stale: Account has not been used in the last 2-3 weeks"
			},
			"Not violation" : {
			  code : "not",
			  summary : "Not a blatant violation of the username policy."
			},
			"Not vio, real name" : {
			  code : "real",
			  summary : "Not a violation of the username policy as real name, consider [[WP:COI/N]]"
			},
			"Not vio, watch edits" : {
			  code : "e",
			  summary : "Not a blatant violation of the username policy, but worth keeping an eye on their edits."
			},
			"Not voi, COI" : {
			  code : "coi",
			  summary : "Not a blatant violation of the username policy. Consider filing a report at the [[WP:COI/N]]."
			},
			"Not vio, RFCN" : {
			  code : "r",
			  summary : "Not a blatant violation of the username policy. Please discuss this with the user or at [[WP:RFCN]] if necessary"
			}
		};
	} else {
		mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Administrator intervention against vandalism', "WP:AIV");
		mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Administrators%27 noticeboard/Edit warring', "WP:ANEW");
		mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Requests for permissions', "WP:PERM");
		mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Requests for page protection', "WP:RFPP");
		mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Usernames for administrator attention', "WP:UAA");
	}
	
	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 ? 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);
		}
		
		if(anew && !unresolved) {
			var textArray = $textarea.val().split("\n");
			$textarea.val(
				textArray[0].replace('(Result: )','(Result: ' + (response.summary[0].toUpperCase() + response.summary.slice(1) + value).trim() + ')') +
				'\n' + $textarea.val().split("\n").splice(1).join("\n")
			);
		}
		
		$("#wpSummary").val($("#wpSummary").val() + (response.summary + value).trim() + " (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>