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

Contenuto cancellato Contenuto aggiunto
...
+opzione per bloccare la talk anche qui
 
(28 versioni intermedie di uno stesso utente non sono mostrate)
Riga 5:
* Adapted from [[:en:User:Timotheus Canens/massblock.js]].
* Go to [[Special:Massblock]] to use it.
* If you want to add localized messages, see instructions on [[MediaWiki:Gadget-Massblock]]
*
* In order to use it, please IMPORT this page, and then add some code calling
* mw.messages.set with a list of localized messages if you wish. For an example,
* see [[:it:MediaWiki:Gadget-Massblock-it.js]]
*
* Memo: only then() can return a new promise object, done() and fail() can't.
*
* @author (i.e. blame him) [[:it:User:Daimona Eaytoy]]
* @todo This should handle the async loop more nicely, and properly use Promise
* 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'
};
 
// Default messages
// This will hold the localized messages and must be defined before importing the
mw.messages.set( {
// script (see [[MediaWiki:Gadget-Massblock.js]])
'massblock-toolbar-text': 'Massblock',
var localMsg = localMessages || {};
'massblock-document-title': 'Mass-blocking tool - Wikipedia, the free encyclopedia',
 
'massblock-page-title': 'Mass-blocking tool',
// OOUI element
'massblock-abuse-disclaimer': 'If you abuse this tool, it\'s your fault, not mine.',
var submitBtn,
'massblock-blockusers': 'Users to block (one on each line, please):',
// Like wgBlockAllowsUTEdit
'massblock-talkmsg': 'Replace talk page with, or text to add if the expiry is not infinite (leave blank to leave no message):',
blockAllowsTalkEdit;
'massblock-upmsg': 'Replace user page text with (leave blank for no change):',
 
'massblock-block-options-label': 'Block options',
/**
'massblock-further-options-label': 'Further options',
* Main form processing routine, called on form submit
'massblock-common-reasons': 'Common reasons:',
*/
'massblock-other-reason': 'Other reason',
function doMassBlock() {
'massblock-extra-reason': 'Other/additional reason:',
var users = $( "#wpMassBlockUsers textarea" ).val().split( "\n" );
'massblock-exptime': 'Expiration time, in english (blank for indefinite):',
 
'massblock-summary-default': 'Blocked user.',
// First trim everything
'massblock-talksummary': 'Edit summary for talk page edit:',
users = users.map( function( s ) {
'massblock-talkprotect': 'Protect the talk (sysop level, infinite):',
return s.trim();
'massblock-upsummary': 'Edit summary for user page edit:',
'massblock-upprotect': 'Protect the user page (sysop level, infinite):',
'massblock-protect-reason-label': 'Reason for protection:',
'massblock-protect-reason-default': 'Blocked user.',
'massblock-anononly': 'Block anonymous users only (IPs only):',
'massblock-autoblock': 'Enable autoblock (accounts only):',
'massblock-nocreate': 'Block account creation:',
'massblock-noemail': 'Block email:',
'massblock-notalk': 'Remove talk page access:',
'massblock-override': 'Override existing blocks:',
'massblock-submit-text': 'Block',
'massblock-result-alert': 'Blocked $1 users. Edited $2 talk pages and $3 user pages. Protected $4 talk pages and $5 user pages.',
'massblock-failed-actions': 'Failed actions with errors:',
'massblock-failure-help': 'help',
'massblock-init-failure': 'Unable to load the Massblock gadget. Error:'
} );
// 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 );
 
// OOUI element
var wpMassBlockReasons = $( "#wpMassBlockReasons select :selected" ).val().trim(),
var submitBtn,
wpMassBlockReason = $( "#wpMassBlockReason input" ).val().trim(),
// Ideally this would use $wgBlockAllowsUTEdit, but it's not available in JS.
blocked = 0,
talkpageeditedblockAllowsTalkEdit = 0true,
mwapi = new mw.Api();
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' );
 
var ErrorHandler = {
/**
errors: {},
* Process an error in any part of the process
/**
* 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} actione The actionerror we're doing. This is of the formcode
* @param {string} user The user we're processing
* {$actionname}-{$page}, where $action name is the name of the API module
* @param {string} action The action we're doing. This is of the form
* being used (e.g. 'block' or 'edit') and $page is either 'talk' or 'user',
* {$actionname}-{$page}, where $action name is the name of the API module
* representing the target of the action. The only special case is 'block',
* being used (e.g. 'block' or 'edit') and $page is either 'talk' or 'user',
* which has no hyphen and no page.
* 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 = {};
add: function( e, user, action ) {
obj[ action ] = e;
if var (obj !errors[= user{ ]action: )e {};
if ( !this.errors[ user ] =) [ obj ];{
this.errors[ user ] = [ obj ];
} else {
} else {
this.errors[ user ].push( obj );
}
},
getCodesForUser: function( user ) {
var cb = 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>)';
};
return this.errors[ user ].map( cb );
}
};
 
var FormData = {
init: function() {
this.dropdownReason = $( "#wpMassBlockReasons select :selected" ).val().trim();
this.otherReason = $( "#wpMassBlockReason input" ).val().trim();
this.anononly = $( "#wpMassBlockAnononly input" ).prop( 'checked' );
this.nocreate = $( "#wpMassBlockNocreate input" ).prop( 'checked' );
this.noEmail = $( "#wpMassBlockEmail input" ).prop( 'checked' );
this.autoblock = $( "#wpMassBlockAutoblock input" ).prop( 'checked' );
this.talkpageBlocked = blockAllowsTalkEdit ? $( "#wpMassBlockTalkpage input" ).prop( 'checked' ) : true;
this.reblock = $( "#wpMassBlockReblock input" ).prop( 'checked' );
this.talkMessage = $( "#wpMassBlockMessage textarea" ).val().trim();
this.expiry = $( "#wpMassBlockExpiry input" ).val().trim();
this.talkSummary = $( "#wpMassBlockSummaryTalk input" ).val().trim();
this.upSummary = $( "#wpMassBlockSummaryUser input" ).val().trim();
this.protectReason = $( "#wpMassBlockProtectReason input" ).val().trim();
 
this.isInfty = isInfinity( this.expiry );
// Several actions can only be executed if the block is infinite
this.protectTalk = $( "#wpMassBlockProtectTalk input" ).prop( 'checked' ) && this.isInfty;
this.protectUser = $( "#wpMassBlockProtectUser input" ).prop( 'checked' ) && this.isInfty;
this.upMessage = this.isInfty ? $( "#wpMassBlockTag textarea" ).val().trim() : '';
}
};
 
var Main = {
var isInfty = isInfinity( wpMassBlockExpiry );
blocked: 0,
// Several actions can only be executed if the block is infinite
talkpageedited: 0,
wpMassBlockProtectTalk = wpMassBlockProtectTalk && isInfty;
userpageedited: 0,
wpMassBlockProtectUser = wpMassBlockProtectUser && isInfty;
talkpageprotected: 0,
wpMassBlockTag = isInfty ? wpMassBlockTag : '';
userpageprotected: 0,
 
_protect: function( page, exists, counter, user ) {
 
var prType = exists ? 'edit=sysop|move=sysop' : 'create=sysop';
/**
return doProtectPage( page, 'edit=sysop|move=sysop' )
* Perform a single block via API
.done( function() {
*
this[counter]++;
* @param {string} user The user to block
} )
* @return {Promise}
.fail( function( e ) {
*/
ErrorHandler.add( e, user, "protect-talk" );
var doBlock = function( user ) {
} )
return new mw.Api().postWithToken( "csrf", {
.always( function() {
action: 'block',
return $.when();
allowusertalk: wpMassBlockTalkpage,
} );
autoblock: wpMassBlockAutoblock,
},
nocreate: wpMassBlockNocreate,
expiry: wpMassBlockExpiry === "" ? "indefinite" : wpMassBlockExpiry,
editTalk: function( user ) {
anononly: wpMassBlockAnononly,
var talkPage = getTalkTitle( user );
noemail: wpMassBlockEmail,
return doEditPage( talkPage, FormData.talkMessage, FormData.talkSummary, !FormData.isInfty )
reblock: wpMassBlockReblock,
.then(
reason: wpMassBlockReasons === "other" ? wpMassBlockReason : wpMassBlockReasons + ( wpMassBlockReason ? ": " + wpMassBlockReason : "" ),
function() {
user: user
this.talkpageedited++;
} );
if ( FormData.protectTalk ) {
return this._protect( talkPage, true, 'talkpageprotected', user );
}
}.bind( this ),
function( e ) {
ErrorHandler.add( e, user, "edit-talk" );
return $.when();
}
);
},
protectTalk: function( user ) {
var talkPage = getTalkTitle( user );
mwapi.get( {
action: 'query',
titles: talkPage
} )
.then(
function( data ) {
var exists = Object.keys( data.query.pages )[ 0 ] !== -1;
return this._protect( talkPage, exists, 'talkpageprotected', user );
}.bind( this ),
function( e ) {
ErrorHandler.add( e, user, "query-talk" );
return $.when();
}
);
},
editUP: function( user ) {
var userPage = getUPTitle( user );
doEditPage( userPage, FormData.upMessage, FormData.upSummary )
.then(
function() {
this.userpageedited++;
if ( FormData.protectUser ) {
return this._protect( userPage, true, 'userpageprotected', user );
}
}.bind( this ),
function( e ) {
ErrorHandler.add( e, user, "edit-user" );
return $.when();
}
);
},
protectUP: function( user ) {
var userPage = getUPTitle( user );
return mwapi.get( {
action: 'query',
titles: userPage
} )
.then(
function( data ) {
var exists = Object.keys( data.query.pages )[ 0 ] !== -1;
return this._protect( userPage, exists, 'userpageprotected', user );
}.bind( this ),
function( e ) {
ErrorHandler.add( e, user, "query-user" );
return $.when();
}
);
},
getAlertText: function() {
return msg( 'result-alert' )
.replace( '$1', this.blocked )
.replace( '$2', this.talkpageedited )
.replace( '$3', this.userpageedited )
.replace( '$4', this.talkpageprotected )
.replace( '$5', this.userpageprotected );
}
};
 
function getTalkTitle( user ) {
return 'User talk:' + user;
}
function getUPTitle( user ) {
return 'User:' + user;
}
 
/**
* The post-block handler. Performs edits and protections.
*
* @param {Objectstring} response The response of the block API calluser
* @return {Promise} A promise which is resolved after all actions are done
* for all pages. This will never be rejected.
*/
varfunction successHandler = function( responseuser ) {
// @var {Promise} These track the state for all actions (edit and protect)
var user = response.block.user,
// on every page. They are resolved as soon as a page is processed, with or
talkPage = 'User talk:' + user,
// without a failure. This way the final $.when will resolve after all promises
userPage = 'User:' + user,
// have been processed, and not after the first rejection.
// @var {Promise} These track the state for all actions (edit and protect)
var talkDone, userDone;
// 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();
 
Main.blocked++;
 
if ( wpMassBlockMessageFormData.talkMessage !== "" ) {
talkDone = Main.editTalk( user );
doEditPage( talkPage, wpMassBlockMessage, wpMassBlockSummaryTalk, !isInfty )
} else if ( FormData.protectTalk ) {
.done( function() {
talkDone = Main.protectTalk( user );
talkpageedited++;
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++;
} )
.fail( function( e ) {
errorHandler( e, user, "protect-talk" );
} )
.always( function() {
talkDone.resolve();
} );
} )
.fail( function( e ) {
errorHandler( e, user, "query-talk" );
talkDone.resolve();
} );
} else {
talkDone = $.resolvewhen();
}
 
