2018-09-26 12:49:10 +00:00
|
|
|
/*!
|
2014-04-10 19:07:40 +00:00
|
|
|
* VisualEditor user interface MWTemplateDialog class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; 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
|
|
|
|
*/
|
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;
|
2014-04-10 19:07:40 +00:00
|
|
|
this.preventReselection = false;
|
2015-04-13 21:30:41 +00:00
|
|
|
this.expandedParamList = {};
|
2014-08-27 15:44:07 +00:00
|
|
|
|
2015-07-22 22:13:09 +00:00
|
|
|
this.confirmOverlay = new ve.ui.Overlay( { classes: [ 've-ui-overlay-global' ] } );
|
2014-11-21 21:58:53 +00:00
|
|
|
this.confirmDialogs = new ve.ui.WindowManager( { factory: ve.ui.windowFactory, isolate: true } );
|
2014-08-27 15:44:07 +00:00
|
|
|
this.confirmOverlay.$element.append( this.confirmDialogs.$element );
|
2018-12-13 16:44:25 +00:00
|
|
|
$( document.body ).append( this.confirmOverlay.$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
|
|
|
/**
|
|
|
|
* Configuration for booklet layout.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {Object}
|
|
|
|
* @inheritable
|
|
|
|
*/
|
2014-04-10 19:07:40 +00:00
|
|
|
ve.ui.MWTemplateDialog.static.bookletLayoutConfig = {
|
2014-08-22 20:50:48 +00:00
|
|
|
continuous: true,
|
|
|
|
outlined: false
|
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 () {
|
|
|
|
this.bookletLayout.focus( 1 );
|
2021-04-22 16:59:30 +00:00
|
|
|
|
|
|
|
this.bookletLayout.stackLayout.getItems().forEach( function ( page ) {
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Called when the transclusion model changes. E.g. parts changes, parameter values changes.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onTransclusionModelChange = function () {
|
|
|
|
if ( this.loaded ) {
|
|
|
|
this.altered = true;
|
|
|
|
this.setApplicableStatus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* Handle parts being replaced.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} removed Removed part
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} added Added part
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
|
2014-10-24 22:14:01 +00:00
|
|
|
var i, len, page, name, names, params, partPage, reselect, addedCount,
|
2014-04-10 19:07:40 +00:00
|
|
|
removePages = [];
|
|
|
|
|
|
|
|
if ( removed ) {
|
|
|
|
// Remove parameter pages of removed templates
|
|
|
|
partPage = this.bookletLayout.getPage( removed.getId() );
|
|
|
|
if ( removed instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
params = removed.getParameters();
|
|
|
|
for ( name in params ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
removePages.push( this.bookletLayout.getPage( params[ name ].getId() ) );
|
|
|
|
delete this.expandedParamList[ params[ name ].getId() ];
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
removed.disconnect( this );
|
|
|
|
}
|
|
|
|
if ( this.loaded && !this.preventReselection && partPage.isActive() ) {
|
2017-09-05 02:08:36 +00:00
|
|
|
reselect = this.bookletLayout.findClosestPage( partPage );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
removePages.push( partPage );
|
|
|
|
this.bookletLayout.removePages( removePages );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( added ) {
|
|
|
|
page = this.getPageFromPart( added );
|
|
|
|
if ( page ) {
|
2014-04-24 00:22:45 +00:00
|
|
|
this.bookletLayout.addPages( [ page ], this.transclusionModel.getIndex( added ) );
|
2014-04-10 19:07:40 +00:00
|
|
|
if ( reselect ) {
|
|
|
|
// Use added page instead of closest page
|
|
|
|
this.setPageByName( added.getId() );
|
|
|
|
}
|
|
|
|
// Add existing params to templates (the template might be being moved)
|
|
|
|
if ( added instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
names = added.getParameterNames();
|
|
|
|
params = added.getParameters();
|
|
|
|
// Prevent selection changes
|
|
|
|
this.preventReselection = true;
|
|
|
|
for ( i = 0, len = names.length; i < len; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
this.onAddParameter( params[ names[ i ] ] );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
this.preventReselection = false;
|
2014-08-22 20:50:48 +00:00
|
|
|
added.connect( this, { add: 'onAddParameter', remove: 'onRemoveParameter' } );
|
2014-04-10 19:07:40 +00:00
|
|
|
if ( names.length ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
this.setPageByName( params[ names[ 0 ] ].getId() );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-28 19:10:31 +00:00
|
|
|
// Add required and suggested params to user created templates
|
2014-04-10 19:07:40 +00:00
|
|
|
if ( added instanceof ve.dm.MWTemplateModel && this.loaded ) {
|
|
|
|
// Prevent selection changes
|
|
|
|
this.preventReselection = true;
|
2014-07-21 21:06:54 +00:00
|
|
|
addedCount = added.addPromptedParameters();
|
2014-04-10 19:07:40 +00:00
|
|
|
this.preventReselection = false;
|
|
|
|
names = added.getParameterNames();
|
|
|
|
params = added.getParameters();
|
|
|
|
if ( names.length ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
this.setPageByName( params[ names[ 0 ] ].getId() );
|
2014-07-21 21:06:54 +00:00
|
|
|
} else if ( addedCount === 0 ) {
|
|
|
|
page.onAddButtonFocus();
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( reselect ) {
|
|
|
|
this.setPageByName( reselect.getName() );
|
|
|
|
}
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-12-09 23:11:41 +00:00
|
|
|
if ( this.loaded && ( added || removed ) ) {
|
|
|
|
this.altered = true;
|
|
|
|
}
|
|
|
|
|
2014-10-24 22:14:01 +00:00
|
|
|
this.setApplicableStatus();
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
this.updateTitle();
|
|
|
|
};
|
|
|
|
|
2015-04-13 21:30:41 +00:00
|
|
|
/**
|
|
|
|
* Respond to showAll event in the placeholder page.
|
|
|
|
* Cache this so we can make sure the parameter list is expanded
|
|
|
|
* when we next load this same pageId placeholder.
|
|
|
|
*
|
|
|
|
* @param {string} pageId Page Id
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onParameterPlaceholderShowAll = function ( pageId ) {
|
|
|
|
this.expandedParamList[ pageId ] = true;
|
|
|
|
};
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* Handle add param events.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWParameterModel} param Added param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onAddParameter = function ( param ) {
|
|
|
|
var page;
|
|
|
|
|
|
|
|
if ( param.getName() ) {
|
2019-02-08 19:18:22 +00:00
|
|
|
page = new ve.ui.MWParameterPage( param, param.getId(), { $overlay: this.$overlay, readOnly: this.isReadOnly() } );
|
2014-04-10 19:07:40 +00:00
|
|
|
} else {
|
2015-04-13 21:30:41 +00:00
|
|
|
page = new ve.ui.MWParameterPlaceholderPage( param, param.getId(), {
|
2018-04-04 20:37:32 +00:00
|
|
|
$overlay: this.$overlay,
|
2015-04-13 21:30:41 +00:00
|
|
|
expandedParamList: !!this.expandedParamList[ param.getId() ]
|
|
|
|
} )
|
|
|
|
.connect( this, { showAll: 'onParameterPlaceholderShowAll' } );
|
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 ) {
|
|
|
|
if ( !this.preventReselection ) {
|
|
|
|
this.setPageByName( param.getId() );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.altered = true;
|
|
|
|
this.setApplicableStatus();
|
2021-04-22 16:59:30 +00:00
|
|
|
|
|
|
|
if ( page instanceof ve.ui.MWParameterPage ) {
|
|
|
|
page.updateSize();
|
|
|
|
}
|
2014-05-30 19:34:23 +00:00
|
|
|
} else {
|
|
|
|
this.onAddParameterBeforeLoad( page );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-30 19:34:23 +00:00
|
|
|
/**
|
|
|
|
* Additional handling of parameter addition events before loading.
|
|
|
|
*
|
|
|
|
* @param {ve.ui.MWParameterPage} page Parameter page object
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onAddParameterBeforeLoad = function () {};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* Handle remove param events.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWParameterModel} param Removed param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onRemoveParameter = function ( param ) {
|
|
|
|
var page = this.bookletLayout.getPage( param.getId() ),
|
2017-09-05 02:08:36 +00:00
|
|
|
reselect = this.bookletLayout.findClosestPage( page );
|
2014-04-10 19:07:40 +00:00
|
|
|
|
2018-06-21 18:45:06 +00:00
|
|
|
// Select the desired page first. Otherwise, if the page we are removing is selected,
|
|
|
|
// OOUI will try to select the first page after it is removed, and scroll to the top.
|
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
|
|
|
this.setPageByName( reselect.getName() );
|
|
|
|
}
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
this.bookletLayout.removePages( [ page ] );
|
2014-12-09 23:11:41 +00:00
|
|
|
|
2018-06-21 18:45:06 +00:00
|
|
|
if ( this.loaded ) {
|
2014-12-09 23:11:41 +00:00
|
|
|
this.altered = true;
|
|
|
|
this.setApplicableStatus();
|
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.
|
2014-04-10 19:07:40 +00:00
|
|
|
*/
|
2014-10-24 22:14:01 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.setApplicableStatus = function () {
|
2014-04-24 00:22:45 +00:00
|
|
|
var parts = this.transclusionModel && this.transclusionModel.getParts();
|
2014-04-10 19:07:40 +00:00
|
|
|
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( parts.length && !( parts[ 0 ] instanceof ve.dm.MWTemplatePlaceholderModel ) ) {
|
2019-02-19 17:08:38 +00:00
|
|
|
this.actions.setAbilities( { done: this.altered, insert: true } );
|
2014-10-24 22:14:01 +00:00
|
|
|
} else {
|
2014-12-09 23:11:41 +00:00
|
|
|
// Loading is resolved. We have either: 1) no parts, or 2) the a placeholder as the first part
|
2019-02-19 17:08:38 +00:00
|
|
|
this.actions.setAbilities( { done: parts.length === 0 && this.altered, insert: false } );
|
2014-10-24 22:14:01 +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.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the page by name.
|
|
|
|
*
|
|
|
|
* Page names are always the ID of the part or param they represent.
|
|
|
|
*
|
|
|
|
* @param {string} name Page name
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.setPageByName = function ( name ) {
|
|
|
|
if ( this.bookletLayout.isOutlined() ) {
|
2015-05-08 15:15:16 +00:00
|
|
|
this.bookletLayout.getOutline().selectItemByData( name );
|
2014-04-10 19:07:40 +00:00
|
|
|
} else {
|
|
|
|
this.bookletLayout.setPage( name );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the dialog title.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.updateTitle = function () {
|
2021-06-02 10:06:36 +00:00
|
|
|
var parts = this.transclusionModel && this.transclusionModel.getParts(),
|
|
|
|
title = ve.msg( 'visualeditor-dialog-transclusion-loading' );
|
|
|
|
|
|
|
|
if ( parts && parts.length === 1 && parts[ 0 ] ) {
|
|
|
|
if ( parts[ 0 ] instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
title = ve.msg(
|
|
|
|
this.getMode() === 'insert' ?
|
|
|
|
'visualeditor-dialog-transclusion-title-insert-known-template' :
|
|
|
|
'visualeditor-dialog-transclusion-title-edit-known-template',
|
|
|
|
parts[ 0 ].getSpec().getLabel()
|
|
|
|
);
|
|
|
|
} 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
|
2015-04-09 23:47:15 +00:00
|
|
|
this.bookletLayout = new OO.ui.BookletLayout( this.constructor.static.bookletLayoutConfig );
|
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
|
|
|
*
|
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 ) {
|
|
|
|
if ( data.action === 'ok' ) {
|
|
|
|
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 ) {
|
2020-12-11 15:09:45 +00:00
|
|
|
var templateEvent, i,
|
|
|
|
dialog = this;
|
|
|
|
|
2019-02-19 17:08:38 +00:00
|
|
|
if ( action === 'done' || action === 'insert' ) {
|
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-01-21 12:17:03 +00:00
|
|
|
var modelPromise, editCountBucket,
|
2016-05-15 11:08:13 +00:00
|
|
|
surfaceModel = dialog.getFragment().getSurface(),
|
2014-12-16 21:14:01 +00:00
|
|
|
obj = dialog.transclusionModel.getPlainObject();
|
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
|
2019-11-02 05:06:28 +00:00
|
|
|
modelPromise = ve.createDeferred().resolve().promise();
|
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
|
|
|
|
templateEvent = {
|
|
|
|
action: 'save',
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
template_names: []
|
|
|
|
};
|
2021-01-21 12:17:03 +00:00
|
|
|
editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
|
|
|
|
if ( editCountBucket !== null ) {
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
templateEvent.user_edit_count_bucket = editCountBucket;
|
|
|
|
}
|
2020-12-11 15:09:45 +00:00
|
|
|
for ( i = 0; i < dialog.transclusionModel.getParts().length; i++ ) {
|
|
|
|
if ( dialog.transclusionModel.getParts()[ i ].getTitle ) {
|
|
|
|
templateEvent.template_names.push( dialog.transclusionModel.getParts()[ i ].getTitle() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-01-21 12:17:03 +00:00
|
|
|
var template, promise, templateEvent, i, editCountBucket,
|
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',
|
|
|
|
change: 'onTransclusionModelChange'
|
|
|
|
} );
|
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();
|
2018-07-18 23:42:09 +00:00
|
|
|
// HACK: Prevent any setPage() calls (from #onReplacePart) from focussing stuff, it messes
|
|
|
|
// with OOUI logic for marking fields as invalid (T199838). We set it back to true below.
|
2018-11-16 00:08:29 +00:00
|
|
|
this.bookletLayout.autoFocus = false;
|
2016-05-09 22:24:22 +00:00
|
|
|
|
2014-05-31 04:47:08 +00:00
|
|
|
// Initialization
|
|
|
|
if ( !this.selectedNode ) {
|
|
|
|
if ( data.template ) {
|
|
|
|
// New specified template
|
|
|
|
template = ve.dm.MWTemplateModel.newFromName(
|
|
|
|
this.transclusionModel, data.template
|
|
|
|
);
|
2017-06-01 14:28:15 +00:00
|
|
|
promise = this.transclusionModel.addPart( template ).then(
|
2014-10-29 01:43:03 +00:00
|
|
|
this.initializeNewTemplateParameters.bind( this )
|
2014-10-14 19:27:26 +00:00
|
|
|
);
|
2014-05-31 04:47:08 +00:00
|
|
|
} else {
|
|
|
|
// New template placeholder
|
|
|
|
promise = this.transclusionModel.addPart(
|
|
|
|
new ve.dm.MWTemplatePlaceholderModel( this.transclusionModel )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Load 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
|
|
|
|
templateEvent = {
|
|
|
|
action: 'edit',
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
template_names: []
|
|
|
|
};
|
2021-01-21 12:17:03 +00:00
|
|
|
editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
|
|
|
|
if ( editCountBucket !== null ) {
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
templateEvent.user_edit_count_bucket = editCountBucket;
|
|
|
|
}
|
2020-12-11 15:09:45 +00:00
|
|
|
for ( i = 0; i < this.selectedNode.partsList.length; i++ ) {
|
|
|
|
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
|
|
|
}
|
2019-02-19 17:08:38 +00:00
|
|
|
this.actions.setAbilities( { done: false, insert: 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
|
|
|
|
2018-11-16 00:08:29 +00:00
|
|
|
dialog.loaded = true;
|
|
|
|
dialog.$element.addClass( 've-ui-mwTemplateDialog-ready' );
|
|
|
|
dialog.$body.append( dialog.bookletLayout.$element );
|
2018-06-21 21:08:17 +00:00
|
|
|
|
2018-11-16 00:08:29 +00:00
|
|
|
dialog.bookletLayout.autoFocus = 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
|
|
|
/**
|
|
|
|
* Initialize parameters for new template insertion
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.initializeNewTemplateParameters = function () {
|
|
|
|
var i, parts = this.transclusionModel.getParts();
|
|
|
|
for ( i = 0; i < parts.length; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( parts[ i ] instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
parts[ i ].addPromptedParameters();
|
2014-10-07 00:06:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Intentionally empty. This is provided for Wikia extensibility.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.initializeTemplateParameters = function () {};
|
|
|
|
|
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 );
|
|
|
|
this.transclusionModel.abortRequests();
|
|
|
|
this.transclusionModel = null;
|
|
|
|
this.bookletLayout.clearPages();
|
|
|
|
this.content = null;
|
|
|
|
}, this );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|