The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* <nowiki> */
/* Bharat Mitra: block module (administrators only) */
( function () {
	'use strict';
	var BM = window.BharatMitra;
	var EXPIRIES = [
		[ '1 hour', '1 hour' ], [ '1 day', '1 day' ], [ '1 week', '1 week' ],
		[ '1 month', '1 month' ], [ '3 months', '3 months' ], [ 'indefinite', 'Indefinite' ]
	];
	function buildNotice( v ) {
		/* Template:Uw-block takes |time= (duration text), |reason=, |indef=yes,
		   |anon=yes and |sig=yes (adds the signature itself) */
		var name = String( v.username || '' ).trim();
		var out = '{{subst:uw-block';
		if ( v.expiry === 'indefinite' ) {
			out += '|indef=yes';
		} else {
			out += '|time=' + v.expiry;
		}
		out += '|reason=' + BM.core.cleanParam( v.reason );
		if ( mw.util.isIPAddress( name ) ) { out += '|anon=yes'; }
		out += '|sig=yes}}';
		return out;
	}
	BM.register( 'block', {
		open: function () {
			var user = BM.targetUser() || '';
			BM.core.dialog( {
				title: 'Block user',
				help: 'After the block, a notice will automatically be posted on the user\'s talk page. This action is for administrators only.',
				fields: [
					{ name: 'username', label: 'User name', type: 'text', value: user, required: true },
					{ name: 'expiry', label: 'Duration', type: 'select', required: true, options: EXPIRIES, value: '1 week' },
					{ name: 'reason', label: 'Reason', type: 'text', required: true },
					{ name: 'nocreate', label: 'Also block new account creation', type: 'checkbox', value: true },
					{ name: 'talkBlock', label: 'Also block editing their own talk page', type: 'checkbox', value: false }
				],
				preview: function ( v ) { return buildNotice( v ); },
				previewTitle: function ( v ) { return 'User talk:' + String( v.username || '' ).trim(); },
				submitLabel: 'Block',
				success: 'Block applied and notice sent.',
				onSubmit: function ( v ) {
					var name = String( v.username || '' ).trim();
					var params = {
						action: 'block', user: name, expiry: v.expiry,
						reason: BM.core.cleanParam( v.reason ), format: 'json'
					};
					if ( v.nocreate ) { params.nocreate = 1; }
					if ( !v.talkBlock ) { params.allowusertalk = 1; }
					return BM.core.api().postWithToken( 'block', params ).then( function ( r ) {
						if ( !( r && r.block ) ) { throw new Error( 'The block could not be applied.' ); }
						var block = buildNotice( v );
						return BM.core.appendUnderMonth( 'User talk:' + name, block,
							'Block notice (using [[Bharatpedia:Bharat Mitra|Bharat Mitra]])' ).catch( function () {
							throw new Error( 'The block was applied, but the notice could not be sent.' );
						} );
					} );
				}
			} );
		}
	} );
}() );
/* </nowiki> */