MediaWiki:QuickDelete.js

/** * Quick Delete * Deletes all the pages in a specific category * * @author: w:User:Fubuki風吹 */ (function ($, mw) {   'use strict';    var config = mw.config.get([ 'wgServer', 'wgScriptPath', 'wgNamespaceNumber', 'wgTitle', 'wgUserGroups' ]),   edittoken = mw.user.tokens.values.editToken,    category = window.category || window.categories,    deletionDelay = window.quickDeleteDelay || 500;

if (       window.QuickDeleteLoaded ||        [14].indexOf(config.wgNamespaceNumber) === -1 ||        !/sysop|content-moderator|content-volunteer|vstf|staff|helper|wiki-manager|content-team-member/.test(config.wgUserGroups.join)    ) { //  return; }   window.QuickDeleteLoaded = true; if (       typeof category === 'undefined' ||         category.indexOf(config.wgTitle) !== -1    ) { $('#mw-page-header-links').append(           $('', { class: 'wds-is-squished wds-button wds-is-secondary deleteAll', title: 'Delete all pages in this category', text: 'Delete All' })       );    }    $( '.deleteAll').click( checkDeletion ); function checkDeletion { $.showCustomModal( 'Reason for deletion', 'All pages including files in this category will be deleted with the reason being:' + ' ' + 'Make sure to check if all the pages and files need to be deleted!', {           id: 'deleteModal',            width: 650,            buttons: [ {                defaultButton: true,                message: 'Delete',                handler: function  {                    deleteAll;                }            }, {                message: 'Cancel',                handler: function  {                    cancelDeletion;                }            } ]        } ); }   function deleteAll  { cancelDeletion; var delItems = []; var deleteURL; var counter = 0; $( '#mw-pages .mw-content-ltr li' ).each( function {            delItems.push( $( this ).text );        } ); $( '.gallery .gallerytext > a' ).each( function {            delItems.push( $( this ).attr( 'title' ).replace( / /g, '_' ) );        } ); var reason = $( '#wpDelReason' ).val || window.reason || 'Marked for deletion'; if ( delItems.length > 0 ) { var deletionInterval = setInterval(function {                if (counter === delItems.length) {                    clearInterval(deletionInterval);                } else {                    deleteURL = config.wgServer + config.wgScriptPath + '/api.php?action=delete&title=' + encodeURIComponent( delItems[ counter ] ) + '&token=' + encodeURIComponent( edittoken ) + '&reason=' + encodeURIComponent( reason );                    $.post( deleteURL );                    counter++;                }            }, deletionDelay); $.showCustomModal( 'Deleted', 'All pages and files in this category have been deleted.', {               id: 'deleted',                width: 450,                buttons: [ {                    defaultButton: true,                    id: 'refresh',                    message: 'Refresh',                    handler: function  {                        window.location.reload;                    }                } ]            } ); } else if ( delItems.length === 0 ) { $.showCustomModal( 'No items found', 'No pages or files found in this category.', {               id: 'no-delItems',                width: 450,                buttons: [ {                    defaultButton: true,                    message: 'OK',                    handler: function  {                        $( '#no-delItems' ).closeModal;                    }                } ]            } ); }   }    function cancelDeletion  { $( '#deleteModal' ).closeModal; } } ) ( jQuery, mediaWiki );