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 function patrol( link ) {
10 const api = new mw.Api();
12 // Preload a module concurrently with the ajax request.
13 mw.loader.load( 'mediawiki.notification' );
15 // Hide the link and show a spinner inside the brackets.
16 const $spinner = $.createSpinner( { size: 'small', type: 'inline' } );
17 $( link ).css( 'display', 'none' ).after( $spinner );
19 api.postWithToken( 'patrol', {
22 rcid: mw.util.getParamValue( 'rcid', link.href )
25 const title = new mw.Title( data.patrol.title );
26 mw.notify( mw.msg( 'markedaspatrollednotify', title.toText() ) );
27 // Remove link wrapper (including the spinner).
28 $( link ).closest( '.patrollink' ).remove();
30 .catch( ( code, data ) => {
31 // Restore the link. This allows the user to try again
32 // (or open it in a new window, bypassing this ajax handler).
34 $( link ).css( 'display', '' );
37 api.getErrorMessage( data ),
38 { type: code === 'noautopatrol' ? 'warn' : 'error' }
43 if ( !mw.user.tokens.exists( 'patrolToken' ) ) {
44 // No patrol right, let normal navigation happen.
49 $( '.patrollink[data-mw="interface"] a' ).on( 'click', function ( e ) {