ResourceLoaderStartUpModule: Improve comment about modifiedTime hack
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderStartUpModule.php
index 207e96b..a551c4a 100644 (file)
@@ -42,7 +42,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        $wgEnableAPI, $wgEnableWriteAPI, $wgDBname,
                        $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath,
                        $wgCookiePrefix, $wgResourceLoaderMaxQueryLength,
-                       $wgResourceLoaderStorageEnabled, $wgResourceLoaderStorageVersion;
+                       $wgResourceLoaderStorageEnabled, $wgResourceLoaderStorageVersion,
+                       $wgSearchType;
 
                $mainPage = Title::newMainPage();
 
@@ -71,6 +72,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        'wgScriptPath' => $wgScriptPath,
                        'wgScriptExtension' => $wgScriptExtension,
                        'wgScript' => $wgScript,
+                       'wgSearchType' => $wgSearchType,
                        'wgVariantArticlePath' => $wgVariantArticlePath,
                        // Force object to avoid "empty" associative array from
                        // becoming [] instead of {} in JS (bug 34604)
@@ -149,24 +151,22 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        // seem to do that, and custom implementations might forget. Coerce it to TS_UNIX
                        $moduleMtime = wfTimestamp( TS_UNIX, $module->getModifiedTime( $context ) );
                        $mtime = max( $moduleMtime, wfTimestamp( TS_UNIX, $wgCacheEpoch ) );
-                       // Modules without dependencies, a group or a foreign source pass two arguments (name, timestamp) to
-                       // mw.loader.register()
+
                        if ( !count( $deps ) && $group === null && $source === 'local' ) {
+                               // Modules without dependencies, a group or a foreign source pass two arguments (name, timestamp) to
+                               // mw.loader.register()
                                $registrations[] = array( $name, $mtime );
-                       }
-                       // Modules with dependencies but no group or foreign source pass three arguments
-                       // (name, timestamp, dependencies) to mw.loader.register()
-                       elseif ( $group === null && $source === 'local' ) {
+                       } elseif ( $group === null && $source === 'local' ) {
+                               // Modules with dependencies but no group or foreign source pass three arguments
+                               // (name, timestamp, dependencies) to mw.loader.register()
                                $registrations[] = array( $name, $mtime, $deps );
-                       }
-                       // Modules with a group but no foreign source pass four arguments (name, timestamp, dependencies, group)
-                       // to mw.loader.register()
-                       elseif ( $source === 'local' ) {
+                       } elseif ( $source === 'local' ) {
+                               // Modules with a group but no foreign source pass four arguments (name, timestamp, dependencies, group)
+                               // to mw.loader.register()
                                $registrations[] = array( $name, $mtime, $deps, $group );
-                       }
-                       // Modules with a foreign source pass five arguments (name, timestamp, dependencies, group, source)
-                       // to mw.loader.register()
-                       else {
+                       } else {
+                               // Modules with a foreign source pass five arguments (name, timestamp, dependencies, group, source)
+                               // to mw.loader.register()
                                $registrations[] = array( $name, $mtime, $deps, $group, $source );
                        }
                }
@@ -221,7 +221,6 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                return  wfAppendQuery( wfScript( 'load' ), $query );
        }
 
-
        /**
         * @param $context ResourceLoaderContext
         * @return string
@@ -235,8 +234,9 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        // Startup function
                        $configuration = $this->getConfig( $context );
                        $registrations = self::getModuleRegistrations( $context );
-                       $registrations = str_replace( "\n", "\n\t", trim( $registrations ) ); // fix indentation
-                       $out .= "var startUp = function() {\n" .
+                       // Fix indentation
+                       $registrations = str_replace( "\n", "\n\t", trim( $registrations ) );
+                       $out .= "var startUp = function () {\n" .
                                "\tmw.config = new " . Xml::encodeJsCall( 'mw.Map', array( $wgLegacyJavaScriptGlobals ) ) . "\n" .
                                "\t$registrations\n" .
                                "\t" . Xml::encodeJsCall( 'mw.config.set', array( $configuration ) ) .
@@ -246,8 +246,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        $scriptTag = Html::linkedScript( self::getStartupModulesUrl( $context ) );
                        $out .= "if ( isCompatible() ) {\n" .
                                "\t" . Xml::encodeJsCall( 'document.write', array( $scriptTag ) ) .
-                               "}\n" .
-                               "delete isCompatible;";
+                               "}";
                }
 
                return $out;
@@ -277,21 +276,27 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                $loader = $context->getResourceLoader();
                $loader->preloadModuleInfo( $loader->getModuleNames(), $context );
 
-               $this->modifiedTime[$hash] = filemtime( "$IP/resources/startup.js" );
-               // ATTENTION!: Because of the line above, this is not going to cause
+               $time = max(
+                       wfTimestamp( TS_UNIX, $wgCacheEpoch ),
+                       filemtime( "$IP/resources/startup.js" )
+               );
+
+               // ATTENTION!: Because of the line below, this is not going to cause
                // infinite recursion - think carefully before making changes to this
                // code!
-               $time = wfTimestamp( TS_UNIX, $wgCacheEpoch );
+               // Pre-populate modifiedTime with something because the the loop over
+               // all modules below includes the 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];
        }
 
-       /* Methods */
-
        /**
         * @return string
         */