Debian Codegraph @

resources/src/mediawiki.misc-authed-curate/patrol.js

raw symbols SCIP
1 /*!
2 * Animate patrol links to use asynchronous API requests to
3 * patrol pages, rather than navigating to a different URI.
4 *
5 * @since 1.21
6 * @author Marius Hoch <[email protected]>
7 */
8 ( function () {
9 function patrol( link ) {
10 const api = new mw.Api();
11
12 // Preload a module concurrently with the ajax request.
13 mw.loader.load( 'mediawiki.notification' );
14
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 );
18
19 api.postWithToken( 'patrol', {
20 formatversion: 2,
21 action: 'patrol',
22 rcid: mw.util.getParamValue( 'rcid', link.href )
23 } )
24 .then( ( data ) => {
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();
29 } )
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).
33 $spinner.remove();
34 $( link ).css( 'display', '' );
35
36 mw.notify(
37 api.getErrorMessage( data ),
38 { type: code === 'noautopatrol' ? 'warn' : 'error' }
39 );
40 } );
41 }
42
43 if ( !mw.user.tokens.exists( 'patrolToken' ) ) {
44 // No patrol right, let normal navigation happen.
45 return;
46 }
47
48 $( () => {
49 $( '.patrollink[data-mw="interface"] a' ).on( 'click', function ( e ) {
50 patrol( this );
51 e.preventDefault();
52 } );
53 } );
54 }() );