MediaWiki:Gadget-Massblock.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
...
Ok, rollbacko tutto
Riga 5:
* Adapted from [[:en:User:Timotheus Canens/massblock.js]].
* Go to [[Special:Massblock]] to use it.
* If you want to add localized messages, seeadd instructionsa onlocalMsg [[MediaWiki:Gadget-Massblock]]variable after loading
* the script. See localMsg below.
*
* @author (i.e. blame him) [[:it:User:Daimona Eaytoy]]
Line 11 ⟶ 12:
* rejections.
*/
( function( mw, $ ) {
// These are default english messages.
'use strict';
var defaultMsg = {
'toolbar-text': 'Massblock',
'document-title': 'Mass-blocking tool - Wikipedia, the free encyclopedia',
'page-title': 'Mass-blocking tool',
'abuse-disclaimer': 'If you abuse this tool, it\'s your fault, not mine.',
'basic-data': 'Basic data',
'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, in english (blank for indefinite):',
'summary-default': 'Blocked user.',
'talksummary': 'Edit summary for talk page edit:',
'talkprotect': 'Protect the talk (sysop level, infinite):',
'upsummary': 'Edit summary for user page edit:',
'upprotect': 'Protect the user page (sysop level, infinite):',
'protect-reason-label': 'Reason for protection:',
'protect-reason-default': 'Blocked user.',
'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 with errors:',
'failure-help': 'help'
};
 
// OOUI element
// This will hold the localized messages and must be defined before importing the
var submitBtn,
// script (see [[MediaWiki:Gadget-Massblock.js]])
// Like wgBlockAllowsUTEdit
var localMsg = localMessages || {};
blockAllowsTalkEdit;
 
// To add localized messages change the values of this variables. The english messages
// OOUI element
// are in defaultMsg below.
var submitBtn,
var localMsg = {
// Like wgBlockAllowsUTEdit
'toolbar-text': 'Massblock',
blockAllowsTalkEdit;
'document-title': 'Il mass-blocker attira-trote',
'page-title': 'Il mass-blocker attira-trote',
'abuse-disclaimer': 'Se abusi di questo strumento, è colpa tua e non mia!',
'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'
};
 
// Default english messages. Don't change these!
/**
var defaultMsg = {
* Main form processing routine, called on form submit
'toolbar-text': 'Massblock',
*/
'document-title': 'Mass-blocking tool - Wikipedia, the free encyclopedia',
function doMassBlock() {
'page-title': 'Mass-blocking tool',
var users = $( "#wpMassBlockUsers textarea" ).val().split( "\n" );
'abuse-disclaimer': 'If you abuse this tool, it\'s your fault, not mine.',
 
'basic-data': 'Basic data',
// First trim everything
'blockusers': 'Users to block (one on each line, please):',
users = users.map( function( s ) {
'talkmsg': 'Replace talk page with, or text to add if the expiry is not infinite (leave blank to leave no message):',
return s.trim();
'upmsg': 'Replace user page text with (leave blank for no change):',
} );
'block-options-label': 'Block options',
// Then remove blanks and duplicates
'further-options-label': 'Further options',
users = users.filter( function( el, index, me ) {
'common-reasons': 'Common reasons:',
return el !== '' && me.indexOf( el ) === index;
'other-reason': 'Other reason',
} );
'extra-reason': 'Other/additional reason:',
if ( users.length === 0 ) {
'exptime': 'Expiration time, in english (blank for indefinite):',
// Easy
'summary-default': 'Blocked user.',
return;
'talksummary': 'Edit summary for talk page edit:',
}
'talkprotect': 'Protect the talk (sysop level, infinite):',
submitBtn.setDisabled( true );
'upsummary': 'Edit summary for user page edit:',
 
'upprotect': 'Protect the user page (sysop level, infinite):',
var wpMassBlockReasons = $( "#wpMassBlockReasons select :selected" ).val().trim(),
'protect-reason-label': 'Reason for protection:',
wpMassBlockReason = $( "#wpMassBlockReason input" ).val().trim(),
'protect-reason-default': 'Blocked user.',
blocked = 0,
'anononly': 'Block anonymous users only (IPs only):',
talkpageedited = 0,
'autoblock': 'Enable autoblock (accounts only):',
userpageedited = 0,
'nocreate': 'Block account creation:',
talkpageprotected = 0,
'noemail': 'Block email:',
userpageprotected = 0,
'notalk': 'Remove talk page access:',
errors = {};
'override': 'Override existing blocks:',
var wpMassBlockAnononly = $( "#wpMassBlockAnononly input" ).prop( 'checked' ),
'submit-text': 'Block',
wpMassBlockNocreate = $( "#wpMassBlockNocreate input" ).prop( 'checked' ),
'result-alert': 'Blocked $1 users. Edited $2 talk pages and $3 user pages. Protected $4 talk pages and $5 user pages.',
wpMassBlockEmail = $( "#wpMassBlockEmail input" ).prop( 'checked' ),
'failed-actions': 'Failed actions with errors:',
wpMassBlockAutoblock = $( "#wpMassBlockAutoblock input" ).prop( 'checked' ),
'failure-help': 'help'
wpMassBlockTalkpage = blockAllowsTalkEdit ? $( "#wpMassBlockTalkpage input" ).prop( 'checked' ) : false,
};
wpMassBlockReblock = $( "#wpMassBlockReblock input" ).prop( 'checked' );
var wpMassBlockMessage = $( "#wpMassBlockMessage textarea" ).val().trim(),
wpMassBlockTag = $( "#wpMassBlockTag textarea" ).val().trim(),
wpMassBlockExpiry = $( "#wpMassBlockExpiry input" ).val().trim();
var wpMassBlockSummaryTalk = $( "#wpMassBlockSummaryTalk input" ).val().trim(),
wpMassBlockSummaryUser = $( "#wpMassBlockSummaryUser input" ).val().trim(),
wpMassBlockProtectTalk = $( "#wpMassBlockProtectTalk input" ).prop( 'checked' ),
wpMassBlockProtectUser = $( "#wpMassBlockProtectUser input" ).prop( 'checked' );
 
/**
* Main form processing routine, called on form submit
* Process an error in any part of the process
*
* @param {string} e The error code
* @param {string} user The user we're processing
* @param {string} action The action we're doing. This is of the form
* {$actionname}-{$page}, where $action name is the name of the API module
* being used (e.g. 'block' or 'edit') and $page is either 'talk' or 'user',
* representing the target of the action. The only special case is 'block',
* which has no hyphen and no page.
*/
function doMassBlock() {
var errorHandler = function( e, user, action ) {
var users = $( "#wpMassBlockUsers textarea" ).val().split( "\n" );
var obj = {};
 
obj[ action ] = e;
// First trim everything
if ( !errors[ user ] ) {
users = users.map( function( s ) {
errors[ user ] = [ obj ];
return s.trim();
} else {
} );
errors[ user ].push( obj );
// Then remove blanks and duplicates
users = users.filter( function( el, index, me ) {
return el !== '' && me.indexOf( el ) === index;
} );
if ( users.length === 0 ) {
// Easy
return;
}
submitBtn.setDisabled( true );
 
var wpMassBlockReasons = $( "#wpMassBlockReasons select :selected" ).val().trim(),
wpMassBlockReason = $( "#wpMassBlockReason input" ).val().trim(),
blocked = 0,
talkpageedited = 0,
userpageedited = 0,
talkpageprotected = 0,
userpageprotected = 0,
errors = {};
var wpMassBlockAnononly = $( "#wpMassBlockAnononly input" ).prop( 'checked' ),
wpMassBlockNocreate = $( "#wpMassBlockNocreate input" ).prop( 'checked' ),
wpMassBlockEmail = $( "#wpMassBlockEmail input" ).prop( 'checked' ),
wpMassBlockAutoblock = $( "#wpMassBlockAutoblock input" ).prop( 'checked' ),
wpMassBlockTalkpage = blockAllowsTalkEdit ? $( "#wpMassBlockTalkpage input" ).prop( 'checked' ) : false,
wpMassBlockReblock = $( "#wpMassBlockReblock input" ).prop( 'checked' );
var wpMassBlockMessage = $( "#wpMassBlockMessage textarea" ).val().trim(),
wpMassBlockTag = $( "#wpMassBlockTag textarea" ).val().trim(),
wpMassBlockExpiry = $( "#wpMassBlockExpiry input" ).val().trim();
var wpMassBlockSummaryTalk = $( "#wpMassBlockSummaryTalk input" ).val().trim(),
wpMassBlockSummaryUser = $( "#wpMassBlockSummaryUser input" ).val().trim(),
wpMassBlockProtectTalk = $( "#wpMassBlockProtectTalk input" ).prop( 'checked' ),
wpMassBlockProtectUser = $( "#wpMassBlockProtectUser input" ).prop( 'checked' );
 
/**
};
* Process an error in any part of the process
*
* @param {string} e The error code
* @param {string} user The user we're processing
* @param {string} action The action we're doing. This is of the form
* {$actionname}-{$page}, where $action name is the name of the API module
* being used (e.g. 'block' or 'edit') and $page is either 'talk' or 'user',
* representing the target of the action. The only special case is 'block',
* which has no hyphen and no page.
*/
var errorHandler = function( e, user, action ) {
var obj = {};
obj[ action ] = e;
if ( !errors[ user ] ) {
errors[ user ] = [ obj ];
} else {
errors[ user ].push( obj );
}
 
var isInfty = isInfinity( wpMassBlockExpiry );
// Several actions can only be executed if the block is infinite
wpMassBlockProtectTalk = wpMassBlockProtectTalk && isInfty;
wpMassBlockProtectUser = wpMassBlockProtectUser && isInfty;
wpMassBlockTag = isInfty ? wpMassBlockTag : '';
 
};
 
var isInfty = isInfinity( wpMassBlockExpiry );
/**
// Several actions can only be executed if the block is infinite
* Perform a single block via API
wpMassBlockProtectTalk = wpMassBlockProtectTalk && isInfty;
*
wpMassBlockProtectUser = wpMassBlockProtectUser && isInfty;
* @param {string} user The user to block
wpMassBlockTag = isInfty ? wpMassBlockTag : '';
* @return {Promise}
*/
var doBlock = function( user ) {
return new mw.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
} );
};
 
/**
* The post-block handler. Performs edits and protections.
*
* @param {Object} response The response of the block API call
* @return {Promise} A promise which is resolved after all actions are done
* for all pages. This will never be rejected.
*/
var successHandler = function( response ) {
var user = response.block.user,
talkPage = 'User talk:' + user,
userPage = 'User:' + user,
// @var {Promise} These track the state for all actions (edit and protect)
// on every page. They are resolved as soon as a page is processed, with or
// without a failure. This way the final $.when will resolve after all promises
// have been processed, and not after the first rejection.
talkDone = $.Deferred(),
userDone = $.Deferred();
 
/**
blocked++;
* Perform a single block via API
*
* @param {string} user The user to block
* @return {Promise}
*/
var doBlock = function( user ) {
return new mw.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
} );
};
 
/**
* The post-block handler. Performs edits and protections.
*
* @param {Object} response The response of the block API call
* @return {Promise} A promise which is resolved after all actions are done
* for all pages. This will never be rejected.
*/
var successHandler = function( response ) {
var user = response.block.user,
talkPage = 'User talk:' + user,
userPage = 'User:' + user,
// @var {Promise} These track the state for all actions (edit and protect)
// on every page. They are resolved as soon as a page is processed, with or
// without a failure. This way the final $.when will resolve after all promises
// have been processed, and not after the first rejection.
talkDone = $.Deferred(),
userDone = $.Deferred();
 
blocked++;
if ( wpMassBlockMessage !== "" ) {
 
doEditPage( talkPage, wpMassBlockMessage, wpMassBlockSummaryTalk, !isInfty )
if ( wpMassBlockMessage !== "" ) {
.done( function() {
doEditPage( talkPage, wpMassBlockMessage, wpMassBlockSummaryTalk, !isInfty )
talkpageedited++;
if.done( function( wpMassBlockProtectTalk ) {
talkpageedited++;
doProtectPage( talkPage, 'edit=sysop|move=sysop' )
if ( wpMassBlockProtectTalk ) {
doProtectPage( talkPage, 'edit=sysop|move=sysop' )
.done( function() {
talkpageprotected++;
} )
.fail( function( e ) {
errorHandler( e, user, "protect-talk" );
} )
.always( function() {
talkDone.resolve();
} );
} else {
talkDone.resolve();
}
} )
.fail( function( e ) {
errorHandler( e, user, "edit-talk" );
talkDone.resolve();
} );
} else if ( wpMassBlockProtectTalk ) {
new mw.Api().get( {
action: 'query',
titles: talkPage
} )
.then( function( data ) {
var exists = Object.keys( data.query.pages )[ 0 ] !== -1,
prType = exists ? 'edit=sysop|move=sysop' : 'create=sysop';
doProtectPage( talkPage, prType )
.done( function() {
talkpageprotected++;
Line 183 ⟶ 245:
talkDone.resolve();
} );
} else {)
.fail( function( e ) {
errorHandler( e, user, "query-talk" );
talkDone.resolve();
} );
} )else {
talkDone.resolve();
.fail( function( e ) {
}
errorHandler( e, user, "edit-talk" );
talkDone.resolve();
} );
} else if ( wpMassBlockProtectTalk ) {
new mw.Api().get( {
action: 'query',
titles: talkPage
} )
.then( function( data ) {
var exists = Object.keys( data.query.pages )[ 0 ] !== -1,
prType = exists ? 'edit=sysop|move=sysop' : 'create=sysop';
doProtectPage( talkPage, prType )
.done( function() {
talkpageprotected++;
} )
.fail( function( e ) {
errorHandler( e, user, "protect-talk" );
} )
.always( function() {
talkDone.resolve();
} );
} )
.fail( function( e ) {
errorHandler( e, user, "query-talk" );
talkDone.resolve();
} );
} else {
talkDone.resolve();
}
 
if ( wpMassBlockTag !== "" ) {
doEditPage( userPage, wpMassBlockTag, wpMassBlockSummaryUser )
.done( function() {
userpageedited++;
if ( wpMassBlockProtectUser ) {
doProtectPage( userPage, 'edit=sysop|move=sysop' )
.done( function() {
userpageprotected++;
} )
.fail( function( e ) {
errorHandler( e, user, "protect-user" );
} )
.always( function() {
userDone.resolve();
} );
} else {
userDone.resolve();
}
} )
.fail( function( e ) {
errorHandler( e, user, "edit-user" );
userDone.resolve();
} );
} else if ( wpMassBlockProtectUser ) {
new mw.Api().get( {
action: 'query',
titles: userPage
} )
.then( function( data ) {
var exists = Object.keys( data.query.pages )[ 0 ] !== -1,
prType = exists ? 'edit=sysop|move=sysop' : 'create=sysop';
doProtectPage( userPage, prType )
.done( function() {
userpageprotected++;
Line 233 ⟶ 295:
userDone.resolve();
} );
} else {)
.fail( function( e ) {
errorHandler( e, user, "query-user" );
userDone.resolve();
} );
} )else {
userDone.resolve();
.fail( function( e ) {
}
errorHandler( e, user, "edit-user" );
userDone.resolve();
} );
} else if ( wpMassBlockProtectUser ) {
new mw.Api().get( {
action: 'query',
titles: userPage
} )
.then( function( data ) {
var exists = Object.keys( data.query.pages )[ 0 ] !== -1,
prType = exists ? 'edit=sysop|move=sysop' : 'create=sysop';
doProtectPage( userPage, prType )
.done( function() {
userpageprotected++;
} )
.fail( function( e ) {
errorHandler( e, user, "protect-user" );
} )
.always( function() {
userDone.resolve();
} );
} )
.fail( function( e ) {
errorHandler( e, user, "query-user" );
userDone.resolve();
} );
} else {
userDone.resolve();
}
 
return $.when( talkDone, userDone );
};
 
// Array of Promises, one for each user. Each one is resolved after the user
// is processed, even in case of failure.
var deferreds = [];
 
users.forEach( function( user ) {
deferreds.push(
doBlock( user )
.then(
function( data ) {
return successHandler( data );
},
function( e ) {
errorHandler( e, user, "block" );
// Return so that this counts as resolved and won't leave
// other promises unresolved.
return $.when();
}
)
);
} );
 
$.when.apply( $, deferreds ).always( function() {
doPostBlockActions( errors );
OO.ui.alert(
msg( 'result-alert' ).replace( '$1', blocked ).replace( '$2', talkpageedited ).replace( '$3', userpageedited )
.replace( '$4', talkpageprotected ).replace( '$5', userpageprotected )
);
} );
}
 
/**
* Executed after all users have been processed.
*
* @param {Object} errors The errors collected on the way. The structure of
* this object is { username: [ { action: errorcode }, ... ], ... }
*/
function doPostBlockActions( errors ) {
if ( Object.keys( errors ).length > 0 ) {
var linkedList = "";
 
var errorsToCodes = function( el ) {
var key = Object.keys( el )[ 0 ],
action = key.split( "-" )[ 0 ],
link = '//mediawiki.org/wiki/API:' + action + '#Possible_errors';
return key + ': <code style="color:red">' +
el[ key ] + '</code> (<a href="' + link + '">' +
msg( 'failure-help' ) + '</a>)';
};
 
for ( var user in errors ) {
var codes = errors[ user ].map( errorsToCodes );
linkedList += "<li><a href=\"" + mw.config.get( 'wgScript' ) + "?title=Special:Contributions/" + encodeURIComponent( user ) + "\">" + user + "</a>: " +
codes.join( "; " ) + "</li>";
}
$( "#wpMassBlockFailedContainer" ).html(
'<h3>' + msg( 'failed-actions' ) + '</h3><ul>' + linkedList + '</ul><hr />'
);
}
$( "#wpMassBlockFailedContainer" ).html(
'<h3>' + msg( 'failed-actions' ) + '</h3><ul>' + linkedList + '</ul><hr />'
);
}
}
 
/**
* Edit the given page.
*
* @param {string} title The title of the page
* @param {string} text The text to add
* @param {string} summary The summary to use
* @param {bool} append Whether to append the text or replace the whole page content
* @return {Promise}
*/
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 );
}
 
