Debian Codegraph @

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

raw symbols SCIP
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 }
21
22 if ( Number( mw.user.options.get( 'showrollbackconfirmation' ) ) !== 1 ) {
23 // Support both 1 or "1" (T54542)
24 return;
25 }
26
27 function postRollback( url ) {
28 $( '<form>' )
29 .attr( {
30 action: url,
31 method: 'post'
32 } )
33 .appendTo( document.body )
34 .trigger( 'submit' );
35 }
36
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 } );
49
50 }() );