| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
( function () { |
| 9 |
function patrol( link ) { |
| 10 |
const api = new mw.Api(); |
| 11 |
|
| 12 |
|
| 13 |
mw.loader.load( 'mediawiki.notification' ); |
| 14 |
|
| 15 |
|
| 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 |
|
| 28 |
$( link ).closest( '.patrollink' ).remove(); |
| 29 |
} ) |
| 30 |
.catch( ( code, data ) => { |
| 31 |
|
| 32 |
|
| 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 |
|
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$( () => { |
| 49 |
$( '.patrollink[data-mw="interface"] a' ).on( 'click', function ( e ) { |
| 50 |
patrol( this ); |
| 51 |
e.preventDefault(); |
| 52 |
} ); |
| 53 |
} ); |
| 54 |
}() ); |