24use Psr\Log\LoggerAwareInterface;
25use Psr\Log\LoggerInterface;
26use Psr\Log\NullLogger;
58 $this->resourceloader = $rl;
59 $this->logger =
$logger ?:
new NullLogger();
64 $this->wanCache = $wanObjectCache ?: MediaWikiServices::getInstance()
65 ->getMainWANObjectCache();
86 return $blobs[$module->
getName()];
104 $cache->makeGlobalKey( __CLASS__ )
107 foreach (
$modules as $name => $module ) {
109 $cacheKeys[$name] = $cacheKey;
111 $checkKeys[$cacheKey][] =
$cache->makeKey( __CLASS__, $name );
114 $result =
$cache->getMulti( array_values( $cacheKeys ), $curTTLs, $checkKeys );
117 foreach (
$modules as $name => $module ) {
118 $key = $cacheKeys[$name];
119 if ( !isset( $result[$key] ) || $curTTLs[$key] ===
null || $curTTLs[$key] < 0 ) {
123 $blobs[$name] = $result[$key];
136 $messages = array_values( array_unique( $module->
getMessages() ) );
138 return $this->wanCache->makeKey( __CLASS__, $module->
getName(),
$lang,
139 md5( json_encode( $messages ) )
155 $cache::TTL_WEEK + mt_rand( 0, $cache::TTL_DAY ),
168 $moduleNames = $this->resourceloader->getModulesByMessage( $key );
169 foreach ( $moduleNames as $moduleName ) {
171 $this->wanCache->touchCheckKey( $this->wanCache->makeKey( __CLASS__, $moduleName ) );
179 self::clearGlobalCacheEntry( $this->wanCache );
197 $cache->touchCheckKey(
$cache->makeGlobalKey( __CLASS__ ), $cache::HOLDOFF_TTL_NONE );
208 if ( !$message->exists() ) {
209 $this->logger->warning(
'Failed to find {messageKey} ({lang})', [
210 'messageKey' => $key,
215 $value = $message->plain();
230 $value = $this->fetchMessage( $key,
$lang );
233 if ( $value !==
null ) {
234 $messages[$key] = $value;
238 $json = FormatJson::encode( (
object)$messages,
false, FormatJson::UTF8_OK );
240 if ( $json ===
false ) {
241 $this->logger->warning(
'Failed to encode message blob for {module} ({lang})', [
242 'module' => $module->
getName(),
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
This class generates message blobs for use by ResourceLoader.
getBlobs(array $modules, $lang)
Get the message blobs for a set of modules.
fetchMessage( $key, $lang)
generateMessageBlob(ResourceLoaderModule $module, $lang)
Generate the message blob for a given module in a given language.
static clearGlobalCacheEntry(WANObjectCache $cache)
Invalidate cache keys for all known modules.
ResourceLoader $resourceloader
__construct(ResourceLoader $rl, ?LoggerInterface $logger, ?WANObjectCache $wanObjectCache)
recacheMessageBlob( $cacheKey, ResourceLoaderModule $module, $lang)
getBlob(ResourceLoaderModule $module, $lang)
Get the message blob for a module.
setLogger(LoggerInterface $logger)
clear()
Invalidate cache keys for all known modules.
updateMessage( $key)
Invalidate cache keys for modules using this message key.
makeCacheKey(ResourceLoaderModule $module, $lang)
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
getMessages()
Get the messages needed for this module.
getName()
Get this module's name.
ResourceLoader is a loading system for JavaScript and CSS resources.
Multi-datacenter aware caching interface.
set( $key, $value, $ttl=self::TTL_INDEFINITE, array $opts=[])
Set the value of a key in cache.
if(!isset( $args[0])) $lang