User:Void/testing.js

From TestWiki
Revision as of 00:08, 2 January 2017 by Void (talk | contribs) (simplify)

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 roundRobin = mw.util.addPortletLink(
    'p-cactions',
    '#',
    'roundRobin',
    'pt-roundrobin',
    'Swap the page titles of the current page and another.',
    null
);

$( roundRobin ).click( function () {
	var newTitle = prompt("What is the title of the other page?");
	var curTitle = mw.config.get("wgPageName");
	var moveReason = prompt("Why is this move being done?");
	var goAhead = confirm( "Move " + curTitle + " to " + newTitle + ", with reason " + moveReason + "?" );
	if (goAhead){
		robinMove( newTitle, curTitle, moveReason );
	}
});

function robinMove ( newTitle, curTitle, moveReason ) {
	var robinReason = moveReason + "; moving page " + curTitle + " to existing page " + newTitle + " (see [[WP:SWAP]])";
	var useTitle = "Draft:Move/" + newTitle;
	movePage ( newTitle, useTitle, robinReason );
    movePage ( curTitle, newTitle, robinReason );
    movePage ( useTitle, curTitle, robinReason );
    alert("Page move completed, please be sure to update any relevant information.");
}

function movePage ( curTitle, newTitle, moveReason ){
	$.ajax( {
        url: mw.util.wikiScript( 'api' ),
        type: 'POST',
        dataType: 'json',
        data: {
            format: 'json',
            action: 'move',
            from: curTitle,
            to: newTitle,
            reason: moveReason,
            movetalk: 1,
            noredirect: 1,
            token: mw.user.tokens.get( 'csrfToken' ),
        }
    } ).done(console.log( "Moved page " + curTitle + " to location " + newTitle )
    ).fail( function ( e, data ){
    	console.log( e.message );
    	console.log( JSON.stringify( data ) );
    });
}