if ( wpMassBlockTagFormData.upMessage !== "" ) {
userDone = Main.editUP( user );
doEditPage( userPage, wpMassBlockTag, wpMassBlockSummaryUser )
} else if ( FormData.protectUser ) {
.done( function() {
userDone = Main.protectUP( user );
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++;
} )
.fail( function( e ) {
errorHandler( e, user, "protect-user" );
} )
.always( function() {
userDone.resolve();
} );
} )
.fail( function( e ) {
errorHandler( e, user, "query-user" );
userDone.resolve();
} );
} else {
userDone = $.resolvewhen();
}
 
return $.when( talkDone, userDone );
};
 
/**
// Array of Promises, one for each user. Each one is resolved after the user
* Main form processing routine, called on form submit
// is processed, even in case of failure.
*/
var deferreds = [];
function doMassBlock() {
var users = $( "#wpMassBlockUsers textarea" ).val().split( "\n" );
 
users = users
users.forEach( function( user ) {
// First trim everything
deferreds.push(
doBlock.map( userfunction( s ) {
return s.thentrim();
function( data} ) {
// Then remove blanks and duplicates
return successHandler( data );
.filter( function( el, index, me ) {
},
return el !== '' && me.indexOf( el ) === index;
function( e ) {
} );
errorHandler( e, user, "block" );
// Return so that this counts as resolved and won't leave
// other promises unresolved.
return $.when();
}
)
);
} );
 
if ( users.length === 0 ) {
$.when.apply( $, deferreds ).always( function() {
// Easy
doPostBlockActions( errors );
return;
OO.ui.alert(
}
msg( 'result-alert' ).replace( '$1', blocked ).replace( '$2', talkpageedited ).replace( '$3', userpageedited )
submitBtn.setDisabled( true );
.replace( '$4', talkpageprotected ).replace( '$5', userpageprotected )
);
} );
}
 
