X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderModule.php;h=eb174f0fe499b72ca67b21879a70990a1de19edf;hb=26e157d31135fd4c74a7e0544722a69face4d6df;hp=ae79dda520252e50596a665debb18141c6a52105;hpb=d98de9926d033b9eaa30306379dc1815ee27b42f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index ae79dda520..eb174f0fe4 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -734,7 +734,6 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { } $content['scripts'] = $scripts; - // Styles $styles = []; // Don't create empty stylesheets like [ '' => '' ] for modules // that don't *have* any stylesheets (T40024). @@ -944,7 +943,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { if ( !$this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) { return $contents; } - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); return $cache->getWithSetCallback( $cache->makeGlobalKey( 'resourceloader', @@ -956,16 +955,25 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { $cache::TTL_WEEK, function () use ( $contents, $fileName ) { $parser = self::javaScriptParser(); + $err = null; try { + Wikimedia\suppressWarnings(); $parser->parse( $contents, $fileName, 1 ); - $result = $contents; } catch ( Exception $e ) { - // We'll save this to cache to avoid having to re-validate broken JS - $err = $e->getMessage(); - $result = "mw.log.error(" . - Xml::encodeJsVar( "JavaScript parse error: $err" ) . ");"; + $err = $e; + } finally { + Wikimedia\restoreWarnings(); } - return $result; + if ( $err ) { + // Send the error to the browser console client-side. + // By returning this as replacement for the actual script, + // we ensure modules are safe to load in a batch request, + // without causing other unrelated modules to break. + return 'mw.log.error(' . + Xml::encodeJsVar( 'JavaScript parse error: ' . $err->getMessage() ) . + ');'; + } + return $contents; } ); }