From facf4dad527d3b1644e4dc702efaea65491e3886 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Thu, 8 Jul 2010 08:23:35 +0000 Subject: [PATCH] Avoid unstubbing in wfGetLangObj, code style --- includes/GlobalFunctions.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 62bed63742..314b37d3d8 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -528,28 +528,33 @@ function wfReadOnlyReason() { * functionality), or if it is true then use the wikis * @return Language object */ -function wfGetLangObj( $langcode = false ){ +function wfGetLangObj( $langcode = false ) { # Identify which language to get or create a language object for. - if( $langcode instanceof Language ) - # Great, we already have the object! + # Using is_object here due to Stub objects. + if( is_object( $langcode ) ) { + # Great, we already have the object (hopefully)! return $langcode; + } - global $wgContLang; - if( $langcode === $wgContLang->getCode() || $langcode === true ) + global $wgContLang, $wgLanguageCode; + if( $langcode === true || $langcode === $wgLanguageCode ) { # $langcode is the language code of the wikis content language object. # or it is a boolean and value is true return $wgContLang; + } global $wgLang; - if( $langcode === $wgLang->getCode() || $langcode === false ) + if( $langcode === false || $langcode === $wgLang->getCode() ) { # $langcode is the language code of user language object. # or it was a boolean and value is false return $wgLang; + } $validCodes = array_keys( Language::getLanguageNames() ); - if( in_array( $langcode, $validCodes ) ) + if( in_array( $langcode, $validCodes ) ) { # $langcode corresponds to a valid language. return Language::factory( $langcode ); + } # $langcode is a string, but not a valid language code; use content language. wfDebug( "Invalid language code passed to wfGetLangObj, falling back to content language.\n" ); -- 2.20.1