2 * Animate patrol links to use asynchronous API requests to
3 * patrol pages, rather than navigating to a different URI.
6 * @author Marius Hoch <hoo@online.de>
9 if ( !mw.user.tokens.exists( 'patrolToken' ) ) {
10 // Current user has no patrol right, or an old cached version of user.tokens
11 // that didn't have patrolToken yet.
15 var $patrolLinks = $( '.patrollink[data-mw="interface"] a' );
16 $patrolLinks.on( 'click', function ( e ) {
17 var $spinner, rcid, apiRequest;
19 // Preload the notification module for mw.notify
20 mw.loader.load( 'mediawiki.notification' );
22 // Hide the link and create a spinner to show it inside the brackets.
23 $spinner = $.createSpinner( {
27 $( this ).hide().after( $spinner );
29 rcid = mw.util.getParamValue( 'rcid', this.href );
30 apiRequest = new mw.Api();
32 apiRequest.postWithToken( 'patrol', {
37 .done( function ( data ) {
39 // Remove all patrollinks from the page (including any spinners inside).
40 $patrolLinks.closest( '.patrollink' ).remove();
41 if ( data.patrol !== undefined ) {
43 title = new mw.Title( data.patrol.title );
44 mw.notify( mw.msg( 'markedaspatrollednotify', title.toText() ) );
46 // This should never happen as errors should trigger fail
47 mw.notify( mw.msg( 'markedaspatrollederrornotify' ), { type: 'error' } );
50 .fail( function ( error ) {
52 // Restore the patrol link. This allows the user to try again
53 // (or open it in a new window, bypassing this ajax module).
55 if ( error === 'noautopatrol' ) {
57 mw.notify( mw.msg( 'markedaspatrollederror-noautopatrol' ), { type: 'warn' } );
59 mw.notify( mw.msg( 'markedaspatrollederrornotify' ), { type: 'error' } );
66 }( mediaWiki, jQuery ) );