jenkins-bot has submitted this change and it was merged.

Change subject: Handlebars helpers have different signature than used
......................................................................


Handlebars helpers have different signature than used

The signature for all handlebar helpers is:

  function( args..., options );

Meaning there is a variable number of arguments and the final argument
is an options object.  Patch updates the l10n helper to appropriatly
take this into account.  Also updates the couple places that call l10n
directly to call it as it expects.

This resolves an inconsistency where the same function was being called two
different ways resulting in different results.

Bug: 71318
Change-Id: I972783d35056ac24b8a81bdc08a4cd99d36e0b76
(cherry picked from commit 05e678a067a95f590a7dacc6367694a69544d0e1)
---
M modules/new/flow-handlebars.js
M tests/qunit/new/test_flow-handlebars.js
2 files changed, 22 insertions(+), 18 deletions(-)

Approvals:
  EBernhardson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/new/flow-handlebars.js b/modules/new/flow-handlebars.js
index 3457f20..55c4606 100644
--- a/modules/new/flow-handlebars.js
+++ b/modules/new/flow-handlebars.js
@@ -255,11 +255,13 @@
         * @param {Object} [options]
         * @returns {String}
         */
-       FlowHandlebars.prototype.l10n = function ( str, args, options ) {
-               var res = flowMessages.apply( mw, arguments ).text();
+       FlowHandlebars.prototype.l10n = function ( str /*, args..., options */ 
) {
+               // chop off str and options leaving just args
+               var args = flowNormalizeL10nParameters( 
Array.prototype.slice.call( arguments, 1, -1 ) ),
+                       res = flowMessages.call( mw, str, args ).text();
 
                if ( !res ) {
-                       mw.flow.debug( "[l10n] Empty String", arguments );
+                       mw.flow.debug( "[l10n] Empty String", args );
                        return "(l10n:" + str + ")";
                }
 
@@ -270,9 +272,11 @@
         * HTML-safe version of l10n.
         * @returns {String|Handlebars.SafeString}
         */
-       FlowHandlebars.prototype.l10nParse = function ( str, args, options ) {
+       FlowHandlebars.prototype.l10nParse = function ( str /*, args..., 
options */ ) {
+               var args = flowNormalizeL10nParameters( 
Array.prototype.slice.call( arguments, 1, -1 ) );
+
                return FlowHandlebars.prototype.html(
-                       mw.message( str ).params( flowNormalizeL10nParameters( 
args ) ).parse()
+                       mw.message( str ).params( args ).parse()
                );
        };
 
@@ -315,7 +319,7 @@
 
                if ( seconds_ago < 2419200 ) {
                        // Return "n ago" for only dates less than 4 weeks ago
-                       time_ago = FlowHandlebars.prototype.l10n( 'time', str, 
seconds_ago );
+                       time_ago = FlowHandlebars.prototype.l10n( 'time', str, 
seconds_ago, {} );
 
                        if ( timeAgoOnly === true ) {
                                // timeAgoOnly: return only this text
@@ -338,7 +342,7 @@
                                'timestamp',
                                {
                                        time_iso: timestamp,
-                                       time_readable: fallback || 
FlowHandlebars.prototype.l10n( 'datetime', timestamp ),
+                                       time_readable: fallback || 
FlowHandlebars.prototype.l10n( 'datetime', timestamp, {} ),
                                        time_ago: time_ago,
                                        guid: guid
                                }
diff --git a/tests/qunit/new/test_flow-handlebars.js 
b/tests/qunit/new/test_flow-handlebars.js
index 0f84ffd..7c839ff 100644
--- a/tests/qunit/new/test_flow-handlebars.js
+++ b/tests/qunit/new/test_flow-handlebars.js
@@ -165,18 +165,18 @@
 } );
 
 QUnit.test( 'FlowHandlebars.prototype.l10n', 11, function( assert ) {
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
2 ), '2 seconds ago', 'Check seconds.' );
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
120 ), '2 minutes ago', 'Check minutes.' );
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
 60 * 60 * 2 ), '2 hours ago', 'Check hour.' );
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
60 * 60 * 24 * 2 ), '2 days ago', 'Check day.' );
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
60 * 60 * 24 * 7 * 2 ), '2 weeks ago', 'Check week.' );
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-active-ago', 60 * 60 * 24 * 7 * 2 ), 'Active 2 weeks ago', 'Check week.' 
);
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-started-ago', 60 * 60 * 24 * 7 * 2 ), 'Started 2 weeks ago', 'Check 
week.' );
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-edited-ago', 60 * 60 * 24 * 7 * 2 ), 'Edited 2 weeks ago', 'Check week.' 
);
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
2, this.opts ), '2 seconds ago', 'Check seconds.' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
120, this.opts ), '2 minutes ago', 'Check minutes.' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
 60 * 60 * 2, this.opts ), '2 hours ago', 'Check hour.' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
60 * 60 * 24 * 2, this.opts ), '2 days ago', 'Check day.' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 'flow-time-ago', 
60 * 60 * 24 * 7 * 2, this.opts ), '2 weeks ago', 'Check week.' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-active-ago', 60 * 60 * 24 * 7 * 2, this.opts ), 'Active 2 weeks ago', 
'Check week.' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-started-ago', 60 * 60 * 24 * 7 * 2, this.opts ), 'Started 2 weeks ago', 
'Check week.' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-edited-ago', 60 * 60 * 24 * 7 * 2, this.opts ), 'Edited 2 weeks ago', 
'Check week.' );
 
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-active-ago', 1 ), 'Active 1 second ago', 'Check non-plural.' );
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-started-ago', 60 * 60 * 24 * 7 * 1 ), 'Started 1 week ago', 'Check 
non-plural' );
-       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-edited-ago', 60 * 60 * 24 * 1 ), 'Edited 1 day ago', 'Check non-plural' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-active-ago', 1, this.opts ), 'Active 1 second ago', 'Check non-plural.' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-started-ago', 60 * 60 * 24 * 7 * 1, this.opts ), 'Started 1 week ago', 
'Check non-plural' );
+       assert.strictEqual( this.handlebarsProto.l10n( 'time', 
'flow-edited-ago', 60 * 60 * 24 * 1, this.opts ), 'Edited 1 day ago', 'Check 
non-plural' );
 } );
 
 } ( jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/162943
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I972783d35056ac24b8a81bdc08a4cd99d36e0b76
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: wmf/1.25wmf1
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to