Merge "Add dotall modifier to EDITSECTION_REGEX"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderStartUpModule.php
index c854fa2..a99305c 100644 (file)
@@ -194,7 +194,6 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
         * @return string JavaScript code for registering all modules with the client loader
         */
        public function getModuleRegistrations( ResourceLoaderContext $context ) {
-
                $resourceLoader = $context->getResourceLoader();
                $target = $context->getRequest()->getVal( 'target', 'desktop' );
                // Bypass target filter if this request is Special:JavaScriptTest.
@@ -202,6 +201,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                $byPassTargetFilter = $this->getConfig()->get( 'EnableJavaScriptTest' ) && $target === 'test';
 
                $out = '';
+               $states = [];
                $registryData = [];
 
                // Get registry data
@@ -219,8 +219,23 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                                continue;
                        }
 
-                       $versionHash = $module->getVersionHash( $context );
-                       if ( strlen( $versionHash ) !== 7 ) {
+                       try {
+                               $versionHash = $module->getVersionHash( $context );
+                       } catch ( Exception $e ) {
+                               // See also T152266 and ResourceLoader::getCombinedVersion()
+                               MWExceptionHandler::logException( $e );
+                               $context->getLogger()->warning(
+                                       'Calculating version for "{module}" failed: {exception}',
+                                       [
+                                               'module' => $name,
+                                               'exception' => $e,
+                                       ]
+                               );
+                               $versionHash = '';
+                               $states[$name] = 'error';
+                       }
+
+                       if ( $versionHash !== '' && strlen( $versionHash ) !== 7 ) {
                                $context->getLogger()->warning(
                                        "Module '{module}' produced an invalid version hash: '{version}'.",
                                        [
@@ -270,6 +285,10 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                // Register modules
                $out .= "\n" . ResourceLoader::makeLoaderRegisterScript( $registrations );
 
+               if ( $states ) {
+                       $out .= "\n" . ResourceLoader::makeLoaderStateScript( $states );
+               }
+
                return $out;
        }
 
@@ -311,14 +330,12 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
         */
        public static function getStartupModulesUrl( ResourceLoaderContext $context ) {
                $rl = $context->getResourceLoader();
-               $moduleNames = self::getStartupModules();
 
                $derivative = new DerivativeResourceLoaderContext( $context );
-               $derivative->setModules( $moduleNames );
+               $derivative->setModules( self::getStartupModules() );
                $derivative->setOnly( 'scripts' );
-               $derivative->setVersion(
-                       $rl->getCombinedVersion( $context, $moduleNames )
-               );
+               // Must setModules() before makeVersionQuery()
+               $derivative->setVersion( $rl->makeVersionQuery( $derivative ) );
 
                return $rl->createLoaderURL( 'local', $derivative );
        }