Merge "The light at the end of the API code format updating tunnel"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderFileModule.php
index b362297..9ed181e 100644 (file)
@@ -490,7 +490,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * @param string $path
         * @return string: the stylesheet language name
         */
-       protected function getStyleSheetLang( $path ) {
+       public function getStyleSheetLang( $path ) {
                return preg_match( '/\.less$/i', $path ) ? 'less' : 'css';
        }
 
@@ -579,6 +579,23 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                );
        }
 
+       /**
+        * Returns all style files used by this module
+        * @return array
+        */
+       public function getAllStyleFiles() {
+               $files = array();
+               foreach( (array)$this->styles as $key => $value ) {
+                       if ( is_array( $value ) ) {
+                               $path = $key;
+                       } else {
+                               $path = $value;
+                       }
+                       $files[] = $this->getLocalPath( $path );
+               }
+               return $files;
+       }
+
        /**
         * Gets the contents of a list of JavaScript files.
         *
@@ -705,21 +722,17 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
        /**
         * Generate a cache key for a LESS file.
         *
-        * The cache key varies on the file name, the names and values of global
-        * LESS variables, and the value of $wgShowExceptionDetails. Varying on
-        * $wgShowExceptionDetails ensures the CSS comment indicating compilation
-        * failure shows the right level of detail.
+        * The cache key varies on the file name and the names and values of global
+        * LESS variables.
         *
         * @since 1.22
         * @param string $fileName File name of root LESS file.
         * @return string: Cache key
         */
        protected static function getLESSCacheKey( $fileName ) {
-               global $wgShowExceptionDetails;
-
-               $vars = json_encode( self::getLESSVars() );
+               $vars = json_encode( ResourceLoader::getLESSVars() );
                $hash = md5( $fileName . $vars );
-               return wfMemcKey( 'resourceloader', 'less', (string)$wgShowExceptionDetails, $hash );
+               return wfMemcKey( 'resourceloader', 'less', $hash );
        }
 
        /**
@@ -736,8 +749,6 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * @return string: CSS source
         */
        protected function compileLESSFile( $fileName ) {
-               global $wgShowExceptionDetails;
-
                $key = self::getLESSCacheKey( $fileName );
                $cache = wfGetCache( CACHE_ANYTHING );
 
@@ -749,35 +760,17 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        $source = $fileName;
                }
 
-               $compiler = self::lessCompiler();
-               $expire = 0;
-               try {
-                       $result = $compiler->cachedCompile( $source );
-                       if ( !is_array( $result ) ) {
-                               throw new Exception( 'LESS compiler result has type ' . gettype( $result ) . '; array expected.' );
-                       }
-               } catch ( Exception $e ) {
-                       // The exception might have been caused by an imported file rather
-                       // than the root node. But we don't know which files were imported,
-                       // because compilation failed; we thus cannot rely on file mtime to
-                       // know when to reattempt compilation. Expire in 5 mins. instead.
-                       $expire = 300;
-                       wfDebugLog( 'resourceloader', __METHOD__ . ": $e" );
-                       $result = array();
-                       $result['root'] = $fileName;
-
-                       if ( $wgShowExceptionDetails ) {
-                               $result['compiled'] = ResourceLoader::makeComment( 'LESS error: ' . $e->getMessage() );
-                       } else {
-                               $result['compiled'] = ResourceLoader::makeComment( 'LESS stylesheet compilation failed. ' .
-                                       'Set "$wgShowExceptionDetails = true;" to show detailed debugging information.' );
-                       }
+               $compiler = ResourceLoader::getLessCompiler();
+               $result = null;
 
-                       $result['files'] = array( $fileName => self::safeFilemtime( $fileName ) );
-                       $result['updated'] = time();
+               $result = $compiler->cachedCompile( $source );
+
+               if ( !is_array( $result ) ) {
+                       throw new MWException( 'LESS compiler result has type ' . gettype( $result ) . '; array expected.' );
                }
+
                $this->localFileRefs += array_keys( $result['files'] );
-               $cache->set( $key, $result, $expire );
+               $cache->set( $key, $result );
                return $result['compiled'];
        }
 }