User:Joeytje50/Merge.js

//Script for merging page histories. Making it easier than deleting, moving then undeleting. if (wgUserGroups.indexOf('sysop')!=1/*&&wgPageName==RuneScape:Administrator requests*/) { function callAPI(data, method, callback) { data['format'] = 'json'; $.ajax({		data: data,		dataType: 'json',		url: wgScriptPath + '/api.php',		type: method,		cache: false,		success: function(response) {			if (response.error)				alert('API error: ' + response.error.info);			else 				callback(response);		},		error: function(xhr, error) { alert('AJAX error: ' + error) }	}); } $('#easyPageMerge').html(' Merge page into Submit (Note: The pagename entered in the 2nd input is used as final pagename) ') $('button#submitMerge').click(function {	if ($('#mergepage1').val.length>0&&$('#mergepage2').val.length>0) {		var frompage = $('#mergepage1').val		var topage = $('#mergepage2').val		$('button#submitMerge').attr('disabled','disabled').html('Loading page info...')		callAPI({ 'action': 'query', 'prop': 'info|revisions', 'intoken': 'delete|move', 'titles': frompage+'|'+topage, 'rvprop': 'timestamp|ids', 'indexpageids': 'true', 'list': 'deletedrevs', 'drprop': 'token' }, 'GET', function(response) { var page1 = response.query.pages[response.query.pageids[0]]; var page2 = response.query.pages[response.query.pageids[1]]; $('button#submitMerge').html('Deleting '+topage+'...') callAPI({				'action':'delete',				'title':topage,				'token':page2.deletetoken,				'reason':'Merging page histories'			}, 'POST', function(response) {			$('button#submitMerge').html('Moving '+frompage+'...')			callAPI({ 'action':'move', 'from':frompage, 'to':topage, 'token':page1.movetoken, 'reason':'Merging page histories', 'ignorewarnings':'yes', 'noredirect': 'yes' }, 'POST', function(response) { $('button#submitMerge').html('Undeleting '+topage+'...') callAPI({				'action': 'query',				'titles': topage,				'list': 'deletedrevs',				'drprop': 'token'			}, 'GET', function(response) {				callAPI({ 'action':'undelete', 'title':topage, 'token':response.query.deletedrevs[0].token, 'reason':'Finishing merge' }, 'POST', function(response) { alert(frompage+' has been merged into '+topage+'.') $('button#submitMerge').removeAttr('disabled').html('Submit') $('#mergepage1, #mergepage2').val('') })			})			})			})		});		$('#success').html(frompage+' has been merged into '+topage+'')	} }) }