Jump to content

User:DannyS712 test/Flagged revs patroller.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.
//<nowiki>
$(() => {
var FRP = {};
window.FlaggedRevsPatroller = FRP;
FRP.config = {
	name: '[[User:DannyS712/Flagged revs patroller.js]]',
	version: 1.1,
	debug: true,
	comment: "BOT: Automatically patrolled"
};
FRP.getPending = function (){
	return new Promise((resolve) => {
		new mw.Api().get({
			action: 'query',
			list: 'oldreviewedpages',
			ormaxsize: 0,
			ornamespace: '*',
			orlimit: 'max',
	        formatversion: 2,
		}).done( function( response ){ 
			console.log( response );
			resolve( response );
		});
	});
};
FRP.checkChange = async function ( oldid, newid ){
	var old_content = await FRP.getPage( oldid );
	var new_content = await FRP.getPage( newid );
	//console.log( old_content, new_content );
	if ( old_content === new_content ) {
		FRP.doPatrol( newid );
	}
}
FRP.getPage = function ( revid ){
	return new Promise((resolve) => {
		new mw.Api().get({
			action: 'parse',
			oldid: revid,
			prop: 'wikitext',
		}).always( function ( response ) {
			//console.log( response );
			resolve( response.parse.wikitext['*'] );
		});
	});
};
FRP.doPatrol = function ( revid ){
	console.log( 'Patrolling:', revid );
	return new Promise((resolve) => {
		new mw.Api().postWithEditToken({
			action: 'review',
			revid: revid,
			comment: 'Testing',
		}).always( function ( response ) {
			console.log( response );
			resolve( response );
		});
	});
};
FRP.run = async function () {
	var pending = await FRP.getPending();
	console.log( pending );
	var possible = pending.query.oldreviewedpages;
	console.log( possible );
	for ( var iii = 0; iii < possible.length; iii++ ) {
		FRP.checkChange( possible[iii].stable_revid, possible[iii].revid );
	}
};
});
mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ], function () {
    $(document).ready( function () { 
    	mw.util.addPortletLink ( 'p-cactions', 'javascript:void(0)', 'Get null changes', 'ca-getChanges');
    	mw.util.addPortletLink ( 'p-cactions', 'javascript:void(0)', 'Patrol changes', 'ca-patrolChanges');
    	$('#ca-getChanges').on('click', function() { getChanges(); } );
    	$('#ca-patrolChanges').on('click', function() { patrolChanges(); } );
    } );
} );
//</nowiki>