Merge "Bump wikimedia/parsoid to 0.21.0-a11"
[mediawiki.git] / resources / src / mediawiki.misc-authed-curate / rollback.js
blobf84a5efffbf18d64310d8c3e79fa8d473fa7b997
1 /*!
2  * JavaScript for:
3  * - rollback confirmation prompt
4  * - firing the postEdit hook upon a successful rollback edit
5  */
6 ( function () {
7         // If a rollback was successful, RollbackAction.php will export wgRollbackSuccess
8         const wgRollbackSuccess = mw.config.get( 'wgRollbackSuccess' );
9         if ( wgRollbackSuccess ) {
10                 mw.loader.using( 'mediawiki.action.view.postEdit', () => {
11                         // wgCurRevisionId is set to the revision of the rollback
12                         // in OutputPage::getJSVars. wgRevisionId is 0, since we're looking at
13                         // the success page for the rollback and not the content of the page.
14                         // It might make sense to display a success message in a toast, like other
15                         // implementations of the postEdit hook, but for now we just want to
16                         // enable code that relies on postEdit firing to know that an edit
17                         // was made.
18                         mw.hook( 'postEdit' ).fire();
19                 } );
20         }
22         if ( Number( mw.user.options.get( 'showrollbackconfirmation' ) ) !== 1 ) {
23                 // Support both 1 or "1" (T54542)
24                 return;
25         }
27         function postRollback( url ) {
28                 $( '<form>' )
29                         .attr( {
30                                 action: url,
31                                 method: 'post'
32                         } )
33                         .appendTo( document.body )
34                         .trigger( 'submit' );
35         }
37         $( '#mw-content-text' ).confirmable( {
38                 i18n: {
39                         confirm: mw.msg( 'rollback-confirmation-confirm' ),
40                         yes: mw.msg( 'rollback-confirmation-yes' ),
41                         no: mw.msg( 'rollback-confirmation-no' )
42                 },
43                 delegate: '.mw-rollback-link a[data-mw="interface"]',
44                 handler: function ( e ) {
45                         e.preventDefault();
46                         postRollback( $( this ).attr( 'href' ) );
47                 }
48         } );
50 }() );