r46247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46246‎ | r46247 | r46248 >
Date:09:48, 26 January 2009
Author:nikerabbit
Status:ok (Comments)
Tags:
Comment:
* (bug 13040) {{GENDER:}} magic word for interface messages
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -27,6 +27,7 @@
2828 $parser->setFunctionHook( 'fullurle', array( __CLASS__, 'fullurle' ), SFH_NO_HASH );
2929 $parser->setFunctionHook( 'formatnum', array( __CLASS__, 'formatnum' ), SFH_NO_HASH );
3030 $parser->setFunctionHook( 'grammar', array( __CLASS__, 'grammar' ), SFH_NO_HASH );
 31+ $parser->setFunctionHook( 'gender', array( __CLASS__, 'gender' ), SFH_NO_HASH );
3132 $parser->setFunctionHook( 'plural', array( __CLASS__, 'plural' ), SFH_NO_HASH );
3233 $parser->setFunctionHook( 'numberofpages', array( __CLASS__, 'numberofpages' ), SFH_NO_HASH );
3334 $parser->setFunctionHook( 'numberofusers', array( __CLASS__, 'numberofusers' ), SFH_NO_HASH );
@@ -155,6 +156,22 @@
156157 return $parser->getFunctionLang()->convertGrammar( $word, $case );
157158 }
158159
 160+ static function gender( $parser, $user ) {
 161+ $forms = array_slice( func_get_args(), 2);
 162+
 163+ // default
 164+ $gender = User::getDefaultOption( 'gender' );
 165+
 166+ // check parameter, or use $wgUser if in interface message
 167+ $user = User::newFromName( $user );
 168+ if ( $user ) {
 169+ $gender = $user->getOption( 'gender' );
 170+ } elseif ( $parser->mOptions->getInterfaceMessage() ) {
 171+ global $wgUser;
 172+ $gender = $wgUser->getOption( 'gender' );
 173+ }
 174+ return $parser->getFunctionLang()->gender( $gender, $forms );
 175+ }
159176 static function plural( $parser, $text = '') {
160177 $forms = array_slice( func_get_args(), 2);
161178 $text = $parser->getFunctionLang()->parseFormattedNumber( $text );
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2430,6 +2430,7 @@
24312431 'watchmoves' => 0,
24322432 'watchdeletion' => 0,
24332433 'noconvertlink' => 0,
 2434+ 'gender' => 'unknown',
24342435 );
24352436
24362437 /** Whether or not to allow and use real name fields. Defaults to true. */
Index: trunk/phase3/languages/Language.php
@@ -2065,6 +2065,21 @@
20662066 }
20672067
20682068 /**
 2069+ * Provides an alternative text depending on specified gender.
 2070+ * Usage {{gender:username|masculine|feminine|neutral}}.
 2071+ * username is optional, in which case the gender of current user is used,
 2072+ * but only in (some) interface messages; otherwise default gender is used.
 2073+ * If second or third parameter are not specified, masculine is used.
 2074+ * These details may be overriden per language.
 2075+ */
 2076+ function gender( $gender, $forms ) {
 2077+ $forms = $this->preConvertPlural( $forms, 2 );
 2078+ if ( $gender === 'male' ) return $forms[0];
 2079+ if ( $gender === 'female' ) return $forms[1];
 2080+ return isset($forms[2]) ? $forms[2] : $forms[0];
 2081+ }
 2082+
 2083+ /**
20692084 * Plural form transformations, needed for some languages.
20702085 * For example, there are 3 form of plural in Russian and Polish,
20712086 * depending on "count mod 10". See [[w:Plural]]
Index: trunk/phase3/RELEASE-NOTES
@@ -63,6 +63,7 @@
6464 * (bug 17145) Specific categories can be excluded from Special:UnusedCategories
6565 with __IGNOREUNUSED__
6666 * (bug 13040) Gender switch in user preferences
 67+* (bug 13040) {{GENDER:}} magic word for interface messages
6768
6869 === Bug fixes in 1.15 ===
6970 * (bug 16968) Special:Upload no longer throws useless warnings.

Sign-offs

UserFlagDate
Claupopokainspected07:42, 8 September 2012
Claupopokatested07:42, 8 September 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r47196* (bug 13040) Gender-aware user namespace aliases...nikerabbit19:54, 12 February 2009
r47391Revert r47196, r47219 "* (bug 13040) Gender-aware user namespace aliases" and...brion23:00, 17 February 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r46246* (bug 13040) Gender switch in user preferencesnikerabbit09:41, 26 January 2009

Comments

#Comment by Siebrand (talk | contribs)   00:01, 27 January 2009

Notice in gender() fixed in r46249

Status & tagging log