Jump to content

User:Tcncv/twinkleundelete.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = {};
}

/**
 TwinkleConfig.deletionSummaryAd (string)
 If ad should be added or not to deletion summary, default [[WP:TWINKLE|TWINKLE]]
 */
if( typeof( TwinkleConfig.deletionSummaryAd ) == 'undefined' ) {
	TwinkleConfig.deletionSummaryAd = " using [[WP:TW|TW]]";
}

function twinkleundelete() {
	if( wgNamespaceNumber < 0 || wgCurRevisionId != false ) {
		return;
	}
	if( userIsInGroup( 'sysop' ) ) {
		mw.util.addPortletLink( 'p-cactions', "javascript:twinkleundelete.callback()", "undel", "tw-undel", "Undelete em all", "");
	}
}
addOnloadHook(twinkleundelete);

twinkleundelete.callback = function twinkleundeleteCallback() {
	Wikipedia.actionCompleted.notice = 'Status';
	Wikipedia.actionCompleted.postfix = 'undeletion is now completed';

	var Window = new SimpleWindow( 800, 400 );
	var div = document.createElement( 'div' );
	Status.init( div );
	Window.setContent( div );
	Window.display();

	var query = {
		'action': 'query',
		'titles': wgPageName,
		'list' : 'deletedrevs',
		'drprop' : 'token'
	};
	var wikipedia_api = new Wikipedia.api( "Retrieving " + wgPageName, query, twinkleundelete.callbacks.QueryComplete);
	wikipedia_api.params = { 'title' : wgPageName };
	wikipedia_api.post();
}

twinkleundelete.callbacks = {
	QueryComplete: function(apiobj) {
		var xmlDoc =apiobj.responseXML;
		//alert("TRACE: Undelete query callback: xmlString= \n" + (new XMLSerializer()).serializeToString(apiobj.responseXML) + "[END]");

		var deletetoken = $(xmlDoc).find('deletedrevs page').attr('token');

		var query = {
			'action': 'undelete',
			'title': apiobj.params.title,
			'reason ': "Speedly undeleted." + TwinkleConfig.deletionSummaryAd,
			'token': deletetoken 
		};
		var wikipedia_api = new Wikipedia.api( "Undeleting " + apiobj.params.title, query, twinkleundelete.callbacks.UndeleteComplete);
		wikipedia_api.params = apiobj.params;
		wikipedia_api.post();
	},
	UndeleteComplete: function(apiobj) {
		var xmlDoc = apiobj.responseXML;
		//alert("TRACE: Undelete completion callback: xmlString= \n" + (new XMLSerializer()).serializeToString(apiobj.responseXML) + "[END]");
	}
};