FormData.init();
/**
* 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 = "";
 
// Array of Promises, one for each user. Each one is resolved after the user
var errorsToCodes = function( el ) {
// is processed, even in case of failure.
var key = Object.keys( el )[ 0 ],
var deferreds = [];
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>)';
};
 
forusers.forEach( function( var user in errors ) {
deferreds.push(
var codes = errors[ user ].map( errorsToCodes );
doBlock( user )
linkedList += "<li><a href=\"" + mw.config.get( 'wgScript' ) + "?title=Special:Contributions/" + encodeURIComponent( user ) + "\">" + user + "</a>: " +
.then(
codes.join( "; " ) + "</li>";
function() {
return successHandler( user );
},
function( e ) {
ErrorHandler.add( e, user, "block" );
// Return so that this counts as resolved and won't leave
// other promises unresolved.
return $.when();
}
)
);
} );
 
$.when.apply( $, deferreds ).always( doPostBlockActions );
}
 
/**
* Executed after all users have been processed.
*/
function doPostBlockActions() {
var errors = ErrorHandler.errors;
if ( Object.keys( errors ).length > 0 ) {
var linkedList = '';
 
for ( var user in errors ) {
var codes = ErrorHandler.getCodesForUser( user );
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(
OO.ui.alert( Main.getAlertText() );
'<h3>' + msg( 'failed-actions' ) + '</h3><ul>' + linkedList + '</ul><hr />'
);
}
}
 
/**
* Perform a single block via API
* Edit the given page.
*
* @param {string} titleuser The title ofuser theto pageblock
* @return {Promise}
* @param {string} text The text to add
*/
* @param {string} summary The summary to use
function doBlock( user ) {
* @param {bool} append Whether to append the text or replace the whole page content
return mwapi.postWithToken( "csrf", {
* @return {Promise}
action: 'block',
*/
allowusertalk: !FormData.talkpageBlocked,
function doEditPage( title, text, summary, append ) {
autoblock: FormData.autoblock,
var appendText = append || false,
nocreate: FormData.nocreate,
params = {
expiry: FormData.expiry === "" ? "indefinite" : FormData.expiry,
action: 'edit',
anononly: FormData.anononly,
noemail: FormData.noEmail,
reblock: FormData.reblock,
reason: FormData.dropdownReason === "other" ? FormData.otherReason : FormData.dropdownReason + ( FormData.otherReason ? ": " + FormData.otherReason : "" ),
user: user
} );
}
 
/**
* 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 mwapi.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 mwapi.postWithToken( 'csrf', {
action: 'protect',
title: title,
summaryprotections: summaryprotections,
reason: FormData.protectReason,
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 mw.messages.get( 'massblock-' + 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 ];
}
 
$( "h1" ).first().html( msg( 'page-title' ) );
/**
document.title = msg( 'document-title' );
* Build the form
*/
function massblockform() {
var reasons = mw.msg( 'Ipbreason-dropdown' ).split( '**' ),
// OOUI elements
talkTextField, userTextField, talkProtectCb, talkSummaryField,
userSummaryField, userProtectCb, protectReasonField;
 
var form = new OO.ui.FormLayout( {
// Ideally this would use $wgBlockAllowsUTEdit, but it's not available.
id: 'wpMassBlock'
blockAllowsTalkEdit = window.___location.href.indexOf( 'it.wikipedia' ) === -1;
} );
 
talkTextField = new OO.ui.MultilineTextInputWidget( {
$( "h1" ).first().html( msg( 'page-title' ) );
rows: 10
document.title = msg( 'document-title' );
} );
 
var form userTextField = new OO.ui.FormLayoutMultilineTextInputWidget( {
rows: 10
id: 'wpMassBlock'
} );
 
talkTextField var mainField = new OO.ui.MultilineTextInputWidgetFieldsetLayout( {
label: msg( 'blockusers' ),
rows: 10
items: [
} );
 
userTextField = new OO.ui.MultilineTextInputWidget( {
rows: 10
} );
 
var basicFieldset = new OO.ui.FieldsetLayout( {
label: msg( 'basic-data' ),
items: [
new OO.ui.FieldLayout(
new OO.ui.MultilineTextInputWidget( {
rows: 10,
} ), {
label: msg( 'blockusers' ),
align: 'top',
id: 'wpMassBlockUsers'
} )
),]
} );
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
} );
 
var toggleUserTextField = function() {
userSummaryField =
var disabled = userTextField.getValue().trim() === '' ||
new OO.ui.TextInputWidget( {
!isInfinity( $( '#wpMassBlockExpiry input' ).val().trim() );
maxLength: 255,
userSummaryField.setDisabled( disabled );
id: 'wpMassBlockSummaryUser',
};
value: msg( 'summary-default' ),
// The text is empty by default
disabled: true
} );
 
userTextField.on( 'change', function(toggleUserTextField ) {;
userSummaryField.setDisabled( userTextField.getValue().trim() === '' );
} );
 
talkProtectCb =
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockProtectTalk',
selected:} true);
} );
 