/**
* Protect the given page
*
* @param {string} title The page to protect
* @param {string} protections As accepted by the Protect API module
* @return {Promise}
*/
function doProtectPage( title, protections ) {
return new mw.Api().postWithToken( 'csrf', {
action: 'protect',
title: title,
summaryprotections: summaryprotections,
reason: $( "#wpMassBlockProtectReason input" ).val().trim(),
watchlist: 'nochange'
} );
if ( appendText ) {
params.appendtext = text;
} else {
params.text = text;
}
return new mw.Api().postWithEditToken( params );
}
 
/**
* Get a localised messages, or the default one as fallback.
* Protect the given page
*
* @param {string} titlemsg The pagekey of the message to protectget
* @return {string}
* @param {string} protections As accepted by the Protect API module
*/
* @return {Promise}
function msg( msg ) {
*/
return localMsg[ msg ] || defaultMsg[ msg ];
function doProtectPage( title, protections ) {
}
return new mw.Api().postWithToken( 'csrf', {
action: 'protect',
title: title,
protections: protections,
reason: $( "#wpMassBlockProtectReason input" ).val().trim(),
watchlist: 'nochange'
} );
}
 
/**
* Build the form
* Get a localised messages, or the default one as fallback.
*/
function massblockform() {
* @param {string} msg The key of the message to get
var reasons = mw.msg( 'Ipbreason-dropdown' ).split( '**' ),
* @return {string}
// OOUI elements
*/
talkTextField, userTextField, talkProtectCb, talkSummaryField,
function msg( msg ) {
userSummaryField, userProtectCb, protectReasonField;
return localMsg[ msg ] || defaultMsg[ msg ];
}
 
// Ideally this would use $wgBlockAllowsUTEdit, but it's not available.
/**
blockAllowsTalkEdit = window.___location.href.indexOf( 'it.wikipedia' ) === -1;
* Build the form
*/
function massblockform() {
var reasons = mw.msg( 'Ipbreason-dropdown' ).split( '**' ),
// OOUI elements
talkTextField, userTextField, talkProtectCb, talkSummaryField,
userSummaryField, userProtectCb, protectReasonField;
 
$( "h1" ).first().html( msg( 'page-title' ) );
// Ideally this would use $wgBlockAllowsUTEdit, but it's not available.
document.title = msg( 'document-title' );
blockAllowsTalkEdit = window.___location.href.indexOf( 'it.wikipedia' ) === -1;
 
var form = new OO.ui.FormLayout( {
$( "h1" ).first().html( msg( 'page-title' ) );
id: 'wpMassBlock'
document.title = msg( 'document-title' );
} );
 
var form talkTextField = new OO.ui.FormLayoutMultilineTextInputWidget( {
rows: 10
id: 'wpMassBlock'
} );
 
talkTextField userTextField = new OO.ui.MultilineTextInputWidget( {
rows: 10
} );
 
userTextField var basicFieldset = new OO.ui.MultilineTextInputWidgetFieldsetLayout( {
label: msg( 'basic-data' ),
rows: 10
items: [
} );
new OO.ui.FieldLayout(
 
var basicFieldset = new OO.ui.FieldsetLayoutMultilineTextInputWidget( {
rows: 10
label: msg( 'basic-data' ),
items: } [), {
label: msg( 'blockusers' ),
new OO.ui.FieldLayout(
align: 'top',
new OO.ui.MultilineTextInputWidget( {
rows id: 10'wpMassBlockUsers'
} ), {
),
label: msg( 'blockusers' ),
new OO.ui.FieldLayout(
talkTextField, {
label: msg( 'talkmsg' ),
align: 'top',
id: 'wpMassBlockMessage'
}
),
new OO.ui.FieldLayout( userTextField, {
label: msg( 'upmsg' ),
align: 'top',
id: 'wpMassBlockUserswpMassBlockTag'
} )
),]
} );
new OO.ui.FieldLayout(
talkTextField, {
label: msg( 'talkmsg' ),
align: 'top',
id: 'wpMassBlockMessage'
}
),
new OO.ui.FieldLayout( userTextField, {
label: msg( 'upmsg' ),
align: 'top',
id: 'wpMassBlockTag'
} )
]
} );
 
var reasonOpts = [ {
optgroup: msg( 'other-reason' )
},
{
data: 'other',
label: msg( 'other-reason' )
},
{
optgroup: msg( 'common-reasons' )
}
];
for ( var i = 1, j = reasons.length; i < j; i++ ) {
reasonOpts.push( {
data: reasons[ i ],
label: reasons[ i ]
} );
}
 
];
var expiryField = new OO.ui.TextInputWidget( {
for ( var i = 1, j = reasons.length; i < j; i++ ) {
maxLength: 255,
reasonOpts.push( {
id: 'wpMassBlockExpiry'
data: reasons[ i ],
label: reasons[ i ]
} );
}
 
var expiryFieldotherReasonField = new OO.ui.TextInputWidget( {
maxLength: 255,
id: 'wpMassBlockExpirywpMassBlockReason'
} );
 
var otherReasonFieldreasonsDropdown = new OO.ui.TextInputWidgetDropdownInputWidget( {
maxLength options: 255reasonOpts,
id: 'wpMassBlockReasonwpMassBlockReasons'
} ).on( 'change', function() {
} );
var reason = reasonsDropdown.getValue(),
maxlength = ( reason === "other" ? 255 : ( 255 - ': '.length ) - reason.length );
 
$( '#wpMassBlockReason input' ).attr( "maxlength", maxlength );
var reasonsDropdown = new OO.ui.DropdownInputWidget( {
} );
options: reasonOpts,
id: 'wpMassBlockReasons'
} ).on( 'change', function() {
var reason = reasonsDropdown.getValue(),
maxlength = ( reason === "other" ? 255 : ( 255 - ': '.length ) - reason.length );
 
$( '#wpMassBlockReason input' ).attr( "maxlength", maxlength );
} );
 
