User:Frigotoni/GSlinks.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
 * Script that adds several global sysop delete and block reasons to action=delete and Special:Block forms
 * 
 * Reasons provided by Mathonius and Trijnstel
 * Rewritten by [[User:Hoo man]]
 * Original script is visible at [[User:Snowolf/GS delete.js]]. This version has been rewritten again according to Frigotoni's wishes. 
 *
 * <nowiki>
 */
 
/*global mw*/
 
$(document).ready(function() {
	"use strict";
 
	if(mw.config.get('wgAction') !== 'delete' && mw.config.get('wgCanonicalSpecialPageName') !== 'Block') {
		return;
	}
 
	// Creates the html for a <optgroup> containing the given reasons
	function constructOptgroup( reasons ) {
		var html = '<optgroup label="Global sysop reasons">';
		for(var i = 0; i<reasons.length; i++) {
			html += mw.html.element('option', {'value' : reasons[i]}, reasons[i]);
		}
		html += '</optgroup>';
		return html;
	}
 
	// Reasons for both delete and block
	var additionalReasons = [
		"Spam ([[m:GS|global sysop]] action)",
		"Vandalism ([[m:GS|global sysop]] action)",
		"Cross-wiki spam ([[m:GS|global sysop]] action)",
                "Cross-wiki spam ([[m:User:Mathonius/Reports/Ntsamr|info]]) ([[:m:GS|global sysop]] action)"
	];
	// Reasons for delete only
	var additionalDelete = 
		additionalReasons.concat([
			"No meaningful content ([[m:GS|global sysop]] action)",
			"Test page ([[m:GS|global sysop]] action)",
			"Not written in this project's language ([[m:GS|global sysop]] action)",
			"Requested by the author ([[m:GS|global sysop]] action)",
			"Outside the project's scope ([[m:GS|global sysop]] action)"
		]);
	// Reasons for blocks only
	var additionalBlock =
		additionalReasons.concat([
			"Intimidating behaviour/harassment ([[m:GS|global sysop]] action)",
			"Cross-wiki issues ([[m:GS|global sysop]] action)",
			"Spam/advertizing-only account ([[m:No open proxies|more info]]) ([[m:GS|global sysop]] action)",
			"Cross-wiki spambot/Abused proxy IP ([[m:No open proxies|more info]]) ([[m:GS|global sysop]] action)"
		]);
	if(mw.config.get('wgAction') === 'delete') {
		// Append reasons to action=delete
		$('#wpDeleteReasonList').append(constructOptgroup(additionalDelete));
	}else{
		// Special:Block
		$('#mw-input-wpReason').append(constructOptgroup(additionalBlock));
		// Unselect the block reason and put it into the "Other:" field
		$('form input[type=submit]').click(
			function() {
				var blockReason =  '';
				if ( $('#mw-input-wpReason').val() !== 'other' ) {
					blockReason = $('#mw-input-wpReason').val();
				}
				if ( $('#mw-input-wpReason-other').val() ) {
					if ( blockReason ) {
						blockReason += ': ';
					}
					blockReason += $('#mw-input-wpReason-other').val();
				}
				$('#mw-input-wpReason-other').attr('value', blockReason);
				$('#mw-input-wpReason option').attr('selected', null);
				$('#mw-input-wpReason option').eq(0).attr('selected', 'selected');
			}
		);
	}
});
 
/* </nowiki> */