Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* <nowiki> */
/* Bharat Mitra: batch delete module (administrators only) */
( function () {
'use strict';
var BM = window.BharatMitra;
function parseList( text ) {
var seen = {};
var out = [];
String( text || '' ).split( '\n' ).forEach( function ( line ) {
var t = line.trim().replace( /^\[\[:?/, '' ).replace( /\]\]$/, '' ).trim();
if ( t && !seen[ t ] ) { seen[ t ] = 1; out.push( t ); }
} );
return out;
}
BM.register( 'batch', {
open: function () {
var stopped = false;
BM.core.dialog( {
title: 'Batch delete',
help: 'Write one page name per line. Deletion happens one page at a time, slowly. To stop in between, press "Cancel".',
stoppable: true,
onStop: function () { stopped = true; },
fields: [
{ name: 'pages', label: 'List of pages (one per line)', type: 'textarea', rows: 8, required: true },
{ name: 'reason', label: 'Reason for deletion', type: 'text', required: true }
],
preview: function ( v ) {
var list = parseList( v.pages );
if ( !list.length ) { throw new Error( 'Write at least one page.' ); }
return '\'\'\'Pages to be deleted (' + list.length + '):\'\'\'\n' + list.map( function ( t ) {
return '* [[:' + t + ']]';
} ).join( '\n' );
},
submitLabel: 'Delete all',
success: 'The batch deletion process has finished.',
onSubmit: function ( v ) {
var list = parseList( v.pages );
var reason = BM.core.cleanParam( v.reason );
var done = 0;
var failed = [];
var chain = $.Deferred().resolve().promise();
list.forEach( function ( t ) {
chain = chain.then( function () {
if ( stopped ) { return null; }
return BM.core.api().postWithToken( 'delete', {
action: 'delete', title: t, reason: reason, format: 'json'
} ).then( function () {
done++;
mw.notify( 'Deleted (' + done + '/' + list.length + '): ' + t );
} ).catch( function () {
failed.push( t );
} ).then( function () {
return new $.Deferred( function ( d ) { setTimeout( d.resolve, 700 ); } ).promise();
} );
} );
} );
return chain.then( function () {
var msg = 'Deleted: ' + done + '/' + list.length;
if ( failed.length ) { msg += '. Failed: ' + failed.join( ', ' ); }
if ( stopped ) { msg += '. Process stopped.'; }
mw.notify( msg, { type: failed.length ? 'warn' : 'success' } );
} );
}
} );
}
} );
}() );
/* </nowiki> */