Jump to content

User:Oshwah/ResponseHelper.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Oshwah (talk | contribs) at 00:01, 20 August 2017 (Fix link). 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;

	// show shortcuts if not editing
	if (!mw.config.get('wgEditMessage')) 
    {
        mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Special:BlankPage/RTRC',"Recent changes - LIVE");
        mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Special:Massblock',"Block multiple users");
        mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Special:MassUnblock',"Unblock multiple users");
                mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Special:NewPages',"New page logs");
        mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/w/index.php?title=Special%3ALog&type=newusers&user=&page=&year=&month=-1&tagfilter=&subtype=create', "New user logs");
        mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/w/index.php?title=Special%3ALog&type=spamblacklist', "Spam blacklist logs");
		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/Category:Requests for unblock', "WP:RFU");
		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");
		//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:Administrators%27 noticeboard/Edit warring', "WP:AN3");
		mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Administrators\' noticeboard/Incidents', "WP:ANI");
		mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Sockpuppet investigations', "WP:SPI");
        mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Arbitration Committee', "WP:ARB");
		return;
	}

	if (/Wikipedia:Administrator_intervention_against_vandalism/.test(mw.config.get('wgPageName'))) 
    {
		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 positive" : {
				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 (/Wikipedia:Usernames_for_administrator_attention/.test(mw.config.get('wgPageName'))) 
	{
		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."
			},
			"Changed username" : {
				code : "ch",
				summary : "User has changed their username."
			},
			"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"
			},
			"False positive" : {
				code: "fp",
				summary: "False positive by bot. Username is not a blatant violation of the username policy"
			}
		};
	}
	else if (mw.config.get('wgEditMessage') === 'editingsection') 
	{
		if (/Wikipedia:Requests_for_permissions\/(?!Rollback|Confirmed|Page_mover)/.test(mw.config.get('wgPageName'))) 
		{
			// base responses for permission pages
			indentation = "::";
			templateName = "";
			defaultPrompt = "Reason?";
			responses = 
			{
				"Done" : {
					code : "done",
					summary : "done"
				},
				"Not done" : {
					code : "not done",
					summary : "Not done. ",
					prompt : "Reason?"
				},
				"Revoked" : {
					code : "revoked",
					summary : "Revoked. "
				},
				"Comment" : {
					code : "comment",
					summary : "Comment. ",
					prompt : "Comment:"
				},
				"Admin note" : {
					code : "administrator note",
					summary : "Admin note. ",
					prompt : "Administrator note:"
				}
			};
		}
		else 
			switch (mw.config.get('wgPageName')) 
			{
				case 'Wikipedia:Requests_for_permissions/Rollback':
					indentation = "::";
					templateName = "subst:RFPR";
					defaultPrompt = "Admin's name?";
					responses = 
					{
						"Done" : {
							code : "d",
							summary : "done"
						},
						"Already done" : {
							code : "ad|X",
							summary : "already done "
						},
						"Revoked" : {
							code : "r",
							summary : "revoked"
						},
						"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"
						}
					};
					break;
				case 'Wikipedia:Requests_for_permissions/Confirmed':
					indentation = "::";
					templateName = "subst:RFPC";
					responses = 
					{
						"Done" : {
							code : "d",
							summary : "done"
						},
						"Already done" : {
							code : "ad",
							summary : "already done",
							id : "adc"
						},
						"Revoked" : {
							code : "r",
							summary : "revoked"
						},
						"Not done" : {
							code : "nd",
							summary : "not done ",
							prompt : "Reason?"
						},
						"Not done (95%)" : {
							code : "nd95",
							summary : "not done: please wait, 95% of articles are unprotected"
						},
						"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?"
						}
					};
					break;
				case 'Wikipedia:Requests_for_permissions/Page_mover':
					indentation = "::";
					templateName = "subst:RFPPM";
					responses = 
					{
						"Done" : {
							code : "d",
							summary : "done"
						},
						"Already done" : {
							code : "ad",
							summary : "already done",
							id : "adc"
						},
						"Revoked" : {
							code : "r",
							summary : "revoked"
						},
						"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 total edits?"
						},
						"Not done (npm)" : {
							code : "npm",
							summary : "not done: not what page mover is for"
						}
					};
					break;
				case 'Wikipedia:Requests_for_page_protection':
					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-changes 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 "
						},
						"EC protected" : {
							code : "ec|X",
							summary : "extended confirmed 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 by administrator ",
							prompt : "Admin's name?"
						},
						"Already prot'd" : {
							code : "ap|X",
							summary : "already protected by administrator ",
							prompt : "Admin's name?"
						},
						"Already done" : {
							code : "ad|X",
							summary : "already done by administrator ",
							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 requester"
						},
						"Edit warring" : {
							code : "ew",
							summary : "consider the edit warring noticeboard"
						}
					};
					break;
				case "Wikipedia:Administrators'_noticeboard/Edit_warring":
					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
						}
					};
					break;
			}
	}

	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());
	};

	for (var response in responses) 
	{
		var id = responses[response].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>