X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=languages%2FLanguage.php;h=ea34363b4f85f722d99f9a811680cb1925d4dc71;hb=0073be25d95541c8cd9ec53de6d4551bad9b62ca;hp=2fd4bb75d024460fe6b1a962fa25fb70a927d2a9;hpb=9cc02e7087755d2ba29d556da07a0ab367aab7af;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/Language.php b/languages/Language.php index 2fd4bb75d0..ea34363b4f 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -32,7 +32,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { # Read language names global $wgLanguageNames; -require_once( __DIR__ . '/Names.php' ); +require_once __DIR__ . '/Names.php'; if ( function_exists( 'mb_strtoupper' ) ) { mb_internal_encoding( 'UTF-8' ); @@ -170,6 +170,14 @@ class Language { 'seconds' => 1, ); + /** + * Cache for language fallbacks. + * @see Language::getFallbacksIncludingSiteLanguage + * @since 1.21 + * @var array + */ + static private $fallbackLanguageCache = array(); + /** * Get a cached or new language object for a given language code * @param $code String @@ -378,7 +386,7 @@ class Language { static $coreLanguageNames; if ( $coreLanguageNames === null ) { - include( MWInit::compiledPath( 'languages/Names.php' ) ); + include MWInit::compiledPath( 'languages/Names.php' ); } if ( isset( $coreLanguageNames[$tag] ) @@ -414,10 +422,8 @@ class Language { return; } - if ( !defined( 'MW_COMPILED' ) ) { - if ( file_exists( "$IP/languages/classes/$class.php" ) ) { - include_once( "$IP/languages/classes/$class.php" ); - } + if ( file_exists( "$IP/languages/classes/$class.php" ) ) { + include_once "$IP/languages/classes/$class.php"; } } @@ -851,7 +857,7 @@ class Language { static $coreLanguageNames; if ( $coreLanguageNames === null ) { - include( MWInit::compiledPath( 'languages/Names.php' ) ); + include MWInit::compiledPath( 'languages/Names.php' ); } $names = array(); @@ -3599,10 +3605,6 @@ class Language { * @return string Correct form of plural for $count in this language */ function convertPlural( $count, $forms ) { - if ( !count( $forms ) ) { - return ''; - } - // Handle explicit n=pluralform cases foreach ( $forms as $index => $form ) { if ( preg_match( '/\d+=/i', $form ) ) { @@ -3613,7 +3615,11 @@ class Language { unset( $forms[$index] ); } } + $forms = array_values( $forms ); + if ( !count( $forms ) ) { + return ''; + } $pluralForm = $this->getPluralRuleIndexNumber( $count ); $pluralForm = min( $pluralForm, count( $forms ) - 1 ); @@ -4055,6 +4061,36 @@ class Language { } } + /** + * Get the ordered list of fallback languages, ending with the fallback + * language chain for the site language. + * + * @since 1.22 + * @param string $code Language code + * @return array array( fallbacks, site fallbacks ) + */ + public static function getFallbacksIncludingSiteLanguage( $code ) { + global $wgLanguageCode; + + // Usually, we will only store a tiny number of fallback chains, so we + // keep them in static memory. + $cacheKey = "{$code}-{$wgLanguageCode}"; + + if ( !array_key_exists( $cacheKey, self::$fallbackLanguageCache ) ) { + $fallbacks = self::getFallbacksFor( $code ); + + // Append the site's fallback chain, including the site language itself + $siteFallbacks = self::getFallbacksFor( $wgLanguageCode ); + array_unshift( $siteFallbacks, $wgLanguageCode ); + + // Eliminate any languages already included in the chain + $siteFallbacks = array_diff( $siteFallbacks, $fallbacks ); + + self::$fallbackLanguageCache[$cacheKey] = array( $fallbacks, $siteFallbacks ); + } + return self::$fallbackLanguageCache[$cacheKey]; + } + /** * Get all messages for a given language * WARNING: this may take a long time. If you just need all message *keys*