From 8cae5ee72d2a187016692b16581298607d82de9b Mon Sep 17 00:00:00 2001 From: Robin Pepermans Date: Sun, 18 Dec 2011 12:17:12 +0000 Subject: [PATCH] Make the output consistent when no second parameter is given and second parameter equals first parameter. This gives preference to names defined in MediaWiki, but when it is not in MediaWiki, it also sees whether there is one defined in the translated language names. --- includes/parser/CoreParserFunctions.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index cd5e0a5665..25278e9788 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -604,21 +604,28 @@ class CoreParserFunctions { * Gives language names. * @param $parser Parser * @param $code String Language code - * @param $language String Language code + * @param $inLanguage String Language code * @return String */ - static function language( $parser, $code = '', $language = '' ) { - global $wgContLang; + static function language( $parser, $code = '', $inLanguage = '' ) { $code = strtolower( $code ); - $language = strtolower( $language ); + $inLanguage = strtolower( $inLanguage ); - if ( $language !== '' ) { - $names = Language::getTranslatedLanguageNames( $language ); - return isset( $names[$code] ) ? $names[$code] : wfBCP47( $code ); + if( $inLanguage === $code || $inLanguage === '' ) { + # Make sure the output is the same when the second parameter + # is the same language + global $wgContLang; + $name = $wgContLang->getLanguageName( $code ); + if( $name !== '' ) { + return $name; + } else { + # Try if there is a language name below + $inLanguage = $code; + } } - $lang = $wgContLang->getLanguageName( $code ); - return $lang !== '' ? $lang : wfBCP47( $code ); + $names = Language::getTranslatedLanguageNames( $inLanguage ); + return isset( $names[$code] ) ? $names[$code] : wfBCP47( $code ); } /** -- 2.20.1