2018-09-26 12:49:10 +00:00
|
|
|
/*!
|
2014-04-10 19:07:40 +00:00
|
|
|
* VisualEditor user interface MWTemplateDialog class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2014-04-10 19:07:40 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-06-03 16:25:15 +00:00
|
|
|
* Abstract base class for dialogs that allow to insert and edit MediaWiki transclusions, i.e. a
|
|
|
|
* sequence of one or more template invocations that strictly belong to each other (e.g. because
|
|
|
|
* they are unbalanced), possibly mixed with raw wikitext snippets. Currently used for:
|
|
|
|
* - {@see ve.ui.MWTransclusionDialog} for arbitrary transclusions. Registered via the name
|
|
|
|
* "transclusion".
|
|
|
|
* - {@see ve.ui.MWCitationDialog} in the Cite extension for the predefined citation types from
|
|
|
|
* [[MediaWiki:visualeditor-cite-tool-definition.json]]. These are strictly limited to a single
|
|
|
|
* template invocation. Registered via the name "cite".
|
2014-04-10 19:07:40 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
2014-04-24 00:22:45 +00:00
|
|
|
* @extends ve.ui.NodeDialog
|
2014-04-10 19:07:40 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
2022-02-03 12:30:29 +00:00
|
|
|
* @property {ve.dm.MWTransclusionModel|null} transclusionModel
|
2022-06-20 17:42:22 +00:00
|
|
|
* @property {ve.ui.MWTransclusionOutlineWidget} sidebar
|
2022-06-15 12:28:22 +00:00
|
|
|
* @property {boolean} [canGoBack=false]
|
2014-04-10 19:07:40 +00:00
|
|
|
*/
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWTemplateDialog = function VeUiMWTemplateDialog( config ) {
|
2014-04-10 19:07:40 +00:00
|
|
|
// Parent constructor
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWTemplateDialog.super.call( this, config );
|
2014-04-10 19:07:40 +00:00
|
|
|
|
|
|
|
// Properties
|
2014-04-24 00:22:45 +00:00
|
|
|
this.transclusionModel = null;
|
2014-04-10 19:07:40 +00:00
|
|
|
this.loaded = false;
|
2014-12-09 23:11:41 +00:00
|
|
|
this.altered = false;
|
2022-06-28 08:34:28 +00:00
|
|
|
this.canGoBack = false;
|
2014-04-10 19:07:40 +00:00
|
|
|
this.preventReselection = false;
|
2014-08-27 15:44:07 +00:00
|
|
|
|
2014-11-21 21:58:53 +00:00
|
|
|
this.confirmDialogs = new ve.ui.WindowManager( { factory: ve.ui.windowFactory, isolate: true } );
|
2023-10-31 21:06:04 +00:00
|
|
|
$( OO.ui.getTeleportTarget() ).append( this.confirmDialogs.$element );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTemplateDialog, ve.ui.NodeDialog );
|
2014-04-10 19:07:40 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
ve.ui.MWTemplateDialog.static.modelClasses = [ ve.dm.MWTransclusionNode ];
|
2014-04-10 19:07:40 +00:00
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
/**
|
2022-06-20 13:31:05 +00:00
|
|
|
* Configuration for the {@see ve.ui.MWTwoPaneTransclusionDialogLayout} used in this dialog.
|
2014-04-24 00:22:45 +00:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {Object}
|
|
|
|
* @inheritable
|
|
|
|
*/
|
2022-07-21 11:55:45 +00:00
|
|
|
ve.ui.MWTemplateDialog.static.bookletLayoutConfig = {};
|
2014-04-10 19:07:40 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2017-06-01 14:28:15 +00:00
|
|
|
* @inheritdoc
|
2014-04-10 19:07:40 +00:00
|
|
|
*/
|
2017-06-01 14:28:15 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
return ve.ui.MWTemplateDialog.super.prototype.getReadyProcess.call( this, data )
|
|
|
|
.next( function () {
|
2021-10-06 15:57:10 +00:00
|
|
|
if ( this.transclusionModel.isEmpty() ) {
|
2022-06-27 10:31:32 +00:00
|
|
|
// Focus the template placeholder input field.
|
|
|
|
this.bookletLayout.focus();
|
2021-10-05 10:57:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-06 07:48:55 +00:00
|
|
|
this.bookletLayout.getPagesOrdered().forEach( function ( page ) {
|
2021-04-22 16:59:30 +00:00
|
|
|
if ( page instanceof ve.ui.MWParameterPage ) {
|
|
|
|
page.updateSize();
|
|
|
|
}
|
|
|
|
} );
|
2017-06-01 14:28:15 +00:00
|
|
|
}, this );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
2014-12-09 23:11:41 +00:00
|
|
|
/**
|
2022-01-10 13:47:40 +00:00
|
|
|
* Update dialog actions whenever the content changes.
|
2021-06-18 13:51:25 +00:00
|
|
|
*
|
|
|
|
* @private
|
2014-12-09 23:11:41 +00:00
|
|
|
*/
|
2022-01-10 13:47:40 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.touch = function () {
|
2014-12-09 23:11:41 +00:00
|
|
|
if ( this.loaded ) {
|
|
|
|
this.altered = true;
|
|
|
|
this.setApplicableStatus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* Handle parts being replaced.
|
|
|
|
*
|
2021-06-18 13:51:25 +00:00
|
|
|
* @protected
|
2021-07-16 12:24:46 +00:00
|
|
|
* @param {ve.dm.MWTransclusionPartModel|null} removed Removed part
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel|null} added Added part
|
2014-04-10 19:07:40 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
|
2022-06-27 09:32:22 +00:00
|
|
|
var removePages = [];
|
2014-04-10 19:07:40 +00:00
|
|
|
|
|
|
|
if ( removed ) {
|
|
|
|
// Remove parameter pages of removed templates
|
|
|
|
if ( removed instanceof ve.dm.MWTemplateModel ) {
|
2021-06-21 08:10:27 +00:00
|
|
|
var params = removed.getParameters();
|
|
|
|
for ( var name in params ) {
|
2022-07-04 14:12:25 +00:00
|
|
|
removePages.push( params[ name ].getId() );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
removed.disconnect( this );
|
|
|
|
}
|
2022-07-04 14:12:25 +00:00
|
|
|
removePages.push( removed.getId() );
|
2014-04-10 19:07:40 +00:00
|
|
|
this.bookletLayout.removePages( removePages );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( added ) {
|
2021-06-21 08:10:27 +00:00
|
|
|
var page = this.getPageFromPart( added );
|
2014-04-10 19:07:40 +00:00
|
|
|
if ( page ) {
|
2022-06-27 09:32:22 +00:00
|
|
|
var reselect;
|
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
this.bookletLayout.addPages( [ page ], this.transclusionModel.getIndex( added ) );
|
2022-06-27 09:32:22 +00:00
|
|
|
if ( removed ) {
|
|
|
|
// When we're replacing a part, it can only be a template placeholder
|
|
|
|
// becoming an actual template. Focus this new template.
|
2021-08-19 13:44:35 +00:00
|
|
|
reselect = added.getId();
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
2021-08-18 12:52:11 +00:00
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
if ( added instanceof ve.dm.MWTemplateModel ) {
|
2021-08-18 12:52:11 +00:00
|
|
|
// Prevent selection changes while parameters are added
|
2014-04-10 19:07:40 +00:00
|
|
|
this.preventReselection = true;
|
2021-08-18 12:52:11 +00:00
|
|
|
|
|
|
|
// Add existing params to templates (the template might be being moved)
|
|
|
|
var names = added.getOrderedParameterNames();
|
2021-06-21 08:10:27 +00:00
|
|
|
for ( var i = 0; i < names.length; i++ ) {
|
2021-06-04 12:04:10 +00:00
|
|
|
this.onAddParameter( added.getParameter( names[ i ] ) );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
2014-08-22 20:50:48 +00:00
|
|
|
added.connect( this, { add: 'onAddParameter', remove: 'onRemoveParameter' } );
|
2014-04-10 19:07:40 +00:00
|
|
|
|
|
|
|
this.preventReselection = false;
|
2021-08-18 12:52:11 +00:00
|
|
|
|
2022-06-27 09:32:22 +00:00
|
|
|
if ( this.loaded ) {
|
|
|
|
if ( reselect ) {
|
2022-06-27 12:33:00 +00:00
|
|
|
this.bookletLayout.focusPart( reselect );
|
2022-06-27 09:32:22 +00:00
|
|
|
}
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
2021-08-18 13:00:48 +00:00
|
|
|
|
2022-06-20 14:05:44 +00:00
|
|
|
var documentedParameters = added.getSpec().getDocumentedParameterOrder(),
|
|
|
|
undocumentedParameters = added.getSpec().getUndocumentedParameterNames();
|
2021-08-18 13:00:48 +00:00
|
|
|
|
2022-06-20 14:05:44 +00:00
|
|
|
if ( !documentedParameters.length || undocumentedParameters.length ) {
|
|
|
|
page.addPlaceholderParameter();
|
2021-08-18 13:00:48 +00:00
|
|
|
}
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-19 13:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 13:47:40 +00:00
|
|
|
if ( added || removed ) {
|
|
|
|
this.touch();
|
|
|
|
}
|
2014-04-10 19:07:40 +00:00
|
|
|
this.updateTitle();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add param events.
|
|
|
|
*
|
2021-06-18 13:51:25 +00:00
|
|
|
* @private
|
2014-04-10 19:07:40 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param Added param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onAddParameter = function ( param ) {
|
|
|
|
var page;
|
|
|
|
|
|
|
|
if ( param.getName() ) {
|
2022-06-23 10:20:19 +00:00
|
|
|
page = new ve.ui.MWParameterPage( param, {
|
2022-06-15 14:47:54 +00:00
|
|
|
$overlay: this.$overlay, readOnly: this.isReadOnly()
|
|
|
|
} )
|
|
|
|
.connect( this, {
|
|
|
|
hasValueChange: 'onHasValueChange'
|
|
|
|
} );
|
2022-06-16 15:55:20 +00:00
|
|
|
} else {
|
2022-07-04 08:40:02 +00:00
|
|
|
// Create parameter placeholder.
|
2021-08-06 11:56:40 +00:00
|
|
|
page = new ve.ui.MWAddParameterPage( param, param.getId(), {
|
|
|
|
$overlay: this.$overlay
|
2021-09-07 15:53:37 +00:00
|
|
|
} )
|
|
|
|
.connect( this, {
|
2022-07-01 10:42:23 +00:00
|
|
|
templateParameterAdded: this.bookletLayout.focusPart.bind( this.bookletLayout )
|
2021-09-07 15:53:37 +00:00
|
|
|
} );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
2014-04-24 00:22:45 +00:00
|
|
|
this.bookletLayout.addPages( [ page ], this.transclusionModel.getIndex( param ) );
|
2014-12-09 23:11:41 +00:00
|
|
|
if ( this.loaded ) {
|
2022-01-10 13:47:40 +00:00
|
|
|
this.touch();
|
2021-04-22 16:59:30 +00:00
|
|
|
|
|
|
|
if ( page instanceof ve.ui.MWParameterPage ) {
|
|
|
|
page.updateSize();
|
|
|
|
}
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle remove param events.
|
|
|
|
*
|
2021-06-18 13:51:25 +00:00
|
|
|
* @private
|
2014-04-10 19:07:40 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param Removed param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onRemoveParameter = function ( param ) {
|
2022-07-04 14:12:25 +00:00
|
|
|
this.bookletLayout.removePages( [ param.getId() ] );
|
2014-12-09 23:11:41 +00:00
|
|
|
|
2022-01-10 13:47:40 +00:00
|
|
|
this.touch();
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-10-24 22:14:01 +00:00
|
|
|
* Sets transclusion applicable status
|
2014-04-10 19:07:40 +00:00
|
|
|
*
|
|
|
|
* If the transclusion is empty or only contains a placeholder it will not be insertable.
|
2014-10-24 22:14:01 +00:00
|
|
|
* If the transclusion only contains a placeholder it will not be editable.
|
2021-06-18 13:51:25 +00:00
|
|
|
*
|
|
|
|
* @private
|
2014-04-10 19:07:40 +00:00
|
|
|
*/
|
2014-10-24 22:14:01 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.setApplicableStatus = function () {
|
2021-10-06 15:57:10 +00:00
|
|
|
var canSave = !this.transclusionModel.isEmpty();
|
2021-10-06 13:37:02 +00:00
|
|
|
this.actions.setAbilities( { done: canSave && this.altered } );
|
2021-10-05 10:57:40 +00:00
|
|
|
};
|
2014-04-10 19:07:40 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.getBodyHeight = function () {
|
2014-07-19 02:14:30 +00:00
|
|
|
return 400;
|
2014-07-14 21:32:49 +00:00
|
|
|
};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* Get a page for a transclusion part.
|
|
|
|
*
|
2021-06-18 13:51:25 +00:00
|
|
|
* @protected
|
2014-04-10 19:07:40 +00:00
|
|
|
* @param {ve.dm.MWTransclusionModel} part Part to get page for
|
|
|
|
* @return {OO.ui.PageLayout|null} Page for part, null if no matching page could be found
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.getPageFromPart = function ( part ) {
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
2019-02-24 12:38:03 +00:00
|
|
|
return new ve.ui.MWTemplatePage( part, part.getId(), { $overlay: this.$overlay, isReadOnly: this.isReadOnly() } );
|
2014-04-10 19:07:40 +00:00
|
|
|
} else if ( part instanceof ve.dm.MWTemplatePlaceholderModel ) {
|
2014-10-28 00:36:19 +00:00
|
|
|
return new ve.ui.MWTemplatePlaceholderPage(
|
|
|
|
part,
|
|
|
|
part.getId(),
|
2015-04-09 23:47:15 +00:00
|
|
|
{ $overlay: this.$overlay }
|
2014-10-28 00:36:19 +00:00
|
|
|
);
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-04-24 00:22:45 +00:00
|
|
|
* @inheritdoc
|
2014-04-10 19:07:40 +00:00
|
|
|
*/
|
2014-04-24 00:22:45 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.getSelectedNode = function ( data ) {
|
|
|
|
var selectedNode = ve.ui.MWTemplateDialog.super.prototype.getSelectedNode.call( this );
|
|
|
|
|
|
|
|
// Data initialization
|
|
|
|
data = data || {};
|
|
|
|
|
|
|
|
// Require template to match if specified
|
|
|
|
if ( selectedNode && data.template && !selectedNode.isSingleTemplate( data.template ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectedNode;
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the dialog title.
|
2021-06-18 13:51:25 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2014-04-10 19:07:40 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.updateTitle = function () {
|
2021-10-06 15:57:10 +00:00
|
|
|
var title = ve.msg( 'visualeditor-dialog-transclusion-loading' );
|
2021-06-02 10:06:36 +00:00
|
|
|
|
2021-10-06 15:57:10 +00:00
|
|
|
if ( this.transclusionModel.isSingleTemplate() ) {
|
|
|
|
var part = this.transclusionModel.getParts()[ 0 ];
|
2021-10-06 13:37:02 +00:00
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
2021-06-02 10:06:36 +00:00
|
|
|
title = ve.msg(
|
|
|
|
this.getMode() === 'insert' ?
|
|
|
|
'visualeditor-dialog-transclusion-title-insert-known-template' :
|
|
|
|
'visualeditor-dialog-transclusion-title-edit-known-template',
|
2021-10-06 13:37:02 +00:00
|
|
|
part.getSpec().getLabel()
|
2021-06-02 10:06:36 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
title = ve.msg( 'visualeditor-dialog-transclusion-title-insert-template' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.title.setLabel( title );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWTemplateDialog.super.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Properties
|
2022-06-20 13:31:05 +00:00
|
|
|
this.bookletLayout = new ve.ui.MWTwoPaneTransclusionDialogLayout( this.constructor.static.bookletLayoutConfig );
|
2022-06-21 13:46:21 +00:00
|
|
|
// TODO: Remove once all references are gone.
|
|
|
|
this.sidebar = this.bookletLayout.sidebar;
|
2014-04-10 19:07:40 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-08-21 00:50:54 +00:00
|
|
|
this.$content.addClass( 've-ui-mwTemplateDialog' );
|
2018-06-21 21:08:17 +00:00
|
|
|
// bookletLayout is appended after the form has been built in getSetupProcess for performance
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
2014-08-27 15:44:07 +00:00
|
|
|
/**
|
|
|
|
* If the user has left blank required parameters, confirm that they actually want to do this.
|
|
|
|
* If no required parameters were left blank, or if they were but the user decided to go ahead
|
|
|
|
* anyway, the returned deferred will be resolved.
|
|
|
|
* Otherwise, the returned deferred will be rejected.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2021-06-18 13:51:25 +00:00
|
|
|
* @private
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {jQuery.Deferred}
|
2014-08-27 15:44:07 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.checkRequiredParameters = function () {
|
2015-01-31 00:41:37 +00:00
|
|
|
var blankRequired = [],
|
2019-11-02 05:06:28 +00:00
|
|
|
deferred = ve.createDeferred();
|
2019-02-08 19:18:22 +00:00
|
|
|
|
|
|
|
this.bookletLayout.stackLayout.getItems().forEach( function ( page ) {
|
|
|
|
if ( !( page instanceof ve.ui.MWParameterPage ) ) {
|
|
|
|
return;
|
2014-08-27 15:44:07 +00:00
|
|
|
}
|
2019-02-08 19:18:22 +00:00
|
|
|
if ( page.parameter.isRequired() && !page.valueInput.getValue() ) {
|
2014-08-27 15:44:07 +00:00
|
|
|
blankRequired.push( mw.msg(
|
|
|
|
'quotation-marks',
|
2019-02-08 19:18:22 +00:00
|
|
|
page.parameter.template.getSpec().getParameterLabel( page.parameter.getName() )
|
2014-08-27 15:44:07 +00:00
|
|
|
) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
if ( blankRequired.length ) {
|
|
|
|
this.confirmDialogs.openWindow( 'requiredparamblankconfirm', {
|
|
|
|
message: mw.msg(
|
|
|
|
'visualeditor-dialog-transclusion-required-parameter-is-blank',
|
|
|
|
mw.language.listToText( blankRequired ),
|
|
|
|
blankRequired.length
|
|
|
|
),
|
|
|
|
title: mw.msg(
|
|
|
|
'visualeditor-dialog-transclusion-required-parameter-dialog-title',
|
|
|
|
blankRequired.length
|
|
|
|
)
|
2017-06-01 22:21:58 +00:00
|
|
|
} ).closed.then( function ( data ) {
|
2022-07-25 11:52:21 +00:00
|
|
|
if ( data && data.action === 'ok' ) {
|
2017-06-01 22:21:58 +00:00
|
|
|
deferred.resolve();
|
|
|
|
} else {
|
|
|
|
deferred.reject();
|
|
|
|
}
|
2014-08-27 15:44:07 +00:00
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
deferred.resolve();
|
|
|
|
}
|
|
|
|
return deferred.promise();
|
|
|
|
};
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.getActionProcess = function ( action ) {
|
2021-06-21 08:10:27 +00:00
|
|
|
var dialog = this;
|
2020-12-11 15:09:45 +00:00
|
|
|
|
2021-06-18 08:57:45 +00:00
|
|
|
if ( action === 'done' ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
return new OO.ui.Process( function () {
|
2019-11-02 05:06:28 +00:00
|
|
|
var deferred = ve.createDeferred();
|
2014-12-16 21:14:01 +00:00
|
|
|
dialog.checkRequiredParameters().done( function () {
|
2021-06-18 07:03:16 +00:00
|
|
|
var surfaceModel = dialog.getFragment().getSurface(),
|
|
|
|
obj = dialog.transclusionModel.getPlainObject(),
|
|
|
|
modelPromise = ve.createDeferred().resolve().promise();
|
2014-08-27 15:44:07 +00:00
|
|
|
|
2016-05-15 11:08:13 +00:00
|
|
|
dialog.pushPending();
|
|
|
|
|
2014-12-16 21:14:01 +00:00
|
|
|
if ( dialog.selectedNode instanceof ve.dm.MWTransclusionNode ) {
|
|
|
|
dialog.transclusionModel.updateTransclusionNode( surfaceModel, dialog.selectedNode );
|
2016-05-15 11:08:13 +00:00
|
|
|
// TODO: updating the node could result in the inline/block state change
|
2014-08-27 15:44:07 +00:00
|
|
|
} else if ( obj !== null ) {
|
2014-12-16 21:14:01 +00:00
|
|
|
// Collapse returns a new fragment, so update dialog.fragment
|
|
|
|
dialog.fragment = dialog.getFragment().collapseToEnd();
|
2016-05-15 11:08:13 +00:00
|
|
|
modelPromise = dialog.transclusionModel.insertTransclusionNode( dialog.getFragment() );
|
2014-08-27 15:44:07 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 15:09:45 +00:00
|
|
|
// TODO tracking will only be implemented temporarily to answer questions on
|
|
|
|
// template usage for the Technical Wishes topic area see T258917
|
2021-06-21 08:10:27 +00:00
|
|
|
var templateEvent = {
|
2020-12-11 15:09:45 +00:00
|
|
|
action: 'save',
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
template_names: []
|
|
|
|
};
|
2021-06-21 08:10:27 +00:00
|
|
|
var editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
|
2021-01-21 12:17:03 +00:00
|
|
|
if ( editCountBucket !== null ) {
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
templateEvent.user_edit_count_bucket = editCountBucket;
|
|
|
|
}
|
2021-10-06 13:37:02 +00:00
|
|
|
var parts = dialog.transclusionModel.getParts();
|
|
|
|
for ( var i = 0; i < parts.length; i++ ) {
|
2022-07-21 11:24:24 +00:00
|
|
|
// Only {@see ve.dm.MWTemplateModel} have a title
|
|
|
|
var title = parts[ i ].getTitle && parts[ i ].getTitle();
|
|
|
|
if ( title ) {
|
|
|
|
templateEvent.template_names.push( title );
|
2020-12-11 15:09:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mw.track( 'event.VisualEditorTemplateDialogUse', templateEvent );
|
|
|
|
|
2016-05-15 11:08:13 +00:00
|
|
|
return modelPromise.then( function () {
|
2017-06-01 22:21:58 +00:00
|
|
|
dialog.close( { action: action } ).closed.always( dialog.popPending.bind( dialog ) );
|
2016-05-15 11:08:13 +00:00
|
|
|
} );
|
2014-12-16 21:14:01 +00:00
|
|
|
} ).always( deferred.resolve );
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-08-27 15:44:07 +00:00
|
|
|
return deferred;
|
2014-12-16 21:14:01 +00:00
|
|
|
} );
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ve.ui.MWTemplateDialog.super.prototype.getActionProcess.call( this, action );
|
|
|
|
};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-05-31 04:47:08 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
|
2014-07-15 22:49:51 +00:00
|
|
|
data = data || {};
|
2014-05-31 04:47:08 +00:00
|
|
|
return ve.ui.MWTemplateDialog.super.prototype.getSetupProcess.call( this, data )
|
|
|
|
.next( function () {
|
2021-06-21 08:10:27 +00:00
|
|
|
var promise,
|
2018-11-16 00:08:29 +00:00
|
|
|
dialog = this;
|
2014-05-31 04:47:08 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.loaded = false;
|
2014-12-09 23:11:41 +00:00
|
|
|
this.altered = false;
|
2018-05-04 13:30:10 +00:00
|
|
|
this.transclusionModel = new ve.dm.MWTransclusionModel( this.getFragment().getDocument() );
|
2014-05-31 04:47:08 +00:00
|
|
|
|
|
|
|
// Events
|
2014-12-09 23:11:41 +00:00
|
|
|
this.transclusionModel.connect( this, {
|
|
|
|
replace: 'onReplacePart',
|
2022-01-10 13:47:40 +00:00
|
|
|
change: 'touch'
|
2014-12-09 23:11:41 +00:00
|
|
|
} );
|
2014-05-31 04:47:08 +00:00
|
|
|
|
2016-05-09 22:24:22 +00:00
|
|
|
// Detach the form while building for performance
|
2018-11-16 00:08:29 +00:00
|
|
|
this.bookletLayout.$element.detach();
|
2016-05-09 22:24:22 +00:00
|
|
|
|
2022-07-21 11:55:45 +00:00
|
|
|
this.transclusionModel.connect( this.bookletLayout, { replace: 'onReplacePart' } );
|
2021-06-17 11:20:50 +00:00
|
|
|
|
2014-05-31 04:47:08 +00:00
|
|
|
// Initialization
|
|
|
|
if ( !this.selectedNode ) {
|
|
|
|
if ( data.template ) {
|
2021-09-23 14:38:33 +00:00
|
|
|
// The template name is from MediaWiki:Visualeditor-cite-tool-definition.json,
|
|
|
|
// passed via a ve.ui.Command, which triggers a ve.ui.MWCitationAction, which
|
|
|
|
// executes ve.ui.WindowAction.open(), which opens this dialog.
|
2021-06-21 08:10:27 +00:00
|
|
|
var template = ve.dm.MWTemplateModel.newFromName(
|
2014-05-31 04:47:08 +00:00
|
|
|
this.transclusionModel, data.template
|
|
|
|
);
|
2022-06-27 11:48:16 +00:00
|
|
|
promise = this.transclusionModel.addPart( template );
|
2014-05-31 04:47:08 +00:00
|
|
|
} else {
|
2021-09-23 14:38:33 +00:00
|
|
|
// Open the dialog to add a new template, always starting with a placeholder
|
2022-07-06 12:40:06 +00:00
|
|
|
var placeholderPage = new ve.dm.MWTemplatePlaceholderModel( this.transclusionModel );
|
|
|
|
promise = this.transclusionModel.addPart( placeholderPage );
|
|
|
|
promise.then( function () {
|
|
|
|
dialog.bookletLayout.setPage( placeholderPage.getId() );
|
|
|
|
} );
|
2022-06-15 12:28:22 +00:00
|
|
|
this.canGoBack = true;
|
2014-05-31 04:47:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-09-23 14:38:33 +00:00
|
|
|
// Open the dialog to edit an existing template
|
2020-12-11 15:09:45 +00:00
|
|
|
|
|
|
|
// TODO tracking will only be implemented temporarily to answer questions on
|
|
|
|
// template usage for the Technical Wishes topic area see T258917
|
2021-06-21 08:10:27 +00:00
|
|
|
var templateEvent = {
|
2020-12-11 15:09:45 +00:00
|
|
|
action: 'edit',
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
template_names: []
|
|
|
|
};
|
2021-06-21 08:10:27 +00:00
|
|
|
var editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
|
2021-01-21 12:17:03 +00:00
|
|
|
if ( editCountBucket !== null ) {
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
templateEvent.user_edit_count_bucket = editCountBucket;
|
|
|
|
}
|
2021-06-21 08:10:27 +00:00
|
|
|
for ( var i = 0; i < this.selectedNode.partsList.length; i++ ) {
|
2020-12-11 15:09:45 +00:00
|
|
|
if ( this.selectedNode.partsList[ i ].templatePage ) {
|
|
|
|
templateEvent.template_names.push( this.selectedNode.partsList[ i ].templatePage );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mw.track( 'event.VisualEditorTemplateDialogUse', templateEvent );
|
|
|
|
|
2014-05-31 04:47:08 +00:00
|
|
|
promise = this.transclusionModel
|
2014-10-07 00:06:02 +00:00
|
|
|
.load( ve.copy( this.selectedNode.getAttribute( 'mw' ) ) )
|
2017-06-01 14:28:15 +00:00
|
|
|
.then( this.initializeTemplateParameters.bind( this ) );
|
2014-05-31 04:47:08 +00:00
|
|
|
}
|
2021-06-18 08:57:45 +00:00
|
|
|
this.actions.setAbilities( { done: false } );
|
2018-06-21 21:08:17 +00:00
|
|
|
|
2018-11-16 00:08:29 +00:00
|
|
|
return promise.then( function () {
|
|
|
|
// Add missing required and suggested parameters to each transclusion.
|
|
|
|
dialog.transclusionModel.addPromptedParameters();
|
2018-06-21 21:08:17 +00:00
|
|
|
|
2021-07-13 07:07:59 +00:00
|
|
|
dialog.$body.append( dialog.bookletLayout.$element );
|
2022-08-30 12:15:50 +00:00
|
|
|
dialog.$element.addClass( 've-ui-mwTemplateDialog-ready' );
|
|
|
|
dialog.loaded = true;
|
2018-07-18 23:42:09 +00:00
|
|
|
} );
|
2014-05-31 04:47:08 +00:00
|
|
|
}, this );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
2014-10-07 00:06:02 +00:00
|
|
|
/**
|
|
|
|
* Intentionally empty. This is provided for Wikia extensibility.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.initializeTemplateParameters = function () {};
|
|
|
|
|
2022-06-15 14:47:54 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {string} pageName
|
|
|
|
* @param {boolean} hasValue
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onHasValueChange = function ( pageName, hasValue ) {
|
2022-06-20 13:48:45 +00:00
|
|
|
this.sidebar.toggleHasValueByPageName( pageName, hasValue );
|
2022-06-15 14:47:54 +00:00
|
|
|
};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-05-31 04:47:08 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
return ve.ui.MWTemplateDialog.super.prototype.getTeardownProcess.call( this, data )
|
|
|
|
.first( function () {
|
|
|
|
// Cleanup
|
|
|
|
this.$element.removeClass( 've-ui-mwTemplateDialog-ready' );
|
|
|
|
this.transclusionModel.disconnect( this );
|
2021-07-06 13:43:13 +00:00
|
|
|
this.transclusionModel.abortAllApiRequests();
|
2014-05-31 04:47:08 +00:00
|
|
|
this.transclusionModel = null;
|
|
|
|
this.bookletLayout.clearPages();
|
|
|
|
this.content = null;
|
|
|
|
}, this );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|