Utente:Daimona Eaytoy/Massblock.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m Estraggo handler dal loop e accorpo
+validazione aggiuntiva sull'input, bellifico funzione spostando l'alert, cambio formato dei messaggi
Riga 13:
// 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'
};
 
/**
Riga 20 ⟶ 54:
var users = $( "#wpMassBlockUsers textarea" ).val().split( "\n" );
 
// First trim everything
users = users.filter( function( el ) {
users = users.map( function ( s ) {
return el.trim() !== '';
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 ) {
Riga 107 ⟶ 146:
 
for ( i = 0; i < users.length; i++ ) {
let user = users[ i ].trim();
 
new mw.Api().postWithToken( "csrf", {
Riga 131 ⟶ 170:
count++;
if ( count === users.length ) {
doPostBlockActions( blocked, talkpageedited, userpageedited, talkpageprotected, userpageprotected, failed, error );
OO.ui.alert(
msg( 'result-alert' ).replace( '$1', blocked ).replace( '$2', talkpageedited ).replace( '$3', userpageedited )
.replace( '$4', talkpageprotected ).replace( '$5', userpageprotected )
);
}
}
Riga 141 ⟶ 184:
/**
* Executed after all users have been processed.
* This SUCKS!
*/
function doPostBlockActions( blocked, talkpageedited, userpageedited, talkpageprotected, userpageprotected, failed, error ) {
var msg = getMessages();
// Hackeroni ripperoni
OO.ui.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 = "";
Riga 159 ⟶ 194:
}
$( "#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>'
);
Riga 199 ⟶ 234:
}
 
var defaultMsg = {
/**
* Get all localised messages, or default ones.
*/
function getMessages() {
var defaultMsg = {
'document-title': 'Tim\'s mass-blocking tool - Wikipedia, the free encyclopedia',
'page-title': 'Tim\'s mass-blocking tool',
Riga 235 ⟶ 266:
'failure-help': 'help',
};
 
var ret = [];
for ( var msg in defaultMsg ) {
ret[ msg ] = getLocalMessage( msg ) || defaultMsg[ msg ];
}
return ret;
}
 
/**
* Get a localised messages, or the default one as fallback.
* Get a single localized message
*/
function getLocalMessage( msg () {
return localMsg[ msg ] || defaultMsg[ 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>',
'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'
};
 
return localMsg[ msg ] || null;
}
 
Riga 289 ⟶ 278:
function massblockform() {
var reasons = mw.msg( 'Ipbreason-dropdown' ).split( '\*\*' ),
msg = getMessages(),
// OOUI elements
userTextField, talkProtectCb, userSummaryField, userProtectCb, protectReasonField;
Riga 296 ⟶ 284:
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( {
Riga 304 ⟶ 292:
 
var basicFieldset = new OO.ui.FieldsetLayout( {
label: msg[( 'basic-data' ]),
items: [
new OO.ui.FieldLayout(
Riga 310 ⟶ 298:
rows: 10
} ), {
label: msg[( 'blockusers' ]),
align: 'top',
id: 'wpMassBlockUsers'
Riga 319 ⟶ 307:
rows: 10
} ), {
label: msg[( 'talkmsg' ]),
align: 'top',
id: 'wpMassBlockMessage'
Riga 334 ⟶ 322:
basicFieldset.addItems( [
new OO.ui.FieldLayout( userTextField, {
label: msg[( 'upmsg' ]),
align: 'top',
id: 'wpMassBlockTag'
Riga 341 ⟶ 329:
 
var reasonOpts = [ {
optgroup: msg[( 'other-reason' ])
},
{
data: 'other',
label: msg[( 'other-reason' ])
},
{
optgroup: msg[( 'common-reasons' ])
}
];
Riga 382 ⟶ 370:
new OO.ui.FieldLayout(
reasonsDropdown, {
label: msg[( 'common-reasons' ])
}
),
Riga 388 ⟶ 376:
new OO.ui.FieldLayout(
otherReasonField, {
label: msg[( 'extra-reason' ])
}
),
 
new OO.ui.FieldLayout( expiryField, {
label: msg[( 'exptime' ])
} ),
 
Riga 400 ⟶ 388:
id: 'wpMassBlockAnononly'
} ), {
label: msg[( 'anononly' ])
}
),
Riga 408 ⟶ 396:
selected: true
} ), {
label: msg[( 'autoblock' ])
}
),
Riga 416 ⟶ 404:
selected: true
} ), {
label: msg[( 'nocreate' ])
}
),
Riga 423 ⟶ 411:
id: 'wpMassBlockEmail'
} ), {
label: msg[( 'noemail' ])
}
)
Riga 433 ⟶ 421:
id: 'wpMassBlockTalkpage'
} ), {
label: msg[( 'notalk' ])
}
) );
Riga 443 ⟶ 431:
selected: true
} ), {
label: msg[( 'override' ])
}
) );
 
var blockOpts = new OO.ui.FieldsetLayout( {
label: msg[( 'block-options-label' ]),
items: blockOptsArray
} );
Riga 454 ⟶ 442:
 
var furtherOpts = new OO.ui.FieldsetLayout( {
label: msg[( 'further-options-label' ]),
items: [
new OO.ui.FieldLayout(
Riga 460 ⟶ 448:
maxLength: 255,
id: 'wpMassBlockSummaryTalk',
value: msg[( 'summary-default' ])
} ), {
label: msg[( 'talksummary' ])
}
)
Riga 472 ⟶ 460:
maxLength: 255,
id: 'wpMassBlockSummaryUser',
value: msg[( 'summary-default' ])
} );
 
Riga 491 ⟶ 479:
maxLength: 255,
id: 'wpMassBlockProtectReason',
value: msg[( 'protect-reason-default' ])
} );
 
Riga 510 ⟶ 498:
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' ])
} )
] );
Riga 541 ⟶ 529:
 
submitBtn = new OO.ui.ButtonInputWidget( {
label: msg[( 'submit-text' ]),
title: msg[( 'submit-text' ]),
id: 'wpMassBlockSubmit',
flags: [
Riga 555 ⟶ 543:
 
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 );
}