X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguage.php;h=a8950f5a138caf6e85d341ba0751e10b5bc98979;hb=29c25bb31c4b558a245f1b0c80a934b8b949ca55;hp=dd5c63265f80a7dc5e602a52c77aad85f10bc017;hpb=369c60f133a5ea36c2a96ee1a276ee43e40c7194;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/Language.php b/languages/Language.php index dd5c63265f..a8950f5a13 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -55,13 +55,15 @@ class Language { const SUPPORTED = 'mwfile'; /** - * @var LanguageConverter + * @var LanguageConverter|FakeConverter */ public $mConverter; public $mVariants, $mCode, $mLoaded = false; public $mMagicExtensions = []; - private $mHtmlCode = null, $mParentLanguage = false; + private $mHtmlCode = null; + /** @var Language|false */ + private $mParentLanguage = false; public $dateFormatStrings = []; public $mExtendedSpecialPageAliases; @@ -75,10 +77,8 @@ class Language { */ public $transformData = []; - /** - * @var LocalisationCache - */ - public static $dataCache; + /** @var LocalisationCache */ + private $localisationCache; public static $mLangObjCache = []; @@ -283,12 +283,12 @@ class Language { * @since 1.32 */ public static function clearCaches() { - if ( !defined( 'MW_PHPUNIT_TEST' ) ) { - throw new MWException( __METHOD__ . ' must not be used outside tests' ); + if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MEDIAWIKI_INSTALL' ) ) { + throw new MWException( __METHOD__ . ' must not be used outside tests/installer' ); + } + if ( defined( 'MW_PHPUNIT_TEST' ) ) { + MediaWikiServices::getInstance()->resetServiceForTesting( 'LocalisationCache' ); } - self::$dataCache = null; - // Reinitialize $dataCache, since it's expected to always be available - self::getLocalisationCache(); self::$mLangObjCache = []; self::$fallbackLanguageCache = []; self::$grammarTransformations = null; @@ -443,15 +443,11 @@ class Language { /** * Get the LocalisationCache instance * + * @deprecated since 1.34, use MediaWikiServices * @return LocalisationCache */ public static function getLocalisationCache() { - if ( is_null( self::$dataCache ) ) { - global $wgLocalisationCacheConf; - $class = $wgLocalisationCacheConf['class']; - self::$dataCache = new $class( $wgLocalisationCacheConf ); - } - return self::$dataCache; + return MediaWikiServices::getInstance()->getLocalisationCache(); } function __construct() { @@ -462,7 +458,7 @@ class Language { } else { $this->mCode = str_replace( '_', '-', strtolower( substr( static::class, 8 ) ) ); } - self::getLocalisationCache(); + $this->localisationCache = MediaWikiServices::getInstance()->getLocalisationCache(); } /** @@ -495,7 +491,7 @@ class Language { * @return array */ public function getBookstoreList() { - return self::$dataCache->getItem( $this->mCode, 'bookstoreList' ); + return $this->localisationCache->getItem( $this->mCode, 'bookstoreList' ); } /** @@ -512,7 +508,7 @@ class Language { getCanonicalNamespaces(); $this->namespaceNames = $wgExtraNamespaces + - self::$dataCache->getItem( $this->mCode, 'namespaceNames' ); + $this->localisationCache->getItem( $this->mCode, 'namespaceNames' ); $this->namespaceNames += $validNamespaces; $this->namespaceNames[NS_PROJECT] = $wgMetaNamespace; @@ -619,7 +615,7 @@ class Language { global $wgExtraGenderNamespaces; $ns = $wgExtraGenderNamespaces + - (array)self::$dataCache->getItem( $this->mCode, 'namespaceGenderAliases' ); + (array)$this->localisationCache->getItem( $this->mCode, 'namespaceGenderAliases' ); return $ns[$index][$gender] ?? $this->getNsText( $index ); } @@ -641,7 +637,7 @@ class Language { return false; } else { // Check what is in i18n files - $aliases = self::$dataCache->getItem( $this->mCode, 'namespaceGenderAliases' ); + $aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceGenderAliases' ); return count( $aliases ) > 0; } } @@ -665,7 +661,7 @@ class Language { */ public function getNamespaceAliases() { if ( is_null( $this->namespaceAliases ) ) { - $aliases = self::$dataCache->getItem( $this->mCode, 'namespaceAliases' ); + $aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceAliases' ); if ( !$aliases ) { $aliases = []; } else { @@ -679,8 +675,8 @@ class Language { } global $wgExtraGenderNamespaces; - $genders = $wgExtraGenderNamespaces + - (array)self::$dataCache->getItem( $this->mCode, 'namespaceGenderAliases' ); + $genders = $wgExtraGenderNamespaces + (array)$this->localisationCache + ->getItem( $this->mCode, 'namespaceGenderAliases' ); foreach ( $genders as $index => $forms ) { foreach ( $forms as $alias ) { $aliases[$alias] = $index; @@ -781,21 +777,21 @@ class Language { * @return string[]|bool List of date format preference keys, or false if disabled. */ public function getDatePreferences() { - return self::$dataCache->getItem( $this->mCode, 'datePreferences' ); + return $this->localisationCache->getItem( $this->mCode, 'datePreferences' ); } /** * @return array */ function getDateFormats() { - return self::$dataCache->getItem( $this->mCode, 'dateFormats' ); + return $this->localisationCache->getItem( $this->mCode, 'dateFormats' ); } /** * @return array|string */ public function getDefaultDateFormat() { - $df = self::$dataCache->getItem( $this->mCode, 'defaultDateFormat' ); + $df = $this->localisationCache->getItem( $this->mCode, 'defaultDateFormat' ); if ( $df === 'dmy or mdy' ) { global $wgAmericanDates; return $wgAmericanDates ? 'mdy' : 'dmy'; @@ -808,7 +804,7 @@ class Language { * @return array */ public function getDatePreferenceMigrationMap() { - return self::$dataCache->getItem( $this->mCode, 'datePreferenceMigrationMap' ); + return $this->localisationCache->getItem( $this->mCode, 'datePreferenceMigrationMap' ); } /** @@ -2275,7 +2271,8 @@ class Language { } if ( !isset( $this->dateFormatStrings[$type][$pref] ) ) { - $df = self::$dataCache->getSubitem( $this->mCode, 'dateFormats', "$pref $type" ); + $df = + $this->localisationCache->getSubitem( $this->mCode, 'dateFormats', "$pref $type" ); if ( $type === 'pretty' && $df === null ) { $df = $this->getDateFormatString( 'date', $pref ); @@ -2283,7 +2280,8 @@ class Language { if ( !$wasDefault && $df === null ) { $pref = $this->getDefaultDateFormat(); - $df = self::$dataCache->getSubitem( $this->mCode, 'dateFormats', "$pref $type" ); + $df = $this->getLocalisationCache() + ->getSubitem( $this->mCode, 'dateFormats', "$pref $type" ); } $this->dateFormatStrings[$type][$pref] = $df; @@ -2647,14 +2645,14 @@ class Language { * @return string|null */ public function getMessage( $key ) { - return self::$dataCache->getSubitem( $this->mCode, 'messages', $key ); + return $this->localisationCache->getSubitem( $this->mCode, 'messages', $key ); } /** * @return array */ function getAllMessages() { - return self::$dataCache->getItem( $this->mCode, 'messages' ); + return $this->localisationCache->getItem( $this->mCode, 'messages' ); } /** @@ -2896,7 +2894,7 @@ class Language { * @return string */ function fallback8bitEncoding() { - return self::$dataCache->getItem( $this->mCode, 'fallback8bitEncoding' ); + return $this->localisationCache->getItem( $this->mCode, 'fallback8bitEncoding' ); } /** @@ -3086,7 +3084,7 @@ class Language { * @return bool */ function isRTL() { - return self::$dataCache->getItem( $this->mCode, 'rtl' ); + return $this->localisationCache->getItem( $this->mCode, 'rtl' ); } /** @@ -3162,7 +3160,7 @@ class Language { * @return array */ function capitalizeAllNouns() { - return self::$dataCache->getItem( $this->mCode, 'capitalizeAllNouns' ); + return $this->localisationCache->getItem( $this->mCode, 'capitalizeAllNouns' ); } /** @@ -3195,7 +3193,7 @@ class Language { * @return bool */ function linkPrefixExtension() { - return self::$dataCache->getItem( $this->mCode, 'linkPrefixExtension' ); + return $this->localisationCache->getItem( $this->mCode, 'linkPrefixExtension' ); } /** @@ -3203,7 +3201,7 @@ class Language { * @return array */ function getMagicWords() { - return self::$dataCache->getItem( $this->mCode, 'magicWords' ); + return $this->localisationCache->getItem( $this->mCode, 'magicWords' ); } /** @@ -3213,7 +3211,7 @@ class Language { */ function getMagic( $mw ) { $rawEntry = $this->mMagicExtensions[$mw->mId] ?? - self::$dataCache->getSubitem( $this->mCode, 'magicWords', $mw->mId ); + $this->localisationCache->getSubitem( $this->mCode, 'magicWords', $mw->mId ); if ( !is_array( $rawEntry ) ) { wfWarn( "\"$rawEntry\" is not a valid magic word for \"$mw->mId\"" ); @@ -3248,7 +3246,7 @@ class Language { if ( is_null( $this->mExtendedSpecialPageAliases ) ) { // Initialise array $this->mExtendedSpecialPageAliases = - self::$dataCache->getItem( $this->mCode, 'specialPageAliases' ); + $this->localisationCache->getItem( $this->mCode, 'specialPageAliases' ); } return $this->mExtendedSpecialPageAliases; @@ -3413,28 +3411,28 @@ class Language { * @return string */ function digitGroupingPattern() { - return self::$dataCache->getItem( $this->mCode, 'digitGroupingPattern' ); + return $this->localisationCache->getItem( $this->mCode, 'digitGroupingPattern' ); } /** * @return array */ function digitTransformTable() { - return self::$dataCache->getItem( $this->mCode, 'digitTransformTable' ); + return $this->localisationCache->getItem( $this->mCode, 'digitTransformTable' ); } /** * @return array */ function separatorTransformTable() { - return self::$dataCache->getItem( $this->mCode, 'separatorTransformTable' ); + return $this->localisationCache->getItem( $this->mCode, 'separatorTransformTable' ); } /** * @return int|null */ function minimumGroupingDigits() { - return self::$dataCache->getItem( $this->mCode, 'minimumGroupingDigits' ); + return $this->localisationCache->getItem( $this->mCode, 'minimumGroupingDigits' ); } /** @@ -4334,7 +4332,7 @@ class Language { * @return string */ public function linkTrail() { - return self::$dataCache->getItem( $this->mCode, 'linkTrail' ); + return $this->localisationCache->getItem( $this->mCode, 'linkTrail' ); } /** @@ -4344,7 +4342,7 @@ class Language { * @return string */ public function linkPrefixCharset() { - return self::$dataCache->getItem( $this->mCode, 'linkPrefixCharset' ); + return $this->localisationCache->getItem( $this->mCode, 'linkPrefixCharset' ); } /** @@ -4934,11 +4932,13 @@ class Language { * @return array Associative array with plural form, and plural rule as key-value pairs */ public function getCompiledPluralRules() { - $pluralRules = self::$dataCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' ); + $pluralRules = + $this->localisationCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' ); $fallbacks = self::getFallbacksFor( $this->mCode ); if ( !$pluralRules ) { foreach ( $fallbacks as $fallbackCode ) { - $pluralRules = self::$dataCache->getItem( strtolower( $fallbackCode ), 'compiledPluralRules' ); + $pluralRules = $this->localisationCache + ->getItem( strtolower( $fallbackCode ), 'compiledPluralRules' ); if ( $pluralRules ) { break; } @@ -4953,11 +4953,13 @@ class Language { * @return array Associative array with plural form number and plural rule as key-value pairs */ public function getPluralRules() { - $pluralRules = self::$dataCache->getItem( strtolower( $this->mCode ), 'pluralRules' ); + $pluralRules = + $this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRules' ); $fallbacks = self::getFallbacksFor( $this->mCode ); if ( !$pluralRules ) { foreach ( $fallbacks as $fallbackCode ) { - $pluralRules = self::$dataCache->getItem( strtolower( $fallbackCode ), 'pluralRules' ); + $pluralRules = $this->localisationCache + ->getItem( strtolower( $fallbackCode ), 'pluralRules' ); if ( $pluralRules ) { break; } @@ -4972,11 +4974,13 @@ class Language { * @return array Associative array with plural form number and plural rule type as key-value pairs */ public function getPluralRuleTypes() { - $pluralRuleTypes = self::$dataCache->getItem( strtolower( $this->mCode ), 'pluralRuleTypes' ); + $pluralRuleTypes = + $this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRuleTypes' ); $fallbacks = self::getFallbacksFor( $this->mCode ); if ( !$pluralRuleTypes ) { foreach ( $fallbacks as $fallbackCode ) { - $pluralRuleTypes = self::$dataCache->getItem( strtolower( $fallbackCode ), 'pluralRuleTypes' ); + $pluralRuleTypes = $this->localisationCache + ->getItem( strtolower( $fallbackCode ), 'pluralRuleTypes' ); if ( $pluralRuleTypes ) { break; }