r110912 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110911‎ | r110912 | r110913 >
Date:06:09, 8 February 2012
Author:tstarling
Status:ok
Tags:
Comment:
* Optimise {{GENDER}} so that it doesn't need to load the user options if only one form is given. For some reason (presumably some detail of how translatewiki.net works) such {{GENDER}} invocations are extremely common.
* Updated Language::gender() documentation accordingly
Modified paths:
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -277,8 +277,15 @@
278278 */
279279 static function gender( $parser, $username ) {
280280 wfProfileIn( __METHOD__ );
281 - $forms = array_slice( func_get_args(), 2);
 281+ $forms = array_slice( func_get_args(), 2 );
282282
 283+ // Some shortcuts to avoid loading user data unnecessarily
 284+ if ( count( $forms ) === 0 ) {
 285+ return '';
 286+ } elseif ( count( $forms ) === 1 ) {
 287+ return $forms[0];
 288+ }
 289+
283290 $username = trim( $username );
284291
285292 // default
Index: trunk/phase3/languages/Language.php
@@ -3169,9 +3169,15 @@
31703170 * Usage {{gender:username|masculine|feminine|neutral}}.
31713171 * username is optional, in which case the gender of current user is used,
31723172 * but only in (some) interface messages; otherwise default gender is used.
3173 - * If second or third parameter are not specified, masculine is used.
3174 - * These details may be overriden per language.
31753173 *
 3174+ * If no forms are given, an empty string is returned. If only one form is
 3175+ * given, it will be returned unconditionally. These details are implied by
 3176+ * the caller and cannot be overridden in subclasses.
 3177+ *
 3178+ * If more than one form is given, the default is to use the neutral one
 3179+ * if it is specified, and to use the masculine one otherwise. These
 3180+ * details can be overridden in subclasses.
 3181+ *
31763182 * @param $gender string
31773183 * @param $forms array
31783184 *

Sign-offs

UserFlagDate
Santhosh.thottingalinspected06:16, 8 February 2012
Nikerabbitinspected21:22, 8 February 2012

Status & tagging log