Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.


Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.

/* jshint sub:true maxerr: 10000 */
/**
 * Tool for mass-blocking a list of IPs/users.
 * Adapted from [[:en:User:Timotheus Canens/massblock.js]].
 * Go to [[Special:Massblock]] to use it.
 * Overwrite values in getLocalMessage to localize.
 *
 * @todo Handle async loop nicely, protection doesn't work, use azioni-dopo-blocco.js, edit and protect numbers aren't updated.
 */
( function( mw, $ ) {
	// OOUI element
	var submitBtn,
		// Like wgBlockAllowsUTEdit
		blockAllowsTalkEdit;

	// To add local messages change the values of this variables.
	localMsg = {
		'document-title': 'Il mass-blocker attira-trote',
		'page-title': 'L\'attira-trote',
		'abuse-disclaimer': '<b>Se abusi di questo strumento, è colpa tua e non mia!</b>',
		'basic-data': 'Dati di base',
		'blockusers': 'Utenti da bloccare (uno per riga):',
		'talkmsg': 'Sostituisci la talk con, oppure aggiungi alla talk se il blocco non è infinito (lasciare vuoto per non modificare la talk):',
		'upmsg': 'Sostituisci la pagina utente con (lasciare vuoto per non modificare la pagina utente):',
		'block-options-label': 'Opzioni del blocco',
		'further-options-label': 'Altre opzioni',
		'common-reasons': 'Motivazioni comuni:',
		'other-reason': 'Altra motivazione',
		'extra-reason': 'Motivazione aggiuntiva:',
		'exptime': 'Durata del blocco, in inglese (lasciare vuoto per blocco infinito):',
		'summary-default': 'Utente bloccato.',
		'talksummary': 'Oggetto per la modifica della talk:',
		'talkprotect': 'Proteggi la talk:',
		'upsummary': 'Oggetto per la modifica della pagina utente:',
		'upprotect': 'Proteggi la pagina utente:',
		'protect-reason-label': 'Motivazione per la protezione:',
		'protect-reason-default': 'Utente bloccato.',
		'anononly': 'Blocca solo utenti anonimi:',
		'autoblock': 'Attiva autoblocco (solo per utenti registrati):',
		'nocreate': 'Blocca la creazione di utenze:',
		'noemail': 'Blocca email:',
		'notalk': 'Blocca anche la modifica della talk:',
		'override': 'Sovrascrivi eventuali blocchi:',
		'submit-text': 'Scatena l\'inferno!',
		'result-alert': 'Bloccati $1 utenti. Modificate $2 talk e $3 pagine utente. Protette $4 talk e $5 pagine utente.',
		'failed-actions': 'Azioni non riuscite e relativi errori:',
		'failure-help': 'aiuto'
	};

	/**
	 * Main form processing routine, called on form submit
	 */
	function doMassBlock() {
		var users = $( "#wpMassBlockUsers textarea" ).val().split( "\n" );

		// First trim everything
		users = users.map( function( s ) {
			return s.trim();
		} );
		// Then remove blanks and duplicates
		users = users.filter( function( el, index, me ) {
			return el !== '' && me.indexOf( el ) === index;
		} );
		if ( users.length === 0 ) {
			// Easy
			return;
		}
		submitBtn.setDisabled( true );

		var wpMassBlockReasons = $( "#wpMassBlockReasons select :selected" ).val().trim(),
			wpMassBlockReason = $( "#wpMassBlockReason input" ).val().trim(),
			blocked = 0,
			talkpageedited = 0,
			userpageedited = 0,
			talkpageprotected = 0,
			userpageprotected = 0,
			failed = [],
			error = [];
		var wpMassBlockAnononly = $( "#wpMassBlockAnononly input" ).prop( 'checked' ),
			wpMassBlockNocreate = $( "#wpMassBlockNocreate input" ).prop( 'checked' ),
			wpMassBlockEmail = $( "#wpMassBlockEmail input" ).prop( 'checked' ),
			wpMassBlockAutoblock = $( "#wpMassBlockAutoblock input" ).prop( 'checked' ),
			wpMassBlockTalkpage = blockAllowsTalkEdit ? $( "#wpMassBlockTalkpage input" ).prop( 'checked' ) : false,
			wpMassBlockReblock = $( "#wpMassBlockReblock input" ).prop( 'checked' );
		var wpMassBlockMessage = $( "#wpMassBlockMessage textarea" ).val().trim(),
			wpMassBlockTag = $( "#wpMassBlockTag textarea" ).val().trim(),
			wpMassBlockExpiry = $( "#wpMassBlockExpiry input" ).val().trim();
		var wpMassBlockSummaryTalk = $( "#wpMassBlockSummaryTalk input" ).val().trim(),
			wpMassBlockSummaryUser = $( "#wpMassBlockSummaryUser input" ).val().trim(),
			wpMassBlockProtectTalk = $( "#wpMassBlockProtectTalk input" ).prop( 'checked' ),
			wpMassBlockProtectUser = $( "#wpMassBlockProtectUser input" ).prop( 'checked' );

		var isInfty = isInfinity( wpMassBlockExpiry );
		var deferreds = [];

		var errorHandler = function( error, user ) {
			failed.push( "Special:Block/" + user );
			error.push( e );
		};

		var successHandler = function( response ) {
			let user = response.block.user;

			blocked++;
			if ( wpMassBlockMessage !== "" ) {
				deferreds.push(
					doEditPage( 'User talk:' + user, wpMassBlockMessage, wpMassBlockSummaryTalk, !isInfty )
					.done( function( data ) {
						talkpageedited++;
					} )
					.fail( function( e ) {
						errorHandler( e, user );
					} ) );
			}
			if ( !isInfty ) {
				// No pages should be protected, and the UP should be left as is
				return;
			}

			if ( wpMassBlockProtectTalk ) {
				deferreds.push(
					doProtectPage( 'User talk:' + user )
					.done( function( data ) {
						talkpageprotected++;
					} )
					.fail( function( e ) {
						errorHandler( e, user );
					} ) );
			}
			if ( wpMassBlockTag !== "" ) {
				deferreds.push(
					doEditPage( 'User:' + user, wpMassBlockTag, wpMassBlockSummaryUser )
					.done( function( data ) {
						userpageedited++;
					} )
					.fail( function( e ) {
						errorHandler( e, user );
					} ) );
			}
			if ( wpMassBlockProtectUser ) {
				deferreds.push(
					doProtectPage( 'User:' + user )
					.done( function( data ) {
						userpageprotected++;
					} )
					.fail( function( e ) {
						errorHandler( e, user );
					} ) );
			}

		};

		for ( i = 0; i < users.length; i++ ) {
			let user = users[ i ];

			deferreds.push(
				new mw.Api().postWithToken( "csrf", {
					action: 'block',
					allowusertalk: wpMassBlockTalkpage,
					autoblock: wpMassBlockAutoblock,
					nocreate: wpMassBlockNocreate,
					expiry: wpMassBlockExpiry === "" ? "indefinite" : wpMassBlockExpiry,
					anononly: wpMassBlockAnononly,
					noemail: wpMassBlockEmail,
					reblock: wpMassBlockReblock,
					reason: wpMassBlockReasons === "other" ? wpMassBlockReason : wpMassBlockReasons + ( wpMassBlockReason ? ": " + wpMassBlockReason : "" ),
					user: user
				} )
				.done( successHandler )
				.fail( function( e ) {
					errorHandler( e, user );
				} ) );
		}

		$.when( ...deferreds ).always( function() {
			doPostBlockActions( failed, error );
			OO.ui.alert(
				msg( 'result-alert' ).replace( '$1', blocked ).replace( '$2', talkpageedited ).replace( '$3', userpageedited )
				.replace( '$4', talkpageprotected ).replace( '$5', userpageprotected )
			);
		} );
	}

	/**
	 * Executed after all users have been processed.
	 */
	function doPostBlockActions( failed, error ) {
		if ( failed.length > 0 ) {
			var linkedList = "";

			for ( x = 0; x < failed.length; x++ ) {
				//Links the titles in the "failed" array
				linkedList += "<li><a href=\"" + mw.config.get( 'wgScript' ) + "?title=" + encodeURIComponent( failed[ x ] ) + "\">" + failed[ x ] + "</a>: <code style=\"color:red\">" + error[ x ] + "</code></li>";
			}
			$( "#wpMassBlockFailedContainer" ).html(
				'<br /><b>' + msg( 'failed-actions' ) + '</b> ' +
				'(<a href="//www.mediawiki.org/wiki/API:Block#Possible_errors">' + msg( 'failure-help' ) + '</a>)' +
				'<ul>' + linkedList + '</ul>'
			);
		}
	}

	/**
	 * Edit the given page
	 */
	function doEditPage( title, text, summary, append ) {
		var appendText = append || false,
			params = {
				action: 'edit',
				title: title,
				summary: summary,
				watchlist: 'nochange'
			};
		if ( appendText ) {
			params.appendtext = text;
		} else {
			params.text = text;
		}
		return new mw.Api().postWithEditToken( params );
	}

	/**
	 * Protect the given page
	 */
	function doProtectPage( title ) {
		return new mw.Api().postWithToken( 'csrf', {
			action: 'protect',
			title: title,
			protections: 'edit=sysop|move=sysop|create=sysop',
			reason: $( "#wpMassBlockProtectReason input" ).val().trim(),
			watchlist: 'nochange',
			format: 'json',
		} );
	}

	var defaultMsg = {
		'document-title': 'Tim\'s mass-blocking tool - Wikipedia, the free encyclopedia',
		'page-title': 'Tim\'s mass-blocking tool',
		'abuse-disclaimer': '<b>If you abuse this tool, it\'s <i>your</i> fault, not mine.</b>',
		'basic-data': 'Basic data',
		'blockusers': 'Users to block (one on each line, please):',
		'talkmsg': 'Replace talk page with, or text to add if the expiry is not infinite (leave blank to leave no message):',
		'upmsg': 'Replace user page text with (leave blank for no change):',
		'block-options-label': 'Block options',
		'further-options-label': 'Further options',
		'common-reasons': 'Common reasons:',
		'other-reason': 'Other reason',
		'extra-reason': 'Other/additional reason:',
		'exptime': 'Expiration time, in english (blank for indefinite):',
		'summary-default': 'Blocked user.',
		'talksummary': 'Edit summary for talk page edit:',
		'talkprotect': 'Protect the talk (sysop level, infinite):',
		'upsummary': 'Edit summary for user page edit:',
		'upprotect': 'Protect the user page (sysop level, infinite):',
		'protect-reason-label': 'Reason for protection:',
		'protect-reason-default': 'Blocked user.',
		'anononly': 'Block anonymous users only (IPs only):',
		'autoblock': 'Enable autoblock (accounts only):',
		'nocreate': 'Block account creation:',
		'noemail': 'Block email:',
		'notalk': 'Remove talk page access:',
		'override': 'Override existing blocks:',
		'submit-text': 'Block',
		'result-alert': 'Blocked $1 users. Edited $2 talk pages and $3 user pages. Protected $4 talk pages and $5 user pages.',
		'failed-actions': 'Failed actions with errors:',
		'failure-help': 'help',
	};
	/**
	 * Get a localised messages, or the default one as fallback.
	 */
	function msg( msg ) {
		return localMsg[ msg ] || defaultMsg[ msg ];
	}

	/**
	 * Build the form
	 */
	function massblockform() {
		var reasons = mw.msg( 'Ipbreason-dropdown' ).split( '\*\*' ),
			// OOUI elements
			userTextField, talkProtectCb, userSummaryField, userProtectCb, protectReasonField;

		// Ideally this would use $wgBlockAllowsUTEdit, but it's not available.
		blockAllowsTalkEdit = window.___location.href.indexOf( 'it.wikipedia' ) === -1;

		document.getElementsByTagName( "h1" )[ 0 ].textContent = msg( 'page-title' );
		document.title = msg( 'document-title' );

		var form = new OO.ui.FormLayout( {
			id: 'wpMassBlock'
		} );

		var basicFieldset = new OO.ui.FieldsetLayout( {
			label: msg( 'basic-data' ),
			items: [
				new OO.ui.FieldLayout(
					new OO.ui.MultilineTextInputWidget( {
						rows: 10
					} ), {
						label: msg( 'blockusers' ),
						align: 'top',
						id: 'wpMassBlockUsers'
					}
				),
				new OO.ui.FieldLayout(
					new OO.ui.MultilineTextInputWidget( {
						rows: 10
					} ), {
						label: msg( 'talkmsg' ),
						align: 'top',
						id: 'wpMassBlockMessage'
					}
				)
			]
		} );

		userTextField =
			new OO.ui.MultilineTextInputWidget( {
				rows: 10
			} );

		basicFieldset.addItems( [
			new OO.ui.FieldLayout( userTextField, {
				label: msg( 'upmsg' ),
				align: 'top',
				id: 'wpMassBlockTag'
			} )
		] );

		var reasonOpts = [ {
				optgroup: msg( 'other-reason' )
			},
			{
				data: 'other',
				label: msg( 'other-reason' )
			},
			{
				optgroup: msg( 'common-reasons' )
			}
		];
		for ( var i = 1, j = reasons.length; i < j; i++ ) {
			reasonOpts.push( {
				data: reasons[ i ],
				label: reasons[ i ]
			} );
		}

		var expiryField = new OO.ui.TextInputWidget( {
			maxLength: 255,
			id: 'wpMassBlockExpiry'
		} );

		var otherReasonField = new OO.ui.TextInputWidget( {
			maxLength: 255,
			id: 'wpMassBlockReason'
		} );

		var reasonsDropdown = new OO.ui.DropdownInputWidget( {
			options: reasonOpts,
			id: 'wpMassBlockReasons'
		} ).on( 'change', function() {
			var reason = reasonsDropdown.getValue(),
				maxlength = ( reason === "other" ? 255 : ( 255 - ': '.length ) - reason.length );

			$( '#wpMassBlockReason input' ).attr( "maxlength", maxlength );
		} );


		var blockOptsArray = [
			new OO.ui.FieldLayout(
				reasonsDropdown, {
					label: msg( 'common-reasons' )
				}
			),

			new OO.ui.FieldLayout(
				otherReasonField, {
					label: msg( 'extra-reason' )
				}
			),

			new OO.ui.FieldLayout( expiryField, {
				label: msg( 'exptime' )
			} ),

			new OO.ui.FieldLayout(
				new OO.ui.CheckboxInputWidget( {
					id: 'wpMassBlockAnononly'
				} ), {
					label: msg( 'anononly' )
				}
			),
			new OO.ui.FieldLayout(
				new OO.ui.CheckboxInputWidget( {
					id: 'wpMassBlockAutoblock',
					selected: true
				} ), {
					label: msg( 'autoblock' )
				}
			),
			new OO.ui.FieldLayout(
				new OO.ui.CheckboxInputWidget( {
					id: 'wpMassBlockNocreate',
					selected: true
				} ), {
					label: msg( 'nocreate' )
				}
			),
			new OO.ui.FieldLayout(
				new OO.ui.CheckboxInputWidget( {
					id: 'wpMassBlockEmail'
				} ), {
					label: msg( 'noemail' )
				}
			)
		];

		if ( blockAllowsTalkEdit ) {
			blockOptsArray.push( new OO.ui.FieldLayout(
				new OO.ui.CheckboxInputWidget( {
					id: 'wpMassBlockTalkpage'
				} ), {
					label: msg( 'notalk' )
				}
			) );
		}

		blockOptsArray.push( new OO.ui.FieldLayout(
			new OO.ui.CheckboxInputWidget( {
				id: 'wpMassBlockReblock',
				selected: true
			} ), {
				label: msg( 'override' )
			}
		) );

		var blockOpts = new OO.ui.FieldsetLayout( {
			label: msg( 'block-options-label' ),
			items: blockOptsArray
		} );


		var furtherOpts = new OO.ui.FieldsetLayout( {
			label: msg( 'further-options-label' ),
			items: [
				new OO.ui.FieldLayout(
					new OO.ui.TextInputWidget( {
						maxLength: 255,
						id: 'wpMassBlockSummaryTalk',
						value: msg( 'summary-default' )
					} ), {
						label: msg( 'talksummary' )
					}
				)
			]
		} );

		userSummaryField =
			new OO.ui.TextInputWidget( {
				maxLength: 255,
				id: 'wpMassBlockSummaryUser',
				value: msg( 'summary-default' )
			} );

		talkProtectCb =
			new OO.ui.CheckboxInputWidget( {
				id: 'wpMassBlockProtectTalk',
				selected: true
			} );

		userProtectCb =
			new OO.ui.CheckboxInputWidget( {
				id: 'wpMassBlockProtectUser',
				selected: true
			} );

		protectReasonField =
			new OO.ui.TextInputWidget( {
				maxLength: 255,
				id: 'wpMassBlockProtectReason',
				value: msg( 'protect-reason-default' )
			} );

		/**
		 * Toggle protection fields
		 */
		var toggleProtectionFields = function() {
			if ( !talkProtectCb.isSelected() && !userProtectCb.isSelected() ) {
				protectReasonField.setDisabled( true );
			} else {
				protectReasonField.setDisabled( false );
			}
		};

		talkProtectCb.on( 'change', toggleProtectionFields );
		userProtectCb.on( 'change', toggleProtectionFields );

		furtherOpts.addItems( [
			new OO.ui.FieldLayout( userSummaryField, {
				label: msg( 'upsummary' )
			} ),
			new OO.ui.FieldLayout( talkProtectCb, {
				label: msg( 'talkprotect' )
			} ),
			new OO.ui.FieldLayout( userProtectCb, {
				label: msg( 'upprotect' )
			} ),
			new OO.ui.FieldLayout( protectReasonField, {
				label: msg( 'protect-reason-label' )
			} )
		] );

		expiryField.on( 'change', function() {
			// Several fields cannot be used if the expiry isn't infinite
			var enable = isInfinity( $( '#wpMassBlockExpiry input' ).val().trim() ),
				// These are OOUI elements
				disableEls = [
					userTextField,
					talkProtectCb,
					userSummaryField,
					userProtectCb,
					protectReasonField
				];

			for ( var el in disableEls ) {
				disableEls[ el ].setDisabled( !enable );
			}
		} );

		submitBtn = new OO.ui.ButtonInputWidget( {
				label: msg( 'submit-text' ),
				title: msg( 'submit-text' ),
				id: 'wpMassBlockSubmit',
				flags: [
					'primary',
					'progressive'
				]
			} )
			.on( 'click', doMassBlock );

		form.addItems( [ basicFieldset, blockOpts, furtherOpts, new OO.ui.FieldLayout( submitBtn ) ] );


		var bodyContentID = ( mw.config.get( 'skin' ) === "cologneblue" ? "#article" : "#bodyContent" );
		$( bodyContentID ).html( '<h2>' + msg( 'abuse-disclaimer' ) + '</h2><br /><div id="wpMassBlockFailedContainer"></div>' );
		$( bodyContentID ).append( form.$element );
	}

	/**
	 * Utility function to tell if an expiry is infinite
	 */
	function isInfinity( expiry ) {
		return /^(indefinite|infinite|infinity|never|)$/i.test( expiry );
	}

	$( function() {
		if ( mw.config.get( "wgNamespaceNumber" ) === -1 &&
			( mw.config.get( "wgTitle" ) == "Massblock" || mw.config.get( "wgTitle" ) === "MassBlock" ) &&
			/sysop/.test( mw.config.get( "wgUserGroups" ) )
		) {
			mw.loader.using( [ 'mediawiki.util', 'mediawiki.api', 'mediawiki.jqueryMsg', 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows' ], $.ready )
				.then( function loadMsg() {
					return new mw.Api().loadMessagesIfMissing( [ 'Ipbreason-dropdown' ] );
				} )
				.then( massblockform );
		}
	} );
}( mediaWiki, jQuery ) );