Merge "ResourceLoaderStartUpModule: Use hashMtime to detect config changes"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 26 Mar 2014 22:36:45 +0000 (22:36 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 26 Mar 2014 22:36:45 +0000 (22:36 +0000)
includes/resourceloader/ResourceLoaderStartUpModule.php

index b4f57c1..b11d6c8 100644 (file)
@@ -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
         */