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 // Hide the link and create a spinner to show it inside the brackets.
20 $spinner = $.createSpinner( {
24 $( this ).hide().after( $spinner );
26 href = $( this ).attr( 'href' );
27 rcid = mw.util.getParamValue( 'rcid', href );
28 apiRequest = new mw.Api();
32 token: mw.user.tokens.get( 'patrolToken' ),
35 .done( function ( data ) {
36 // Remove all patrollinks from the page (including any spinners inside).
37 $patrolLinks.closest( '.patrollink' ).remove();
38 if ( data.patrol !== undefined ) {
40 var title = new mw.Title( data.patrol.title );
41 mw.notify( mw.msg( 'markedaspatrollednotify', title.toText() ) );
43 // This should never happen as errors should trigger fail
44 mw.notify( mw.msg( 'markedaspatrollederrornotify' ) );
47 .fail( function ( error ) {
49 // Restore the patrol link. This allows the user to try again
50 // (or open it in a new window, bypassing this ajax module).
52 if ( error === 'noautopatrol' ) {
54 mw.notify( mw.msg( 'markedaspatrollederror-noautopatrol' ) );
56 mw.notify( mw.msg( 'markedaspatrollederrornotify' ) );
63 }( mediaWiki, jQuery ) );