mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
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:
parent
052a879c3c
commit
55aec8f977
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue