mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 00:00:49 +00:00
Use Parsoid data for template names rather than detect from wikitext
We were incorrectly handling transclusions with trailing newlines after the template name. This also improves handling of non-template transclusions, e.g. parser functions like `{{int:mainpage}}`, which are no longer mangled as if they were page names. ve.dm.MWTransclusionNode#isSingleTemplate will now match a template even if it's name is itself template-generated. Logic for turning Parsoid's hrefs into page names stolen from ve.dm.MWImageNode.prototype.getFilename. Bug: T167613 Change-Id: Ibecf71338eb37bb3da81a7372e4ed41140a9af57
This commit is contained in:
parent
5fbe84a4e6
commit
624211a60f
|
@ -50,17 +50,22 @@ ve.ce.MWTransclusionNode.static.iconWhenInvisible = 'template';
|
|||
* Get a list of descriptions of template parts in a transclusion node
|
||||
*
|
||||
* @static
|
||||
* @param {ve.dm.Node} model Node model
|
||||
* @param {ve.dm.MWTransclusionNode} model Node model
|
||||
* @return {string[]} List of template part descriptions
|
||||
*/
|
||||
ve.ce.MWTransclusionNode.static.getTemplatePartDescriptions = function ( model ) {
|
||||
var i, len, part,
|
||||
var i, len, part, title,
|
||||
parts = model.getPartsList(),
|
||||
words = [];
|
||||
|
||||
for ( i = 0, len = parts.length; i < len; i++ ) {
|
||||
part = parts[ i ];
|
||||
if ( part.template ) {
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
|
@ -73,14 +78,6 @@ ve.ce.MWTransclusionNode.static.getTemplatePartDescriptions = function ( model )
|
|||
*/
|
||||
ve.ce.MWTransclusionNode.static.getDescription = function ( model ) {
|
||||
return this.getTemplatePartDescriptions( model )
|
||||
.map( function ( template ) {
|
||||
var title = mw.Title.newFromText( template, mw.config.get( 'wgNamespaceIds' ).template );
|
||||
if ( title ) {
|
||||
return title.getRelativeText( mw.config.get( 'wgNamespaceIds' ).template );
|
||||
} else {
|
||||
return template;
|
||||
}
|
||||
} )
|
||||
.join( ve.msg( 'comma-separator' ) );
|
||||
};
|
||||
|
||||
|
|
|
@ -357,8 +357,8 @@ ve.dm.MWTransclusionNode.prototype.isSingleTemplate = function ( templates ) {
|
|||
}
|
||||
for ( i = 0, len = templates.length; i < len; i++ ) {
|
||||
if (
|
||||
partsList[ 0 ].template &&
|
||||
normalizeTitle( partsList[ 0 ].template ) === normalizeTitle( templates[ i ] )
|
||||
partsList[ 0 ].templatePage &&
|
||||
partsList[ 0 ].templatePage === normalizeTitle( templates[ i ] )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
@ -372,18 +372,23 @@ ve.dm.MWTransclusionNode.prototype.isSingleTemplate = function ( templates ) {
|
|||
* @return {Object[]} List of objects with either template or content properties
|
||||
*/
|
||||
ve.dm.MWTransclusionNode.prototype.getPartsList = function () {
|
||||
var i, len, part, content;
|
||||
var i, len, href, page, part, content;
|
||||
|
||||
if ( !this.partsList ) {
|
||||
this.partsList = [];
|
||||
content = this.getAttribute( 'mw' );
|
||||
for ( i = 0, len = content.parts.length; i < len; i++ ) {
|
||||
part = content.parts[ i ];
|
||||
this.partsList.push(
|
||||
part.template ?
|
||||
{ template: part.template.target.wt } :
|
||||
{ content: part }
|
||||
);
|
||||
if ( part.template ) {
|
||||
href = part.template.target.href;
|
||||
page = href ? ve.decodeURIComponentIntoArticleTitle( href.replace( /^(\.+\/)*/, '' ) ) : null;
|
||||
this.partsList.push( {
|
||||
template: part.template.target.wt,
|
||||
templatePage: page
|
||||
} );
|
||||
} else {
|
||||
this.partsList.push( { content: part } );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue