User:DodoMan/smartpatrol.js: Difference between revisions
Jump to navigation
Jump to search
m Justarandomamerican moved page User:Rafdodo/smartpatrol.js to User:DodoMan/smartpatrol.js: Automatically moved page while renaming the user "Rafdodo" to "DodoMan" |
m Justarandomamerican moved page User:DodoMan/smartpatrol.js to User:DodoMan~usurped/smartpatrol.js without leaving a redirect: Automatically moved page while renaming the user "DodoMan" to "DodoMan~usurped" |
||
(No difference)
|
Revision as of 13:04, 1 April 2024
/*
* This script adds a tab which allows a mass patrolling on the current page. Because it was pointless to mark as patrolled 10 intermediate versions when we can read the difference between the first and the last
*/
var totalRevisions;
var treatedRevisions = 0;
if (mw.config.get('wgNamespaceNumber') >= 0) {
mw.loader.using( [ 'mediawiki.util', 'mediawiki.api', 'oojs-ui' ], function() {
mw.util.addPortletLink( 'p-cactions', 'javascript:markAllAsPatrolled()', 'Smart patrol', 'ca-smartpatrol' );
mw.util.addPortletLink( 'p-views', 'javascript:markAllAsPatrolled()', 'Smart patrol', 'ca-smartpatrol2', 'Tout marquer comme relue', '', 'ca-history' );
} );
}
function markAllAsPatrolled() {
new OO.ui.confirm('Êtes-vous sur de vouloir marquer comme relue toutes les modifications ?').then( function( response ) {
if ( response === true ) {
getRevisionsList();
}
} );
}
function getRevisionsList() {
var api = new mw.Api();
api.get( {
'action': 'query',
'format': 'json',
'prop': 'revisions',
'titles': mw.config.get( 'wgPageName' ),
'formatversion': '2',
'rvprop': 'ids|user',
'rvlimit': 'max'
} ).then( function ( data ) {
var revisions = data.query.pages[ 0 ].revisions;
//var user = revisions[ 0 ].user;
totalRevisions = revisions.length;
revisions.forEach( function ( revision ) {
treatedRevisions++;
//if ( user === revision.user ) {
markRevAsPatrolled( revision.revid );
//}
} );
} ).fail( function ( error ) {
mw.notification.notify( 'Something went wrong: ' + error, { title: 'Smart Patrol', type: 'error' } );
} );
}
function markRevAsPatrolled( revid ) {
var api = new mw.Api();
api.postWithToken( 'patrol', {
'action': 'patrol',
'revid': revid
} ).then( function ( info ) {
console.log( 'Success for ' + revid, { title: 'Smart Patrol', type: 'info' } );
if ( totalRevisions == treatedRevisions ) { window.location.reload(); }
} ).fail( function ( error ) {
console.log( 'Something went wrong: ' + error, { title: 'Smart Patrol', type: 'error' } );
} );
}