From 49179c7c314417dbcd8a07e24cd91a49a6008b84 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 23 Jun 2013 17:25:52 -0700 Subject: [PATCH] ve.dm.MWTemplateSpecModel: Expand parameter aliases We were previously ignoring this data leading to situations where a template that can be invoked like {{foo|1=bar}} and {{foo|thing=bar}} (where the template data documents param thing with alias '1') will show up in the editor with no parameter information or label for the 1= call, but will show up for the thing= call. Now they are properly aliases so both will appear the same in the editor dialog. Bug: 49838 Change-Id: I37ec0e152df905844ac58ed1834fca29dccb4eec --- modules/ve/dm/models/ve.dm.MWTemplateSpecModel.js | 13 +++++++++++-- modules/ve/dm/models/ve.dm.MWTransclusionModel.js | 11 ++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/modules/ve/dm/models/ve.dm.MWTemplateSpecModel.js b/modules/ve/dm/models/ve.dm.MWTemplateSpecModel.js index 0f3b0fe81c..9823a92692 100644 --- a/modules/ve/dm/models/ve.dm.MWTemplateSpecModel.js +++ b/modules/ve/dm/models/ve.dm.MWTemplateSpecModel.js @@ -67,16 +67,25 @@ ve.dm.MWTemplateSpecModel.getMessage = function ( val, fallback, lang ) { * @param {string[][]} [data.sets] Lists of param sets */ ve.dm.MWTemplateSpecModel.prototype.extend = function ( data ) { - var key; + var key, paramObj, i, len; if ( data.description !== null ) { this.description = data.description; } if ( ve.isPlainObject( data.params ) ) { for ( key in data.params ) { + paramObj = data.params[key]; this.params[key] = ve.extendObject( - true, this.getDefaultParameterSpec( key ), data.params[key] + true, + this.getDefaultParameterSpec( key ), + paramObj ); + if ( paramObj.aliases.length ) { + for ( i = 0, len = paramObj.aliases.length; i < len; i++ ) { + this.params[ paramObj.aliases[i] ] = paramObj; + } + } + delete paramObj.aliases; } } if ( data.sets ) { diff --git a/modules/ve/dm/models/ve.dm.MWTransclusionModel.js b/modules/ve/dm/models/ve.dm.MWTransclusionModel.js index 7dacad884d..595c3e2009 100644 --- a/modules/ve/dm/models/ve.dm.MWTransclusionModel.js +++ b/modules/ve/dm/models/ve.dm.MWTransclusionModel.js @@ -79,10 +79,10 @@ ve.dm.MWTransclusionModel.prototype.load = function ( data ) { } } } - // Promise is resolved passing the specs object as the first argument - binding #specs - // to precede that argument and passing them both to extendObject will cause #specs to be added - // to when the promise is resolved - return this.fetchSpecs( templates ).done( ve.bind( ve.extendObject, null, this.specs ) ); + // Add fetched specs to #specs store when the promise is resolved + return this.fetchSpecs( templates ).done( function ( specs ) { + ve.extendObject( this.specs, specs ); + } ); }; /** @@ -92,7 +92,8 @@ ve.dm.MWTransclusionModel.prototype.load = function ( data ) { * @returns {jQuery.Promise} Promise, resolved when spec is loaded */ ve.dm.MWTransclusionModel.prototype.fetchSpecs = function ( templates ) { - var i, len, title, deferred = $.Deferred(), + var i, len, title, + deferred = $.Deferred(), specs = {}, titles = [];