- /**
- * 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 lessc
- */
- protected function getLessCompiler( ResourceLoaderContext $context = null ) {
- return ResourceLoader::getLessCompiler( $this->getConfig() );
+ // Construct a cache key from the LESS file name and a hash digest
+ // of the LESS variables used for compilation.
+ $vars = $this->getLessVars( $context );
+ ksort( $vars );
+ $varsHash = hash( 'md4', serialize( $vars ) );
+ $cacheKey = wfGlobalCacheKey( 'LESS', $fileName, $varsHash );
+ $cachedCompile = $cache->get( $cacheKey );
+
+ // If we got a cached value, we have to validate it by getting a
+ // checksum of all the files that were loaded by the parser and
+ // ensuring it matches the cached entry's.
+ if ( isset( $cachedCompile['hash'] ) ) {
+ $contentHash = FileContentsHasher::getFileContentsHash( $cachedCompile['files'] );
+ if ( $contentHash === $cachedCompile['hash'] ) {
+ $this->localFileRefs += $cachedCompile['files'];
+ return $cachedCompile['css'];
+ }
+ }
+
+ $compiler = ResourceLoader::getLessCompiler( $this->getConfig(), $vars );
+ $css = $compiler->parseFile( $fileName )->getCss();
+ $files = $compiler->AllParsedFiles();
+ $this->localFileRefs = array_merge( $this->localFileRefs, $files );
+
+ $cache->set( $cacheKey, array(
+ 'css' => $css,
+ 'files' => $files,
+ 'hash' => FileContentsHasher::getFileContentsHash( $files ),
+ ), 60 * 60 * 24 ); // 86400 seconds, or 24 hours.
+
+ return $css;