User:DannyS712 test/Flagged revs patroller.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:DannyS712 test/Flagged revs patroller. |
//<nowiki>
$(function (){
var patroller_config = {
name: '[[User:DannyS712/patrol|patrol.js]]',
version: 1.1,
debug: true,
comment: "BOT: Automatically patrolled"
};
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(); } );
} );
} );
async function getChanges(){
var data = await getFiltered();
console.log( data );
var stringy = JSON.stringify( data, null, 2 );
console.log( stringy );
//set_JSON ( 'User:DannyS712 test/patrol.json', stringy, 'Candidates to patrol');
}
async function getFiltered( offset ){
return new Promise((resolve) => {
new mw.Api().get({
action: 'query',
list: 'oldreviewedpages',
ormaxsize: 0,
orlimit: 'max',
formatversion: 2,
}).done( function( response ){
console.log( response );
resolve( response );
});
});
}
function shouldPatrol( page ){
if (page.diff_size === 0){
if (checkChange( page.stable_revid, page.revid )){
console.log("Will patrol:", page.title);
return true;
}
}
return false;
}
function checkChange( oldid, newid ){
var old_content = get_page( oldid );
var new_content = get_page( newid );
//console.log( old_content, new_content );
if (old_content === new_content) return true;
return false;
}
function get_page( revid ){
return new Promise((resolve) => {
new mw.Api().parse({
revid: revid,
prop: 'wikitext',
}).always( function ( response ) {
console.log( response );
resolve( response );
});
});
}
function doPatrol( revid ){
return new Promise((resolve) => {
new mw.Api().postWithEditToken({
action: 'review',
revid: revid,
comment: 'Testing',
}).always( function ( response ) {
console.log( response );
resolve( response );
});
});
}
});
//</nowiki>