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 = MediaWikiServices::getInstance()->getMainWANObjectCache();
85 return $blobs[$module->
getName()];
103 $cache->makeGlobalKey( __CLASS__ )
106 foreach (
$modules as $name => $module ) {
108 $cacheKeys[$name] = $cacheKey;
110 $checkKeys[$cacheKey][] =
$cache->makeKey( __CLASS__, $name );
113 $result =
$cache->getMulti( array_values( $cacheKeys ), $curTTLs, $checkKeys );
116 foreach (
$modules as $name => $module ) {
117 $key = $cacheKeys[$name];
118 if ( !isset( $result[$key] ) || $curTTLs[$key] ===
null || $curTTLs[$key] < 0 ) {
122 $blobs[$name] = $result[$key];
135 $messages = array_values( array_unique( $module->
getMessages() ) );
137 return $this->wanCache->makeKey( __CLASS__, $module->
getName(),
$lang,
138 md5( json_encode( $messages ) )
154 $cache::TTL_WEEK + mt_rand( 0, $cache::TTL_DAY ),
168 foreach ( $moduleNames as $moduleName ) {
170 $this->wanCache->touchCheckKey( $this->wanCache->makeKey( __CLASS__, $moduleName ) );
196 $cache->touchCheckKey(
$cache->makeGlobalKey( __CLASS__ ), $cache::HOLDOFF_TTL_NONE );
215 if ( !$message->exists() ) {
216 $this->logger->warning(
'Failed to find {messageKey} ({lang})', [
217 'messageKey' => $key,
222 $value = $message->plain();
238 if ( $value !==
null ) {
239 $messages[$key] = $value;
243 $json = FormatJson::encode( (
object)$messages,
false, FormatJson::UTF8_OK );
245 if ( $json ===
false ) {
246 $this->logger->warning(
'Failed to encode message blob for {module} ({lang})', [
247 '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.
__construct(ResourceLoader $rl, LoggerInterface $logger=null)
static clearGlobalCacheEntry(WANObjectCache $cache)
Invalidate cache keys for all known modules.
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