From: Tim Starling Date: Wed, 8 Feb 2012 06:09:58 +0000 (+0000) Subject: * Optimise {{GENDER}} so that it doesn't need to load the user options if only one... X-Git-Tag: 1.31.0-rc.0~24878 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_del%27%2C%20idvote=vote.voteid%29%20%7D%7D?a=commitdiff_plain;h=a444986c453762e6aaf7c229de7088eb888adb6c;p=lhc%2Fweb%2Fwiklou.git * 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 --- diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 3ba9f7d471..f9ae237983 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -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 ); diff --git a/languages/Language.php b/languages/Language.php index 8050407935..bb9abf16a8 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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