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

Contenuto cancellato Contenuto aggiunto
m Beautify, -controllo non necessario
Prova a gestire loop async
Riga 6:
*
* @todo Switch to OOUI, build the HTML in a prettier way. Use system messages for block opts?
* handle async loop, msg for API errors.
*/
/**
* Main form processing routine, called on form submit
*/
function doMassBlock() {
var users = document.getElementById( "wpMassBlockUsers" ).value.split( "\n" ),;
msg = getMessages();
 
users = users.filter( function( el ) {
Riga 43 ⟶ 47:
wpMassBlockProtectUser = document.getElementById( "wpMassBlockProtectUser" ).checked;
 
var count = 0;
for ( i = 0; i < users.length; i++ ) {
var user = users[ i ].trim();
Riga 118 ⟶ 123:
failed.push( "Special:Block/" + user );
error.push( e );
}
)
.always(
function() {
count++;
if ( count === users.length ) {
doPostBlockActions( blocked, talkpageedited, userpageedited, talkpageprotected, userpageprotected, failed, error );
}
}
);
 
}
}
 
/**
* Executed after all users have been processed.
* This SUCKS!
*/
function doPostBlockActions( blocked, talkpageedited, userpageedited, talkpageprotected, userpageprotected, failed, error ) {
var msg = getMessages();
// Hackeroni ripperoni
alert(
Riga 131 ⟶ 151:
if ( failed.length > 0 ) {
var linkedList = "";
for ( x = 0; x < failed.length; x++ ) {
error = error.map( function( el ) {
//Links the titles in the "failed" array
return 'apierror-' + el;
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>';
mw.Api().loadMessagesIfMissing( error )
.then(
function() {
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>: " + mw.msg( error[ x ] ) + "</li>";
}
document.getElementById( "wpMassBlockFailedContainer" ).innerHTML += '<br /><b>' + msg[ 'failed-actions' ] + '</b><ul>' + linkedList + '</ul>';
}
);
}
}
 
/**
* Edit the given page
*/
function doEditPage( title, text, summary, append ) {
var appendText = append || false,
Riga 155 ⟶ 188:
}
 
/**
* Protect the given page
*/
function doProtectPage( title ) {
return new mw.Api().postWithToken( 'csrf', {
Riga 160 ⟶ 196:
title: title,
protections: protections,
reason: document.getElementById( "wpMassBlockProtectReason" ).value.trim(),
reason: 'utente bloccato infinito',
watchlist: 'nochange',
format: 'json',
Riga 166 ⟶ 202:
}
 
/**
* Get all localised messages, or default ones.
*/
function getMessages() {
var defaultMsg = {
Riga 185 ⟶ 224:
'upsummary': 'Edit summary for user page edit:',
'upprotect': 'Protect the user page:',
'protect-reason-label': 'Reason for protection:',
'protect-reason-default': 'Blocked user.',
'anononly': 'Block anonymous users only (IPs only):',
'autoblock': 'Enable autoblock (accounts only):',
Riga 203 ⟶ 244:
}
 
/**
* Get a single localized message
*/
function getLocalMessage( msg ) {
// Not an optimal way to localise, but better than hardcoded inside the HTML
Riga 223 ⟶ 267:
'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):',
Riga 237 ⟶ 283:
}
 
/**
* Build the form
*/
function massblockform() {
var bodyContent = ( mw.config.get( 'skin' ) === "cologneblue" ? "article" : "bodyContent" );
Riga 294 ⟶ 343:
'<tr><td>' + msg[ 'upprotect' ] + '</td>' +
'<td><input type="checkbox" id="wpMassBlockProtectUser" name="wpMassBlockProtectUser" /></td></tr>';
'<tr><td>' + msg[ 'protect-reason-label' ] + '</td>' +
'<tr><td><input type="text" id="wpMassBlockProtectReason" name="wpMassBlockProtectReason" value="' + msg['protect-reason-default'] +'" /></td></tr>';
 
 
Riga 327 ⟶ 378:
}
 
/**
* Utility function to tell if an expiry is infinite
*/
function isInfinity( expiry ) {
return /^(indefinite|infinite never|)$/i.test( expiry );