r107824 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107823‎ | r107824 | r107825 >
Date:12:21, 2 January 2012
Author:santhosh
Status:ok (Comments)
Tags:
Comment:
Parser can take mw.user too along with male, female for {{gender:$1|..}}
If the parameter passed is mw.user, use the gender from mw.user.options. If not, use the passed gender.
Update the qunit tests.
Update the documentation.
Followup r107811
Modified paths:
  • /trunk/phase3/resources/mediawiki.language/mediawiki.language.js (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.jqueryMsg.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
@@ -17,13 +17,18 @@
1818
1919
2020 test( 'mw.jqueryMsg Gender', function() {
21 - expect( 14 );
 21+ expect( 16 );
2222 //TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
 23+ var user = mw.user;
 24+ user.options.set( 'gender', 'male' );
2325 var parser = mw.jqueryMsg.getMessageFunction();
2426 ok( parser, 'Parser Function initialized' );
2527 //TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
2628 ok( mw.messages.set( 'gender-msg', '$1 reverted {{GENDER:$2|his|her|their}} last edit' ), 'mw.messages.set: Register' );
2729 equal( parser( 'gender-msg', 'Bob', 'male' ) , 'Bob reverted his last edit', 'Gender masculine' );
 30+ equal( parser( 'gender-msg', 'Bob', user ) , 'Bob reverted his last edit', 'Gender masculine' );
 31+ user.options.set( 'gender', 'unknown' );
 32+ equal( parser( 'gender-msg', 'They', user ) , 'They reverted their last edit', 'Gender masculine' );
2833 equal( parser( 'gender-msg', 'Alice', 'female' ) , 'Alice reverted her last edit', 'Gender feminine' );
2934 equal( parser( 'gender-msg', 'User' ) , 'User reverted their last edit', 'Gender neutral' );
3035 equal( parser( 'gender-msg', 'User', 'unknown' ) , 'User reverted their last edit', 'Gender neutral' );
Index: trunk/phase3/resources/mediawiki/mediawiki.jqueryMsg.js
@@ -635,11 +635,17 @@
636636
637637 /**
638638 * Transform parsed structure into gender
639 - * @param {Array} of nodes, [ {String}, {String}, {String} ... ]
 639+ * Usage {{gender:[gender| mw.user object ] | masculine|feminine|neutral}}.
 640+ * @param {Array} of nodes, [ {String|mw.User}, {String}, {String} , {String} ]
640641 * @return {String} selected gender form according to current language
641642 */
642643 gender: function( nodes ) {
643 - var gender = nodes[0];
 644+ var gender;
 645+ if ( nodes[0] && nodes[0].options instanceof mw.Map ){
 646+ gender = nodes[0].options.get( 'gender' )
 647+ } else {
 648+ gender = nodes[0];
 649+ }
644650 var forms = nodes.slice(1);
645651 return this.language.gender( gender, forms );
646652 }
Index: trunk/phase3/resources/mediawiki.language/mediawiki.language.js
@@ -98,12 +98,12 @@
9999 },
100100 /**
101101 * Provides an alternative text depending on specified gender.
102 - * Usage {{gender:username|masculine|feminine|neutral}}.
 102+ * Usage {{gender:[gender|user object]|masculine|feminine|neutral}}.
103103 * If second or third parameter are not specified, masculine is used.
104104 *
105105 * These details may be overriden per language.
106106 *
107 - * @param gender string
 107+ * @param gender string male, female, or anything else for neutral.
108108 * @param forms array List of gender forms
109109 *
110110 * @return string

Follow-up revisions

RevisionCommit summaryAuthorDate
r108195Correction in the test comment, followup r107824santhosh06:56, 6 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107811Make mw.jqueryMsg understand gender....santhosh09:44, 2 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   13:34, 2 January 2012
+	equal( parser( 'gender-msg', 'They', user ) , 'They reverted their last edit', 'Gender masculine' );

This should probably say neutral or unknown denger.

Status & tagging log