User:Void/testing.js

/* * Simple script designed to swap the titles of two pages. Does not seem to work, 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 = newTitle + "/temp"; 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 ) );    }); }