r106551 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106550‎ | r106551 | r106552 >
Date:02:59, 18 December 2011
Author:kaldari
Status:ok
Tags:
Comment:
follow-up to r106491 and r106496 - fixing for 1.19, moving embargo filter out of CLDR
Modified paths:
  • /trunk/extensions/cldr/CountryNames.body.php (modified) (history)
  • /trunk/extensions/cldr/LanguageNames.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/cldr/CountryNames.body.php
@@ -3,7 +3,8 @@
44 /**
55 * A class for querying translated country names from CLDR data.
66 *
7 - * @author Niklas Laxström, Ryan Kaldari
 7+ * @author Niklas Laxström
 8+ * @author Ryan Kaldari
89 * @copyright Copyright © 2007-2011
910 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1011 */
@@ -11,36 +12,35 @@
1213
1314 private static $cache = array();
1415
15 - const LIST_CLDR = 0; // Return all countries listed in CLDR
16 - const LIST_FUNDRAISING = 1; // Return only countries that are not embargoed
17 -
1816 /**
1917 * Get localized country names for a particular language, using fallback languages for missing
2018 * items.
2119 *
2220 * @param string $code The language to return the list in
2321 * @param int $fbMethod The fallback method
24 - * @param int $list Which type of list to return
2522 * @return an associative array of country codes and localized country names
2623 */
27 - public static function getNames( $code, $list = self::LIST_CLDR ) {
 24+ public static function getNames( $code ) {
2825 // Load country names localized for the requested language
2926 $names = self::loadLanguage( $code );
3027
3128 // Load missing country names from fallback languages
32 - $fallback = $code;
33 - while ( $fallback = Language::getFallbackFor( $fallback ) ) {
34 - // Overwrite the things in fallback with what we have already
35 - $names = array_merge( self::loadLanguage( $fallback ), $names );
 29+ if ( is_callable( array( 'Language', 'getFallbacksFor' ) ) ) {
 30+ // MediaWiki 1.19
 31+ $fallbacks = Language::getFallbacksFor( $code );
 32+ foreach ( $fallbacks as $fallback ) {
 33+ // Overwrite the things in fallback with what we have already
 34+ $names = array_merge( self::loadLanguage( $fallback ), $names );
 35+ }
 36+ } else {
 37+ // MediaWiki 1.18 or earlier
 38+ $fallback = $code;
 39+ while ( $fallback = Language::getFallbackFor( $fallback ) ) {
 40+ // Overwrite the things in fallback with what we have already
 41+ $names = array_merge( self::loadLanguage( $fallback ), $names );
 42+ }
3643 }
3744
38 - if ( $list == self::LIST_FUNDRAISING ) {
39 - // Remove embargoed countries
40 - unset( $names['CU'] ); // Cuba
41 - unset( $names['IR'] ); // Iran
42 - unset( $names['SY'] ); // Syria
43 - }
44 -
4545 return $names;
4646 }
4747
Index: trunk/extensions/cldr/LanguageNames.body.php
@@ -33,11 +33,23 @@
3434 if ( $fbMethod === self::FALLBACK_NATIVE ) {
3535 $names = array_merge( $native, $xx );
3636 } elseif ( $fbMethod === self::FALLBACK_NORMAL ) {
37 - $fallback = $code;
 37+
 38+ // Load missing language names from fallback languages
3839 $fb = $xx;
39 - while ( $fallback = Language::getFallbackFor( $fallback ) ) {
40 - /* Overwrite the things in fallback with what we have already */
41 - $fb = array_merge( self::loadLanguage( $fallback ), $fb );
 40+ if ( is_callable( array( 'Language', 'getFallbacksFor' ) ) ) {
 41+ // MediaWiki 1.19
 42+ $fallbacks = Language::getFallbacksFor( $code );
 43+ foreach ( $fallbacks as $fallback ) {
 44+ // Overwrite the things in fallback with what we have already
 45+ $fb = array_merge( self::loadLanguage( $fallback ), $fb );
 46+ }
 47+ } else {
 48+ // MediaWiki 1.18 or earlier
 49+ $fallback = $code;
 50+ while ( $fallback = Language::getFallbackFor( $fallback ) ) {
 51+ // Overwrite the things in fallback with what we have already
 52+ $fb = array_merge( self::loadLanguage( $fallback ), $fb );
 53+ }
4254 }
4355
4456 /* Add native names for codes that are not in cldr */

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106491beginning to build CountryNameskaldari01:08, 17 December 2011
r106496finished adding support for country lists, making backwards compatible with 1...kaldari02:02, 17 December 2011

Status & tagging log