mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 23:05:35 +00:00
Improve abstraction around template context description
* Separate partDescription from partDescription*s* and use Array#map * Lookup CE node class of current model, instead of using ve.ce.MWTransclusionNode hard-coded. Change-Id: Ief07b865b4c216dc13408b12e8a1354cd2c28dfe
This commit is contained in:
parent
c06f913e66
commit
de2a2ca06f
|
@ -54,23 +54,26 @@ ve.ce.MWTransclusionNode.static.iconWhenInvisible = 'puzzle';
|
|||
* @return {string[]} List of template part descriptions
|
||||
*/
|
||||
ve.ce.MWTransclusionNode.static.getTemplatePartDescriptions = function ( model ) {
|
||||
var i, len, part, title,
|
||||
parts = model.getPartsList(),
|
||||
words = [];
|
||||
return model.getPartsList().map( this.getTemplatePartDescription );
|
||||
};
|
||||
|
||||
for ( i = 0, len = parts.length; i < len; i++ ) {
|
||||
part = parts[ i ];
|
||||
// Ignore parts that are just content
|
||||
if ( part.templatePage ) {
|
||||
title = mw.Title.newFromText( part.templatePage );
|
||||
words.push( title.getRelativeText( mw.config.get( 'wgNamespaceIds' ).template ) );
|
||||
} else if ( part.template ) {
|
||||
// Not actually a template, but e.g. a parser function
|
||||
words.push( part.template );
|
||||
}
|
||||
/**
|
||||
* Get a description of a template part in a transclusion node
|
||||
*
|
||||
* @static
|
||||
* @param {Object} part Template part
|
||||
* @return {string} Template part description
|
||||
*/
|
||||
ve.ce.MWTransclusionNode.static.getTemplatePartDescription = function ( part ) {
|
||||
var title;
|
||||
// Ignore parts that are just content
|
||||
if ( part.templatePage ) {
|
||||
title = mw.Title.newFromText( part.templatePage );
|
||||
return title.getRelativeText( mw.config.get( 'wgNamespaceIds' ).template );
|
||||
} else if ( part.template ) {
|
||||
// Not actually a template, but e.g. a parser function
|
||||
return part.template;
|
||||
}
|
||||
|
||||
return words;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -67,10 +67,11 @@ ve.ui.MWTransclusionContextItem.static.isCompatibleWith =
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWTransclusionContextItem.prototype.getDescription = function () {
|
||||
var nodeClass = ve.ce.nodeFactory.lookup( this.model.constructor.static.name );
|
||||
return ve.msg(
|
||||
'visualeditor-dialog-transclusion-contextitem-description',
|
||||
ve.ce.MWTransclusionNode.static.getDescription( this.model ),
|
||||
ve.ce.MWTransclusionNode.static.getTemplatePartDescriptions( this.model ).length
|
||||
nodeClass.static.getDescription( this.model ),
|
||||
nodeClass.static.getTemplatePartDescriptions( this.model ).length
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -78,8 +79,9 @@ ve.ui.MWTransclusionContextItem.prototype.getDescription = function () {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWTransclusionContextItem.prototype.renderDescription = function () {
|
||||
var nodeClass = ve.ce.nodeFactory.lookup( this.model.constructor.static.name );
|
||||
// No "Generated from" prefix in mobile context
|
||||
this.$description.text( ve.ce.MWTransclusionNode.static.getDescription( this.model ) );
|
||||
this.$description.text( nodeClass.static.getDescription( this.model ) );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue