Change 1.26 to 1.27, mostly in doc comments
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderFileModule.php
index ca10ab7..bc17821 100644 (file)
@@ -416,8 +416,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        $context
                );
                // Collect referenced files
-               $this->localFileRefs = array_unique( $this->localFileRefs );
-               $this->saveFileDependencies( $context->getSkin(), $this->localFileRefs );
+               $this->saveFileDependencies( $context, $this->localFileRefs );
 
                return $styles;
        }
@@ -561,7 +560,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                }
                $files = array_map( array( $this, 'getLocalPath' ), $files );
                // File deps need to be treated separately because they're already prefixed
-               $files = array_merge( $files, $this->getFileDependencies( $context->getSkin() ) );
+               $files = array_merge( $files, $this->getFileDependencies( $context ) );
                // Filter out any duplicates from getFileDependencies() and others.
                // Most commonly introduced by compileLessFile(), which always includes the
                // entry point Less file we already know about.
@@ -854,13 +853,21 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * @param array $styles List of media type/list of file paths pairs, to read, remap and
         * concetenate
         * @param bool $flip
-        * @param ResourceLoaderContext $context (optional)
+        * @param ResourceLoaderContext $context
         *
         * @throws MWException
         * @return array List of concatenated and remapped CSS data from $styles,
         *     keyed by media type
+        *
+        * @since 1.27 Calling this method without a ResourceLoaderContext instance
+        *   is deprecated.
         */
        public function readStyleFiles( array $styles, $flip, $context = null ) {
+               if ( $context === null ) {
+                       wfDeprecated( __METHOD__ . ' without a ResourceLoader context', '1.27' );
+                       $context = ResourceLoaderContext::newDummyContext();
+               }
+
                if ( empty( $styles ) ) {
                        return array();
                }
@@ -882,12 +889,12 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         *
         * @param string $path File path of style file to read
         * @param bool $flip
-        * @param ResourceLoaderContext $context (optional)
+        * @param ResourceLoaderContext $context
         *
         * @return string CSS data in script file
         * @throws MWException If the file doesn't exist
         */
-       protected function readStyleFile( $path, $flip, $context = null ) {
+       protected function readStyleFile( $path, $flip, $context ) {
                $localPath = $this->getLocalPath( $path );
                $remotePath = $this->getRemotePath( $path );
                if ( !file_exists( $localPath ) ) {
@@ -897,8 +904,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                }
 
                if ( $this->getStyleSheetLang( $localPath ) === 'less' ) {
-                       $compiler = $this->getLessCompiler( $context );
-                       $style = $this->compileLessFile( $localPath, $compiler );
+                       $style = $this->compileLessFile( $localPath, $context );
                        $this->hasGeneratedStyles = true;
                } else {
                        $style = file_get_contents( $localPath );
@@ -918,9 +924,8 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                                $this->missingLocalFileRefs[] = $file;
                        }
                }
-               return CSSMin::remap(
-                       $style, $localDir, $remoteDir, true
-               );
+               return MemoizedCallable::call( 'CSSMin::remap',
+                       array( $style, $localDir, $remoteDir, true ) );
        }
 
        /**
@@ -947,12 +952,13 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * Keeps track of all used files and adds them to localFileRefs.
         *
         * @since 1.22
+        * @since 1.27 Added $context paramter.
         * @throws Exception If less.php encounters a parse error
         * @param string $fileName File path of LESS source
-        * @param Less_Parser $parser Compiler to use, if not default
+        * @param ResourceLoaderContext $context Context in which to generate script
         * @return string CSS source
         */
-       protected function compileLessFile( $fileName, $compiler = null ) {
+       protected function compileLessFile( $fileName, ResourceLoaderContext $context ) {
                static $cache;
 
                if ( !$cache ) {
@@ -961,7 +967,9 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
 
                // Construct a cache key from the LESS file name and a hash digest
                // of the LESS variables used for compilation.
-               $varsHash = hash( 'md4', serialize( ResourceLoader::getLessVars( $this->getConfig() ) ) );
+               $vars = $this->getLessVars( $context );
+               ksort( $vars );
+               $varsHash = hash( 'md4', serialize( $vars ) );
                $cacheKey = wfGlobalCacheKey( 'LESS', $fileName, $varsHash );
                $cachedCompile = $cache->get( $cacheKey );
 
@@ -971,15 +979,12 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                if ( isset( $cachedCompile['hash'] ) ) {
                        $contentHash = FileContentsHasher::getFileContentsHash( $cachedCompile['files'] );
                        if ( $contentHash === $cachedCompile['hash'] ) {
-                               $this->localFileRefs += $cachedCompile['files'];
+                               $this->localFileRefs = array_merge( $this->localFileRefs, $cachedCompile['files'] );
                                return $cachedCompile['css'];
                        }
                }
 
-               if ( !$compiler ) {
-                       $compiler = $this->getLessCompiler();
-               }
-
+               $compiler = ResourceLoader::getLessCompiler( $this->getConfig(), $vars );
                $css = $compiler->parseFile( $fileName )->getCss();
                $files = $compiler->AllParsedFiles();
                $this->localFileRefs = array_merge( $this->localFileRefs, $files );
@@ -993,20 +998,6 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                return $css;
        }
 
-       /**
-        * Get a LESS compiler instance for this module in given context.
-        *
-        * Just calls ResourceLoader::getLessCompiler() by default to get a global compiler.
-        *
-        * @param ResourceLoaderContext $context
-        * @throws MWException
-        * @since 1.24
-        * @return Less_Parser
-        */
-       protected function getLessCompiler( ResourceLoaderContext $context = null ) {
-               return ResourceLoader::getLessCompiler( $this->getConfig() );
-       }
-
        /**
         * Takes named templates by the module and returns an array mapping.
         * @return array of templates mapping template alias to content