User:Prtksxna/block.js

// 1. Find your common.js //       https://mediawiki.org/wiki/Special:MyPage/common.js

// 2. Add the following code to it: //       mw.loader.load('/w/index.php?title=User:Prtksxna/block.js&action=raw&ctype=text/javascript', 'text/javascript'); //       mw.loader.load('/w/index.php?title=User:Prtksxna/block.css&action=raw&ctype=text/css', 'text/css');

// 3. Go to Special:BlankPage (that is where we'll load the form) //       https://www.mediawiki.org/wiki/Special:BlankPage

// 4. ???

// 5. PROFIT!

mw.loader.using( 	[		'oojs', 		'oojs-ui-core', 		'oojs-ui-widgets', 		'oojs-ui.styles.icons-editing-core',		'moment',		'mediawiki.widgets.datetime',		'mediawiki.widgets.UserInputWidget',		'mediawiki.widgets.SelectWithInputWidget',		'mediawiki.widgets.expiry'	],	function {		if ( window.location.pathname === "/wiki/Special:BlankPage") {			updateTitle;			makeForm;		}		if ( window.location.pathname.indexOf("Special:Block") > -1 ) {			window.location.pathname = "/wiki/Special:BlankPage";		}	} );

function updateTitle { $('#firstHeading').text( 'Block user' ); }

