* Optimise {{GENDER}} so that it doesn't need to load the user options if only one...
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 8 Feb 2012 06:09:58 +0000 (06:09 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 8 Feb 2012 06:09:58 +0000 (06:09 +0000)
* Updated Language::gender() documentation accordingly

includes/parser/CoreParserFunctions.php
languages/Language.php

index 3ba9f7d..f9ae237 100644 (file)
@@ -277,7 +277,14 @@ class CoreParserFunctions {
         */
        static function gender( $parser, $username ) {
                wfProfileIn( __METHOD__ );
-               $forms = array_slice( func_get_args(), 2);
+               $forms = array_slice( func_get_args(), 2 );
+
+               // Some shortcuts to avoid loading user data unnecessarily
+               if ( count( $forms ) === 0 ) {
+                       return '';
+               } elseif ( count( $forms ) === 1 ) {
+                       return $forms[0];
+               }
 
                $username = trim( $username );
 
index 8050407..bb9abf1 100644 (file)
@@ -3169,8 +3169,14 @@ class Language {
         * 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.
+        *
+        * If no forms are given, an empty string is returned. If only one form is
+        * given, it will be returned unconditionally. These details are implied by
+        * the caller and cannot be overridden in subclasses.
+        *
+        * If more than one form is given, the default is to use the neutral one
+        * if it is specified, and to use the masculine one otherwise. These
+        * details can be overridden in subclasses.
         *
         * @param $gender string
         * @param $forms array