dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make LocalisationCache a service
[lhc/web/wiklou.git]
/
languages
/
Language.php
diff --git
a/languages/Language.php
b/languages/Language.php
index
16a6e1a
..
a8950f5
100644
(file)
--- a/
languages/Language.php
+++ b/
languages/Language.php
@@
-77,10
+77,8
@@
class Language {
*/
public $transformData = [];
*/
public $transformData = [];
- /**
- * @var LocalisationCache
- */
- public static $dataCache;
+ /** @var LocalisationCache */
+ private $localisationCache;
public static $mLangObjCache = [];
public static $mLangObjCache = [];
@@
-285,12
+283,12
@@
class Language {
* @since 1.32
*/
public static function clearCaches() {
* @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;
self::$mLangObjCache = [];
self::$fallbackLanguageCache = [];
self::$grammarTransformations = null;
@@
-445,15
+443,11
@@
class Language {
/**
* Get the LocalisationCache instance
*
/**
* Get the LocalisationCache instance
*
+ * @deprecated since 1.34, use MediaWikiServices
* @return LocalisationCache
*/
public static function getLocalisationCache() {
* @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() {
}
function __construct() {
@@
-464,7
+458,7
@@
class Language {
} else {
$this->mCode = str_replace( '_', '-', strtolower( substr( static::class, 8 ) ) );
}
} else {
$this->mCode = str_replace( '_', '-', strtolower( substr( static::class, 8 ) ) );
}
-
self::
getLocalisationCache();
+
$this->localisationCache = MediaWikiServices::getInstance()->
getLocalisationCache();
}
/**
}
/**
@@
-497,7
+491,7
@@
class Language {
* @return array
*/
public function getBookstoreList() {
* @return array
*/
public function getBookstoreList() {
- return
self::$data
Cache->getItem( $this->mCode, 'bookstoreList' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'bookstoreList' );
}
/**
}
/**
@@
-514,7
+508,7
@@
class Language {
getCanonicalNamespaces();
$this->namespaceNames = $wgExtraNamespaces +
getCanonicalNamespaces();
$this->namespaceNames = $wgExtraNamespaces +
-
self::$data
Cache->getItem( $this->mCode, 'namespaceNames' );
+
$this->localisation
Cache->getItem( $this->mCode, 'namespaceNames' );
$this->namespaceNames += $validNamespaces;
$this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
$this->namespaceNames += $validNamespaces;
$this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
@@
-527,7
+521,6
@@
class Language {
}
# Sometimes a language will be localised but not actually exist on this wiki.
}
# Sometimes a language will be localised but not actually exist on this wiki.
- // @phan-suppress-next-line PhanTypeMismatchForeach
foreach ( $this->namespaceNames as $key => $text ) {
if ( !isset( $validNamespaces[$key] ) ) {
unset( $this->namespaceNames[$key] );
foreach ( $this->namespaceNames as $key => $text ) {
if ( !isset( $validNamespaces[$key] ) ) {
unset( $this->namespaceNames[$key] );
@@
-536,7
+529,6
@@
class Language {
# The above mixing may leave namespaces out of canonical order.
# Re-order by namespace ID number...
# The above mixing may leave namespaces out of canonical order.
# Re-order by namespace ID number...
- // @phan-suppress-next-line PhanTypeMismatchArgumentInternal
ksort( $this->namespaceNames );
Hooks::run( 'LanguageGetNamespaces', [ &$this->namespaceNames ] );
ksort( $this->namespaceNames );
Hooks::run( 'LanguageGetNamespaces', [ &$this->namespaceNames ] );
@@
-623,7
+615,7
@@
class Language {
global $wgExtraGenderNamespaces;
$ns = $wgExtraGenderNamespaces +
global $wgExtraGenderNamespaces;
$ns = $wgExtraGenderNamespaces +
- (array)
self::$data
Cache->getItem( $this->mCode, 'namespaceGenderAliases' );
+ (array)
$this->localisation
Cache->getItem( $this->mCode, 'namespaceGenderAliases' );
return $ns[$index][$gender] ?? $this->getNsText( $index );
}
return $ns[$index][$gender] ?? $this->getNsText( $index );
}
@@
-645,7
+637,7
@@
class Language {
return false;
} else {
// Check what is in i18n files
return false;
} else {
// Check what is in i18n files
- $aliases =
self::$data
Cache->getItem( $this->mCode, 'namespaceGenderAliases' );
+ $aliases =
$this->localisation
Cache->getItem( $this->mCode, 'namespaceGenderAliases' );
return count( $aliases ) > 0;
}
}
return count( $aliases ) > 0;
}
}
@@
-669,7
+661,7
@@
class Language {
*/
public function getNamespaceAliases() {
if ( is_null( $this->namespaceAliases ) ) {
*/
public function getNamespaceAliases() {
if ( is_null( $this->namespaceAliases ) ) {
- $aliases =
self::$data
Cache->getItem( $this->mCode, 'namespaceAliases' );
+ $aliases =
$this->localisation
Cache->getItem( $this->mCode, 'namespaceAliases' );
if ( !$aliases ) {
$aliases = [];
} else {
if ( !$aliases ) {
$aliases = [];
} else {
@@
-683,8
+675,8
@@
class Language {
}
global $wgExtraGenderNamespaces;
}
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;
foreach ( $genders as $index => $forms ) {
foreach ( $forms as $alias ) {
$aliases[$alias] = $index;
@@
-785,21
+777,21
@@
class Language {
* @return string[]|bool List of date format preference keys, or false if disabled.
*/
public function getDatePreferences() {
* @return string[]|bool List of date format preference keys, or false if disabled.
*/
public function getDatePreferences() {
- return
self::$data
Cache->getItem( $this->mCode, 'datePreferences' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'datePreferences' );
}
/**
* @return array
*/
function getDateFormats() {
}
/**
* @return array
*/
function getDateFormats() {
- return
self::$data
Cache->getItem( $this->mCode, 'dateFormats' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'dateFormats' );
}
/**
* @return array|string
*/
public function getDefaultDateFormat() {
}
/**
* @return array|string
*/
public function getDefaultDateFormat() {
- $df =
self::$data
Cache->getItem( $this->mCode, 'defaultDateFormat' );
+ $df =
$this->localisation
Cache->getItem( $this->mCode, 'defaultDateFormat' );
if ( $df === 'dmy or mdy' ) {
global $wgAmericanDates;
return $wgAmericanDates ? 'mdy' : 'dmy';
if ( $df === 'dmy or mdy' ) {
global $wgAmericanDates;
return $wgAmericanDates ? 'mdy' : 'dmy';
@@
-812,7
+804,7
@@
class Language {
* @return array
*/
public function getDatePreferenceMigrationMap() {
* @return array
*/
public function getDatePreferenceMigrationMap() {
- return
self::$data
Cache->getItem( $this->mCode, 'datePreferenceMigrationMap' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'datePreferenceMigrationMap' );
}
/**
}
/**
@@
-2279,7
+2271,8
@@
class Language {
}
if ( !isset( $this->dateFormatStrings[$type][$pref] ) ) {
}
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 );
if ( $type === 'pretty' && $df === null ) {
$df = $this->getDateFormatString( 'date', $pref );
@@
-2287,7
+2280,8
@@
class Language {
if ( !$wasDefault && $df === null ) {
$pref = $this->getDefaultDateFormat();
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;
}
$this->dateFormatStrings[$type][$pref] = $df;
@@
-2651,14
+2645,14
@@
class Language {
* @return string|null
*/
public function getMessage( $key ) {
* @return string|null
*/
public function getMessage( $key ) {
- return
self::$data
Cache->getSubitem( $this->mCode, 'messages', $key );
+ return
$this->localisation
Cache->getSubitem( $this->mCode, 'messages', $key );
}
/**
* @return array
*/
function getAllMessages() {
}
/**
* @return array
*/
function getAllMessages() {
- return
self::$data
Cache->getItem( $this->mCode, 'messages' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'messages' );
}
/**
}
/**
@@
-2900,7
+2894,7
@@
class Language {
* @return string
*/
function fallback8bitEncoding() {
* @return string
*/
function fallback8bitEncoding() {
- return
self::$data
Cache->getItem( $this->mCode, 'fallback8bitEncoding' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'fallback8bitEncoding' );
}
/**
}
/**
@@
-3090,7
+3084,7
@@
class Language {
* @return bool
*/
function isRTL() {
* @return bool
*/
function isRTL() {
- return
self::$data
Cache->getItem( $this->mCode, 'rtl' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'rtl' );
}
/**
}
/**
@@
-3166,7
+3160,7
@@
class Language {
* @return array
*/
function capitalizeAllNouns() {
* @return array
*/
function capitalizeAllNouns() {
- return
self::$data
Cache->getItem( $this->mCode, 'capitalizeAllNouns' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'capitalizeAllNouns' );
}
/**
}
/**
@@
-3199,7
+3193,7
@@
class Language {
* @return bool
*/
function linkPrefixExtension() {
* @return bool
*/
function linkPrefixExtension() {
- return
self::$data
Cache->getItem( $this->mCode, 'linkPrefixExtension' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'linkPrefixExtension' );
}
/**
}
/**
@@
-3207,7
+3201,7
@@
class Language {
* @return array
*/
function getMagicWords() {
* @return array
*/
function getMagicWords() {
- return
self::$data
Cache->getItem( $this->mCode, 'magicWords' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'magicWords' );
}
/**
}
/**
@@
-3217,7
+3211,7
@@
class Language {
*/
function getMagic( $mw ) {
$rawEntry = $this->mMagicExtensions[$mw->mId] ??
*/
function getMagic( $mw ) {
$rawEntry = $this->mMagicExtensions[$mw->mId] ??
-
self::$data
Cache->getSubitem( $this->mCode, 'magicWords', $mw->mId );
+
$this->localisation
Cache->getSubitem( $this->mCode, 'magicWords', $mw->mId );
if ( !is_array( $rawEntry ) ) {
wfWarn( "\"$rawEntry\" is not a valid magic word for \"$mw->mId\"" );
if ( !is_array( $rawEntry ) ) {
wfWarn( "\"$rawEntry\" is not a valid magic word for \"$mw->mId\"" );
@@
-3237,7
+3231,6
@@
class Language {
$fallbackChain = array_reverse( $fallbackChain );
foreach ( $fallbackChain as $code ) {
if ( isset( $newWords[$code] ) ) {
$fallbackChain = array_reverse( $fallbackChain );
foreach ( $fallbackChain as $code ) {
if ( isset( $newWords[$code] ) ) {
- // @phan-suppress-next-line PhanTypeMismatchProperty
$this->mMagicExtensions = $newWords[$code] + $this->mMagicExtensions;
}
}
$this->mMagicExtensions = $newWords[$code] + $this->mMagicExtensions;
}
}
@@
-3253,7
+3246,7
@@
class Language {
if ( is_null( $this->mExtendedSpecialPageAliases ) ) {
// Initialise array
$this->mExtendedSpecialPageAliases =
if ( is_null( $this->mExtendedSpecialPageAliases ) ) {
// Initialise array
$this->mExtendedSpecialPageAliases =
-
self::$data
Cache->getItem( $this->mCode, 'specialPageAliases' );
+
$this->localisation
Cache->getItem( $this->mCode, 'specialPageAliases' );
}
return $this->mExtendedSpecialPageAliases;
}
return $this->mExtendedSpecialPageAliases;
@@
-3418,28
+3411,28
@@
class Language {
* @return string
*/
function digitGroupingPattern() {
* @return string
*/
function digitGroupingPattern() {
- return
self::$data
Cache->getItem( $this->mCode, 'digitGroupingPattern' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'digitGroupingPattern' );
}
/**
* @return array
*/
function digitTransformTable() {
}
/**
* @return array
*/
function digitTransformTable() {
- return
self::$data
Cache->getItem( $this->mCode, 'digitTransformTable' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'digitTransformTable' );
}
/**
* @return array
*/
function separatorTransformTable() {
}
/**
* @return array
*/
function separatorTransformTable() {
- return
self::$data
Cache->getItem( $this->mCode, 'separatorTransformTable' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'separatorTransformTable' );
}
/**
* @return int|null
*/
function minimumGroupingDigits() {
}
/**
* @return int|null
*/
function minimumGroupingDigits() {
- return
self::$data
Cache->getItem( $this->mCode, 'minimumGroupingDigits' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'minimumGroupingDigits' );
}
/**
}
/**
@@
-4339,7
+4332,7
@@
class Language {
* @return string
*/
public function linkTrail() {
* @return string
*/
public function linkTrail() {
- return
self::$data
Cache->getItem( $this->mCode, 'linkTrail' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'linkTrail' );
}
/**
}
/**
@@
-4349,7
+4342,7
@@
class Language {
* @return string
*/
public function linkPrefixCharset() {
* @return string
*/
public function linkPrefixCharset() {
- return
self::$data
Cache->getItem( $this->mCode, 'linkPrefixCharset' );
+ return
$this->localisation
Cache->getItem( $this->mCode, 'linkPrefixCharset' );
}
/**
}
/**
@@
-4939,11
+4932,13
@@
class Language {
* @return array Associative array with plural form, and plural rule as key-value pairs
*/
public function getCompiledPluralRules() {
* @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 ) {
$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;
}
if ( $pluralRules ) {
break;
}
@@
-4958,11
+4953,13
@@
class Language {
* @return array Associative array with plural form number and plural rule as key-value pairs
*/
public function getPluralRules() {
* @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 ) {
$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;
}
if ( $pluralRules ) {
break;
}
@@
-4977,11
+4974,13
@@
class Language {
* @return array Associative array with plural form number and plural rule type as key-value pairs
*/
public function getPluralRuleTypes() {
* @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 ) {
$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;
}
if ( $pluralRuleTypes ) {
break;
}