r111451 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111450‎ | r111451 | r111452 >
Date:09:17, 14 February 2012
Author:tstarling
Status:ok
Tags:i18nreview 
Comment:
* Fixed an exception generated with {{#language:<nowiki>xx</nowiki>}} due to CldrNames::getOverrideFileName() being called outside of the Language::isValidBuiltInCode() guard. Observed on Commons.
* Unindented and simplified slightly, for readability
Modified paths:
  • /trunk/extensions/cldr/LanguageNames.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/cldr/LanguageNames.body.php
@@ -83,39 +83,47 @@
8484 * @return an associative array of language codes and localized language names
8585 */
8686 private static function loadLanguage( $code ) {
87 - if ( !isset( self::$cache[$code] ) ) {
88 - wfProfileIn( __METHOD__ . '-recache' );
 87+ if ( isset( self::$cache[$code] ) ) {
 88+ return self::$cache[$code];
 89+ }
8990
90 - /* Load override for wrong or missing entries in cldr */
91 - $override = dirname( __FILE__ ) . '/LocalNames/' . self::getOverrideFileName( $code );
92 - if ( Language::isValidBuiltInCode( $code ) && file_exists( $override ) ) {
93 - $languageNames = false;
94 - require( $override );
95 - if ( is_array( $languageNames ) ) {
96 - self::$cache[$code] = $languageNames;
97 - }
 91+ self::$cache[$code] = array();
 92+
 93+ if ( !Language::isValidBuiltInCode( $code ) ) {
 94+ return array();
 95+ }
 96+
 97+ wfProfileIn( __METHOD__ . '-recache' );
 98+
 99+ /* Load override for wrong or missing entries in cldr */
 100+ $override = dirname( __FILE__ ) . '/LocalNames/' . self::getOverrideFileName( $code );
 101+ if ( file_exists( $override ) ) {
 102+ $languageNames = false;
 103+ require( $override );
 104+ if ( is_array( $languageNames ) ) {
 105+ self::$cache[$code] = $languageNames;
98106 }
 107+ }
99108
100 - $filename = dirname( __FILE__ ) . '/CldrNames/' . self::getFileName( $code );
101 - if ( Language::isValidBuiltInCode( $code ) && file_exists( $filename ) ) {
102 - $languageNames = false;
103 - require( $filename );
104 - if ( is_array( $languageNames ) ) {
105 - if ( isset( self::$cache[$code] ) ) {
106 - // Add to existing list of localized language names
107 - self::$cache[$code] = self::$cache[$code] + $languageNames;
108 - } else {
109 - // No list exists, so create it
110 - self::$cache[$code] = $languageNames;
111 - }
 109+ $filename = dirname( __FILE__ ) . '/CldrNames/' . self::getFileName( $code );
 110+ if ( file_exists( $filename ) ) {
 111+ $languageNames = false;
 112+ require( $filename );
 113+ if ( is_array( $languageNames ) ) {
 114+ if ( isset( self::$cache[$code] ) ) {
 115+ // Add to existing list of localized language names
 116+ self::$cache[$code] = self::$cache[$code] + $languageNames;
 117+ } else {
 118+ // No list exists, so create it
 119+ self::$cache[$code] = $languageNames;
112120 }
113 - } else {
114 - wfDebug( __METHOD__ . ": Unable to load language names for $filename\n" );
115121 }
116 - wfProfileOut( __METHOD__ . '-recache' );
 122+ } else {
 123+ wfDebug( __METHOD__ . ": Unable to load language names for $filename\n" );
117124 }
 125+ wfProfileOut( __METHOD__ . '-recache' );
118126
119 - return isset( self::$cache[$code] ) ? self::$cache[$code] : array();
 127+ return self::$cache[$code];
120128 }
121129
122130 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r111452Fix exception like in trunk r111349, simplified for easier mergingtstarling09:25, 14 February 2012
r111453Merged r111452 from 1.19, equivalent to trunk r111451tstarling09:27, 14 February 2012
r111454Merged r111452 from 1.19tstarling09:35, 14 February 2012

Status & tagging log