mediawiki-extensions-Visual.../modules/ve-mw/dm/models/ve.dm.MWTransclusionPartModel.js

90 lines
1.8 KiB
JavaScript
Raw Normal View History

/*!
* VisualEditor DataModel MWTransclusionPartModel class.
*
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* MediaWiki transclusion part model.
*
* @class
* @mixins OO.EventEmitter
*
* @constructor
* @param {ve.dm.MWTransclusionModel} transclusion Transclusion
*/
Preserve unused Parsoid template properties Problem: Parsoid has a property called "i" which we don't use, but they need for round-tripping purposes. Since we were generating a structure from Parsoid data and then generating data from the structure without preserving properties we didn't use, it was getting lost. Solution: Abstract creating a template from data vs. creating it from name. Make only templates have an origin argument in their constructors, so and set it within a set of static constructors that create a template for either data or a template name. Store the original data in the former case, and use it as a base when serializing. Changes: ve.ui.MWTranslcusionDialog.js * Remove no-longer-needed mw global declaration * Move most of the addTemplate function to a static constructor in the template model class ve.dm.MWTransclusionPartModel.js, ve.dm.MWTransclusionContentModel.js, ve.dm.MWTemplatePlaceholder * Remove unused origin argument/property/getter * Add serialize method (if needed) ve.dm.MWTranclusionModel.js * Move template/parameter generation from data into static constructor of template model * Move serialization to part classes ve.dm.MWTemplateModel.js * Add mw global declaration * Stop passing origin to parent constructor, store it locally instead * Add original data property/setter for preserving unused properties when round tripping * Add static constructors for generating a template from data or by name * Add serialize method Bug: 51150 Change-Id: Ide596a0ca0ae8f93ffce6e79b7234a1db7e0586c
2013-07-12 00:23:33 +00:00
ve.dm.MWTransclusionPartModel = function VeDmMWTransclusionPartModel( transclusion ) {
// Mixin constructors
OO.EventEmitter.call( this );
// Properties
this.transclusion = transclusion;
this.id = 'part_' + this.transclusion.getUniquePartId();
};
/* Inheritance */
OO.mixinClass( ve.dm.MWTransclusionPartModel, OO.EventEmitter );
/* Events */
/**
* @event change
*/
/* Methods */
/**
* Get transclusion part is in.
*
* @return {ve.dm.MWTransclusionModel} Transclusion
*/
ve.dm.MWTransclusionPartModel.prototype.getTransclusion = function () {
return this.transclusion;
};
/**
* Get a unique part ID within the transclusion.
*
* @return {string} Unique ID
*/
ve.dm.MWTransclusionPartModel.prototype.getId = function () {
return this.id;
};
/**
* Remove part from transclusion.
*/
ve.dm.MWTransclusionPartModel.prototype.remove = function () {
this.transclusion.removePart( this );
};
Preserve unused Parsoid template properties Problem: Parsoid has a property called "i" which we don't use, but they need for round-tripping purposes. Since we were generating a structure from Parsoid data and then generating data from the structure without preserving properties we didn't use, it was getting lost. Solution: Abstract creating a template from data vs. creating it from name. Make only templates have an origin argument in their constructors, so and set it within a set of static constructors that create a template for either data or a template name. Store the original data in the former case, and use it as a base when serializing. Changes: ve.ui.MWTranslcusionDialog.js * Remove no-longer-needed mw global declaration * Move most of the addTemplate function to a static constructor in the template model class ve.dm.MWTransclusionPartModel.js, ve.dm.MWTransclusionContentModel.js, ve.dm.MWTemplatePlaceholder * Remove unused origin argument/property/getter * Add serialize method (if needed) ve.dm.MWTranclusionModel.js * Move template/parameter generation from data into static constructor of template model * Move serialization to part classes ve.dm.MWTemplateModel.js * Add mw global declaration * Stop passing origin to parent constructor, store it locally instead * Add original data property/setter for preserving unused properties when round tripping * Add static constructors for generating a template from data or by name * Add serialize method Bug: 51150 Change-Id: Ide596a0ca0ae8f93ffce6e79b7234a1db7e0586c
2013-07-12 00:23:33 +00:00
/**
* Get serialized representation of transclusion part.
*
* @return {Mixed} Serialized representation, or undefined if empty
Preserve unused Parsoid template properties Problem: Parsoid has a property called "i" which we don't use, but they need for round-tripping purposes. Since we were generating a structure from Parsoid data and then generating data from the structure without preserving properties we didn't use, it was getting lost. Solution: Abstract creating a template from data vs. creating it from name. Make only templates have an origin argument in their constructors, so and set it within a set of static constructors that create a template for either data or a template name. Store the original data in the former case, and use it as a base when serializing. Changes: ve.ui.MWTranslcusionDialog.js * Remove no-longer-needed mw global declaration * Move most of the addTemplate function to a static constructor in the template model class ve.dm.MWTransclusionPartModel.js, ve.dm.MWTransclusionContentModel.js, ve.dm.MWTemplatePlaceholder * Remove unused origin argument/property/getter * Add serialize method (if needed) ve.dm.MWTranclusionModel.js * Move template/parameter generation from data into static constructor of template model * Move serialization to part classes ve.dm.MWTemplateModel.js * Add mw global declaration * Stop passing origin to parent constructor, store it locally instead * Add original data property/setter for preserving unused properties when round tripping * Add static constructors for generating a template from data or by name * Add serialize method Bug: 51150 Change-Id: Ide596a0ca0ae8f93ffce6e79b7234a1db7e0586c
2013-07-12 00:23:33 +00:00
*/
ve.dm.MWTransclusionPartModel.prototype.serialize = function () {
return undefined;
};
/**
* Get the wikitext for this part.
*
* @return {string} Wikitext
*/
ve.dm.MWTransclusionPartModel.prototype.getWikitext = function () {
return '';
};
/**
* Add all non-existing required and suggested parameters, if any.
*
* @method
* @return {number} Number of parameters added
*/
ve.dm.MWTransclusionPartModel.prototype.addPromptedParameters = function () {
return 0;
};