User:Snowolf/Stew delete.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 steward delete and block reasons to action=delete and Special:Block forms; it is meant to complement the GS one
 * 
 * Reasons provided by Mathonius and Trijnstel
 * Rewritten by [[User:Hoo man]]
 *
 * <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:Steward|Steward]] action)",
		"Vandalism ([[:m:Steward|Steward]] action)",
	];
	// Reasons for delete only
	var additionalDelete = 
		additionalReasons.concat([
			"No useful 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:Steward|Steward]] action)",
			"Cross-wiki issues ([[:m:Steward|Steward]] action)",
			"[[:w:Open proxy|Open proxy]] ([[:m:No open proxies|more info]]) ([[:m:Steward|Steward]] 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> */