From: Timo Tijhof Date: Thu, 20 Mar 2014 06:04:48 +0000 (+0100) Subject: ResourceLoaderStartUpModule: Use hashMtime to detect config changes X-Git-Tag: 1.31.0-rc.0~16469^2 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=f9a951abc2c1e5a8d8aa361415843875a96d68bd;p=lhc%2Fweb%2Fwiklou.git ResourceLoaderStartUpModule: Use hashMtime to detect config changes Changes to the static startup.js file are covered by the file mtime in #getModifiedTime. Changes to the module registrations are covered by the max module mtime loop in #getModifiedTime. But changes to LocalSettings.php etc. affecting mw.config values embedded in #getScript aren't traceable. Resort to hashing those and detecting changes between calls that way. Without this, changes to mw.config never made it live (not even after the rebuild every 5 minutes) because of 304 Not Modified being sent between Apache and Varnish. Changes to config either didn't matter to front-end right away and made it with the next deployment that changes a different module, or by touching startup.js to force a version bump. Simple third party installs were not affected by this bug as their settings would only be coming from LocalSettings.php (as opposed to included files) and $wgInvalidateCacheOnLocalSettingsChange is true by default. Bug: 28899 Change-Id: I484166923d97368d95beeb40bb209dec9b849033 --- diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index a551c4ae0d..1e2f65cdbb 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -27,6 +27,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { /* Protected Members */ protected $modifiedTime = array(); + protected $configVars = array(); protected $targets = array( 'desktop', 'mobile' ); /* Protected Methods */ @@ -36,6 +37,12 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { * @return array */ protected function getConfig( $context ) { + + $hash = $context->getHash(); + if ( isset( $this->configVars[$hash] ) ) { + return $this->configVars[$hash]; + } + global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgVersion, @@ -106,7 +113,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { wfRunHooks( 'ResourceLoaderGetConfigVars', array( &$vars ) ); - return $vars; + $this->configVars[$hash] = $vars; + return $this->configVars[$hash]; } /** @@ -278,7 +286,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { $time = max( wfTimestamp( TS_UNIX, $wgCacheEpoch ), - filemtime( "$IP/resources/startup.js" ) + filemtime( "$IP/resources/startup.js" ), + $this->getHashMtime( $context ) ); // ATTENTION!: Because of the line below, this is not going to cause @@ -297,6 +306,25 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { return $this->modifiedTime[$hash]; } + /** + * Hash of all dynamic data embedded in getScript(). + * + * Detect changes to mw.config settings embedded in #getScript (bug 28899). + * + * @param $context ResourceLoaderContext + * @return string: Hash + */ + public function getModifiedHash( ResourceLoaderContext $context ) { + global $wgLegacyJavaScriptGlobals; + + $data = array( + 'vars' => $this->getConfig( $context ), + 'wgLegacyJavaScriptGlobals' => $wgLegacyJavaScriptGlobals, + ); + + return md5( serialize( $data ) ); + } + /** * @return string */