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 a' );
16 $patrolLinks.on( 'click', function ( e ) {
17 var $spinner, href, rcid, apiRequest;
19 // Start preloading the notification module (normally loaded by mw.notify())
20 mw.loader.load( ['mediawiki.notification'], null, true );
22 // Hide the link and create a spinner to show it inside the brackets.
23 $spinner = $.createSpinner( {
27 $( this ).hide().after( $spinner );
29 href = $( this ).attr( 'href' );
30 rcid = mw.util.getParamValue( 'rcid', href );
31 apiRequest = new mw.Api();
33 apiRequest.postWithToken( 'patrol', {
37 .done( function ( data ) {
38 // Remove all patrollinks from the page (including any spinners inside).
39 $patrolLinks.closest( '.patrollink' ).remove();
40 if ( data.patrol !== undefined ) {
42 var title = new mw.Title( data.patrol.title );
43 mw.notify( mw.msg( 'markedaspatrollednotify', title.toText() ) );
45 // This should never happen as errors should trigger fail
46 mw.notify( mw.msg( 'markedaspatrollederrornotify' ) );
49 .fail( function ( error ) {
51 // Restore the patrol link. This allows the user to try again
52 // (or open it in a new window, bypassing this ajax module).
54 if ( error === 'noautopatrol' ) {
56 mw.notify( mw.msg( 'markedaspatrollederror-noautopatrol' ) );
58 mw.notify( mw.msg( 'markedaspatrollederrornotify' ) );
65 }( mediaWiki, jQuery ) );