r106559 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106558‎ | r106559 | r106560 >
Date:12:17, 18 December 2011
Author:robin
Status:reverted (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -604,21 +604,28 @@
605605 * Gives language names.
606606 * @param $parser Parser
607607 * @param $code String Language code
608 - * @param $language String Language code
 608+ * @param $inLanguage String Language code
609609 * @return String
610610 */
611 - static function language( $parser, $code = '', $language = '' ) {
612 - global $wgContLang;
 611+ static function language( $parser, $code = '', $inLanguage = '' ) {
613612 $code = strtolower( $code );
614 - $language = strtolower( $language );
 613+ $inLanguage = strtolower( $inLanguage );
615614
616 - if ( $language !== '' ) {
617 - $names = Language::getTranslatedLanguageNames( $language );
618 - return isset( $names[$code] ) ? $names[$code] : wfBCP47( $code );
 615+ if( $inLanguage === $code || $inLanguage === '' ) {
 616+ # Make sure the output is the same when the second parameter
 617+ # is the same language
 618+ global $wgContLang;
 619+ $name = $wgContLang->getLanguageName( $code );
 620+ if( $name !== '' ) {
 621+ return $name;
 622+ } else {
 623+ # Try if there is a language name below
 624+ $inLanguage = $code;
 625+ }
619626 }
620627
621 - $lang = $wgContLang->getLanguageName( $code );
622 - return $lang !== '' ? $lang : wfBCP47( $code );
 628+ $names = Language::getTranslatedLanguageNames( $inLanguage );
 629+ return isset( $names[$code] ) ? $names[$code] : wfBCP47( $code );
623630 }
624631
625632 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r106573Follow-up r106559: it's better to set the preference for own MediaWiki names ...robin17:58, 18 December 2011
r106864Provisional revert r106573, r106559: may be the wrong thing to do, and should...brion21:24, 20 December 2011

Comments

#Comment by SPQRobin (talk | contribs)   12:22, 18 December 2011

Examples:

  • {{#language:nl-be}} gave "nl-be", {{#language:nl-be|nl-be}} gave "Vlaams" with CLDR enabled
  • When "nl-be" was added in MediaWiki through wgExtraLanguageNames, {{#language:nl-be}} was that value, but {{#language:nl-be|nl-be}} was still the CLDR value

With this change, both are the MediaWiki value (including wgExtraLanguageNames), and fall back to the CLDR when not in MediaWiki

#Comment by Brion VIBBER (talk | contribs)   21:16, 20 December 2011

This is screaming for a unit test / regression test.

#Comment by Brion VIBBER (talk | contribs)   21:24, 20 December 2011

Reverted for now in r106864.

Status & tagging log