Page MenuHomeWickedGov Phorge

patrol.js
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

patrol.js

/*!
* Animate patrol links to use asynchronous API requests to
* patrol pages, rather than navigating to a different URI.
*
* @since 1.21
* @author Marius Hoch <hoo@online.de>
*/
( function () {
function patrol( link ) {
const api = new mw.Api();
// Preload a module concurrently with the ajax request.
mw.loader.load( 'mediawiki.notification' );
// Hide the link and show a spinner inside the brackets.
const $spinner = $.createSpinner( { size: 'small', type: 'inline' } );
$( link ).css( 'display', 'none' ).after( $spinner );
api.postWithToken( 'patrol', {
formatversion: 2,
action: 'patrol',
rcid: mw.util.getParamValue( 'rcid', link.href )
} )
.then( ( data ) => {
const title = new mw.Title( data.patrol.title );
mw.notify( mw.msg( 'markedaspatrollednotify', title.toText() ) );
// Remove link wrapper (including the spinner).
$( link ).closest( '.patrollink' ).remove();
} )
.catch( ( code, data ) => {
// Restore the link. This allows the user to try again
// (or open it in a new window, bypassing this ajax handler).
$spinner.remove();
$( link ).css( 'display', '' );
mw.notify(
api.getErrorMessage( data ),
{ type: code === 'noautopatrol' ? 'warn' : 'error' }
);
} );
}
if ( !mw.user.tokens.exists( 'patrolToken' ) ) {
// No patrol right, let normal navigation happen.
return;
}
$( () => {
$( '.patrollink[data-mw="interface"] a' ).on( 'click', function ( e ) {
patrol( this );
e.preventDefault();
} );
} );
}() );

File Metadata

Mime Type
text/plain
Expires
Tue, Aug 18, 15:18 (3 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
60/a5/1ba893ecf361cf52813bc4e9fc05
Default Alt Text
patrol.js (1 KB)

Event Timeline