function makeForm { var $c = $('#mw-content-text'); $c.empty.addClass('specialblock'); $c.text( 'Use the form below to block write access from a specific IP address or username. This should be done only to prevent vandalism, and in accordance with policy. Fill in a specific reason below (for example, citing particular pages that were vandalized). You can block IP address ranges using the CIDR syntax; the largest allowed range is /16 for IPv4 and /19 for IPv6.'); $c.append(' '); var user = new mw.widgets.UserInputWidget({		required: true	}); var create = new OO.ui.ButtonWidget( {		label: 'Create block',		flags: [		'primary',		'progressive'		]	} ); // Need this for the enabling/disabling functions var radio = getRadio; var r = radio[1]; var pages = multi( 'Pages', getPages, 'shift2 multipg', 'Select existing pages to prevent the user or IP from editing. The corresponding talk page and subpages are not automatically blocked.' ); var pg = pages[1]; pg.setDisabled( true ); var namespaces = multi( 'Namespaces', getNamespaces, 'shift2 multins', 'Select namespaces to prevent the user or IP from editing within.' ); var ns = namespaces[1]; pages[0].find('label').addClass( 'disabled-label' ); namespaces[0].find('label').addClass( 'disabled-label' ); ns.setDisabled( true ); var upload = check( 'Uploading files', false, 'shift2' ); var up = upload[1]; up.setDisabled( true ); var move = check( 'Moving pages', false, 'shift2' ); var mo = move[1]; mo.setDisabled( true ); var reason = getReason; var expiry = getExpiry;

$c.append( 		$(' ').text('Username or IP address').addClass( 'block' ).addClass( 'bold' ),		user.$element,		$(' ').text('Actions to block:').addClass( 'block' ).addClass( 'bold' ),		check( 'Editing', true )[0],		radio[0],		pages[0],		namespaces[0],		upload[0],		move[0],		check( 'Account creation', true )[0],		check( 'Sending email' )[0],		check( 'Editing their own talk page' )[0],		$(' ').text('Expiration:').addClass( 'block' ).addClass( 'bold' ),		expiry.$element,		$(' ').text('Reason:').addClass( 'block' ).addClass( 'bold' ),		reason.$element,		$(' ').text('Additional options:').addClass( 'block' ).addClass( 'bold' ),		check('Automatically block the last IP address used by this user, and any subsequent IP addresses they try to edit from', true, 'left-col')[0],		check('Watch this user‘s user and talk pages')[0],		'  ',		create.$element	); r.on('choose', function (v) {		var disabled = ( v.data === 's' ); // Disable on sitewide option		pg.setDisabled( disabled );		ns.setDisabled( disabled );		up.setDisabled( disabled );		mo.setDisabled( disabled );		pages[0].find('label').toggleClass( 'disabled-label', disabled );		namespaces[0].find('label').toggleClass( 'disabled-label', disabled );	} ); }

function wrap( $element, className ) { return $( ' ' ).addClass('wrap').addClass( className ).append( $element ); }

function getRadio { var option1 = new OO.ui.RadioOptionWidget( {   	data: 's',    	label: 'Sitewide'	} ); var helpEl1 = new OO.ui.PopupButtonWidget( {			icon: 'info',			framed: false,			popup: {				head: true,				label: 'Sitewide blocks prevent the user or IP from editing every page on the wiki and all other contribution actions.',				$content: $( 'Some help text' ),				padded: true,				align: 'force-right'			}		} ).$element; option1.$element.append(helpEl1);

var option2 = new OO.ui.RadioOptionWidget( {   	data: 'p',    	label: 'Partial'	} ); var helpEl2 = new OO.ui.PopupButtonWidget( {			icon: 'info',			framed: false,			popup: {				head: true,				label: 'Partial blocks can be configured to block the user or IP from editing certain pages and/or performing other contribution actions.',				$content: $( 'Some help text' ),				padded: true,				align: 'force-right'			}		} ).$element; option2.$element.append(helpEl2);

var radioSelect=new OO.ui.RadioSelectWidget( {   	items: [ option1, option2 ]	} ); radioSelect.selectItem(option1); radioSelect.$element.addClass( 'shift' ); return [ radioSelect.$element, radioSelect ]; }

function check( label, checked, className, help ) { var el, labelEl, helpEl; el = new OO.ui.CheckboxInputWidget({		selected: checked	});

if ( help ) { helpEl = new OO.ui.PopupButtonWidget( {			icon: 'info',			framed: false,			popup: {				head: true,				label: help,				padded: true,				align: 'force-right'			}		} ).$element; }	labelEl = $( ' ' ).text( label ); return [ wrap( [ el.$element, labelEl, helpEl ], className ), el ]; }

function multi( label, options, className, help ) { var el = new OO.ui.MenuTagMultiselectWidget( {		options: options	} ); var labelEl = $( ' ' ).text( label ); var helpEl = new OO.ui.PopupButtonWidget( {			icon: 'info',			framed: false,			popup: {				head: true,				label: help,				padded: true,				align: 'force-right'			}		} ).$element; return [wrap( [ labelEl, helpEl, el.$element ], className ), el]; } function getNamespaces { var namespaces = Object.keys(mw.config.get( 'wgNamespaceIds' )); namespaces = namespaces.filter( function (n) {		return n !== '';	} ); return namespaces.map( function ( n ) {		var name = toTitleCase( n.split( '_' ).join( ' ' ) );		return { data: name, label: name };	}); } function getPages { var pages = [ 'Main page', 'Get MediaWiki', 'Get extensions', 'Tech blog', 'Contribute', 'User help', 'FAQ', 'Technical manual', 'Support desk', 'Communication', 'Bug tracker', 'Code repository', 'Code docs', 'Statistics', 'Wikimedia technology', 'Wikimedia audiences', 'Community portal', 'Current issues' ];	return pages.map( function ( p ) {		return { data: p, name: p };	}); }

function getReason { return new mw.widgets.SelectWithInputWidget( {   	or: false,    	dropdowninput: {    	options: [	        { data: 'other', label: 'Other' },        	{ data: 'a', label: 'Inserting false information' },        	{ data: 'b', label: 'Removing content from pages' },        	{ data: 'c', label: 'Spammings links to external sites' },        	{ data: 'c', label: 'Inserting nonsense/gibberish into pages' },        	{ data: 'c', label: 'Intimidating behavior/harassment' },        	{ data: 'c', label: 'Abusing multiple accounts' },        	{ data: 'c', label: 'Unacceptable username' }    	]    	},    	textinput: {    	}	} ); }

function getExpiry { return new mw.widgets.ExpiryWidget({		noDatePicker: false,		RelativeInputClass: mw.widgets.SelectWithInputWidget,		relativeInput: {			or: true,			dropdowninput: {				options: [					{ data: 'c', label: '2 hours' },					{ data: 'c', label: '1 day' },					{ data: 'c', label: '3 days' },					{ data: 'c', label: '1 week' },					{ data: 'c', label: '2 weeks' },					{ data: 'c', label: '1 month' },					{ data: 'c', label: '3 months' },					{ data: 'c', label: '6 months' },					{ data: 'c', label: '1 year' },					{ data: 'c', label: 'Indefinite' },					{ data: 'other', label: 'Other time:' }				]			},			textinput: {				required: true			}		}	}); }

function toTitleCase(str) { return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase + txt.substr(1).toLowerCase;}); }