// Script spostato a [[MediaWiki:Gadget-Massblock.js]]. Questa pagina esiste solo per la crono.
/* jshint sub:true */
/**
* Tool for mass-blocking a list of IPs/users.
* Adapted from [[:en:User:Timotheus Canens/massblock.js]] to work a bit better
* with local config.
*
* @todo Switch to OOUI, build the HTML in a prettier way. Use system messages for block opts?
*/
function doMassBlock() {
var users = document.getElementById( "wpMassBlockUsers" ).value.split( "\n" ),
msg = getMessages();
users = users.filter( function( el ) {
return el.trim() !== '';
} );
if ( users.length === 0 ) {
// Easy
return;
}
document.getElementById( "wpMassBlockSubmit" ).disabled = true;
var wpMassBlockReasons = document.getElementById( "wpMassBlockReasons" ).value.trim(),
wpMassBlockReason = document.getElementById( "wpMassBlockReason" ).value.trim(),
blocked = 0,
talkpageedited = 0,
userpageedited = 0,
talkpageprotected = 0,
userpageprotected = 0,
failed = [],
error = [];
var wpMassBlockAnononly = document.getElementById( "wpMassBlockAnononly" ).checked,
wpMassBlockNocreate = document.getElementById( "wpMassBlockNocreate" ).checked,
wpMassBlockEmail = document.getElementById( "wpMassBlockEmail" ).checked,
wpMassBlockAutoblock = document.getElementById( "wpMassBlockAutoblock" ).checked,
wpMassBlockTalkpage = mw.config.get( 'wgBlockAllowsUTEdit' ) === true ? document.getElementById( "wpMassBlockTalkpage" ).checked : false,
wpMassBlockReblock = document.getElementById( "wpMassBlockReblock" ).checked;
var wpMassBlockMessage = document.getElementById( "wpMassBlockMessage" ).value.trim(),
wpMassBlockTag = document.getElementById( "wpMassBlockTag" ).value.trim(),
wpMassBlockExpiry = document.getElementById( "wpMassBlockExpiry" ).value.trim();
var wpMassBlockSummaryTalk = document.getElementById( "wpMassBlockSummaryTalk" ).value.trim(),
wpMassBlockSummaryUser = document.getElementById( "wpMassBlockSummaryUser" ).value.trim(),
wpMassBlockProtectTalk = document.getElementById( "wpMassBlockProtectTalk" ).checked,
wpMassBlockProtectUser = document.getElementById( "wpMassBlockProtectUser" ).checked;
for ( i = 0; i < users.length; i++ ) {
var user = users[ i ];
if ( user.length > 0 ) {
var api = new mw.Api();
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
} )
.then(
function( data ) {
var isInfty = /^(indefinite|indefinito|infinito|)$/i.test( wpMassBlockExpiry );
blocked++;
if ( wpMassBlockMessage !== "" ) {
doEditPage( 'User talk:' + user, wpMassBlockMessage, wpMassBlockSummaryTalk, isInfty )
.done( function( data ) {
talkpageedited++;
} )
.fail( function( e ) {
//If not edited, add the title to the "failed" array and a description of the error to the "error" array.
failed.push( 'User talk:' + user );
error.push( e );
} );
}
if ( !isInfty ) {
// No pages should be protected, and the UP should be left as is
return;
}
if ( wpMassBlockProtectTalk ) {
doProtectPage( 'User talk:' + user )
.done( function( data ) {
talkpageprotected++;
} )
.fail( function( e ) {
//If not edited, add the title to the "failed" array and a description of the error to the "error" array.
failed.push( 'User talk:' + user );
error.push( e );
} );
}
if ( wpMassBlockTag !== "" ) {
doEditPage( 'User:' + user, wpMassBlockTag, wpMassBlockSummaryUser )
.done( function( data ) {
userpageedited++;
} )
.fail( function( e ) {
//If not edited, add the title to the "failed" array and a description of the error to the "error" array.
failed.push( 'User:' + user );
error.push( e );
} );
}
if ( wpMassBlockProtectUserPage ) {
doProtectPage( 'User:' + user )
.done( function( data ) {
userpageprotected++;
} )
.fail( function( e ) {
//If not edited, add the title to the "failed" array and a description of the error to the "error" array.
failed.push( 'User:' + user );
error.push( e );
} );
}
},
function( e ) {
// If not blocked, add the title to the "failed" array and a description of the error to the "error" array.
failed.push( "Special:Block/" + user );
error.push( e );
}
);
}
}
// Hackeroni ripperoni
alert(
msg[ 'result-alert' ].replace( '$1', blocked ).replace( '$2', talkpageedited ).replace( '$3', userpageedited )
.replace( '$4', talkpageprotected ).replace( '$5', userpageprotected )
);
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>: " + error[ x ] + "</li>";
}
document.getElementById( "wpMassBlockFailedContainer" ).innerHTML += '<br /><b>' + msg[ 'failed-actions' ] + '</b><ul>' + linkedList + '</ul>';
}
}
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 );
}
function doProtectPage( title ) {
return new mw.Api().postWithToken( 'csrf', {
action: 'protect',
title: title,
protections: protections,
reason: 'utente bloccato infinito',
watchlist: 'nochange',
format: 'json',
} );
}
function getMessages() {
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>',
'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 (blank for indefinite):',
'summary-default': 'Blocked user.',
'talksummary': 'Edit summary for talk page edit:',
'talkprotect': 'Protect the talk:',
'upsummary': 'Edit summary for user page edit:',
'upprotect': 'Protect the user page:',
'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:'
};
var ret = [];
for ( var msg in defaultMsg ) {
ret[ msg ] = getLocalMessage( msg ) || defaultMsg[ msg ];
}
return ret;
}
function getLocalMessage( msg ) {
// Not an optimal way to localise, but better than hardcoded inside the HTML
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>',
'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 (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:',
'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:'
};
return localMsg[ msg ] || null;
}
function massblockform() {
var bodyContent = ( mw.config.get( 'skin' ) === "cologneblue" ? "article" : "bodyContent" );
var reasons = mw.msg( 'Ipbreason-dropdown' ).split( '\*\*' ),
msg = getMessages();
document.getElementsByTagName( "h1" )[ 0 ].textContent = msg[ 'page-title' ];
document.title = msg[ 'document-title' ];
var content =
'<form id="wpMassBlock" name="wpMassBlock">' +
msg[ 'abuse-disclaimer' ] +
'<div id="wpMassBlockFailedContainer"></div>' +
'<br /><br />' +
msg[ 'blockusers' ] + '<br />' +
'<textarea tabindex="1" accesskey="," name="wpMassBlockUsers" id="wpMassBlockUsers" rows="10" cols="80"></textarea>' +
msg[ 'talkmsg' ] + '<br />' +
'<textarea tabindex="2" accesskey="," name="wpMassBlockMessage" id="wpMassBlockMessage" rows="10" cols="80"></textarea>' +
msg[ 'upmsg' ] + '<br />' +
'<textarea tabindex="3" accesskey="," name="wpMassBlockTag" id="wpMassBlockTag" rows="10" cols="80"></textarea>' +
'<br /><br /><fieldset><legend>' + msg['block-options-label'] + '</legend>' +
'<table style="background-color:transparent">' +
'<tr><td>' + msg[ 'common-reasons' ] + '</td>' +
'<td><select id="wpMassBlockReasons">' +
'<optgroup label="' + msg[ 'other-reason' ] + '">' +
'<option value="other">' + msg[ 'other-reason' ] + '</option>' +
'</optgroup>' +
'<optgroup label="' + msg[ 'common-reasons' ] + '">';
for ( var i = 1, j = reasons.length; i < j; i++ ) {
content += '<option value="' + reasons[ i ] + '">' + reasons[ i ] + '</option>';
}
content +=
'</optgroup>' +
'</select></td></tr>' +
'<tr><td>' + msg[ 'extra-reason' ] + '</td>' +
'<td><input type="text" id="wpMassBlockReason" name="wpMassBlockReason" maxlength="255" /></td></tr>' +
'<tr><td>' + msg[ 'exptime' ] + '</td>' +
'<td><input type="text" id="wpMassBlockExpiry" name="wpMassBlockExpiry" maxlength="255" /></td></tr>' +
'<tr><td>' + msg[ 'anononly' ] + '</td><td><input type="checkbox" id="wpMassBlockAnononly" name="wpMassBlockAnononly" /></td></tr>' +
'<tr><td>' + msg[ 'autoblock' ] + '</td><td><input type="checkbox" id="wpMassBlockAutoblock" name="wpMassBlockAutoblock" checked="checked" /></td></tr>' +
'<tr><td>' + msg[ 'nocreate' ] + '</td><td><input type="checkbox" id="wpMassBlockNocreate" name="wpMassBlockNocreate" checked="checked" /></td></tr>' +
'<tr><td>' + msg[ 'noemail' ] + '</td><td><input type="checkbox" id="wpMassBlockEmail" name="wpMassBlockEmail" /></td></tr>' +
'<tr><td>' + msg[ 'override' ] + '</td><td><input type="checkbox" id="wpMassBlockReblock" name="wpMassBlockReblock" checked="checked" /></td></tr>' +
'</table></fieldset>' +
'<fieldset><legend>' + msg['further-options-label'] + '</legend>' +
'<table style="background-color:transparent">' +
'<tr><td>' + msg[ 'talksummary' ] + '</td>' +
'<td><input type="text" id="wpMassBlockSummaryTalk" name="wpMassBlockSummaryTalk" maxlength="255" value="' +
msg['summary-default'] + '"/></td></tr>' +
'<tr><td>' + msg[ 'talkprotect' ] + '</td>' +
'<td><input type="checkbox" id="wpMassBlockProtectTalk" name="wpMassBlockProtectTalk" /></td></tr>' +
'<tr><td>' + msg[ 'upsummary' ] + '</td>' +
'<td><input type="text" id="wpMassBlockSummaryUser" name="wpMassBlockSummaryUser" maxlength="255" value="' +
msg['summary-default'] + '"/></td></tr>' +
'<tr><td>' + msg[ 'upprotect' ] + '</td>' +
'<td><input type="checkbox" id="wpMassBlockProtectUser" name="wpMassBlockProtectUser" /></td></tr>';
if ( mw.config.get( 'wgBlockAllowsUTEdit' ) === true ) {
content += '<tr><td>' + msg[ 'notalk' ] + '</td><td><input type="checkbox" id="wpMassBlockTalkpage" name="wpMassBlockTalkpage" /></td></tr>';
}
content +=
'</table></fieldset></form>' +
'<input type="button" id="wpMassBlockSubmit" name="wpMassBlockSubmit" value="' + msg[ 'submit-text' ] + '" onclick="doMassBlock()" />';
document.getElementById( bodyContent ).innerHTML = content;
document.getElementById( "wpMassBlockReasons" ).onkeyup = function() {
var maxlength = ( document.getElementById( "wpMassBlockReasons" ).value === "other" ? 255 : ( 255 - ': '.length ) - document.getElementById( "wpMassBlockReasons" ).value.length );
document.getElementById( "wpMassBlockReason" ).setAttribute( "maxlength", maxlength );
};
document.getElementById( 'wpMassBlockExpiry' ).onkeyup = function() {
var enable = /^(indefinite|indefinito|infinito|)$/i.test( this.value.trim() );
var disableIDs = [
'wpMassBlockTag',
'wpMassBlockProtectTalk',
'wpMassBlockSummaryUser',
'wpMassBlockProtectUser'
];
for ( var id in disableIDs ) {
$( '#' + disableIDs[ id ] ).prop( 'disabled', !enable );
}
};
}
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' ], $.ready )
.then( function loadMsg() {
return new mw.Api().loadMessagesIfMissing( [ 'Ipbreason-dropdown' ] );
} )
.then( massblockform );
}
|