* (bug 13040) {{GENDER:}} magic word for interface messages
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 26 Jan 2009 09:48:17 +0000 (09:48 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 26 Jan 2009 09:48:17 +0000 (09:48 +0000)
RELEASE-NOTES
includes/DefaultSettings.php
includes/parser/CoreParserFunctions.php
languages/Language.php

index 9eef071..1524277 100644 (file)
@@ -63,6 +63,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 17145) Specific categories can be excluded from Special:UnusedCategories
   with __IGNOREUNUSED__
 * (bug 13040) Gender switch in user preferences
+* (bug 13040) {{GENDER:}} magic word for interface messages
 
 === Bug fixes in 1.15 ===
 * (bug 16968) Special:Upload no longer throws useless warnings.
index 3119e4b..2566a4e 100644 (file)
@@ -2430,6 +2430,7 @@ $wgDefaultUserOptions = array(
        'watchmoves'              => 0,
        'watchdeletion'           => 0,
        'noconvertlink'           => 0,
+       'gender'                  => 'unknown',
 );
 
 /** Whether or not to allow and use real name fields. Defaults to true. */
index 35d7de8..8e7914d 100644 (file)
@@ -27,6 +27,7 @@ class CoreParserFunctions {
                $parser->setFunctionHook( 'fullurle',         array( __CLASS__, 'fullurle'         ), SFH_NO_HASH );
                $parser->setFunctionHook( 'formatnum',        array( __CLASS__, 'formatnum'        ), SFH_NO_HASH );
                $parser->setFunctionHook( 'grammar',          array( __CLASS__, 'grammar'          ), SFH_NO_HASH );
+               $parser->setFunctionHook( 'gender',           array( __CLASS__, 'gender'           ), SFH_NO_HASH );
                $parser->setFunctionHook( 'plural',           array( __CLASS__, 'plural'           ), SFH_NO_HASH );
                $parser->setFunctionHook( 'numberofpages',    array( __CLASS__, 'numberofpages'    ), SFH_NO_HASH );
                $parser->setFunctionHook( 'numberofusers',    array( __CLASS__, 'numberofusers'    ), SFH_NO_HASH );
@@ -155,6 +156,22 @@ class CoreParserFunctions {
                return $parser->getFunctionLang()->convertGrammar( $word, $case );
        }
 
+       static function gender( $parser, $user ) {
+               $forms = array_slice( func_get_args(), 2);
+
+               // default
+               $gender = User::getDefaultOption( 'gender' );
+
+               // check parameter, or use $wgUser if in interface message
+               $user = User::newFromName( $user );
+               if ( $user ) {
+                       $gender = $user->getOption( 'gender' );
+               } elseif ( $parser->mOptions->getInterfaceMessage() ) {
+                       global $wgUser;
+                       $gender = $wgUser->getOption( 'gender' );
+               }
+               return $parser->getFunctionLang()->gender( $gender, $forms );
+       }
        static function plural( $parser, $text = '') {
                $forms = array_slice( func_get_args(), 2);
                $text = $parser->getFunctionLang()->parseFormattedNumber( $text );
index 6502aa0..3acc4ec 100644 (file)
@@ -2064,6 +2064,21 @@ class Language {
                return $word;
        }
 
+       /**
+        * Provides an alternative text depending on specified gender.
+        * Usage {{gender:username|masculine|feminine|neutral}}.
+        * username is optional, in which case the gender of current user is used,
+        * but only in (some) interface messages; otherwise default gender is used.
+        * If second or third parameter are not specified, masculine is used.
+        * These details may be overriden per language.
+        */
+       function gender( $gender, $forms ) {
+               $forms = $this->preConvertPlural( $forms, 2 );
+               if ( $gender === 'male' ) return $forms[0];
+               if ( $gender === 'female' ) return $forms[1];
+               return isset($forms[2]) ? $forms[2] : $forms[0];
+       }
+
        /**
         * Plural form transformations, needed for some languages.
         * For example, there are 3 form of plural in Russian and Polish,