userProtectCb =
new OO.ui.CheckboxInputWidget( {
id: 'wpMassBlockProtectUser',
selected:} true);
} );
 
protectReasonField =
new OO.ui.TextInputWidget( {
maxLength: 255,
id: 'wpMassBlockProtectReason',
value: msg( 'protect-reason-default' ),
disabled: true
} );
} );
 
/**
* Toggle protection fields
*/
var toggleProtectionFields = function() {
if (
if ( !talkProtectCb.isSelected() && !userProtectCb.isSelected() ) {
!( talkProtectCb.isSelected() || userProtectCb.isSelected() ) ||
protectReasonField.setDisabled( true );
!isInfinity( $( '#wpMassBlockExpiry input' ).val().trim() )
} else {
) {
protectReasonField.setDisabled( false );
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.FieldLayoutHorizontalLayout( talkSummaryField, {
items: [
label: msg( 'talksummary' )
new OO.ui.FieldLayout(
} ),
talkTextField,
new OO.ui.FieldLayout( userSummaryField, {
{
label: msg( 'upsummary' )
label: msg( 'talkmsg' ),
} ),
align: 'top',
new OO.ui.FieldLayout( talkProtectCb, {
label id: msg( 'talkprotectwpMassBlockMessage' ),
classes: [ 'massblock-horiz-element' ]
} ),
}
new OO.ui.FieldLayout( userProtectCb, {
),
label: msg( 'upprotect' )
new OO.ui.FieldLayout(
} ),
userTextField,
new OO.ui.FieldLayout( protectReasonField, {
{
label: msg( 'protect-reason-label' )
label: msg( 'upmsg' ),
} )
align: 'top',
]
id: 'wpMassBlockTag',
} );
classes: [ 'massblock-horiz-element' ]
}
)
]
} ),
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
var enable = isInfinity( $( '#wpMassBlockExpiry input' ).val().trim() ),
// These are OOUI elements
disableEls = [
userTextField,
talkProtectCb,
userProtectCb
userSummaryField,
userProtectCb,];
protectReasonField
];
 
