User:MusikAnimal/responseHelper.js

This is an old revision of this page, as edited by MusikAnimal (talk | contribs) at 19:59, 14 December 2014. 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() {
	if(document.title.indexOf("Editing Wikipedia:Requests for page protection (section)") !== -1) {
		var 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 "
			},
			"Feedback protected" : {
				code : "fb|X",
				summary : "feedback 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"
			}
		};
		
		var respondFn = function(e) {
			var response = e.data.response;
			var code = response.code, value = "";
			
			if(code.indexOf("|X") !== -1) {
				value = prompt((response.prompt ? response.prompt : "Expiration date?") + " (optional)");
				code = code.slice(0,-1) + value;
			} else if(response.prompt) {
				value = prompt(response.prompt + " (optional)");
			}
			
			if(value === null) return false;
			
			$(".wikiEditor-ui-text textarea").val($(".wikiEditor-ui-text textarea").val() + ":{{RFPP|" + code + "}} "+value+" ~~~~");
			$("#wpSummary").val($("#wpSummary").val() + response.summary + value);
		};
		
		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>