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: protection request module */
( function () {
	'use strict';
	var BM = window.BharatMitra;
	var BOARD = 'Bharatpedia:Requests for page protection';
	var SECTION = 'Current requests for increase in protection level';
	function levelLabel( level ) {
		if ( level.indexOf( 'autoconfirmed' ) !== -1 ) { return 'Semi-protection'; }
		if ( level.indexOf( 'Move only' ) !== -1 ) { return 'Move protection'; }
		return 'Full protection';
	}
	function buildEntry( v ) {
		var reason = String( v.reason || '' ).replace( /\r\n/g, '\n' ).trim();
		if ( reason && !/[.!?]$/.test( reason ) ) { reason += '.'; }
		return '\'\'\'' + levelLabel( v.level ) + ':\'\'\' ' + reason +
			' \'\'\'Duration:\'\'\' ' + v.duration + '. ' + BM.SIG;
	}
	function buildBlock( v ) {
		var page = BM.core.cleanParam( v.page );
		return '=== [[' + page + ']] ===\n* {{pagelinks|' + page + '}}\n' + buildEntry( v );
	}
	function fileRequest( v ) {
		var page = BM.core.cleanParam( v.page );
		return BM.core.getPage( BOARD ).then( function ( p ) {
			if ( !p.exists ) { throw new Error( 'The protection request board could not be read.' ); }
			var content = p.content;
			var secHead = '== ' + SECTION + ' ==';
			var secIdx = content.indexOf( secHead );
			if ( secIdx === -1 ) { throw new Error( 'Could not find the "' + SECTION + '" section on the board.' ); }
			var secEnd = content.indexOf( '\n== ', secIdx + secHead.length );
			if ( secEnd === -1 ) { secEnd = content.length; }
			var section = content.slice( secIdx, secEnd );
			var entry = buildEntry( v );
			var subIdx = section.indexOf( '=== [[' + page + ']] ===' );
			if ( subIdx === -1 ) { subIdx = section.indexOf( '===[[' + page + ']]===' ); }
			var out;
			if ( subIdx !== -1 ) {
				var subEnd = section.indexOf( '\n===', subIdx + 5 );
				if ( subEnd === -1 ) { subEnd = section.length; }
				out = content.slice( 0, secIdx ) +
					section.slice( 0, subEnd ).replace( /\s+$/, '' ) + '\n' + entry + '\n' +
					section.slice( subEnd ) + content.slice( secEnd );
			} else {
				out = content.slice( 0, secIdx ) +
					section.replace( /\s+$/, '' ) + '\n\n' + buildBlock( v ) + '\n' +
					content.slice( secEnd );
			}
			return BM.core.savePage( BOARD, out, 'Page protection request (using [[Bharatpedia:Bharat Mitra|Bharat Mitra]])', p.revid );
		} );
	}
	BM.register( 'protect', {
		open: function () {
			var title = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' );
			BM.core.dialog( {
				title: 'Request page protection',
				help: 'The request will be added to the "Current requests for increase in protection level" section of Bharatpedia:Requests for page protection, in the standard format used there. An administrator will apply the protection.',
				fields: [
					{ name: 'page', label: 'Page', type: 'text', value: title, required: true },
					{ name: 'level', label: 'Protection level', type: 'select', required: true, options: [
						[ 'Edit and move: autoconfirmed users only', 'Autoconfirmed users only (edit and move)' ],
						[ 'Edit and move: administrators only', 'Administrators only (edit and move)' ],
						[ 'Move only: administrators only', 'Move only: administrators' ]
					] },
					{ name: 'duration', label: 'Duration', type: 'select', required: true, options: [
						[ '1 week', '1 week' ], [ '1 month', '1 month' ], [ '3 months', '3 months' ], [ 'Indefinite', 'Indefinite' ]
					], value: '1 month' },
					{ name: 'reason', label: 'Reason', type: 'textarea', rows: 3, required: true }
				],
				preview: function ( v ) { return buildBlock( v ); },
				previewTitle: function () { return BOARD; },
				submitLabel: 'Send request',
				success: 'Protection request added.',
				onSubmit: function ( v ) {
					return fileRequest( v );
				}
			} );
		}
	} );
}() );
/* </nowiki> */