From fd83cafa4bd1a457f723e14c790904b62731923f Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 9 Jul 2014 22:09:05 +0200 Subject: [PATCH] MWTemplatePage: Account for template.title being null Example: * Transclusion with html comment in target {{ Unsigned |Example}}. * Transclusion with wikitext expression as target {{ {{echo|Unsigned}} |Example}}. The first case was handled already (Parsoid strips the comment when it normalises the target title). The second case, however, is not handled and ends in template.title being null. This was already documented (MWTemplateModel#getTitle returns {string|null}), but not used correctly. The title of the dialog is unaffected as it fallsback to displaying target.wt instead of target.title. Bug: 66724 Change-Id: Ib6696ac3538f6cb9e93da2f6f8666f373247eeb4 --- .../ve-mw/ui/pages/ve.ui.MWTemplatePage.js | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js b/modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js index 3e582059d9..bf658c91ec 100644 --- a/modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js +++ b/modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js @@ -62,23 +62,32 @@ ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) { if ( this.spec.getDescription() ) { this.$description.text( this.spec.getDescription() ); } else { - title = new mw.Title( this.template.getTitle() ); - if ( title.getNamespaceId() === 10 ) { - titleText = title.getMainText(); - } else if ( title.getNamespaceId() === 0 ) { - titleText = ':' + title.getPrefixedText(); - } else { - titleText = title.getPrefixedText(); + title = this.template.getTitle(); + // The transcluded page may be dynamically generated or unspecified in the DOM + // for other reasons (bug 66724). In that case we can't tell the user what + // the template is called nor link to the template page. + if ( title ) { + title = mw.Title.newFromText( title ); + } + if ( title ) { + if ( title.getNamespaceId() === 10 ) { + titleText = title.getMainText(); + } else if ( title.getNamespaceId() === 0 ) { + titleText = ':' + title.getPrefixedText(); + } else { + titleText = title.getPrefixedText(); + } + this.$description + .addClass( 've-ui-mwTemplatePage-description-missing' ) + .append( ve.msg( + 'visualeditor-dialog-transclusion-no-template-description', + titleText, + ve.getHtmlAttributes( { 'target': '_blank', 'href': title.getUrl() } ), + mw.user + ) ); } - this.$description - .addClass( 've-ui-mwTemplatePage-description-missing' ) - .append( ve.msg( - 'visualeditor-dialog-transclusion-no-template-description', - titleText, - ve.getHtmlAttributes( { 'target': '_blank', 'href': title.getUrl() } ), - mw.user - ) ); } + this.infoFieldset.$element.append( this.$description ); this.$more .addClass( 've-ui-mwTemplatePage-more' )