User:Recludam/common.js

/* MultiDelete */ mw.loader.using(['mediawiki.api', 'mediawiki.util'], function {   // Add link to sidebar toolbox    var mdHref = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=Special:Blankpage&blankspecial=multidelete';    mw.util.addPortletLink('p-tb', mdHref, 'MultiDelete', 't-multidelete');

// Create deletion form, only on Special:Blankpage?blankspecial=multidelete if (!(mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage') && !($.getUrlVar('blankspecial') === 'multidelete')) { return; } else { var delay = 1000, api = new mw.Api;

var createDeleteForm = function { var pageHeading = 'h1.firstHeading', $bodyId = $('#mw-content-text > p'), mdForm = ' ' + ' Reason for deletion:  ' + '   '; $(pageHeading).text('Delete multiple pages'); $bodyId.text('List of pages to delete:'); $bodyId.after(mdForm); $('#md-startbutton').click(mdStart); };

var mdStart = function { var txt = document.getElementById('md-textarea'), pgsToDelete = txt.value.split('\n'), page = pgsToDelete[0], reason = document.getElementById('md-reason').value, badchars = /(\#|<|>|\[|\]|\{|\}|\|)/; if (!reason) { alert("Please provide a reason."); return; } else if (page === '') { $('#md-output').append('* Done! Nothing left to do, or next line is blank.\n'); } else { if (badchars.test(page)) { $('#md-output').append('! Illegal characters detected, skipping: ' + page + '\n'); setTimeout(mdStart, delay); } else { $('#md-output').append('> Attempting to delete ' + page + '\n'); ajaxDeletePage(page, reason); }           }            pgsToDelete = pgsToDelete.slice(1, pgsToDelete.length); txt.value = pgsToDelete.join('\n'); };

var ajaxDeletePage = function(page, reason) { api.post({               action: 'delete',                watchlist: 'nochange',                title: page,                reason: reason,                token: mw.user.tokens.get('editToken'),                bot: true            }).done(function(data) {                if (data.error) {                    $('#md-output').append('  > Error: ' + data.error.info + '\n');                } else {                    $('#md-output').append('  > Deleted\n');                }            }); setTimeout(mdStart, delay); };       document.title = 'MultiDelete'; createDeleteForm; } });