2 * Enhance rollback links by using asynchronous API requests,
3 * rather than navigating to an action page.
11 $( '.mw-rollback-link' ).on( 'click', 'a[data-mw="interface"]', function ( e
) {
15 page
= mw
.util
.getParamValue( 'title', url
),
16 user
= mw
.util
.getParamValue( 'from', url
);
18 if ( !page
|| user
=== null ) {
19 // Let native browsing handle the link
23 // Preload the notification module for mw.notify
24 mw
.loader
.load( 'mediawiki.notification' );
26 // Remove event handler so that next click (re-try) uses server action
27 $( e
.delegateTarget
).off( 'click' );
29 // Hide the link and create a spinner to show it inside the brackets.
30 $spinner
= $.createSpinner( { size
: 'small', type
: 'inline' } );
31 $link
.hide().after( $spinner
);
33 // @todo: data.messageHtml is no more. Convert to using errorformat=html.
35 api
.rollback( page
, user
)
36 .then( function ( data
) {
37 mw
.notify( $.parseHTML( data
.messageHtml
), {
38 title
: mw
.msg( 'actioncomplete' )
41 // Remove link container and the subsequent text node containing " | ".
42 if ( e
.delegateTarget
.nextSibling
&& e
.delegateTarget
.nextSibling
.nodeType
=== Node
.TEXT_NODE
) {
43 $( e
.delegateTarget
.nextSibling
).remove();
45 $( e
.delegateTarget
).remove();
46 }, function ( errorCode
, data
) {
47 var message
= data
&& data
.error
&& data
.error
.messageHtml
?
48 $.parseHTML( data
.error
.messageHtml
) :
49 mw
.msg( 'rollbackfailed' ),
50 type
= errorCode
=== 'alreadyrolled' ? 'warn' : 'error';
54 title
: mw
.msg( 'rollbackfailed' ),
58 // Restore the link (enables user to try again)
67 }( mediaWiki
, jQuery
) );