ve.ui.MWDefinedTransclusionContextItem: Fix handling of template names

The ...target.wt property contains the wikitext used to generate
the template name. It can contain trailing newlines (T234817) and
all kinds of funny wikitext syntax. Instead, use ...target.href,
which is the title of the page that is actually transcluded. Compare
the new code to ve.dm.MWTransclusionNode.prototype.getPartsList.

Additionally, fix some confusion about namespaces (treating template
names as titles in the main namespace). The template names in the
configuration page (visualeditor-template-tools-definition.json)
now support overriding namespaces in the same way as in wikitext.

Bug: T234817
Change-Id: I7c557d28e961d0b9117fc0380c65cdd42035ae96
This commit is contained in:
Bartosz Dziewoński 2019-10-07 14:53:26 +02:00
parent 052a879c3c
commit 55aec8f977

View file

@ -99,7 +99,7 @@ ve.ui.MWDefinedTransclusionContextItem.static.getToolsByTitle = function () {
var titles = Array.isArray( template.title ) ? template.title : [ template.title ];
// 'title' can be a single title, or list of titles (including redirects)
titles.forEach( function ( title ) {
toolsByTitle[ mw.Title.newFromText( title ).getPrefixedText() ] = template;
toolsByTitle[ mw.Title.newFromText( title, mw.config.get( 'wgNamespaceIds' ).template ).getPrefixedText() ] = template;
} );
} );
}
@ -113,9 +113,11 @@ ve.ui.MWDefinedTransclusionContextItem.static.getToolsByTitle = function () {
* @return {Object|null} Tool definition, or null if no match
*/
ve.ui.MWDefinedTransclusionContextItem.static.getMatchedTool = function ( model ) {
var rawTitle = ve.getProp( model.getAttribute( 'mw' ), 'parts', 0, 'template', 'target', 'wt' );
if ( rawTitle ) {
return this.getToolsByTitle()[ mw.Title.newFromText( rawTitle ).getPrefixedText() ] || null;
var resource, title;
resource = ve.getProp( model.getAttribute( 'mw' ), 'parts', 0, 'template', 'target', 'href' );
if ( resource ) {
title = mw.Title.newFromText( ve.normalizeParsoidResourceName( resource ) ).getPrefixedText();
return this.getToolsByTitle()[ title ] || null;
}
return null;
};