var blockOptsArray = [
new OO.ui.FieldLayout(
reasonsDropdown, {
label: msg( 'common-reasons' )
}
),
 
new OO.ui.FieldLayout(
var blockOptsArray = [
otherReasonField, {
new OO.ui.FieldLayout(
label: msg( 'extra-reason' )
reasonsDropdown, {
}
label: msg( 'common-reasons' )
}),
),
 
new OO.ui.FieldLayout( expiryField, {
label: msg( 'exptime' )
otherReasonField, {
} ),
label: msg( 'extra-reason' )
}
),
 
new OO.ui.FieldLayout( expiryField, {
new OO.ui.CheckboxInputWidget( {
label: msg( 'exptime' )
id: 'wpMassBlockAnononly',
} ),
selected: true
} ), {
label: msg( 'anononly' )
}
),
new OO.ui.FieldLayout(
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockAutoblock',
selected: true
} ), {
label: msg( 'autoblock' )
}
),
new OO.ui.FieldLayout(
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockNocreate',
selected: true
} ), {
label: msg( 'nocreate' )
}
),
new OO.ui.FieldLayout(
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockEmail'
} ), {
label: msg( 'noemail' )
}
)
];
 
if ( blockAllowsTalkEdit ) {
new OO.ui.FieldLayout(
blockOptsArray.push( new OO.ui.CheckboxInputWidgetFieldLayout( {
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockAnononly',
id: 'wpMassBlockTalkpage'
selected: true
} ), {
label: msg( 'anononlynotalk' )
}
), );
}
new OO.ui.FieldLayout(
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockAutoblock',
selected: true
} ), {
label: msg( 'autoblock' )
}
),
new OO.ui.FieldLayout(
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockNocreate',
selected: true
} ), {
label: msg( 'nocreate' )
}
),
new OO.ui.FieldLayout(
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockEmail'
} ), {
label: msg( 'noemail' )
}
)
];
 
