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

Contenuto cancellato Contenuto aggiunto
m ah ecco
m Convenzioni stilistiche
Riga 5:
*/
function doMassBlock() {
document.getElementById( "wpMassBlockSubmit" ).disabled = true;
var users = document.getElementById( "wpMassBlockUsers" ).value.split( "\n" );
if ( users.length === 0 ) {
return;
}
var wpMassBlockReasons = document.getElementById( "wpMassBlockReasons" ).value,
wpMassBlockReason = document.getElementById( "wpMassBlockReason" ).value,
blocked = 0,
talkpageedited = 0,
Riga 17:
failed = [],
error = [];
var wpMassBlockAnononly = document.getElementById( "wpMassBlockAnononly" ).checked,
wpMassBlockNocreate = document.getElementById( "wpMassBlockNocreate" ).checked,
wpMassBlockEmail = document.getElementById( "wpMassBlockEmail" ).checked,
wpMassBlockAutoblock = document.getElementById( "wpMassBlockAutoblock" ).checked,
wpMassBlockTalkpage = document.getElementById( "wpMassBlockTalkpage" ).checked || false,
wpMassBlockReblock = document.getElementById( "wpMassBlockReblock" ).checked;
var wpMassBlockMessage = document.getElementById( "wpMassBlockMessage" ).value,
wpMassBlockTag = document.getElementById( "wpMassBlockTag" ).value,
wpMassBlockExpiry = document.getElementById( "wpMassBlockExpiry" ).value;
var wpMassBlockSummaryTalk = document.getElementById( "wpMassBlockSummaryTalk" ).value,
wpMassBlockSummaryUser = document.getElementById( "wpMassBlockSummaryUser" ).value;
 
for ( i = 0; i < users.length; i++ ) {
var user = users[ i ];
if ( user.length > 0 ) {
var api = new mw.Api();
api.postWithToken( "block", {
action: 'block',
allowusertalk: wpMassBlockTalkpage,
Riga 42:
noemail: wpMassBlockEmail,
reblock: wpMassBlockReblock,
reason: wpMassBlockReasons === "other" ? wpMassBlockReason : wpMassBlockReasons + ( wpMassBlockReason ? ": " + wpMassBlockReason : "" ),
user: user
} )
.then(
function( data ) {
blocked++;
if ( wpMassBlockMessage !== "" ) {
doEditTalk();
}
if ( wpMassBlockTag !== "" ) {
doEditUserPage();
}
},
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 );
}
);
Riga 64:
}
 
document.getElementById( "wpMassBlockSubmit" ).value = "(" + blocked + "/" + talkpageedited + "/" + userpageedited + ")";
if ( failed.length > 0 ) {
var linkedList = "";
for ( x = 0; x < failed.length; x++ ) {
linkedList += "<li><a href=\"" + wgScript + "?title=" + encodeURIComponent( failed[ x ] ) + "\">" + failed[ x ] + "</a>: " + error[ x ] + "</li>"; //Links the titles in the "failed" array
}
document.getElementById( "wpMassBlockFailedContainer" ).innerHTML += '<br /><b>Failed actions:</b><ul>' + linkedList + '</ul>';
}
}
 
function doEditUserPage() {
new mw.Api().postWithEditToken( {
action: 'edit',
title: 'User:' + user,
Riga 81:
summary: wpMassBlockSummaryUser,
watchlist: 'nochange'
} ).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 talk:" + user );
error.push( e );
} );
}
 
function doEditTalk() {
new mw.Api().postWithEditToken( {
action: 'edit',
title: 'User talk:' + user,
Riga 97:
summary: wpMassBlockSummaryTalk,
watchlist: 'nochange'
} ).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 );
} );
}
 
function massblockform() {
var bodyContent = ( mw.config.get( 'skin' ) === "cologneblue" ? "article" : "bodyContent" );
document.getElementsByTagName( "h1" )[ 0 ].textContent = "Tim's mass-blocking tool";
document.title = "Tim's mass-blocking tool - Wikipedia, the free encyclopedia";
var reasons = mw.msg( 'Ipbreason-dropdown' ).split( '\*\*' );
 
var content = '<h3 id="siteSub">From Wikipedia, the free encyclopedia</h3><br /><br />' +
Riga 130:
'</optgroup>' +
'<optgroup label="Common reasons">';
 
console.log(reasons);
for ( var i = 1, j = reasons.length; i < j; i++ ) {
content += '<option value="' + reasons[ i ] + '">' + reasons[ i ] + '</option>';
console.log(reasons[i]);
content += '<option value="' + reasons[i] + '">' + reasons[i] + '</option>';
}
 
Riga 151 ⟶ 150:
'<tr><td>Block account creation:</td><td><input type="checkbox" id="wpMassBlockNocreate" name="wpMassBlockNocreate" checked="checked" /></td></tr>' +
'<tr><td>Block email:</td><td><input type="checkbox" id="wpMassBlockEmail" name="wpMassBlockEmail" /></td></tr>';
if ( mw.config.get('wgBlockAllowsUTEdit') === true ) {
content += '<tr><td>Remove talk page access:</td><td><input type="checkbox" id="wpMassBlockTalkpage" name="wpMassBlockTalkpage" /></td></tr>';
}
 
if ( mw.config.get( 'wgBlockAllowsUTEdit' ) === true ) {
content += '<tr><td>Override existing blocks:</td><td><input type="checkbox" id="wpMassBlockReblock" name="wpMassBlockReblock" checked="checked" /></td></tr>' +
content += '<tr><td>Remove talk page access:</td><td><input type="checkbox" id="wpMassBlockTalkpage" name="wpMassBlockTalkpage" /></td></tr>';
}
 
content += '<tr><td>Override existing blocks:</td><td><input type="checkbox" id="wpMassBlockReblock" name="wpMassBlockReblock" checked="checked" /></td></tr>' +
'<tr><td><input type="button" id="wpMassBlockSubmit" name="wpMassBlockSubmit" value="Block" onclick="doMassBlock()" /></td></tr>' +
'</form>';
 
document.getElementById( bodyContent ).innerHTML = content;
 
document.getElementById( "wpMassBlockReasons" ).onchange = function() {
var maxlength = ( document.getElementById( "wpMassBlockReasons" ).value === "other" ? 255 : ( 255 - ': '.length ) - document.getElementById( "wpMassBlockReasons" ).value.length );
 
document.getElementById( "wpMassBlockReason" ).setAttribute( "maxlength", maxlength );
};
}
 
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 );
}