MediaWiki:Gadget-globalblockoptions.js

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.
function QuickGlobalBlock( settings ) {
	var globalBlockForm = document.forms[ 0 ];
	var inputs = globalBlockForm.getElementsByTagName( 'input' );
	for ( i = 0; i < inputs.length; i++ ) {
		var input = inputs[ i ],
			setting = settings[ input.name ];

		if ( input.type == 'checkbox' ) {
			input.checked = setting || false;
		} else {
			input.value = setting || null;
		}
	}
	globalBlockForm.submit();
}

function addGlobalBlockOptions() {
	var options = {
		'vandal: 31h (AO)': {
			'wpExpiry-other': '31 hours',
			'wpReason-other': 'recent vandalism',
			wpAnonOnly: true
		},
		'vandal: 1w': {
			'wpExpiry-other': '1 week',
			'wpReason-other': 'recent vandalism',
			wpAnonOnly: true
		},
		'vandal: 1m': {
			'wpExpiry-other': '1 month',
			'wpReason-other': 'chronic vandalism',
			wpAnonOnly: true
		},
		'xwiki: 3mo': {
			'wpExpiry-other': '3 months',
			'wpReason-other': 'cross-wiki abuse'
		},
		'op': {
			'wpExpiry-other': '1 year',
			'wpReason-other': '[[m:Special:MyLanguage/NOP|Open proxy]]',
			wpAlsoLocal: true
		},
		'vandal: 31h (hard)': {
			'wpExpiry-other': '31 hours',
			'wpReason-other': 'vandalism'
		}
	};

	$.each( options, function( k, obj ) {
		var node = mw.util.addPortletLink( 'p-cactions', '#', k );
		$( node ).on( 'click', function( e ) {
			e.preventDefault();
			QuickGlobalBlock( obj );
		} );
	} );
}

if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'GlobalBlock' ) {
	$.when(
		mw.loader.using( 'mediawiki.util' ),
		$.ready
	).then( addGlobalBlockOptions );
}