if ( blockAllowsTalkEdit ) {
blockOptsArray.push( new OO.ui.FieldLayout(
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockTalkpagewpMassBlockReblock'
} ), {
label: msg( 'notalkoverride' )
}
) );
}
 
blockOptsArray.push( var blockOpts = new OO.ui.FieldLayoutFieldsetLayout( {
label: msg( 'block-options-label' ),
new OO.ui.CheckboxInputWidget( {
items: blockOptsArray
id: 'wpMassBlockReblock'
} ), {;
label: msg( 'override' )
}
) );
 
var blockOpts = new OO.ui.FieldsetLayout( {
label: msg( 'block-options-label' ),
items: blockOptsArray
} );
 
talkSummaryField =
new OO.ui.TextInputWidget( {
maxLength: 255,
id: 'wpMassBlockSummaryTalk',
value: msg( 'summary-default' ),
// The text is empty by default
disabled: true
} );
 
talkTextField.on( 'change', function() {
talkSummaryField =
talkSummaryField.setDisabled( talkTextField.getValue().trim() === '' );
new OO.ui.TextInputWidget( {
maxLength: 255,
id: 'wpMassBlockSummaryTalk',
value: msg( 'summary-default' ),
// The text is empty by default
disabled: true
} );
 
userSummaryField =
talkTextField.on( 'change', function() {
new OO.ui.TextInputWidget( {
talkSummaryField.setDisabled( talkTextField.getValue().trim() === '' );
maxLength: 255,
} );
id: 'wpMassBlockSummaryUser',
value: msg( 'summary-default' ),
// The text is empty by default
disabled: true
} );
 
userTextField.on( 'change', function() {
userSummaryField =
userSummaryField.setDisabled( userTextField.getValue().trim() === '' );
new OO.ui.TextInputWidget( {
maxLength: 255,
id: 'wpMassBlockSummaryUser',
value: msg( 'summary-default' ),
// The text is empty by default
disabled: true
} );
 
talkProtectCb =
userTextField.on( 'change', function() {
new OO.ui.CheckboxInputWidget( {
userSummaryField.setDisabled( userTextField.getValue().trim() === '' );
id: 'wpMassBlockProtectTalk',
} );
selected: true
} );
 
userProtectCb =
talkProtectCb =
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockProtectTalkwpMassBlockProtectUser',
selected: true
} );
 
protectReasonField =
userProtectCb =
new OO.ui.CheckboxInputWidgetTextInputWidget( {
maxLength: 255,
id: 'wpMassBlockProtectUser',
id: 'wpMassBlockProtectReason',
selected: true
value: msg( 'protect-reason-default' )
} );
} );
 
/**
protectReasonField =
* Toggle protection fields
new OO.ui.TextInputWidget( {
*/
maxLength: 255,
var toggleProtectionFields = function() {
id: 'wpMassBlockProtectReason',
if ( !talkProtectCb.isSelected() && !userProtectCb.isSelected() ) {
value: msg( 'protect-reason-default' )
protectReasonField.setDisabled( true );
} else {
protectReasonField.setDisabled( false );
}
};
 
talkProtectCb.on( 'change', toggleProtectionFields );
userProtectCb.on( 'change', toggleProtectionFields );
 
var furtherOpts = new OO.ui.FieldsetLayout( {
label: msg( 'further-options-label' ),
items: [
new OO.ui.FieldLayout( talkSummaryField, {
label: msg( 'talksummary' )
} ),
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' )
} )
]
} );
 
