Merge "xhprof: Guard against division by 0 when computing percentages"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderStartUpModule.php
index 78fe45c..5370424 100644 (file)
@@ -92,9 +92,6 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        'wgSiteName' => $conf->get( 'Sitename' ),
                        'wgFileExtensions' => array_values( array_unique( $conf->get( 'FileExtensions' ) ) ),
                        'wgDBname' => $conf->get( 'DBname' ),
-                       // This sucks, it is only needed on Special:Upload, but I could
-                       // not find a way to add vars only for a certain module
-                       'wgFileCanRotate' => BitmapHandler::canRotate(),
                        'wgAvailableSkins' => Skin::getSkinNames(),
                        'wgExtensionAssetsPath' => $conf->get( 'ExtensionAssetsPath' ),
                        // MediaWiki sets cookies to have this prefix by default
@@ -207,12 +204,17 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                                continue;
                        }
 
-                       // getModifiedTime() is supposed to return a UNIX timestamp, but it doesn't always
-                       // 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, $this->getConfig()->get( 'CacheEpoch' ) ) );
+                       if ( $module->isRaw() ) {
+                               // Don't register "raw" modules (like 'jquery' and 'mediawiki') client-side because
+                               // depending on them is illegal anyway and would only lead to them being reloaded
+                               // causing any state to be lost (like jQuery plugins, mw.config etc.)
+                               continue;
+                       }
 
-                       // FIXME: Convert to numbers, wfTimestamp always gives us stings, even for TS_UNIX
+                       // 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 ) );
 
                        $skipFunction = $module->getSkipFunction();
                        if ( $skipFunction !== null && !ResourceLoader::inDebugMode() ) {
@@ -225,8 +227,14 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                                );
                        }
 
+                       $mtime = max(
+                               $moduleMtime,
+                               wfTimestamp( TS_UNIX, $this->getConfig()->get( 'CacheEpoch' ) )
+                       );
+
                        $registryData[$name] = array(
-                               'version' => $mtime,
+                               // Convert to numbers as wfTimestamp always returns a string, even for TS_UNIX
+                               'version' => (int) $mtime,
                                'dependencies' => $module->getDependencies(),
                                'group' => $module->getGroup(),
                                'source' => $module->getSource(),
@@ -348,7 +356,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
 
                // Get the latest version
                $loader = $context->getResourceLoader();
-               $version = 0;
+               $version = 1;
                foreach ( $moduleNames as $moduleName ) {
                        $version = max( $version,
                                $loader->getModule( $moduleName )->getModifiedTime( $context )
@@ -383,11 +391,20 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        $registrations = $this->getModuleRegistrations( $context );
                        // Fix indentation
                        $registrations = str_replace( "\n", "\n\t", trim( $registrations ) );
+                       $mwMapJsCall = Xml::encodeJsCall(
+                               'mw.Map',
+                               array( $this->getConfig()->get( 'LegacyJavaScriptGlobals' ) )
+                       );
+                       $mwConfigSetJsCall = Xml::encodeJsCall(
+                               'mw.config.set',
+                               array( $configuration )
+                       );
+
                        $out .= "var startUp = function () {\n" .
                                "\tmw.config = new " .
-                               Xml::encodeJsCall( 'mw.Map', array( $this->getConfig()->get( 'LegacyJavaScriptGlobals' ) ) ) . "\n" .
+                               $mwMapJsCall . "\n" .
                                "\t$registrations\n" .
-                               "\t" . Xml::encodeJsCall( 'mw.config.set', array( $configuration ) ) .
+                               "\t" . $mwConfigSetJsCall .
                                "};\n";
 
                        // Conditional script injection