User:Void/testing.js

From TestWiki
Revision as of 01:58, 25 October 2016 by Void (talk | contribs) (yes it is)

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
 * Simple script designed to delete all pages added to a simple browser prompt. Currently un-tested, use at your own risk!
 * You are responsible for any and all actions you take using this tool. PLEASE be careful.
 */

//Add link
var deleteLink = mw.util.addPortletLink(
    'p-personal',
    '#',
    'Mass delete',
    'pt-massdelete',
    'Mass delete pages',
    null,
    '#pt-adminlinks'
);

//Activate on link click
$( deleteLink ).click( function () {
	var pages = prompt( 'What pages to delete?\nSeparate titles with "|"' );
	var reason = prompt( 'Why are all these pages being deleted?' );
	var pagesArray = pages.split('|');											//Converts pages to an array for later
	var pagesNum = pagesArray.length;
	var goAhead = confirm( 'Go ahead and delete: ' + pagesArray );				//Yes, I realize that this method of displaying this list is messy; no, I won't fix it.
	if ( goAhead ) {
		massDelete( pagesArray );
	}
} );

//Delete the pages
function massDelete ( pagesArray ) {
	for ( var i = 0 ; i !== pagesNum ; ++i )
	{
		$.ajax( {
            url: mw.util.wikiScript( 'api' ),
            type: 'POST',
            dataType: 'json',
            data: {
                format: 'json',
                action: 'delete',
                title: pageArray[i],
                reason: "Mass deleting: " + reason,
                token: mw.user.tokens.get( 'csrfToken' ),
            }
        } );
	}
	alert('Everything has been deleted, please see the deletion log to review the deletions.');
}