for ( var el in disableEls ) {
disableEls[ el ].setDisabled( !enable );
}
} );
 
toggleProtectionFields();
submitBtn = new OO.ui.ButtonInputWidget( {
toggleUserTextField();
label: msg( 'submit-text' ),
} );
title: msg( 'submit-text' ),
id: 'wpMassBlockSubmit',
flags: [
'primary',
'progressive'
]
} )
.on( 'click', doMassBlock );
 
submitBtn = new OO.ui.ButtonInputWidget( {
form.addItems( [ basicFieldset, blockOpts, furtherOpts, new OO.ui.FieldLayout( submitBtn ) ] );
label: msg( 'submit-text' ),
title: msg( 'submit-text' ),
id: 'wpMassBlockSubmit',
flags: [
'primary',
'progressive'
]
} )
.on( 'click', doMassBlock );
 
form.addItems( [ mainField, blockOpts, furtherOpts, new OO.ui.FieldLayout( submitBtn ) ] );
 
var bodyContentID = ( mw.config.get( 'skin' ) === "cologneblue" ? "#article" : "#bodyContent" );
$( bodyContentID ).html( '<div style="font-size:150%"><u>' + msg( 'abuse-disclaimer' ) + '</u></div><br /><hr /><div id="wpMassBlockFailedContainer"></div>' );
$( bodyContentID ).append( form.$element );
}
 
