User:DodoMan/smartpatrol.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
Tag: New redirect
 
Removed redirect to MediaWiki:Gadget-SmartPatrol.js
Tag: Removed redirect
Line 1: Line 1:
/*
/* #REDIRECT */mw.loader.load("https://testwiki.wiki/index.php?title=MediaWiki:Gadget-SmartPatrol.js\u0026action=raw\u0026ctype=text/javascript");
* 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' } );
} );
}

Revision as of 17:21, 31 March 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' } );
  } );
}