X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderStartUpModule.php;h=a578ece687c5371726cd6d494c26b5f009ddd31f;hb=b51076a84446d157bed511246450e70d26e0f945;hp=48b357653d9d13ec775f6fbb46885b4ce5230911;hpb=7958fe5dc9ed94591fe1f7b5c70cd9362c989ba7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index 48b357653d..a578ece687 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -24,14 +24,10 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { - /* Protected Members */ - - protected $modifiedTime = array(); + // Cache for getConfigSettings() as it's called by multiple methods protected $configVars = array(); protected $targets = array( 'desktop', 'mobile' ); - /* Protected Methods */ - /** * @param ResourceLoaderContext $context * @return array @@ -82,6 +78,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { 'wgServerName' => $conf->get( 'ServerName' ), 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), + 'wgTranslateNumerals' => $conf->get( 'TranslateNumerals' ), 'wgVersion' => $conf->get( 'Version' ), 'wgEnableAPI' => $conf->get( 'EnableAPI' ), 'wgEnableWriteAPI' => $conf->get( 'EnableWriteAPI' ), @@ -158,7 +155,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { * data send to the client. * * @param array &$registryData Modules keyed by name with properties: - * - number 'version' + * - string 'version' * - array 'dependencies' * - string|null 'group' * - string 'source' @@ -209,31 +206,27 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { continue; } - // Coerce module timestamp to UNIX timestamp. - // getModifiedTime() is supposed to return a UNIX timestamp, but custom implementations - // might forget. TODO: Maybe emit warning? - $moduleMtime = wfTimestamp( TS_UNIX, $module->getModifiedTime( $context ) ); + $versionHash = $module->getVersionHash( $context ); + if ( strlen( $versionHash ) !== 8 ) { + // Module implementation either broken or deviated from ResourceLoader::makeHash + // Asserted by tests/phpunit/structure/ResourcesTest. + $versionHash = ResourceLoader::makeHash( $versionHash ); + } $skipFunction = $module->getSkipFunction(); if ( $skipFunction !== null && !ResourceLoader::inDebugMode() ) { $skipFunction = $resourceLoader->filter( 'minify-js', $skipFunction, - // There will potentially be lots of these little string in the registrations + // There will potentially be lots of these little strings in the registrations // manifest, we don't want to blow up the startup module with - // "/* cache key: ... */" all over it in non-debug mode. + // "/* cache key: ... */" all over it. /* cacheReport = */ false ); } - $mtime = max( - $moduleMtime, - wfTimestamp( TS_UNIX, $this->getConfig()->get( 'CacheEpoch' ) ) - ); - $registryData[$name] = array( - // Convert to numbers as wfTimestamp always returns a string, even for TS_UNIX - 'version' => (int) $mtime, - 'dependencies' => $module->getDependencies(), + 'version' => $versionHash, + 'dependencies' => $module->getDependencies( $context ), 'group' => $module->getGroup(), 'source' => $module->getSource(), 'loader' => $module->getLoaderScript(), @@ -262,7 +255,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { continue; } - // Call mw.loader.register(name, timestamp, dependencies, group, source, skip) + // Call mw.loader.register(name, version, dependencies, group, source, skip) $registrations[] = array( $name, $data['version'], @@ -280,8 +273,6 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { return $out; } - /* Methods */ - /** * @return bool */ @@ -308,24 +299,16 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { * @return string */ public static function getStartupModulesUrl( ResourceLoaderContext $context ) { + $rl = $context->getResourceLoader(); $moduleNames = self::getStartupModules(); - // Get the latest version - $loader = $context->getResourceLoader(); - $version = 1; - foreach ( $moduleNames as $moduleName ) { - $version = max( $version, - $loader->getModule( $moduleName )->getModifiedTime( $context ) - ); - } - $query = array( 'modules' => ResourceLoader::makePackedModulesString( $moduleNames ), 'only' => 'scripts', 'lang' => $context->getLanguage(), 'skin' => $context->getSkin(), 'debug' => $context->getDebug() ? 'true' : 'false', - 'version' => wfTimestamp( TS_ISO_8601_BASIC, $version ) + 'version' => $rl->getCombinedVersion( $context, $moduleNames ), ); // Ensure uniform query order ksort( $query ); @@ -382,59 +365,48 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { } /** + * Get the definition summary for this module. + * * @param ResourceLoaderContext $context - * @return array|mixed + * @return array */ - public function getModifiedTime( ResourceLoaderContext $context ) { + public function getDefinitionSummary( ResourceLoaderContext $context ) { global $IP; + $summary = parent::getDefinitionSummary( $context ); + $summary[] = array( + // Detect changes to variables exposed in mw.config (T30899). + 'vars' => $this->getConfigSettings( $context ), + // Changes how getScript() creates mw.Map for mw.config + 'wgLegacyJavaScriptGlobals' => $this->getConfig()->get( 'LegacyJavaScriptGlobals' ), + // Detect changes to the module registrations + 'moduleHashes' => $this->getAllModuleHashes( $context ), - $hash = $context->getHash(); - if ( isset( $this->modifiedTime[$hash] ) ) { - return $this->modifiedTime[$hash]; - } - - // Call preloadModuleInfo() on ALL modules as we're about - // to call getModifiedTime() on all of them - $loader = $context->getResourceLoader(); - $loader->preloadModuleInfo( $loader->getModuleNames(), $context ); - - $time = max( - wfTimestamp( TS_UNIX, $this->getConfig()->get( 'CacheEpoch' ) ), - filemtime( "$IP/resources/src/startup.js" ), - $this->getHashMtime( $context ) + 'fileMtimes' => array( + filemtime( "$IP/resources/src/startup.js" ), + ), ); - - // ATTENTION!: Because of the line below, this is not going to cause - // infinite recursion - think carefully before making changes to this - // code! - // Pre-populate modifiedTime with something because the loop over - // all modules below includes the startup module (this module). - $this->modifiedTime[$hash] = 1; - - foreach ( $loader->getModuleNames() as $name ) { - $module = $loader->getModule( $name ); - $time = max( $time, $module->getModifiedTime( $context ) ); - } - - $this->modifiedTime[$hash] = $time; - return $this->modifiedTime[$hash]; + return $summary; } /** - * Hash of all dynamic data embedded in getScript(). - * - * Detect changes to mw.config settings embedded in #getScript (bug 28899). + * Helper method for getDefinitionSummary(). * * @param ResourceLoaderContext $context - * @return string Hash + * @return string SHA-1 */ - public function getModifiedHash( ResourceLoaderContext $context ) { - $data = array( - 'vars' => $this->getConfigSettings( $context ), - 'wgLegacyJavaScriptGlobals' => $this->getConfig()->get( 'LegacyJavaScriptGlobals' ), - ); - - return md5( serialize( $data ) ); + protected function getAllModuleHashes( ResourceLoaderContext $context ) { + $rl = $context->getResourceLoader(); + // Preload for getCombinedVersion() + $rl->preloadModuleInfo( $rl->getModuleNames(), $context ); + + // ATTENTION: Because of the line below, this is not going to cause infinite recursion. + // Think carefully before making changes to this code! + // Pre-populate versionHash with something because the loop over all modules below includes + // the startup module (this module). + // See ResourceLoaderModule::getVersionHash() for usage of this cache. + $this->versionHash[$context->getHash()] = null; + + return $rl->getCombinedVersion( $context, $rl->getModuleNames() ); } /**