var bodyContentID = ( mw.config.get( 'skin' ) === "cologneblue" ? "#article" : "#bodyContent" );
/**
$( bodyContentID ).html( '<div style="font-size:150%"><u>' + msg( 'abuse-disclaimer' ) + '</u></div><br /><hr /><div id="wpMassBlockFailedContainer"></div>' );
* Utility function to tell if an expiry is infinite
$( bodyContentID ).append( form.$element );
*
}
* @param {string} expiry
* @return {bool}
*/
function isInfinity( expiry ) {
return /^(indefinite|infinite|infinity|never|)$/i.test( expiry );
}
 
/**
* Utility function to tell if an expiry is infinite
* Init this gadget.
*/
* @param {string} expiry
$( function() {
* @return {bool}
console.log( 'Loading Massblock.' );
*/
if ( mw.config.get( "wgNamespaceNumber" ) === -1 &&
function isInfinity( expiry ) {
( mw.config.get( "wgTitle" ) == "Massblock" || mw.config.get( "wgTitle" ) === "MassBlock" ) &&
return /^(indefinite|infinite|infinity|never|)$/i.test( expiry );
( /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' ) );
} );
}
 
} );
$( function() {
if ( mw.config.get( "wgNamespaceNumber" ) === -1 &&
( mw.config.get( "wgTitle" ) === "Massblock" || mw.config.get( "wgTitle" ) === "MassBlock" ) &&
( /sysop/ ).test( mw.config.get( "wgUserGroups" ) )
) {
var style ='.massblock-horiz-element{ width: 40%; }';
mw.util.addCSS( style );
mw.loader.using( [ 'mediawiki.jqueryMsg', 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows' ], $.ready )
.done( function loadMsg() {
mwapi.loadMessagesIfMissing( [ 'Ipbreason-dropdown' ] )
.done( massblockform )
.fail( function ( e ) {
mw.log.error( msg( 'init-failure' ) + ' ' + e );
} );
} )
.fail( function ( e ) {
mw.log.error( msg( 'init-failure' ) + ' ' + e );
} );
} else {
mw.util.addPortletLink( 'p-tb', mw.util.getUrl( 'Special:Massblock' ), msg( 'toolbar-text' ) );
}
} );
}( mediaWiki, jQuery ) );