EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/162117

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.

Change-Id: I972783d35056ac24b8a81bdc08a4cd99d36e0b76
---
M modules/new/flow-handlebars.js
M tests/qunit/new/test_flow-handlebars.js
2 files changed, 23 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/17/162117/1

diff --git a/modules/new/flow-handlebars.js b/modules/new/flow-handlebars.js
index eb4be15..dba1f96 100644
--- a/modules/new/flow-handlebars.js
+++ b/modules/new/flow-handlebars.js
@@ -178,9 +178,8 @@
         * @param Object... [parameters] Parameters to pass as Message 
parameters or custom function
         *   parameters
         */
-       function flowMessages( str ) {
-               var parameters = Array.prototype.slice.call( arguments, 1 ),
-                       strings = ( {
+       function flowMessages( str, parameters ) {
+               var strings = ( {
                                "post_moderation_state": function( type, 
replyToId, name ) {
                                        var str;
                                        if ( !replyToId ) {
@@ -240,11 +239,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 = 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 + ")";
                }
 
@@ -255,7 +256,9 @@
         * 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 = Array.prototype.slice.call( arguments, 1, -1 );
+
                return FlowHandlebars.prototype.html(
                        mw.message( str ).params( args ).parse()
                );
@@ -300,7 +303,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
@@ -323,7 +326,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/162117
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I972783d35056ac24b8a81bdc08a4cd99d36e0b76
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

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

Reply via email to