* The UserIsBlockedFrom hook is only called if a block is found first, and
should only be used to unblock a blocked user.
* …
+* Language::$dataCache has been removed (without prior deprecation, for
+ practical reasons). Use MediaWikiServices instead to get a LocalisationCache.
=== Deprecations in 1.34 ===
* The MWNamespace class is deprecated. Use NamespaceInfo.
* Constructing MovePage directly is deprecated. Use MovePageFactory.
* TempFSFile::factory() has been deprecated. Use TempFSFileFactory instead.
* wfIsBadImage() is deprecated. Use the BadFileLookup service instead.
+* Language::getLocalisationCache() is deprecated. Use MediaWikiServices.
=== Other changes in 1.34 ===
* …
'store' => 'detect',
'storeClass' => false,
'storeDirectory' => false,
+ 'storeServer' => [],
+ 'forceRecache' => false,
'manualRecache' => false,
];
use Hooks;
use IBufferingStatsdDataFactory;
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
+use LocalisationCache;
use MediaWiki\Block\BlockManager;
use MediaWiki\Block\BlockRestrictionStore;
use MediaWiki\FileBackend\FSFile\TempFSFileFactory;
return $this->getService( 'LinkRendererFactory' );
}
+ /**
+ * @since 1.34
+ * @return LocalisationCache
+ */
+ public function getLocalisationCache() : LocalisationCache {
+ return $this->getService( 'LocalisationCache' );
+ }
+
/**
* @since 1.28
* @return \BagOStuff
);
},
+ 'LocalisationCache' => function ( MediaWikiServices $services ) : LocalisationCache {
+ $conf = $services->getMainConfig()->get( 'LocalisationCacheConf' );
+
+ $logger = LoggerFactory::getInstance( 'localisation' );
+
+ // Figure out what class to use for the LCStore
+ $storeArg = [];
+ $storeArg['directory'] =
+ $conf['storeDirectory'] ?? $services->getMainConfig()->get( 'CacheDirectory' );
+
+ if ( !empty( $conf['storeClass'] ) ) {
+ $storeClass = $conf['storeClass'];
+ } elseif ( $conf['store'] === 'files' || $conf['store'] === 'file' ||
+ ( $conf['store'] === 'detect' && $storeArg['directory'] )
+ ) {
+ $storeClass = LCStoreCDB::class;
+ } elseif ( $conf['store'] === 'db' || $conf['store'] === 'detect' ) {
+ $storeClass = LCStoreDB::class;
+ $storeArg['server'] = $conf['storeServer'] ?? [];
+ } elseif ( $conf['store'] === 'array' ) {
+ $storeClass = LCStoreStaticArray::class;
+ } else {
+ throw new MWException(
+ 'Please set $wgLocalisationCacheConf[\'store\'] to something sensible.'
+ );
+ }
+ $logger->debug( "LocalisationCache: using store $storeClass" );
+
+ return new $conf['class'](
+ new ServiceOptions(
+ LocalisationCache::$constructorOptions,
+ // Two of the options are stored in $wgLocalisationCacheConf
+ $conf,
+ // In case someone set that config variable and didn't reset all keys, set defaults.
+ [
+ 'forceRecache' => false,
+ 'manualRecache' => false,
+ ],
+ // Some other options come from config itself
+ $services->getMainConfig()
+ ),
+ new $storeClass( $storeArg ),
+ $logger,
+ [ function () use ( $services ) {
+ $services->getResourceLoader()->getMessageBlobStore()->clear();
+ } ]
+ );
+ },
+
'LocalServerObjectCache' => function ( MediaWikiServices $services ) : BagOStuff {
$config = $services->getMainConfig();
$cacheId = \ObjectCache::detectLocalServerCache();
use CLDRPluralRuleParser\Evaluator;
use CLDRPluralRuleParser\Error as CLDRPluralRuleError;
-use MediaWiki\Logger\LoggerFactory;
-use MediaWiki\MediaWikiServices;
+use MediaWiki\Config\ServiceOptions;
+use Psr\Log\LoggerInterface;
/**
* Class for caching the contents of localisation files, Messages*.php
* and *.i18n.php.
*
- * An instance of this class is available using Language::getLocalisationCache().
+ * An instance of this class is available using MediaWikiServices.
*
* The values retrieved from here are merged, containing items from extension
* files, core messages files and the language fallback sequence (e.g. zh-cn ->
class LocalisationCache {
const VERSION = 4;
- /** Configuration associative array */
- private $conf;
+ /** @var ServiceOptions */
+ private $options;
/**
* True if recaching should only be done on an explicit call to recache().
*/
private $manualRecache = false;
- /**
- * True to treat all files as expired until they are regenerated by this object.
- */
- private $forceRecache = false;
-
/**
* The cache data. 3-d array, where the first key is the language code,
* the second key is the item key e.g. 'messages', and the third key is
private $store;
/**
- * @var \Psr\Log\LoggerInterface
+ * @var LoggerInterface
*/
private $logger;
+ /** @var callable[] See comment for parameter in constructor */
+ private $clearStoreCallbacks;
+
/**
* A 2-d associative array, code/key, where presence indicates that the item
* is loaded. Value arbitrary.
private $mergeableKeys = null;
+ /**
+ * @todo Make this a const when HHVM support is dropped (T192166)
+ *
+ * @var array
+ * @since 1.34
+ */
+ public static $constructorOptions = [
+ // True to treat all files as expired until they are regenerated by this object.
+ 'forceRecache',
+ 'manualRecache',
+ 'ExtensionMessagesFiles',
+ 'MessagesDirs',
+ ];
+
/**
* For constructor parameters, see the documentation in DefaultSettings.php
* for $wgLocalisationCacheConf.
*
- * @param array $conf
+ * Do not construct this directly. Use MediaWikiServices.
+ *
+ * @param ServiceOptions $options
+ * @param LCStore $store What backend to use for storage
+ * @param LoggerInterface $logger
+ * @param callable[] $clearStoreCallbacks To be called whenever the cache is cleared. Can be
+ * used to clear other caches that depend on this one, such as ResourceLoader's
+ * MessageBlobStore.
* @throws MWException
*/
- function __construct( $conf ) {
- global $wgCacheDirectory;
-
- $this->conf = $conf;
- $this->logger = LoggerFactory::getInstance( 'localisation' );
-
- $directory = !empty( $conf['storeDirectory'] ) ? $conf['storeDirectory'] : $wgCacheDirectory;
- $storeArg = [];
- $storeArg['directory'] = $directory;
-
- if ( !empty( $conf['storeClass'] ) ) {
- $storeClass = $conf['storeClass'];
- } else {
- switch ( $conf['store'] ) {
- case 'files':
- case 'file':
- $storeClass = LCStoreCDB::class;
- break;
- case 'db':
- $storeClass = LCStoreDB::class;
- $storeArg['server'] = $conf['storeServer'] ?? [];
- break;
- case 'array':
- $storeClass = LCStoreStaticArray::class;
- break;
- case 'detect':
- if ( $directory ) {
- $storeClass = LCStoreCDB::class;
- } else {
- $storeClass = LCStoreDB::class;
- $storeArg['server'] = $conf['storeServer'] ?? [];
- }
- break;
- default:
- throw new MWException(
- 'Please set $wgLocalisationCacheConf[\'store\'] to something sensible.'
- );
- }
- }
- $this->logger->debug( static::class . ": using store $storeClass" );
-
- $this->store = new $storeClass( $storeArg );
- foreach ( [ 'manualRecache', 'forceRecache' ] as $var ) {
- if ( isset( $conf[$var] ) ) {
- $this->$var = $conf[$var];
- }
- }
+ function __construct(
+ ServiceOptions $options,
+ LCStore $store,
+ LoggerInterface $logger,
+ array $clearStoreCallbacks = []
+ ) {
+ $options->assertRequiredOptions( self::$constructorOptions );
+
+ $this->options = $options;
+ $this->store = $store;
+ $this->logger = $logger;
+ $this->clearStoreCallbacks = $clearStoreCallbacks;
+
+ // Keep this separate from $this->options so it can be mutable
+ $this->manualRecache = $options->get( 'manualRecache' );
}
/**
* @return bool
*/
public function isExpired( $code ) {
- if ( $this->forceRecache && !isset( $this->recachedLangs[$code] ) ) {
+ if ( $this->options->get( 'forceRecache' ) && !isset( $this->recachedLangs[$code] ) ) {
$this->logger->debug( __METHOD__ . "($code): forced reload" );
return true;
public function getMessagesDirs() {
global $IP;
- $config = MediaWikiServices::getInstance()->getMainConfig();
- $messagesDirs = $config->get( 'MessagesDirs' );
return [
'core' => "$IP/languages/i18n",
'exif' => "$IP/languages/i18n/exif",
'api' => "$IP/includes/api/i18n",
'oojs-ui' => "$IP/resources/lib/ooui/i18n",
- ] + $messagesDirs;
+ ] + $this->options->get( 'MessagesDirs' );
}
/**
* @throws MWException
*/
public function recache( $code ) {
- global $wgExtensionMessagesFiles;
-
if ( !$code ) {
throw new MWException( "Invalid language code requested" );
}
# Load non-JSON localisation data for extensions
$extensionData = array_fill_keys( $codeSequence, $initialData );
- foreach ( $wgExtensionMessagesFiles as $extension => $fileName ) {
+ foreach ( $this->options->get( 'ExtensionMessagesFiles' ) as $extension => $fileName ) {
if ( isset( $messageDirs[$extension] ) ) {
# This extension has JSON message data; skip the PHP shim
continue;
# HACK: If using a null (i.e. disabled) storage backend, we
# can't write to the MessageBlobStore either
if ( !$this->store instanceof LCStoreNull ) {
- $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
- $blobStore->clear();
+ foreach ( $this->clearStoreCallbacks as $callback ) {
+ $callback();
+ }
}
}
$this->store = new LCStoreNull;
$this->manualRecache = false;
}
-
}
// This will be overridden in the web installer with the user-specified language
RequestContext::getMain()->setLanguage( 'en' );
- // Disable the i18n cache
- // TODO: manage LocalisationCache singleton in MediaWikiServices
- Language::getLocalisationCache()->disableBackend();
-
// Disable all global services, since we don't have any configuration yet!
MediaWikiServices::disableStorageBackend();
$mwServices = MediaWikiServices::getInstance();
+
+ // Disable i18n cache
+ $mwServices->getLocalisationCache()->disableBackend();
+
+ // Clear language cache so the old i18n cache doesn't sneak back in
+ Language::clearCaches();
+
// Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
// SqlBagOStuff will then throw since we just disabled wfGetDB)
$wgObjectCaches = $mwServices->getMainConfig()->get( 'ObjectCaches' );
*/
public $transformData = [];
- /**
- * @var LocalisationCache
- */
- public static $dataCache;
+ /** @var LocalisationCache */
+ private $localisationCache;
public static $mLangObjCache = [];
* @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( 'MEDIAWIKI_INSTALL' ) ) {
+ 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;
/**
* 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() {
} else {
$this->mCode = str_replace( '_', '-', strtolower( substr( static::class, 8 ) ) );
}
- self::getLocalisationCache();
+ $this->localisationCache = MediaWikiServices::getInstance()->getLocalisationCache();
}
/**
* @return array
*/
public function getBookstoreList() {
- return self::$dataCache->getItem( $this->mCode, 'bookstoreList' );
+ return $this->localisationCache->getItem( $this->mCode, 'bookstoreList' );
}
/**
getCanonicalNamespaces();
$this->namespaceNames = $wgExtraNamespaces +
- self::$dataCache->getItem( $this->mCode, 'namespaceNames' );
+ $this->localisationCache->getItem( $this->mCode, 'namespaceNames' );
$this->namespaceNames += $validNamespaces;
$this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
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 );
}
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;
}
}
*/
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 {
}
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;
* @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';
* @return array
*/
public function getDatePreferenceMigrationMap() {
- return self::$dataCache->getItem( $this->mCode, 'datePreferenceMigrationMap' );
+ return $this->localisationCache->getItem( $this->mCode, 'datePreferenceMigrationMap' );
}
/**
}
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 ( !$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;
* @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' );
}
/**
* @return string
*/
function fallback8bitEncoding() {
- return self::$dataCache->getItem( $this->mCode, 'fallback8bitEncoding' );
+ return $this->localisationCache->getItem( $this->mCode, 'fallback8bitEncoding' );
}
/**
* @return bool
*/
function isRTL() {
- return self::$dataCache->getItem( $this->mCode, 'rtl' );
+ return $this->localisationCache->getItem( $this->mCode, 'rtl' );
}
/**
* @return array
*/
function capitalizeAllNouns() {
- return self::$dataCache->getItem( $this->mCode, 'capitalizeAllNouns' );
+ return $this->localisationCache->getItem( $this->mCode, 'capitalizeAllNouns' );
}
/**
* @return bool
*/
function linkPrefixExtension() {
- return self::$dataCache->getItem( $this->mCode, 'linkPrefixExtension' );
+ return $this->localisationCache->getItem( $this->mCode, 'linkPrefixExtension' );
}
/**
* @return array
*/
function getMagicWords() {
- return self::$dataCache->getItem( $this->mCode, 'magicWords' );
+ return $this->localisationCache->getItem( $this->mCode, 'magicWords' );
}
/**
*/
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\"" );
if ( is_null( $this->mExtendedSpecialPageAliases ) ) {
// Initialise array
$this->mExtendedSpecialPageAliases =
- self::$dataCache->getItem( $this->mCode, 'specialPageAliases' );
+ $this->localisationCache->getItem( $this->mCode, 'specialPageAliases' );
}
return $this->mExtendedSpecialPageAliases;
* @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' );
}
/**
* @return string
*/
public function linkTrail() {
- return self::$dataCache->getItem( $this->mCode, 'linkTrail' );
+ return $this->localisationCache->getItem( $this->mCode, 'linkTrail' );
}
/**
* @return string
*/
public function linkPrefixCharset() {
- return self::$dataCache->getItem( $this->mCode, 'linkPrefixCharset' );
+ return $this->localisationCache->getItem( $this->mCode, 'linkPrefixCharset' );
}
/**
* @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;
}
* @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;
}
* @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;
}
* @ingroup Maintenance
*/
+use MediaWiki\Config\ServiceOptions;
+use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/Maintenance.php';
/**
$conf = $wgLocalisationCacheConf;
$conf['manualRecache'] = false; // Allow fallbacks to create CDB files
- if ( $force ) {
- $conf['forceRecache'] = true;
- }
+ $conf['forceRecache'] = $force || !empty( $conf['forceRecache'] );
if ( $this->hasOption( 'outdir' ) ) {
$conf['storeDirectory'] = $this->getOption( 'outdir' );
}
- $lc = new LocalisationCacheBulkLoad( $conf );
+ // XXX Copy-pasted from ServiceWiring.php. Do we need a factory for this one caller?
+ $lc = new LocalisationCacheBulkLoad(
+ new ServiceOptions(
+ LocalisationCache::$constructorOptions,
+ $conf,
+ MediaWikiServices::getInstance()->getMainConfig()
+ ),
+ new LCStoreDB( [] ),
+ LoggerFactory::getInstance( 'localisation' ),
+ [ function () {
+ MediaWikiServices::getInstance()->getResourceLoader()
+ ->getMessageBlobStore()->clear();
+ } ]
+ );
$allCodes = array_keys( Language::fetchLanguageNames( null, 'mwfile' ) );
if ( $this->hasOption( 'lang' ) ) {
$wgRequest = new FauxRequest();
MediaWiki\Session\SessionManager::resetCache();
+ Language::clearCaches();
}
public function run( PHPUnit_Framework_TestResult $result = null ) {
<?php
+
+use MediaWiki\Config\ServiceOptions;
+use Psr\Log\NullLogger;
+
/**
* @group Database
* @group Cache
*/
protected function getMockLocalisationCache() {
global $IP;
- $lc = $this->getMockBuilder( \LocalisationCache::class )
- ->setConstructorArgs( [ [ 'store' => 'detect' ] ] )
+
+ $lc = $this->getMockBuilder( LocalisationCache::class )
+ ->setConstructorArgs( [
+ new ServiceOptions( LocalisationCache::$constructorOptions, [
+ 'forceRecache' => false,
+ 'manualRecache' => false,
+ 'ExtensionMessagesFiles' => [],
+ 'MessagesDirs' => [],
+ ] ),
+ new LCStoreDB( [] ),
+ new NullLogger
+ ] )
->setMethods( [ 'getMessagesDirs' ] )
->getMock();
$lc->expects( $this->any() )->method( 'getMessagesDirs' )
return $lc;
}
- public function testPuralRulesFallback() {
+ public function testPluralRulesFallback() {
$cache = $this->getMockLocalisationCache();
$this->assertEquals(
global $wgExtensionMessagesFiles;
self::$oldExtMsgFiles = $wgExtensionMessagesFiles;
$wgExtensionMessagesFiles['LogTests'] = __DIR__ . '/LogTests.i18n.php';
- Language::getLocalisationCache()->recache( 'en' );
+ Language::clearCaches();
}
public static function tearDownAfterClass() {
global $wgExtensionMessagesFiles;
$wgExtensionMessagesFiles = self::$oldExtMsgFiles;
- Language::getLocalisationCache()->recache( 'en' );
+ Language::clearCaches();
parent::tearDownAfterClass();
}
public function testClearCaches() {
$languageClass = TestingAccessWrapper::newFromClass( Language::class );
- // Populate $dataCache
- Language::getLocalisationCache()->getItem( 'zh', 'mainpage' );
- $oldCacheObj = Language::$dataCache;
- $this->assertNotCount( 0,
- TestingAccessWrapper::newFromObject( Language::$dataCache )->loadedItems );
-
// Populate $mLangObjCache
$lang = Language::factory( 'en' );
$this->assertNotCount( 0, Language::$mLangObjCache );
Language::clearCaches();
- $this->assertNotSame( $oldCacheObj, Language::$dataCache );
- $this->assertCount( 0,
- TestingAccessWrapper::newFromObject( Language::$dataCache )->loadedItems );
$this->assertCount( 0, Language::$mLangObjCache );
$this->assertCount( 0, $languageClass->fallbackLanguageCache );
$this->assertNull( $languageClass->grammarTransformations );