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.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 ) {
Riga 107 ⟶ 146:
for ( i = 0; i < users.length; i++ ) {
let user = users[ i ]
new mw.Api().postWithToken( "csrf", {
Riga 131 ⟶ 170:
count++;
if ( count === users.length ) {
doPostBlockActions(
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.
*/
function doPostBlockActions(
if ( failed.length > 0 ) {
var linkedList = "";
Riga 159 ⟶ 194:
}
$( "#wpMassBlockFailedContainer" ).html(
'<br /><b>' + msg
'(<a href="//www.mediawiki.org/wiki/API:Block#Possible_errors">' + msg
'<ul>' + linkedList + '</ul>'
);
Riga 199 ⟶ 234:
}
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',
};
/**
* Get a localised messages, or the default one as fallback.
*/
function
return localMsg[ msg ] || defaultMsg[ msg ];
}
Riga 289 ⟶ 278:
function massblockform() {
var reasons = mw.msg( 'Ipbreason-dropdown' ).split( '\*\*' ),
// OOUI elements
userTextField, talkProtectCb, userSummaryField, userProtectCb, protectReasonField;
Riga 296 ⟶ 284:
blockAllowsTalkEdit = window.___location.href.indexOf( 'it.wikipedia' ) === -1;
document.getElementsByTagName( "h1" )[ 0 ].textContent = msg
document.title = msg
var form = new OO.ui.FormLayout( {
Riga 304 ⟶ 292:
var basicFieldset = new OO.ui.FieldsetLayout( {
label: msg
items: [
new OO.ui.FieldLayout(
Riga 310 ⟶ 298:
rows: 10
} ), {
label: msg
align: 'top',
id: 'wpMassBlockUsers'
Riga 319 ⟶ 307:
rows: 10
} ), {
label: msg
align: 'top',
id: 'wpMassBlockMessage'
Riga 334 ⟶ 322:
basicFieldset.addItems( [
new OO.ui.FieldLayout( userTextField, {
label: msg
align: 'top',
id: 'wpMassBlockTag'
Riga 341 ⟶ 329:
var reasonOpts = [ {
optgroup: msg
},
{
data: 'other',
label: msg
},
{
optgroup: msg
}
];
Riga 382 ⟶ 370:
new OO.ui.FieldLayout(
reasonsDropdown, {
label: msg
}
),
Riga 388 ⟶ 376:
new OO.ui.FieldLayout(
otherReasonField, {
label: msg
}
),
new OO.ui.FieldLayout( expiryField, {
label: msg
} ),
Riga 400 ⟶ 388:
id: 'wpMassBlockAnononly'
} ), {
label: msg
}
),
Riga 408 ⟶ 396:
selected: true
} ), {
label: msg
}
),
Riga 416 ⟶ 404:
selected: true
} ), {
label: msg
}
),
Riga 423 ⟶ 411:
id: 'wpMassBlockEmail'
} ), {
label: msg
}
)
Riga 433 ⟶ 421:
id: 'wpMassBlockTalkpage'
} ), {
label: msg
}
) );
Riga 443 ⟶ 431:
selected: true
} ), {
label: msg
}
) );
var blockOpts = new OO.ui.FieldsetLayout( {
label: msg
items: blockOptsArray
} );
Riga 454 ⟶ 442:
var furtherOpts = new OO.ui.FieldsetLayout( {
label: msg
items: [
new OO.ui.FieldLayout(
Riga 460 ⟶ 448:
maxLength: 255,
id: 'wpMassBlockSummaryTalk',
value: msg
} ), {
label: msg
}
)
Riga 472 ⟶ 460:
maxLength: 255,
id: 'wpMassBlockSummaryUser',
value: msg
} );
Riga 491 ⟶ 479:
maxLength: 255,
id: 'wpMassBlockProtectReason',
value: msg
} );
Riga 510 ⟶ 498:
furtherOpts.addItems( [
new OO.ui.FieldLayout( userSummaryField, {
label: msg
} ),
new OO.ui.FieldLayout( talkProtectCb, {
label: msg
} ),
new OO.ui.FieldLayout( userProtectCb, {
label: msg
} ),
new OO.ui.FieldLayout( protectReasonField, {
label: msg
} )
] );
Riga 541 ⟶ 529:
submitBtn = new OO.ui.ButtonInputWidget( {
label: msg
title: msg
id: 'wpMassBlockSubmit',
flags: [
Riga 555 ⟶ 543:
var bodyContentID = ( mw.config.get( 'skin' ) === "cologneblue" ? "#article" : "#bodyContent" );
$( bodyContentID ).html( '<h2>' + msg
$( bodyContentID ).append( form.$element );
}
|