expiryField.on( 'change', function() {
/**
// Several fields cannot be used if the expiry isn't infinite
* Toggle protection fields
var enable = isInfinity( $( '#wpMassBlockExpiry input' ).val().trim() ),
*/
// These are OOUI elements
var toggleProtectionFields = function() {
disableEls = [
if ( !talkProtectCb.isSelected() && !userProtectCb.isSelected() ) {
userTextField,
protectReasonField.setDisabled( true );
talkProtectCb,
} else {
userSummaryField,
protectReasonField.setDisabled( false );
userProtectCb,
}
protectReasonField
};
];
 
for ( var el in disableEls ) {
talkProtectCb.on( 'change', toggleProtectionFields );
disableEls[ el ].setDisabled( !enable );
userProtectCb.on( 'change', toggleProtectionFields );
}
} );
 
var furtherOpts submitBtn = new OO.ui.FieldsetLayoutButtonInputWidget( {
label: msg( 'furthersubmit-options-labeltext' ),
title: msg( 'submit-text' ),
items: [
id: 'wpMassBlockSubmit',
new OO.ui.FieldLayout( talkSummaryField, {
flags: [
label: msg( 'talksummary' )
} ) 'primary',
'progressive'
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' )
} )
.on( 'click', doMassBlock );
]
} );
 
