27use Psr\Log\LoggerAwareInterface;
28use Psr\Log\LoggerInterface;
29use Psr\Log\NullLogger;
44 private $resourceloader;
62 $this->resourceloader = $rl;
63 $this->logger =
$logger ?:
new NullLogger();
69 ->getMainWANObjectCache();
90 return $blobs[$module->
getName()];
101 public function getBlobs( array $modules, $lang ) {
106 self::makeGlobalPurgeKey( $this->wanCache )
109 foreach ( $modules as $name => $module ) {
110 $cacheKey = $this->makeBlobCacheKey( $name, $lang, $module );
111 $cacheKeys[$name] = $cacheKey;
112 $checkKeys[$cacheKey][] = $this->makeModulePurgeKey( $name );
115 $result = $this->wanCache->getMulti( array_values( $cacheKeys ), $curTTLs, $checkKeys );
118 foreach ( $modules as $name => $module ) {
119 $key = $cacheKeys[$name];
120 if ( !isset( $result[$key] ) || $curTTLs[$key] ===
null || $curTTLs[$key] < 0 ) {
124 $blobs[$name] = $result[$key];
136 private static function makeGlobalPurgeKey(
WANObjectCache $cache ) {
137 return $cache->
makeGlobalKey(
'resourceloader-messageblob' );
146 private function makeModulePurgeKey( $name ) {
147 return $this->wanCache->makeKey(
'resourceloader-messageblob', $name );
156 private function makeBlobCacheKey( $name, $lang, Module $module ) {
157 $messages = array_values( array_unique( $module->getMessages() ) );
159 return $this->wanCache->makeKey(
'resourceloader-messageblob',
162 md5( json_encode( $messages ) )
174 $blob = $this->generateMessageBlob( $module, $lang );
177 $cache->
set( $cacheKey, $blob,
179 $cache::TTL_WEEK + mt_rand( 0, $cache::TTL_DAY ),
192 $moduleNames = $this->resourceloader->getModulesByMessage( $key );
193 foreach ( $moduleNames as $moduleName ) {
196 $this->wanCache->touchCheckKey( $this->makeModulePurgeKey( $moduleName ) );
206 self::clearGlobalCacheEntry( $this->wanCache );
224 $cache->
touchCheckKey( self::makeGlobalPurgeKey( $cache ), $cache::HOLDOFF_TTL_NONE );
234 $message =
wfMessage( $key )->inLanguage( $lang );
235 if ( !$message->exists() ) {
236 $this->logger->warning(
'Failed to find {messageKey} ({lang})', [
237 'messageKey' => $key,
242 $value = $message->plain();
254 private function generateMessageBlob(
Module $module, $lang ) {
257 $value = $this->fetchMessage( $key, $lang );
260 if ( $value !==
null ) {
261 $messages[$key] = $value;
265 $json = FormatJson::encode( (
object)$messages,
false, FormatJson::UTF8_OK );
267 if ( $json ===
false ) {
268 $this->logger->warning(
'Failed to encode message blob for {module} ({lang})', [
269 'module' => $module->
getName(),
wfMessage( $key,... $params)
This is the function for getting translated interface messages.