Merge "Remove unnecessary title parsing from template related code"

This commit is contained in:
jenkins-bot 2021-08-26 15:08:13 +00:00 committed by Gerrit Code Review
commit a5718f01c5
5 changed files with 28 additions and 29 deletions

View file

@ -174,7 +174,7 @@
"visualeditor-dialog-transclusion-add-content": "Add content",
"visualeditor-dialog-transclusion-add-wikitext": "Add wikitext",
"visualeditor-dialog-transclusion-add-param": "Add more information",
"visualeditor-dialog-transclusion-add-param-help": "If known, enter undocumented parameter names. If the parameter is not already part of the template, adding it will have no effect. You may find information about existing parameters on the [[{{ns:template}}:$1|template's page]].",
"visualeditor-dialog-transclusion-add-param-help": "If known, enter undocumented parameter names. If the parameter is not already part of the template, adding it will have no effect. You may find information about existing parameters on the [[$1|template's page]].",
"visualeditor-dialog-transclusion-add-param-save": "Add parameter",
"visualeditor-dialog-transclusion-add-template": "Add template",
"visualeditor-dialog-transclusion-add-undocumented-param": "Add undocumented parameter",
@ -187,9 +187,9 @@
"visualeditor-dialog-transclusion-deprecated-parameter": "Deprecated field",
"visualeditor-dialog-transclusion-deprecated-parameter-description": "Field is deprecated. $1",
"visualeditor-dialog-transclusion-loading": "Loading...",
"visualeditor-dialog-transclusion-more-template-description": "There might be some additional information about the \"$1\" template on [[{{ns:template}}:$1|its page]].",
"visualeditor-dialog-transclusion-more-template-description": "There might be some additional information about the \"$1\" template on [[$2|its page]].",
"visualeditor-dialog-transclusion-multipart-message": "You are currently editing a template and one or more pieces of connected content (wikitext and/or additional templates).",
"visualeditor-dialog-transclusion-no-template-description": "The \"$1\" template doesn't yet have a description, but there might be some information on the [[$1|template's page]].",
"visualeditor-dialog-transclusion-no-template-description": "The \"$1\" template doesn't yet have a description, but there might be some information on the [[$2|template's page]].",
"visualeditor-dialog-transclusion-options": "Options",
"visualeditor-dialog-transclusion-param-default": "Default: $1",
"visualeditor-dialog-transclusion-param-example": "e.g. $1",

View file

@ -129,7 +129,8 @@ ve.dm.MWTemplateModel.prototype.getTarget = function () {
};
/**
* @return {string|null} Template title, if available
* @return {string|null} Prefixed template title including the "Template:" namespace, if available.
* Use {@see ve.dm.MWTemplateSpecModel.getLabel} for a human-readable label without the namespace.
*/
ve.dm.MWTemplateModel.prototype.getTitle = function () {
return this.title;

View file

@ -129,12 +129,12 @@ ve.dm.MWTemplateSpecModel.prototype.fillFromTemplate = function () {
};
/**
* @return {string} Normalized template name without the "Template:" namespace prefix
* @return {string} Normalized template name without the "Template:" namespace prefix, if possible.
* Otherwise the unnormalized template name as used in the wikitext. Might even be a string like
* `{{example}}` when a template name is dynamically generated.
*/
ve.dm.MWTemplateSpecModel.prototype.getLabel = function () {
var title = this.template.getTitle(),
target = this.template.getTarget();
var title = this.template.getTitle();
if ( title ) {
try {
// Normalize and remove namespace prefix if in the Template: namespace
@ -142,8 +142,7 @@ ve.dm.MWTemplateSpecModel.prototype.getLabel = function () {
.getRelativeText( mw.config.get( 'wgNamespaceIds' ).template );
} catch ( e ) { }
}
return title || target.wt;
return title || this.template.getTarget().wt;
};
/**

View file

@ -50,7 +50,7 @@ ve.ui.MWAddParameterPage = function VeUiMWAddParameterPage( parameter, name, con
helpInline: true,
help: mw.message(
'visualeditor-dialog-transclusion-add-param-help',
this.template.getSpec().getLabel()
this.template.getTitle() || this.template.getTarget().wt
).parseDom(),
classes: [ 've-ui-mwTransclusionDialog-addParameterFieldset' ],
$content: this.addParameterInputField.$element

View file

@ -19,7 +19,7 @@
* @cfg {boolean} [isReadOnly] Page is read-only
*/
ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) {
var title = template.getTitle() ? mw.Title.newFromText( template.getTitle() ) : null,
var link = template.getTitle(),
veConfig = mw.config.get( 'wgVisualEditorConfig' );
// Configuration initialization
@ -33,17 +33,22 @@ ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) {
// Properties
this.template = template;
this.spec = template.getSpec();
this.$description = $( '<div>' );
this.$description = $( '<div>' )
.addClass( 've-ui-mwTemplatePage-description' );
this.infoFieldset = new OO.ui.FieldsetLayout( {
label: this.spec.getLabel(),
icon: 'puzzle'
} );
// Initialization
this.$description.addClass( 've-ui-mwTemplatePage-description' );
if ( this.spec.getDescription() ) {
this.$description.text( this.spec.getDescription() );
if ( title ) {
this.$description
.text( this.spec.getDescription() );
// The transcluded page may be dynamically generated or unspecified in the DOM
// for other reasons (T68724). In that case we can't tell the user what the
// template is called, nor link to the template page. However, if we know for
// certain that the template doesn't exist, be explicit about it (T162694).
if ( link ) {
if ( this.spec.getDescription() ) {
this.$description
.append(
$( '<hr>' ),
@ -51,18 +56,12 @@ ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) {
.addClass( 've-ui-mwTemplatePage-description-extra' )
.append( mw.message(
'visualeditor-dialog-transclusion-more-template-description',
title.getRelativeText( mw.config.get( 'wgNamespaceIds' ).template )
this.spec.getLabel(),
link
).parseDom() )
);
ve.targetLinksToNewWindow( this.$description[ 0 ] );
}
} else {
// The transcluded page may be dynamically generated or unspecified in the DOM
// for other reasons (T68724). In that case we can't tell the user what the
// template is called, nor link to the template page. However, if we know for
// certain that the template doesn't exist, be explicit about it (T162694).
if ( title ) {
var linkData = ve.init.platform.linkCache.getCached( '_missing/' + title );
} else {
var linkData = ve.init.platform.linkCache.getCached( '_missing/' + link );
var messageKey = linkData && linkData.missing ?
'visualeditor-dialog-transclusion-absent-template' :
'visualeditor-dialog-transclusion-no-template-description';
@ -72,9 +71,9 @@ ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) {
// The following messages are used here:
// * visualeditor-dialog-transclusion-absent-template
// * visualeditor-dialog-transclusion-no-template-description
.append( mw.message( messageKey, title.getPrefixedText() ).parseDom() );
ve.targetLinksToNewWindow( this.$description[ 0 ] );
.append( mw.message( messageKey, this.spec.getLabel(), link ).parseDom() );
}
ve.targetLinksToNewWindow( this.$description[ 0 ] );
}
this.$description.find( 'a[href]' )
.on( 'click', function () {