Merge "Add 3D filetype for STL files"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index a2b4b1d..3ad6a84 100644 (file)
@@ -147,8 +147,8 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                if ( $deprecationInfo ) {
                        $name = $this->getName();
                        $warning = 'This page is using the deprecated ResourceLoader module "' . $name . '".';
-                       if ( !is_bool( $deprecationInfo ) && isset( $deprecationInfo['message'] ) ) {
-                               $warning .= "\n" . $deprecationInfo['message'];
+                       if ( is_string( $deprecationInfo ) ) {
+                               $warning .= "\n" . $deprecationInfo;
                        }
                        return Xml::encodeJsCall(
                                'mw.log.warn',
@@ -624,7 +624,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
         */
        final protected function buildContent( ResourceLoaderContext $context ) {
                $rl = $context->getResourceLoader();
-               $stats = RequestContext::getMain()->getStats();
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
                $statStart = microtime( true );
 
                // Only include properties that are relevant to this context (e.g. only=scripts)
@@ -931,36 +931,33 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
         * @return string JS with the original, or a replacement error
         */
        protected function validateScriptFile( $fileName, $contents ) {
-               if ( $this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) {
-                       // Try for cache hit
-                       $cache = ObjectCache::getMainWANInstance();
-                       $key = $cache->makeKey(
+               if ( !$this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) {
+                       return $contents;
+               }
+               $cache = ObjectCache::getMainWANInstance();
+               return $cache->getWithSetCallback(
+                       $cache->makeGlobalKey(
                                'resourceloader',
                                'jsparse',
                                self::$parseCacheVersion,
-                               md5( $contents )
-                       );
-                       $cacheEntry = $cache->get( $key );
-                       if ( is_string( $cacheEntry ) ) {
-                               return $cacheEntry;
-                       }
-
-                       $parser = self::javaScriptParser();
-                       try {
-                               $parser->parse( $contents, $fileName, 1 );
-                               $result = $contents;
-                       } catch ( Exception $e ) {
-                               // We'll save this to cache to avoid having to validate broken JS over and over...
-                               $err = $e->getMessage();
-                               $result = "mw.log.error(" .
-                                       Xml::encodeJsVar( "JavaScript parse error: $err" ) . ");";
+                               md5( $contents ),
+                               $fileName
+                       ),
+                       $cache::TTL_WEEK,
+                       function () use ( $contents, $fileName ) {
+                               $parser = self::javaScriptParser();
+                               try {
+                                       $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" ) . ");";
+                               }
+                               return $result;
                        }
-
-                       $cache->set( $key, $result );
-                       return $result;
-               } else {
-                       return $contents;
-               }
+               );
        }
 
        /**