form.addItems( [ basicFieldset, blockOpts, furtherOpts, new OO.ui.FieldLayout( submitBtn ) ] );
expiryField.on( 'change', function() {
// Several fields cannot be used if the expiry isn't infinite
var enable = isInfinity( $( '#wpMassBlockExpiry input' ).val().trim() ),
// These are OOUI elements
disableEls = [
userTextField,
talkProtectCb,
userSummaryField,
userProtectCb,
protectReasonField
];
 
for ( var el in disableEls ) {
disableEls[ el ].setDisabled( !enable );
}
} );
 
var bodyContentID = ( mw.config.get( 'skin' ) === "cologneblue" ? "#article" : "#bodyContent" );
submitBtn = new OO.ui.ButtonInputWidget( {
$( bodyContentID ).html( '<div style="font-size:150%"><u>' + msg( 'abuse-disclaimer' ) + '</u></div><br /><hr /><div id="wpMassBlockFailedContainer"></div>' );
label: msg( 'submit-text' ),
$( bodyContentID ).append( form.$element );
title: msg( 'submit-text' ),
}
id: 'wpMassBlockSubmit',
flags: [
'primary',
'progressive'
]
} )
.on( 'click', doMassBlock );
 
/**
form.addItems( [ basicFieldset, blockOpts, furtherOpts, new OO.ui.FieldLayout( submitBtn ) ] );
* Utility function to tell if an expiry is infinite
*
* @param {string} expiry
* @return {bool}
*/
function isInfinity( expiry ) {
return /^(indefinite|infinite|infinity|never|)$/i.test( expiry );
}
 
