| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
use MediaWiki\MediaWikiServices; |
| 5 |
use Wikimedia\TestingAccessWrapper; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class TestLocalisationCache extends LocalisationCache { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
private static MapCacheLRU $testingCache; |
| 18 |
|
| 19 |
private const PROPERTY_NAMES = [ 'data', 'sourceLanguage' ]; |
| 20 |
|
| 21 |
|
| 22 |
private $selfAccess; |
| 23 |
|
| 24 |
public function __construct( ...$params ) { |
| 25 |
parent::__construct( ...$params ); |
| 26 |
|
| 27 |
|
| 28 |
… |
| 29 |
self::$testingCache ??= new MapCacheLRU( 16 ); |
| 30 |
$this->selfAccess = TestingAccessWrapper::newFromObject( $this ); |
| 31 |
} |
| 32 |
|
| 33 |
public function recache( $code ) { |
| 34 |
$hookContainer = MediaWikiServices::getInstance()->getHookContainer(); |
| 35 |
|
| 36 |
$cacheKey = sha1( json_encode( [ |
| 37 |
$code, |
| 38 |
$this->selfAccess->options->get( MainConfigNames::ExtensionMessagesFiles ), |
| 39 |
$this->selfAccess->options->get( MainConfigNames::MessagesDirs ), |
| 40 |
$hookContainer->getHandlerDescriptions( 'LocalisationCacheRecacheFallback' ), |
| 41 |
$hookContainer->getHandlerDescriptions( 'LocalisationCacheRecache' ), |
| 42 |
] ) ); |
| 43 |
$cache = self::$testingCache->get( $cacheKey ); |
| 44 |
if ( $cache ) { |
| 45 |
foreach ( self::PROPERTY_NAMES as $prop ) { |
| 46 |
$this->$prop[$code] = $cache[$prop]; |
| 47 |
} |
| 48 |
$loadedItems = $this->selfAccess->loadedItems; |
| 49 |
foreach ( $cache['data'] as $key => $_ ) { |
| 50 |
$loadedItems[$code][$key] = true; |
| 51 |
} |
| 52 |
$this->selfAccess->loadedItems = $loadedItems; |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
parent::recache( $code ); |
| 57 |
|
| 58 |
$cache = []; |
| 59 |
foreach ( self::PROPERTY_NAMES as $prop ) { |
| 60 |
$cache[$prop] = $this->$prop[$code]; |
| 61 |
} |
| 62 |
self::$testingCache->set( $cacheKey, $cache ); |
| 63 |
} |
| 64 |
} |