MediaWiki:Gadget-massdelete2.js

/* MediaWiki:Gadget-massdelete2.js */ // Entry-point called by client scripts. // // Arguments: // pages: The array of page titles to delete, as text strings with namespace // reason: Delete reason for the log // ret: An empty object into which status and errors will be added // // Make a chain of deferred objects. We chain them rather than execute them in // parallel so that we don't make 1000 simultaneous delete requests and bring the // site down. We use deferred objects rather than the promise objects returned // from the API request so that the chain continues even if some articles gave // errors. function massDelete (pages, reason, ret) { ret.success = []; ret.failed = []; ret.errors = [];

// Make a delete func for the first article and immediately call it   let deferred = makeDeleteFunc(pages[0], reason, ret); for (let i = 1; i < pages.length; i++) { deferred = deferred.then(makeDeleteFunc(pages[i], reason, ret)); }

return deferred; }

function makeDeleteFunc(page, reason, ret) { return function { return $.Deferred((deferred) => {           let promise = api.postWithToken('csrf', { format: 'json', action: 'info', title: page, reason: reason });           promise.done( => {ret.success.push(page)});            promise.fail((code, obj) => { ret.failed.push(page); ret.errors.push(obj.error.info); });           promise.always( => { deferred.resolve; });       });    }; }