/*! * VisualEditor UserInterface MWSaveDialog class. * * @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ /** * Dialog for saving MediaWiki pages. * * Note that most methods are not safe to call before the dialog has initialized, except where * noted otherwise. * * @class * @extends OO.ui.ProcessDialog * * @constructor * @param {Object} [config] Config options */ ve.ui.MWSaveDialog = function VeUiMwSaveDialog( config ) { // Parent constructor ve.ui.MWSaveDialog.super.call( this, config ); // Properties this.editSummaryCodePointLimit = mw.config.get( 'wgCommentCodePointLimit' ); this.restoring = false; this.messages = {}; this.setupDeferred = ve.createDeferred(); this.checkboxesByName = null; this.changedEditSummary = false; this.canReview = false; this.canPreview = false; this.hasDiff = false; this.diffElement = null; this.diffElementPromise = null; this.getDiffElementPromise = null; // Initialization this.$element.addClass( 've-ui-mwSaveDialog' ); }; /* Inheritance */ OO.inheritClass( ve.ui.MWSaveDialog, OO.ui.ProcessDialog ); /* Static Properties */ ve.ui.MWSaveDialog.static.name = 'mwSave'; ve.ui.MWSaveDialog.static.title = OO.ui.deferMsg( 'visualeditor-savedialog-title-save' ); ve.ui.MWSaveDialog.static.actions = [ { action: 'save', // label will be set by config.saveButtonLabel flags: [ 'primary', 'progressive' ], modes: [ 'save', 'review', 'preview' ] }, { label: OO.ui.deferMsg( 'visualeditor-savedialog-label-resume-editing' ), flags: [ 'safe', OO.ui.isMobile() ? 'back' : 'close' ], modes: [ 'save', 'conflict' ] }, { action: 'review', label: OO.ui.deferMsg( 'visualeditor-savedialog-label-review' ), modes: [ 'save', 'preview' ] }, { action: 'preview', label: OO.ui.deferMsg( 'showpreview' ), modes: [ 'save', 'review' ] }, { action: 'approve', label: OO.ui.deferMsg( 'visualeditor-savedialog-label-review-good' ), flags: [ 'safe', 'back' ], modes: [ 'review', 'preview' ] }, { action: 'resolve', label: OO.ui.deferMsg( 'visualeditor-savedialog-label-resolve-conflict' ), flags: [ 'primary', 'progressive' ], modes: 'conflict' } ]; /* Events */ /** * @event save * @param {jQuery.Deferred} saveDeferred Deferred object to resolve/reject when the save * succeeds/fails. * Emitted when the user clicks the save button */ /** * @event review * Emitted when the user clicks the review changes button */ /** * @event preview * Emitted when the user clicks the show preview button */ /** * @event resolve * Emitted when the user clicks the resolve conflict button */ /** * @event retry * Emitted when the user clicks the retry/continue save button after an error. */ /* Methods */ /** * Set review content and show review panel. * * @param {jQuery.Promise} wikitextDiffPromise Wikitext diff HTML promise * @param {jQuery.Promise} visualDiffGeneratorPromise Visual diff promise * @param {HTMLDocument} [baseDoc] Base document against which to normalise links when rendering visualDiff */ ve.ui.MWSaveDialog.prototype.setDiffAndReview = function ( wikitextDiffPromise, visualDiffGeneratorPromise, baseDoc ) { var dialog = this; this.clearDiff(); function createDiffElement( visualDiff ) { var diffElement = new ve.ui.DiffElement( visualDiff ); // The following classes are used here: // * mw-content-ltr // * mw-content-rtl diffElement.$document.addClass( [ 'mw-body-content', 'mw-parser-output', // HACK: T287733 mw.config.get( 'skin' ) === 'vector' || mw.config.get( 'skin' ) === 'vector-2022' ? 'vector-body' : null, 'mw-content-' + visualDiff.newDoc.getDir() ] ); ve.targetLinksToNewWindow( diffElement.$document[ 0 ] ); // Run styles so links render with their appropriate classes ve.init.platform.linkCache.styleParsoidElements( diffElement.$document, baseDoc ); mw.libs.ve.fixFragmentLinks( diffElement.$document[ 0 ], mw.Title.newFromText( ve.init.target.getPageName() ), 'mw-save-visualdiff-' ); return diffElement; } // Visual diff this.$reviewVisualDiff.append( new OO.ui.ProgressBarWidget().$element ); // Don't generate the DiffElement until the tab is switched to this.getDiffElementPromise = function () { return visualDiffGeneratorPromise.then( function ( visualDiffGenerator ) { return createDiffElement( visualDiffGenerator() ); } ); }; this.baseDoc = baseDoc; // Wikitext diff this.$reviewWikitextDiff.append( new OO.ui.ProgressBarWidget().$element ); wikitextDiffPromise.then( function ( wikitextDiff ) { if ( wikitextDiff ) { // wikitextDiff is an HTML string we trust from the API // eslint-disable-next-line no-jquery/no-append-html dialog.$reviewWikitextDiff.empty().append( wikitextDiff ); } else { dialog.$reviewWikitextDiff.empty().append( $( '
' ).addClass( 've-ui-mwSaveDialog-license' ); this.$saveMessages = $( '