$( function() {
 
var bodyContentID = if ( mw.config.get( 'skin'"wgNamespaceNumber" ) === "cologneblue"-1 ? "#article" : "#bodyContent" );&&
( mw.config.get( "wgTitle" ) == "Massblock" || mw.config.get( "wgTitle" ) === "MassBlock" ) &&
$( bodyContentID ).html( '<div style="font-size:150%"><u>' + msg( 'abuse-disclaimer' ) + '</u></div><br /><hr /><div id="wpMassBlockFailedContainer"></div>' );
( /sysop/ ).test( mw.config.get( "wgUserGroups" ) )
$( bodyContentID ).append( form.$element );
) {
}
mw.loader.using( [ 'mediawiki.util', 'mediawiki.api', 'mediawiki.jqueryMsg', 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows' ], $.ready )
 
.then( function loadMsg() {
/**
return new mw.Api().loadMessagesIfMissing( [ 'Ipbreason-dropdown' ] );
* Utility function to tell if an expiry is infinite
} )
*
.then( massblockform );
* @param {string} expiry
} else {
* @return {bool}
mw.loader.using( 'mediawiki.util' )
*/
.then( function isInfinity( expiry ) {
mw.util.addPortletLink( 'p-tb', '//it.wikipedia.org/wiki/Special:Massblock', msg( 'toolbar-text' ) );
return /^(indefinite|infinite|infinity|never|)$/i.test( expiry );
} );
}
}
 
} );
/**
}( mediaWiki, jQuery ) );
* Init this gadget.
*/
$( function() {
console.log( 'Loading Massblock.' );
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', 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows' ], $.ready )
.then( function loadMsg() {
return new mw.Api().loadMessagesIfMissing( [ 'Ipbreason-dropdown' ] );
} )
.then( massblockform );
} else {
mw.loader.using( 'mediawiki.util' )
.then( function() {
mw.util.addPortletLink( 'p-tb', mw.config.get( 'wgScript' ) + '?title=Special:Massblock', msg( 'toolbar-text' ) );
} );
}
} );