2013-10-07 10:01:43 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWSaveDialog class.
|
|
|
|
*
|
2019-01-01 13:24:23 +00:00
|
|
|
* @copyright 2011-2019 VisualEditor Team and others; see AUTHORS.txt
|
2013-10-07 10:01:43 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-07-14 21:32:49 +00:00
|
|
|
* Dialog for saving MediaWiki pages.
|
2013-10-07 10:01:43 +00:00
|
|
|
*
|
2013-11-14 23:14:16 +00:00
|
|
|
* Note that most methods are not safe to call before the dialog has initialized, except where
|
|
|
|
* noted otherwise.
|
|
|
|
*
|
2013-10-07 10:01:43 +00:00
|
|
|
* @class
|
2016-12-03 23:47:29 +00:00
|
|
|
* @extends OO.ui.ProcessDialog
|
2013-10-07 10:01:43 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.ui.MWSaveDialog = function VeUiMwSaveDialog( config ) {
|
2013-10-07 10:01:43 +00:00
|
|
|
// Parent constructor
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWSaveDialog.super.call( this, config );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
|
|
|
// Properties
|
2018-02-27 21:34:27 +00:00
|
|
|
this.editSummaryByteLimit = mw.config.get( 'wgCommentByteLimit' );
|
|
|
|
this.editSummaryCodePointLimit = mw.config.get( 'wgCommentCodePointLimit' );
|
2013-10-07 10:01:43 +00:00
|
|
|
this.restoring = false;
|
|
|
|
this.messages = {};
|
2019-11-02 05:06:28 +00:00
|
|
|
this.setupDeferred = ve.createDeferred();
|
2015-08-13 16:39:24 +00:00
|
|
|
this.checkboxesByName = null;
|
2016-02-21 08:35:05 +00:00
|
|
|
this.changedEditSummary = false;
|
2016-12-13 21:55:01 +00:00
|
|
|
this.canReview = false;
|
|
|
|
this.canPreview = false;
|
2016-10-31 17:17:50 +00:00
|
|
|
this.hasDiff = false;
|
2017-04-09 12:04:15 +00:00
|
|
|
this.diffElement = null;
|
|
|
|
this.diffElementPromise = null;
|
|
|
|
this.getDiffElementPromise = null;
|
2015-08-05 21:43:23 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwSaveDialog' );
|
2013-10-07 10:01:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2016-12-03 23:47:29 +00:00
|
|
|
OO.inheritClass( ve.ui.MWSaveDialog, OO.ui.ProcessDialog );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWSaveDialog.static.name = 'mwSave';
|
|
|
|
|
2014-02-12 21:45:37 +00:00
|
|
|
ve.ui.MWSaveDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-savedialog-title-save' );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2017-08-29 20:39:11 +00:00
|
|
|
ve.ui.MWSaveDialog.static.feedbackUrl = 'https://www.mediawiki.org/wiki/Talk:VisualEditor/Diffs';
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWSaveDialog.static.actions = [
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'save',
|
2019-08-05 20:16:21 +00:00
|
|
|
// label will be set by config.saveButtonLabel
|
2017-09-26 18:59:38 +00:00
|
|
|
flags: [ 'primary', 'progressive' ],
|
2018-01-08 17:52:06 +00:00
|
|
|
modes: [ 'save', 'review', 'preview' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-09-11 18:52:21 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-resume-editing' ),
|
2019-08-14 16:38:38 +00:00
|
|
|
flags: [ 'safe', OO.ui.isMobile() ? 'back' : 'close' ],
|
2019-07-01 13:11:57 +00:00
|
|
|
modes: [ 'save', 'conflict' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'review',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-review' ),
|
2016-09-01 23:54:56 +00:00
|
|
|
modes: [ 'save', 'preview' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'preview',
|
|
|
|
label: OO.ui.deferMsg( 'showpreview' ),
|
|
|
|
modes: [ 'save', 'review' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'approve',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-review-good' ),
|
2019-07-01 13:11:57 +00:00
|
|
|
flags: [ 'safe', 'back' ],
|
2016-09-01 23:54:56 +00:00
|
|
|
modes: [ 'review', 'preview' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'resolve',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-resolve-conflict' ),
|
2017-09-26 18:59:38 +00:00
|
|
|
flags: [ 'primary', 'progressive' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
modes: 'conflict'
|
2017-08-29 20:39:11 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'report',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-visual-diff-report' ),
|
|
|
|
flags: [ 'progressive' ],
|
|
|
|
modes: 'review',
|
|
|
|
framed: false,
|
|
|
|
icon: 'feedback',
|
|
|
|
classes: [ 've-ui-mwSaveDialog-visualDiffFeedback' ],
|
|
|
|
href: ve.ui.MWSaveDialog.static.feedbackUrl
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/* Events */
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/**
|
|
|
|
* @event save
|
2014-05-28 22:05:17 +00:00
|
|
|
* @param {jQuery.Deferred} saveDeferred Deferred object to resolve/reject when the save
|
|
|
|
* succeeds/fails.
|
2013-11-14 23:14:16 +00:00
|
|
|
* Emitted when the user clicks the save button
|
|
|
|
*/
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/**
|
|
|
|
* @event review
|
|
|
|
* Emitted when the user clicks the review changes button
|
|
|
|
*/
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2016-09-01 23:54:56 +00:00
|
|
|
/**
|
|
|
|
* @event preview
|
|
|
|
* Emitted when the user clicks the show preview button
|
|
|
|
*/
|
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/**
|
|
|
|
* @event resolve
|
|
|
|
* Emitted when the user clicks the resolve conflict button
|
|
|
|
*/
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2014-10-30 00:36:02 +00:00
|
|
|
/**
|
|
|
|
* @event retry
|
|
|
|
* Emitted when the user clicks the retry/continue save button after an error.
|
|
|
|
*/
|
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/* Methods */
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
2013-11-14 23:14:16 +00:00
|
|
|
* Set review content and show review panel.
|
2013-11-05 00:29:50 +00:00
|
|
|
*
|
2017-05-08 18:57:43 +00:00
|
|
|
* @param {jQuery.Promise} wikitextDiffPromise Wikitext diff HTML promise
|
2017-07-17 16:38:32 +00:00
|
|
|
* @param {jQuery.Promise} visualDiffGeneratorPromise Visual diff promise
|
2017-03-30 16:37:54 +00:00
|
|
|
* @param {HTMLDocument} [baseDoc] Base document against which to normalise links when rendering visualDiff
|
2013-11-05 00:29:50 +00:00
|
|
|
*/
|
2017-05-08 18:57:43 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.setDiffAndReview = function ( wikitextDiffPromise, visualDiffGeneratorPromise, baseDoc ) {
|
2017-04-10 11:38:11 +00:00
|
|
|
var dialog = this;
|
|
|
|
|
|
|
|
this.clearDiff();
|
|
|
|
|
2017-07-17 16:38:32 +00:00
|
|
|
function createDiffElement( visualDiff ) {
|
|
|
|
var diffElement = new ve.ui.DiffElement( visualDiff );
|
2019-01-04 22:23:23 +00:00
|
|
|
diffElement.$document.addClass( 'mw-body-content mw-parser-output mw-content-' + visualDiff.newDoc.getDir() );
|
2019-02-22 21:41:33 +00:00
|
|
|
ve.targetLinksToNewWindow( diffElement.$document[ 0 ] );
|
2017-07-17 16:38:32 +00:00
|
|
|
// Run styles so links render with their appropriate classes
|
|
|
|
ve.init.platform.linkCache.styleParsoidElements( diffElement.$document, baseDoc );
|
2019-02-22 21:42:38 +00:00
|
|
|
ve.fixFragmentLinks( diffElement.$document[ 0 ], mw.Title.newFromText( ve.init.target.getPageName() ), 'mw-save-visualdiff-' );
|
2017-07-17 16:38:32 +00:00
|
|
|
return diffElement;
|
|
|
|
}
|
|
|
|
|
2017-04-10 11:38:11 +00:00
|
|
|
// Visual diff
|
|
|
|
this.$reviewVisualDiff.append( new OO.ui.ProgressBarWidget().$element );
|
2017-07-17 16:38:32 +00:00
|
|
|
// 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;
|
2016-10-31 17:17:50 +00:00
|
|
|
|
2017-04-10 11:38:11 +00:00
|
|
|
// Wikitext diff
|
|
|
|
this.$reviewWikitextDiff.append( new OO.ui.ProgressBarWidget().$element );
|
|
|
|
wikitextDiffPromise.then( function ( wikitextDiff ) {
|
|
|
|
if ( wikitextDiff ) {
|
|
|
|
dialog.$reviewWikitextDiff.empty().append( wikitextDiff );
|
|
|
|
} else {
|
|
|
|
dialog.$reviewWikitextDiff.empty().append(
|
|
|
|
$( '<div>' ).addClass( 've-ui-mwSaveDialog-no-changes' ).text( ve.msg( 'visualeditor-diff-no-changes' ) )
|
|
|
|
);
|
|
|
|
}
|
2019-11-04 14:54:53 +00:00
|
|
|
}, function ( code, errorObject ) {
|
|
|
|
dialog.$reviewWikitextDiff.empty().append(
|
|
|
|
new OO.ui.MessageWidget( {
|
|
|
|
type: 'error',
|
|
|
|
label: ve.init.target.extractErrorMessages( errorObject )
|
|
|
|
} ).$element
|
|
|
|
);
|
2017-04-10 11:38:11 +00:00
|
|
|
} ).always( function () {
|
|
|
|
dialog.updateSize();
|
|
|
|
} );
|
|
|
|
|
2016-10-31 17:17:50 +00:00
|
|
|
this.hasDiff = true;
|
2014-04-18 20:32:25 +00:00
|
|
|
this.popPending();
|
2013-11-05 00:29:50 +00:00
|
|
|
this.swapPanel( 'review' );
|
|
|
|
};
|
|
|
|
|
2016-09-01 23:54:56 +00:00
|
|
|
/**
|
|
|
|
* Set preview content and show preview panel.
|
|
|
|
*
|
2017-06-17 01:20:06 +00:00
|
|
|
* @param {HTMLDocument|string} docOrMsg Document to preview, or error message
|
|
|
|
* @param {HTMLDocument} [baseDoc] Base document against which to normalise links, if document provided
|
2016-09-01 23:54:56 +00:00
|
|
|
*/
|
2017-06-17 01:20:06 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.showPreview = function ( docOrMsg, baseDoc ) {
|
2018-05-09 20:12:26 +00:00
|
|
|
var body, contents, $heading, redirectMeta, deferred,
|
2018-04-02 16:34:51 +00:00
|
|
|
$redirect = $(),
|
2017-08-13 19:22:04 +00:00
|
|
|
categories = [],
|
2018-05-09 20:12:26 +00:00
|
|
|
modules = [],
|
|
|
|
dialog = this;
|
2017-06-17 01:20:06 +00:00
|
|
|
|
|
|
|
if ( docOrMsg instanceof HTMLDocument ) {
|
2017-08-13 19:22:04 +00:00
|
|
|
// Extract required modules for stylesheet tags (avoids re-loading styles)
|
2018-03-08 16:02:48 +00:00
|
|
|
Array.prototype.forEach.call( docOrMsg.head.querySelectorAll( 'link[rel~=stylesheet]' ), function ( link ) {
|
2017-08-13 19:22:04 +00:00
|
|
|
var uri = new mw.Uri( link.href );
|
|
|
|
if ( uri.query.modules ) {
|
|
|
|
modules = modules.concat( ve.expandModuleNames( uri.query.modules ) );
|
|
|
|
}
|
|
|
|
} );
|
2018-02-13 16:22:56 +00:00
|
|
|
// Remove skin-specific modules (T187075)
|
|
|
|
modules = modules.filter( function ( module ) {
|
|
|
|
return module.indexOf( 'skins.' ) !== 0;
|
|
|
|
} );
|
2017-08-13 19:22:04 +00:00
|
|
|
mw.loader.using( modules );
|
2017-06-17 01:20:06 +00:00
|
|
|
body = docOrMsg.body;
|
2017-06-17 01:24:34 +00:00
|
|
|
// Take a snapshot of all categories
|
2018-03-08 16:02:48 +00:00
|
|
|
Array.prototype.forEach.call( body.querySelectorAll( 'link[rel~="mw:PageProp/Category"]' ), function ( element ) {
|
2018-05-09 20:12:26 +00:00
|
|
|
categories.push( ve.dm.nodeFactory.createFromElement( ve.dm.MWCategoryMetaItem.static.toDataElement( [ element ] ) ) );
|
2017-06-17 01:24:34 +00:00
|
|
|
} );
|
2017-06-17 01:20:06 +00:00
|
|
|
// Import body to current document, then resolve attributes against original document (parseDocument called #fixBase)
|
|
|
|
document.adoptNode( body );
|
|
|
|
|
|
|
|
// TODO: This code is very similar to ve.ui.PreviewElement+ve.ui.MWPreviewElement
|
|
|
|
ve.resolveAttributes( body, docOrMsg, ve.dm.Converter.static.computedAttributes );
|
|
|
|
|
2018-03-13 10:23:15 +00:00
|
|
|
$heading = $( '<h1>' ).addClass( 'firstHeading' );
|
|
|
|
|
|
|
|
// Document title will only be set if wikitext contains {{DISPLAYTITLE}}
|
|
|
|
if ( docOrMsg.title ) {
|
|
|
|
// HACK: Parse title as it can contain basic wikitext (T122976)
|
2018-05-04 13:30:10 +00:00
|
|
|
ve.init.target.getContentApi().post( {
|
2018-03-13 10:23:15 +00:00
|
|
|
action: 'parse',
|
2018-05-04 13:30:10 +00:00
|
|
|
title: ve.init.target.getPageName(),
|
2018-03-13 10:23:15 +00:00
|
|
|
prop: 'displaytitle',
|
|
|
|
text: '{{DISPLAYTITLE:' + docOrMsg.title + '}}\n'
|
|
|
|
} ).then( function ( response ) {
|
|
|
|
if ( ve.getProp( response, 'parse', 'displaytitle' ) ) {
|
|
|
|
$heading.html( response.parse.displaytitle );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2018-04-02 16:34:51 +00:00
|
|
|
// Redirect
|
|
|
|
redirectMeta = body.querySelector( 'link[rel="mw:PageProp/redirect"]' );
|
|
|
|
if ( redirectMeta ) {
|
|
|
|
$redirect = ve.init.mw.ArticleTarget.static.buildRedirectMsg(
|
|
|
|
ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref(
|
|
|
|
redirectMeta.getAttribute( 'href' ),
|
|
|
|
document
|
|
|
|
).title
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-23 21:02:24 +00:00
|
|
|
// Remove metadata
|
|
|
|
contents = ve.filterMetaElements( Array.prototype.slice.call( body.childNodes ) );
|
|
|
|
|
2017-06-17 01:20:06 +00:00
|
|
|
this.$previewViewer.empty().append(
|
2018-03-12 23:07:02 +00:00
|
|
|
// TODO: This won't work with formatted titles (T122976)
|
2018-05-04 13:30:10 +00:00
|
|
|
$heading.text( docOrMsg.title || mw.Title.newFromText( ve.init.target.getPageName() ).getPrefixedText() ),
|
2018-04-02 16:34:51 +00:00
|
|
|
$redirect,
|
2017-06-17 01:20:06 +00:00
|
|
|
$( '<div>' ).addClass( 'mw-content-' + mw.config.get( 'wgVisualEditor' ).pageLanguageDir ).append(
|
|
|
|
contents
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2017-11-29 17:24:32 +00:00
|
|
|
ve.targetLinksToNewWindow( this.$previewViewer[ 0 ] );
|
|
|
|
// Add styles so links render with their appropriate classes
|
|
|
|
ve.init.platform.linkCache.styleParsoidElements( this.$previewViewer, baseDoc );
|
2019-01-03 17:11:29 +00:00
|
|
|
ve.fixFragmentLinks( this.$previewViewer[ 0 ], mw.Title.newFromText( ve.init.target.getPageName() ), 'mw-save-preview-' );
|
2017-11-29 17:24:32 +00:00
|
|
|
|
2018-05-09 20:12:26 +00:00
|
|
|
if ( categories.length ) {
|
|
|
|
// If there are categories, we need to render them. This involves
|
|
|
|
// a delay, since they might be hidden categories.
|
|
|
|
deferred = ve.init.target.renderCategories( categories ).done( function ( $categories ) {
|
|
|
|
dialog.$previewViewer.append( $categories );
|
|
|
|
|
|
|
|
ve.targetLinksToNewWindow( $categories[ 0 ] );
|
|
|
|
// Add styles so links render with their appropriate classes
|
|
|
|
ve.init.platform.linkCache.styleParsoidElements( $categories, baseDoc );
|
|
|
|
} );
|
|
|
|
} else {
|
2019-11-02 05:06:28 +00:00
|
|
|
deferred = ve.createDeferred().resolve();
|
2018-05-09 20:12:26 +00:00
|
|
|
}
|
|
|
|
deferred.done( function () {
|
|
|
|
// Run hooks so other things can alter the document
|
|
|
|
mw.hook( 'wikipage.content' ).fire( dialog.$previewViewer );
|
|
|
|
} );
|
2017-06-17 01:20:06 +00:00
|
|
|
} else {
|
|
|
|
this.$previewViewer.empty().append(
|
|
|
|
$( '<em>' ).text( docOrMsg )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-09-01 23:54:56 +00:00
|
|
|
this.popPending();
|
|
|
|
this.swapPanel( 'preview' );
|
|
|
|
};
|
|
|
|
|
2014-11-05 23:23:48 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.pushPending = function () {
|
2016-09-01 23:54:56 +00:00
|
|
|
this.getActions().setAbilities( { review: false, preview: false } );
|
2014-11-05 23:23:48 +00:00
|
|
|
return ve.ui.MWSaveDialog.super.prototype.pushPending.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.popPending = function () {
|
|
|
|
var ret = ve.ui.MWSaveDialog.super.prototype.popPending.call( this );
|
|
|
|
if ( !this.isPending() ) {
|
2016-09-01 23:54:56 +00:00
|
|
|
this.getActions().setAbilities( { review: true, preview: true } );
|
2014-11-05 23:23:48 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/**
|
|
|
|
* Clear the diff displayed in the review panel, if any.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.clearDiff = function () {
|
2016-10-31 17:17:50 +00:00
|
|
|
this.$reviewWikitextDiff.empty();
|
2017-04-10 11:38:11 +00:00
|
|
|
this.$reviewVisualDiff.empty();
|
2016-09-01 23:54:56 +00:00
|
|
|
this.$previewViewer.empty();
|
2016-10-31 17:17:50 +00:00
|
|
|
this.hasDiff = false;
|
2017-04-10 11:38:11 +00:00
|
|
|
this.diffElement = null;
|
|
|
|
this.diffElementPromise = null;
|
|
|
|
this.getDiffElementPromise = null;
|
2013-11-14 23:14:16 +00:00
|
|
|
};
|
|
|
|
|
2013-10-07 10:01:43 +00:00
|
|
|
/**
|
|
|
|
* Swap state in the save dialog.
|
|
|
|
*
|
2017-04-10 11:38:11 +00:00
|
|
|
* @param {string} panel One of 'save', 'review' or 'conflict'
|
2016-12-13 12:57:13 +00:00
|
|
|
* @param {boolean} [noFocus] Don't attempt to focus anything (e.g. while setting up)
|
2013-10-07 10:01:43 +00:00
|
|
|
* @throws {Error} Unknown saveDialog panel
|
|
|
|
*/
|
2016-12-13 12:57:13 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.swapPanel = function ( panel, noFocus ) {
|
2014-02-10 18:33:13 +00:00
|
|
|
var currentEditSummaryWikitext,
|
2016-10-27 00:56:18 +00:00
|
|
|
mode = panel,
|
2015-09-21 17:19:53 +00:00
|
|
|
size = 'medium',
|
2014-02-10 18:33:13 +00:00
|
|
|
dialog = this,
|
2015-08-19 17:33:02 +00:00
|
|
|
panelObj = dialog[ panel + 'Panel' ];
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2017-04-10 11:38:11 +00:00
|
|
|
if ( ( [ 'save', 'review', 'preview', 'conflict' ].indexOf( panel ) ) === -1 ) {
|
2013-10-07 10:01:43 +00:00
|
|
|
throw new Error( 'Unknown saveDialog panel: ' + panel );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the window title
|
2019-08-28 15:41:19 +00:00
|
|
|
// The following messages are used here:
|
|
|
|
// * visualeditor-savedialog-title-conflict
|
|
|
|
// * visualeditor-savedialog-title-preview
|
|
|
|
// * visualeditor-savedialog-title-review
|
|
|
|
// * visualeditor-savedialog-title-save
|
2014-07-14 21:32:49 +00:00
|
|
|
this.title.setLabel( ve.msg( 'visualeditor-savedialog-title-' + panel ) );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
|
|
|
// Reset save button if we disabled it for e.g. unrecoverable spam error
|
2014-08-22 20:50:48 +00:00
|
|
|
this.actions.setAbilities( { save: true } );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2016-12-13 12:57:13 +00:00
|
|
|
if ( !noFocus ) {
|
|
|
|
// On panels without inputs, ensure the dialog is focused so events
|
|
|
|
// are captured, e.g. 'Esc' to close
|
|
|
|
this.$content[ 0 ].focus();
|
|
|
|
}
|
2015-09-21 17:19:53 +00:00
|
|
|
|
2013-12-06 02:34:44 +00:00
|
|
|
switch ( panel ) {
|
2013-10-07 10:01:43 +00:00
|
|
|
case 'save':
|
2017-05-02 16:17:03 +00:00
|
|
|
if ( !noFocus && this.panels.getCurrentItem() !== this.savePanel ) {
|
2016-12-13 12:57:13 +00:00
|
|
|
// HACK: FF needs *another* defer
|
|
|
|
setTimeout( function () {
|
|
|
|
dialog.editSummaryInput.moveCursorToEnd();
|
|
|
|
} );
|
|
|
|
}
|
2013-10-07 10:01:43 +00:00
|
|
|
break;
|
|
|
|
case 'conflict':
|
2016-10-27 00:56:18 +00:00
|
|
|
this.actions.setAbilities( { save: false } );
|
2013-10-07 10:01:43 +00:00
|
|
|
break;
|
2016-09-01 23:54:56 +00:00
|
|
|
case 'preview':
|
|
|
|
size = 'full';
|
2016-12-31 22:04:19 +00:00
|
|
|
this.previewPanel.$element[ 0 ].focus();
|
2019-06-21 11:54:13 +00:00
|
|
|
this.previewPanel.$element.prepend( this.$previewEditSummaryContainer );
|
2016-09-01 23:54:56 +00:00
|
|
|
break;
|
2013-10-07 10:01:43 +00:00
|
|
|
case 'review':
|
2015-09-21 17:19:53 +00:00
|
|
|
size = 'larger';
|
2019-06-21 11:54:13 +00:00
|
|
|
this.reviewModeButtonSelect.$element.after( this.$previewEditSummaryContainer );
|
2016-10-31 17:17:50 +00:00
|
|
|
setTimeout( function () {
|
|
|
|
dialog.updateReviewMode();
|
2019-09-09 15:52:50 +00:00
|
|
|
|
|
|
|
ve.track(
|
|
|
|
'activity.' + dialog.constructor.static.name,
|
|
|
|
{ action: 'review-initial-' + dialog.reviewModeButtonSelect.findSelectedItem().getData() }
|
|
|
|
);
|
2016-10-31 17:17:50 +00:00
|
|
|
} );
|
2016-10-27 00:56:18 +00:00
|
|
|
break;
|
2013-10-07 10:01:43 +00:00
|
|
|
}
|
2019-06-21 11:54:13 +00:00
|
|
|
if ( panel === 'preview' || panel === 'review' ) {
|
|
|
|
currentEditSummaryWikitext = this.editSummaryInput.getValue();
|
|
|
|
if ( this.lastEditSummaryWikitext === undefined || this.lastEditSummaryWikitext !== currentEditSummaryWikitext ) {
|
|
|
|
if ( this.editSummaryXhr ) {
|
|
|
|
this.editSummaryXhr.abort();
|
|
|
|
}
|
|
|
|
this.lastEditSummaryWikitext = currentEditSummaryWikitext;
|
|
|
|
this.$previewEditSummary.empty();
|
|
|
|
|
|
|
|
if ( !currentEditSummaryWikitext || currentEditSummaryWikitext.trim() === '' ) {
|
|
|
|
// Don't bother with an API request for an empty summary
|
|
|
|
this.$previewEditSummary.text( ve.msg( 'visualeditor-savedialog-review-nosummary' ) );
|
|
|
|
} else {
|
|
|
|
this.$previewEditSummary.parent()
|
|
|
|
.removeClass( 'oo-ui-element-hidden' )
|
|
|
|
.addClass( 'mw-ajax-loader' );
|
|
|
|
this.editSummaryXhr = ve.init.target.getContentApi().post( {
|
|
|
|
action: 'parse',
|
|
|
|
title: ve.init.target.getPageName(),
|
|
|
|
prop: '',
|
|
|
|
summary: currentEditSummaryWikitext
|
|
|
|
} ).done( function ( result ) {
|
|
|
|
if ( result.parse.parsedsummary === '' ) {
|
|
|
|
dialog.$previewEditSummary.parent().addClass( 'oo-ui-element-hidden' );
|
|
|
|
} else {
|
|
|
|
// Intentionally treated as HTML
|
|
|
|
dialog.$previewEditSummary.html( ve.msg( 'parentheses', result.parse.parsedsummary ) );
|
|
|
|
ve.targetLinksToNewWindow( dialog.$previewEditSummary[ 0 ] );
|
|
|
|
}
|
|
|
|
} ).fail( function () {
|
|
|
|
dialog.$previewEditSummary.parent().addClass( 'oo-ui-element-hidden' );
|
|
|
|
} ).always( function () {
|
|
|
|
dialog.$previewEditSummary.parent().removeClass( 'mw-ajax-loader' );
|
|
|
|
dialog.updateSize();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2016-10-27 00:56:18 +00:00
|
|
|
// Show the target panel
|
|
|
|
this.panels.setItem( panelObj );
|
|
|
|
this.setSize( size );
|
|
|
|
|
|
|
|
// Set mode after setting size so that the footer is measured correctly
|
|
|
|
this.actions.setMode( mode );
|
|
|
|
|
2016-09-01 23:54:56 +00:00
|
|
|
// Only show preview in source mode
|
|
|
|
this.actions.forEach( { actions: 'preview' }, function ( action ) {
|
2016-12-13 21:55:01 +00:00
|
|
|
action.toggle( dialog.canPreview );
|
2016-09-01 23:54:56 +00:00
|
|
|
} );
|
|
|
|
|
2016-12-08 19:24:10 +00:00
|
|
|
// Diff API doesn't support section=new
|
|
|
|
this.actions.forEach( { actions: 'review' }, function ( action ) {
|
2016-12-13 21:55:01 +00:00
|
|
|
action.toggle( dialog.canReview );
|
2016-12-08 19:24:10 +00:00
|
|
|
} );
|
|
|
|
|
2019-04-23 18:27:38 +00:00
|
|
|
// Support: iOS
|
|
|
|
// HACK: iOS Safari sometimes makes the entire panel completely disappear (T221289).
|
|
|
|
// Rebuilding it makes it reappear.
|
|
|
|
OO.ui.Element.static.reconsiderScrollbars( panelObj.$element[ 0 ] );
|
|
|
|
|
2013-10-07 10:01:43 +00:00
|
|
|
mw.hook( 've.saveDialog.stateChanged' ).fire();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a message in the save dialog.
|
|
|
|
*
|
|
|
|
* @param {string} name Message's unique name
|
|
|
|
* @param {string|jQuery|Array} message Message content (string of HTML, jQuery object or array of
|
|
|
|
* Node objects)
|
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {boolean} [options.wrap="warning"] Whether to wrap the message in a paragraph and if
|
|
|
|
* so, how. One of "warning", "error" or false.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.showMessage = function ( name, message, options ) {
|
|
|
|
var $message;
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( !this.messages[ name ] ) {
|
2013-10-07 10:01:43 +00:00
|
|
|
options = options || {};
|
|
|
|
if ( options.wrap === undefined ) {
|
|
|
|
options.wrap = 'warning';
|
|
|
|
}
|
2018-02-19 15:41:20 +00:00
|
|
|
$message = $( '<div>' ).addClass( 've-ui-mwSaveDialog-message' );
|
2013-10-07 10:01:43 +00:00
|
|
|
if ( options.wrap !== false ) {
|
2015-04-09 23:47:15 +00:00
|
|
|
$message.append( $( '<p>' ).append(
|
2019-08-28 15:41:19 +00:00
|
|
|
// The following messages are used here:
|
|
|
|
// * visualeditor-savedialog-label-error
|
|
|
|
// * visualeditor-savedialog-label-warning
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<strong>' ).text( mw.msg( 'visualeditor-savedialog-label-' + options.wrap ) ),
|
2013-10-07 10:01:43 +00:00
|
|
|
document.createTextNode( mw.msg( 'colon-separator' ) ),
|
|
|
|
message
|
|
|
|
) );
|
|
|
|
} else {
|
|
|
|
$message.append( message );
|
|
|
|
}
|
2018-12-12 12:20:24 +00:00
|
|
|
this.$saveMessages.append( $message.css( 'display', 'none' ) );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2019-01-08 17:00:09 +00:00
|
|
|
// FIXME: Use CSS transitions
|
2019-02-20 20:23:43 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-slide
|
2017-01-31 13:00:25 +00:00
|
|
|
$message.slideDown( {
|
2018-12-12 12:20:24 +00:00
|
|
|
duration: 250,
|
2017-01-31 13:00:25 +00:00
|
|
|
progress: this.updateSize.bind( this )
|
|
|
|
} );
|
|
|
|
|
2017-02-16 16:32:21 +00:00
|
|
|
this.swapPanel( 'save' );
|
|
|
|
|
2015-08-19 17:33:02 +00:00
|
|
|
this.messages[ name ] = $message;
|
2013-10-07 10:01:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a message from the save dialog.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2013-10-07 10:01:43 +00:00
|
|
|
* @param {string} name Message's unique name
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.clearMessage = function ( name ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( this.messages[ name ] ) {
|
2017-01-31 13:00:25 +00:00
|
|
|
this.messages[ name ].slideUp( {
|
|
|
|
progress: this.updateSize.bind( this )
|
|
|
|
} );
|
2015-08-19 17:33:02 +00:00
|
|
|
delete this.messages[ name ];
|
2013-10-07 10:01:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all messages from the save dialog.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.clearAllMessages = function () {
|
|
|
|
this.$saveMessages.empty();
|
|
|
|
this.messages = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the fields of the save dialog.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.reset = function () {
|
|
|
|
// Reset summary input
|
2014-10-08 20:14:53 +00:00
|
|
|
this.editSummaryInput.setValue( '' );
|
2013-10-07 10:01:43 +00:00
|
|
|
// Uncheck minoredit
|
2015-08-13 16:39:24 +00:00
|
|
|
if ( this.checkboxesByName.wpMinoredit ) {
|
|
|
|
this.checkboxesByName.wpMinoredit.setSelected( false );
|
|
|
|
}
|
2016-09-01 23:54:56 +00:00
|
|
|
this.clearDiff();
|
2013-10-07 10:01:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-11-14 23:14:16 +00:00
|
|
|
* Initialize MediaWiki page specific checkboxes.
|
|
|
|
*
|
|
|
|
* This method is safe to call even when the dialog hasn't been initialized yet.
|
2013-10-07 10:01:43 +00:00
|
|
|
*
|
2015-08-13 16:39:24 +00:00
|
|
|
* @param {OO.ui.FieldLayout[]} checkboxFields Checkbox fields
|
2013-10-07 10:01:43 +00:00
|
|
|
*/
|
2015-08-13 16:39:24 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.setupCheckboxes = function ( checkboxFields ) {
|
2014-12-16 21:14:01 +00:00
|
|
|
var dialog = this;
|
2013-11-14 23:14:16 +00:00
|
|
|
this.setupDeferred.done( function () {
|
2015-08-13 16:39:24 +00:00
|
|
|
checkboxFields.forEach( function ( field ) {
|
|
|
|
dialog.$saveCheckboxes.append( field.$element );
|
|
|
|
} );
|
2019-07-16 13:28:25 +00:00
|
|
|
dialog.updateOptionsBar();
|
2014-12-16 21:14:01 +00:00
|
|
|
} );
|
2013-11-14 23:14:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the edit summary prefilled in the save dialog.
|
|
|
|
*
|
|
|
|
* This method is safe to call even when the dialog hasn't been initialized yet.
|
|
|
|
*
|
|
|
|
* @param {string} summary Edit summary to prefill
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.setEditSummary = function ( summary ) {
|
2014-12-16 21:14:01 +00:00
|
|
|
var dialog = this;
|
2013-11-14 23:14:16 +00:00
|
|
|
this.setupDeferred.done( function () {
|
2014-12-16 21:14:01 +00:00
|
|
|
dialog.editSummaryInput.setValue( summary );
|
|
|
|
} );
|
2013-10-07 10:01:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-11-05 00:29:50 +00:00
|
|
|
* @inheritdoc
|
2013-10-07 10:01:43 +00:00
|
|
|
*/
|
2013-11-05 00:29:50 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.initialize = function () {
|
2018-02-27 21:34:27 +00:00
|
|
|
var dialog = this,
|
|
|
|
mwString = require( 'mediawiki.String' );
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Parent method
|
2014-05-31 04:47:08 +00:00
|
|
|
ve.ui.MWSaveDialog.super.prototype.initialize.call( this );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Properties
|
2018-11-02 20:30:37 +00:00
|
|
|
this.panels = new OO.ui.StackLayout( { scrollable: false } );
|
2014-05-19 17:41:06 +00:00
|
|
|
this.savePanel = new OO.ui.PanelLayout( {
|
2015-09-21 16:52:19 +00:00
|
|
|
expanded: false,
|
2015-01-31 02:14:07 +00:00
|
|
|
padded: true,
|
2015-07-22 22:13:09 +00:00
|
|
|
classes: [ 've-ui-mwSaveDialog-savePanel' ]
|
2014-05-19 17:41:06 +00:00
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2014-10-09 20:52:51 +00:00
|
|
|
// Byte counter in edit summary
|
2015-01-05 21:05:42 +00:00
|
|
|
this.editSummaryCountLabel = new OO.ui.LabelWidget( {
|
2014-10-09 20:52:51 +00:00
|
|
|
classes: [ 've-ui-mwSaveDialog-editSummary-count' ],
|
2018-05-19 14:25:22 +00:00
|
|
|
label: '',
|
2018-02-27 21:34:27 +00:00
|
|
|
title: ve.msg( this.editSummaryCodePointLimit ?
|
|
|
|
'visualeditor-editsummary-characters-remaining' : 'visualeditor-editsummary-bytes-remaining' )
|
2014-10-09 20:52:51 +00:00
|
|
|
} );
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Save panel
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$editSummaryLabel = $( '<div>' ).addClass( 've-ui-mwSaveDialog-summaryLabel' )
|
2018-11-28 22:42:19 +00:00
|
|
|
.html( ve.init.platform.getParsedMessage( 'summary' ) );
|
|
|
|
ve.targetLinksToNewWindow( this.$editSummaryLabel[ 0 ] );
|
2017-04-25 11:01:41 +00:00
|
|
|
this.editSummaryInput = new ve.ui.MWEditSummaryWidget( {
|
|
|
|
$overlay: this.$overlay,
|
2015-07-20 11:51:38 +00:00
|
|
|
placeholder: ve.msg( 'visualeditor-editsummary' ),
|
|
|
|
classes: [ 've-ui-mwSaveDialog-summary' ],
|
|
|
|
inputFilter: function ( value ) {
|
|
|
|
// Prevent the user from inputting newlines (this kicks in on paste, etc.)
|
|
|
|
return value.replace( /\r?\n/g, ' ' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
// Prevent the user from inputting newlines from keyboard
|
|
|
|
this.editSummaryInput.$input.on( 'keypress', function ( e ) {
|
|
|
|
if ( e.which === OO.ui.Keys.ENTER ) {
|
|
|
|
e.preventDefault();
|
2017-02-07 20:06:44 +00:00
|
|
|
|
|
|
|
dialog.showMessage(
|
|
|
|
'keyboard-shortcut-submit',
|
|
|
|
$( '<p>' ).msg(
|
|
|
|
'visualeditor-savedialog-keyboard-shortcut-submit',
|
|
|
|
new ve.ui.Trigger( ve.ui.commandHelpRegistry.lookup( 'dialogConfirm' ).shortcuts[ 0 ] ).getMessage()
|
|
|
|
),
|
|
|
|
{ wrap: false }
|
|
|
|
);
|
2015-07-20 11:51:38 +00:00
|
|
|
}
|
|
|
|
} );
|
2018-02-27 21:34:27 +00:00
|
|
|
// Limit length, and display the remaining bytes/characters
|
|
|
|
if ( this.editSummaryCodePointLimit ) {
|
|
|
|
this.editSummaryInput.$input.codePointLimit( this.editSummaryCodePointLimit );
|
|
|
|
} else {
|
|
|
|
this.editSummaryInput.$input.byteLimit( this.editSummaryByteLimit );
|
|
|
|
}
|
2018-05-19 14:25:22 +00:00
|
|
|
this.editSummaryInput.on( 'change', function () {
|
|
|
|
var remaining;
|
|
|
|
if ( dialog.editSummaryCodePointLimit ) {
|
|
|
|
remaining = dialog.editSummaryCodePointLimit - mwString.codePointLength( dialog.editSummaryInput.getValue() );
|
|
|
|
} else {
|
|
|
|
remaining = dialog.editSummaryByteLimit - mwString.byteLength( dialog.editSummaryInput.getValue() );
|
|
|
|
}
|
|
|
|
// TODO: This looks a bit weird, there is no unit in the UI, just
|
2018-08-09 14:10:53 +00:00
|
|
|
// numbers. Users likely assume characters but then it seems to count
|
2018-05-19 14:25:22 +00:00
|
|
|
// down quicker than expected if it's byteLimit. Facing users with the
|
2018-08-09 14:10:53 +00:00
|
|
|
// word "byte" is bad? (T42035)
|
2018-05-19 14:25:22 +00:00
|
|
|
dialog.changedEditSummary = true;
|
|
|
|
if ( remaining > 99 ) {
|
|
|
|
dialog.editSummaryCountLabel.setLabel( '' );
|
|
|
|
} else {
|
|
|
|
dialog.editSummaryCountLabel.setLabel( mw.language.convertNumber( remaining ) );
|
|
|
|
}
|
2019-07-16 13:28:25 +00:00
|
|
|
|
|
|
|
dialog.updateOptionsBar();
|
2018-05-19 14:25:22 +00:00
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2015-08-13 16:39:24 +00:00
|
|
|
this.$saveCheckboxes = $( '<div>' ).addClass( 've-ui-mwSaveDialog-checkboxes' );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$saveOptions = $( '<div>' ).addClass( 've-ui-mwSaveDialog-options' ).append(
|
2015-08-13 16:39:24 +00:00
|
|
|
this.$saveCheckboxes,
|
2014-10-09 20:52:51 +00:00
|
|
|
this.editSummaryCountLabel.$element
|
2013-11-05 00:29:50 +00:00
|
|
|
);
|
2019-08-01 14:45:42 +00:00
|
|
|
this.$license = $( '<p>' ).addClass( 've-ui-mwSaveDialog-license' )
|
|
|
|
.html( ve.init.platform.getParsedMessage( 'copyrightwarning' ) );
|
2017-01-31 13:00:25 +00:00
|
|
|
this.$saveMessages = $( '<div>' ).addClass( 've-ui-mwSaveDialog-messages' );
|
2019-08-01 14:45:42 +00:00
|
|
|
this.$saveFoot = $( '<div>' ).addClass( 've-ui-mwSaveDialog-foot' ).append( this.$license );
|
2018-11-28 22:42:19 +00:00
|
|
|
ve.targetLinksToNewWindow( this.$saveFoot[ 0 ] );
|
2013-11-05 00:29:50 +00:00
|
|
|
this.savePanel.$element.append(
|
|
|
|
this.$editSummaryLabel,
|
|
|
|
this.editSummaryInput.$element,
|
|
|
|
this.$saveOptions,
|
2018-12-12 12:53:55 +00:00
|
|
|
this.$saveMessages,
|
|
|
|
this.$saveFoot
|
2013-11-05 00:29:50 +00:00
|
|
|
);
|
|
|
|
|
2019-07-16 13:28:25 +00:00
|
|
|
this.updateOptionsBar();
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Review panel
|
2015-01-31 02:14:07 +00:00
|
|
|
this.reviewPanel = new OO.ui.PanelLayout( {
|
2015-09-21 16:52:19 +00:00
|
|
|
expanded: false,
|
2015-01-31 02:14:07 +00:00
|
|
|
padded: true
|
|
|
|
} );
|
2016-10-31 17:17:50 +00:00
|
|
|
|
|
|
|
this.$reviewVisualDiff = $( '<div>' ).addClass( 've-ui-mwSaveDialog-viewer' );
|
|
|
|
this.$reviewWikitextDiff = $( '<div>' ).addClass( 've-ui-mwSaveDialog-viewer' );
|
|
|
|
|
|
|
|
this.reviewModeButtonSelect = new OO.ui.ButtonSelectWidget( {
|
|
|
|
items: [
|
|
|
|
new OO.ui.ButtonOptionWidget( { data: 'visual', icon: 'eye', label: ve.msg( 'visualeditor-savedialog-review-visual' ) } ),
|
|
|
|
new OO.ui.ButtonOptionWidget( { data: 'source', icon: 'wikiText', label: ve.msg( 'visualeditor-savedialog-review-wikitext' ) } )
|
|
|
|
],
|
|
|
|
classes: [ 've-ui-mwSaveDialog-reviewMode' ]
|
|
|
|
} );
|
2019-09-09 15:52:50 +00:00
|
|
|
this.reviewModeButtonSelect.connect( this, {
|
|
|
|
choose: 'onReviewChoose',
|
|
|
|
select: 'updateReviewMode'
|
|
|
|
} );
|
2016-10-31 17:17:50 +00:00
|
|
|
|
2019-06-21 11:54:13 +00:00
|
|
|
this.$previewEditSummary = $( '<span>' ).addClass( 've-ui-mwSaveDialog-summaryPreview' ).addClass( 'comment' );
|
|
|
|
this.$previewEditSummaryContainer = $( '<div>' )
|
|
|
|
.addClass( 'mw-summary-preview' )
|
|
|
|
.text( ve.msg( 'summary-preview' ) )
|
|
|
|
.append( $( '<br>' ), this.$previewEditSummary );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$reviewActions = $( '<div>' ).addClass( 've-ui-mwSaveDialog-actions' );
|
2014-02-10 18:33:13 +00:00
|
|
|
this.reviewPanel.$element.append(
|
2016-10-31 17:17:50 +00:00
|
|
|
this.reviewModeButtonSelect.$element,
|
|
|
|
this.$reviewVisualDiff,
|
|
|
|
this.$reviewWikitextDiff,
|
2014-02-10 18:33:13 +00:00
|
|
|
this.$reviewActions
|
|
|
|
);
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2016-09-01 23:54:56 +00:00
|
|
|
// Preview panel
|
|
|
|
this.previewPanel = new OO.ui.PanelLayout( {
|
|
|
|
expanded: false,
|
|
|
|
padded: true
|
|
|
|
} );
|
2017-11-10 14:59:01 +00:00
|
|
|
this.$previewViewer = $( '<div>' ).addClass( 'mw-body-content mw-parser-output' );
|
2016-12-31 22:04:19 +00:00
|
|
|
this.previewPanel.$element
|
|
|
|
// Make focusable for keyboard accessible scrolling
|
|
|
|
.prop( 'tabIndex', 0 )
|
|
|
|
.append( this.$previewViewer );
|
2016-09-01 23:54:56 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Conflict panel
|
2015-01-31 02:14:07 +00:00
|
|
|
this.conflictPanel = new OO.ui.PanelLayout( {
|
2015-09-21 16:52:19 +00:00
|
|
|
expanded: false,
|
2015-01-31 02:14:07 +00:00
|
|
|
padded: true
|
|
|
|
} );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$conflict = $( '<div>' ).addClass( 've-ui-mwSaveDialog-conflict' )
|
2018-11-28 22:42:19 +00:00
|
|
|
.html( ve.init.platform.getParsedMessage( 'visualeditor-editconflict' ) );
|
|
|
|
ve.targetLinksToNewWindow( this.$conflict[ 0 ] );
|
2013-11-05 00:29:50 +00:00
|
|
|
this.conflictPanel.$element.append( this.$conflict );
|
|
|
|
|
|
|
|
// Panel stack
|
2014-07-14 21:32:49 +00:00
|
|
|
this.panels.addItems( [
|
|
|
|
this.savePanel,
|
|
|
|
this.reviewPanel,
|
2016-09-01 23:54:56 +00:00
|
|
|
this.previewPanel,
|
2017-04-10 11:38:11 +00:00
|
|
|
this.conflictPanel
|
2014-07-14 21:32:49 +00:00
|
|
|
] );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-07-14 21:32:49 +00:00
|
|
|
this.$body.append( this.panels.$element );
|
2013-11-14 23:14:16 +00:00
|
|
|
|
|
|
|
this.setupDeferred.resolve();
|
|
|
|
};
|
|
|
|
|
2019-07-16 13:28:25 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.updateOptionsBar = function () {
|
|
|
|
var showOptions = !!this.editSummaryCountLabel.getLabel() || !this.$saveCheckboxes.is( ':empty' );
|
|
|
|
if ( showOptions !== this.showOptions ) {
|
|
|
|
this.savePanel.$element.toggleClass( 've-ui-mwSaveDialog-withOptions', showOptions );
|
|
|
|
this.showOptions = showOptions;
|
|
|
|
this.updateSize();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-09 15:52:50 +00:00
|
|
|
/**
|
|
|
|
* Update the current review mode
|
|
|
|
* @param {OO.ui.ButtonOptionWidget} [button] The button clicked, or false if this is the initial setup
|
|
|
|
*/
|
2016-10-31 17:17:50 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.updateReviewMode = function () {
|
2017-04-09 12:04:15 +00:00
|
|
|
var dialog = this,
|
2017-11-04 18:31:23 +00:00
|
|
|
diffMode = this.reviewModeButtonSelect.findSelectedItem().getData(),
|
|
|
|
surfaceMode = ve.init.target.getSurface().getMode(),
|
|
|
|
isVisual = diffMode === 'visual';
|
|
|
|
|
|
|
|
if ( !this.hasDiff ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config values used here:
|
|
|
|
// * visualeditor-diffmode-visual
|
|
|
|
// * visualeditor-diffmode-source
|
|
|
|
ve.userConfig( 'visualeditor-diffmode-' + surfaceMode, diffMode );
|
2017-08-29 20:39:11 +00:00
|
|
|
|
|
|
|
// Hack: cache report action so it is getable even when hidden (see T174497)
|
|
|
|
if ( !this.report ) {
|
|
|
|
this.report = this.getActions().get( { actions: 'report' } )[ 0 ];
|
|
|
|
}
|
|
|
|
|
2016-10-31 17:17:50 +00:00
|
|
|
this.$reviewVisualDiff.toggleClass( 'oo-ui-element-hidden', !isVisual );
|
|
|
|
this.$reviewWikitextDiff.toggleClass( 'oo-ui-element-hidden', isVisual );
|
|
|
|
if ( isVisual ) {
|
2017-08-29 20:39:11 +00:00
|
|
|
this.report.toggle( true );
|
2017-03-25 13:14:07 +00:00
|
|
|
if ( !this.diffElement ) {
|
2017-04-09 12:04:15 +00:00
|
|
|
if ( !this.diffElementPromise ) {
|
2017-04-10 11:38:34 +00:00
|
|
|
this.diffElementPromise = this.getDiffElementPromise().then( function ( diffElement ) {
|
2017-04-09 12:04:15 +00:00
|
|
|
dialog.diffElement = diffElement;
|
2017-04-10 11:38:34 +00:00
|
|
|
dialog.$reviewVisualDiff.empty().append( diffElement.$element );
|
|
|
|
dialog.positionDiffElement();
|
2017-04-09 12:04:15 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
return;
|
2017-03-25 13:14:07 +00:00
|
|
|
}
|
2017-04-10 11:38:34 +00:00
|
|
|
this.positionDiffElement();
|
2017-08-29 20:39:11 +00:00
|
|
|
} else {
|
|
|
|
this.report.toggle( false );
|
2016-10-31 17:17:50 +00:00
|
|
|
}
|
2019-04-10 20:56:08 +00:00
|
|
|
|
2019-04-23 18:27:38 +00:00
|
|
|
// Support: iOS
|
2019-04-10 20:56:08 +00:00
|
|
|
// HACK: iOS Safari sometimes makes the entire panel completely disappear (T219680).
|
|
|
|
// Rebuilding it makes it reappear.
|
|
|
|
OO.ui.Element.static.reconsiderScrollbars( this.reviewPanel.$element[ 0 ] );
|
|
|
|
|
2017-03-30 16:37:54 +00:00
|
|
|
this.updateSize();
|
2016-10-31 17:17:50 +00:00
|
|
|
};
|
|
|
|
|
2019-09-09 15:52:50 +00:00
|
|
|
/**
|
|
|
|
* Update the current review mode
|
|
|
|
* @param {OO.ui.OptionWidget} item Item chosen
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.onReviewChoose = function ( item ) {
|
|
|
|
ve.track( 'activity.' + this.constructor.static.name, { action: 'review-switch-' + item.getData() } );
|
|
|
|
};
|
|
|
|
|
2017-04-10 11:38:34 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.setDimensions = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWSaveDialog.parent.prototype.setDimensions.apply( this, arguments );
|
|
|
|
|
2018-03-03 18:46:01 +00:00
|
|
|
if ( !this.positioning ) {
|
|
|
|
this.positionDiffElement();
|
|
|
|
}
|
2017-04-10 11:38:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Re-position elements within the diff element
|
|
|
|
*
|
|
|
|
* Should be called whenever the diff element's container has changed width.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.positionDiffElement = function () {
|
|
|
|
var dialog = this;
|
2017-04-24 09:26:28 +00:00
|
|
|
if ( this.panels.getCurrentItem() === this.reviewPanel ) {
|
2017-04-10 11:38:34 +00:00
|
|
|
setTimeout( function () {
|
|
|
|
dialog.withoutSizeTransitions( function () {
|
2018-02-16 15:21:12 +00:00
|
|
|
// This is delayed, so check the visual diff is still visible
|
|
|
|
if ( dialog.diffElement && dialog.isVisible() && dialog.reviewModeButtonSelect.findSelectedItem().getData() === 'visual' ) {
|
2017-04-24 09:26:28 +00:00
|
|
|
dialog.diffElement.positionDescriptions();
|
2018-03-03 18:46:01 +00:00
|
|
|
dialog.positioning = true;
|
2017-04-24 09:26:28 +00:00
|
|
|
dialog.updateSize();
|
2018-03-03 18:46:01 +00:00
|
|
|
dialog.positioning = false;
|
2017-04-24 09:26:28 +00:00
|
|
|
}
|
2017-04-10 11:38:34 +00:00
|
|
|
} );
|
|
|
|
}, OO.ui.theme.getDialogTransitionDuration() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-12 00:35:46 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
2016-06-30 14:01:24 +00:00
|
|
|
* @param {Object} [data]
|
2016-12-13 21:55:01 +00:00
|
|
|
* @param {boolean} [data.canReview] User can review changes
|
|
|
|
* @param {boolean} [data.canPreview] User can preview changes
|
|
|
|
* @param {OO.ui.FieldLayout[]} [data.checkboxFields] Checkbox fields
|
|
|
|
* @param {Object} [data.checkboxesByName] Checkbox widgets, indexed by name
|
|
|
|
* @param {string} [data.sectionTitle] Section title, if in new section mode
|
|
|
|
* @param {string} [data.editSummary] Edit summary
|
|
|
|
* @param {string} [data.initialPanel='save'] Initial panel to show
|
|
|
|
* @param {jQuery|string|OO.ui.HtmlSnippet|Function|null} [data.saveButtonLabel] Label for the save button
|
2014-06-12 00:35:46 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWSaveDialog.super.prototype.getSetupProcess.call( this, data )
|
2014-07-14 21:32:49 +00:00
|
|
|
.next( function () {
|
2019-09-09 15:52:50 +00:00
|
|
|
var name,
|
|
|
|
surfaceMode = ve.init.target.getSurface().getMode();
|
2018-03-10 22:54:54 +00:00
|
|
|
|
2016-12-13 21:55:01 +00:00
|
|
|
this.canReview = !!data.canReview;
|
|
|
|
this.canPreview = !!data.canPreview;
|
2015-08-18 20:10:37 +00:00
|
|
|
this.setupCheckboxes( data.checkboxFields || [] );
|
2015-08-13 16:39:24 +00:00
|
|
|
this.checkboxesByName = data.checkboxesByName || {};
|
2016-12-13 21:55:01 +00:00
|
|
|
|
2019-09-09 15:52:50 +00:00
|
|
|
function trackCheckbox( name ) {
|
|
|
|
ve.track( 'activity.mwSave', { action: 'checkbox-' + name } );
|
|
|
|
}
|
|
|
|
for ( name in this.checkboxesByName ) {
|
2019-10-03 17:44:43 +00:00
|
|
|
this.checkboxesByName[ name ].$element.off( '.mwSave' ).on( 'click.mwSave', trackCheckbox.bind( this, name ) );
|
2019-09-09 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 21:55:01 +00:00
|
|
|
if ( data.sectionTitle ) {
|
|
|
|
this.setEditSummary( ve.msg( 'newsectionsummary', data.sectionTitle ) );
|
|
|
|
this.editSummaryInput.setDisabled( true );
|
|
|
|
} else {
|
|
|
|
this.editSummaryInput.setDisabled( false );
|
|
|
|
if ( !this.changedEditSummary ) {
|
|
|
|
this.setEditSummary( data.editSummary );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-04 18:31:23 +00:00
|
|
|
// Config values used here:
|
|
|
|
// * visualeditor-diffmode-visual
|
|
|
|
// * visualeditor-diffmode-source
|
|
|
|
this.reviewModeButtonSelect.selectItemByData(
|
2018-03-12 12:24:18 +00:00
|
|
|
ve.userConfig( 'visualeditor-diffmode-' + surfaceMode ) || surfaceMode
|
2017-11-04 18:31:23 +00:00
|
|
|
);
|
|
|
|
|
2014-07-25 18:39:03 +00:00
|
|
|
// Old messages should not persist
|
2014-06-12 00:35:46 +00:00
|
|
|
this.clearAllMessages();
|
2016-12-13 12:57:13 +00:00
|
|
|
// Don't focus during setup to prevent scroll jumping (T153010)
|
|
|
|
this.swapPanel( data.initialPanel || 'save', true );
|
2014-07-14 21:32:49 +00:00
|
|
|
// Update save button label
|
2019-08-05 20:16:21 +00:00
|
|
|
this.actions.forEach( { actions: 'save' }, function ( action ) {
|
|
|
|
action.setLabel( data.saveButtonLabel );
|
|
|
|
} );
|
2014-06-12 00:35:46 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2015-01-06 00:51:38 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
return ve.ui.MWSaveDialog.super.prototype.getReadyProcess.call( this, data )
|
|
|
|
.next( function () {
|
2019-05-13 10:50:55 +00:00
|
|
|
// HACK: iOS Safari sometimes makes the entire panel completely disappear (T221289).
|
|
|
|
// Rebuilding it makes it reappear.
|
|
|
|
OO.ui.Element.static.reconsiderScrollbars( this.panels.getCurrentItem().$element[ 0 ] );
|
|
|
|
|
2017-01-26 16:11:45 +00:00
|
|
|
// Support: Firefox
|
|
|
|
// In Firefox, trying to focus a hidden input will throw an
|
|
|
|
// exception. This would happen when opening the preview via
|
|
|
|
// keyboard shortcut.
|
|
|
|
if ( this.panels.getCurrentItem() === this.savePanel ) {
|
|
|
|
// This includes a #focus call
|
|
|
|
this.editSummaryInput.moveCursorToEnd();
|
|
|
|
}
|
2015-01-06 00:51:38 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2015-07-31 12:15:31 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
return ve.ui.MWSaveDialog.super.prototype.getTeardownProcess.call( this, data )
|
|
|
|
.next( function () {
|
|
|
|
this.emit( 'close' );
|
2017-08-29 20:39:11 +00:00
|
|
|
this.report = null;
|
2015-07-31 12:15:31 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2014-05-28 22:05:17 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.getActionProcess = function ( action ) {
|
2019-09-09 15:52:50 +00:00
|
|
|
ve.track( 'activity.' + this.constructor.static.name, { action: 'dialog-' + ( action || 'abort' ) } );
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
if ( action === 'save' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
2019-11-02 05:06:28 +00:00
|
|
|
var saveDeferred = ve.createDeferred();
|
2017-02-07 20:06:44 +00:00
|
|
|
this.clearMessage( 'keyboard-shortcut-submit' );
|
2014-07-14 21:32:49 +00:00
|
|
|
this.emit( 'save', saveDeferred );
|
|
|
|
return saveDeferred.promise();
|
|
|
|
}, this );
|
|
|
|
}
|
2016-09-01 23:54:56 +00:00
|
|
|
if ( action === 'review' || action === 'preview' || action === 'resolve' ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.emit( action );
|
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
if ( action === 'approve' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.swapPanel( 'save' );
|
|
|
|
}, this );
|
|
|
|
}
|
2017-08-29 20:39:11 +00:00
|
|
|
if ( action === 'report' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
2018-07-03 16:36:35 +00:00
|
|
|
window.open( this.constructor.static.feedbackUrl );
|
2017-08-29 20:39:11 +00:00
|
|
|
}, this );
|
|
|
|
}
|
2014-05-28 22:05:17 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
return ve.ui.MWSaveDialog.super.prototype.getActionProcess.call( this, action );
|
2014-05-28 22:05:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.getBodyHeight = function () {
|
|
|
|
// Don't vary the height when the foot is made visible or not
|
2015-09-21 16:52:19 +00:00
|
|
|
return this.panels.getCurrentItem().$element.outerHeight( true );
|
2014-05-28 22:05:17 +00:00
|
|
|
};
|
|
|
|
|
2014-10-30 00:36:02 +00:00
|
|
|
/**
|
|
|
|
* Handle retry button click events.
|
|
|
|
*
|
|
|
|
* Hides errors and then tries again.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.onRetryButtonClick = function () {
|
|
|
|
this.emit( 'retry' );
|
|
|
|
ve.ui.MWSaveDialog.super.prototype.onRetryButtonClick.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
2013-10-07 10:01:43 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2014-04-21 22:31:21 +00:00
|
|
|
ve.ui.windowFactory.register( ve.ui.MWSaveDialog );
|