* @param string $localBasePath Base path to prepend to all local paths in $options. Defaults
* to $IP
* @param string $remoteBasePath Base path to prepend to all remote paths in $options. Defaults
- * to $wgScriptPath
+ * to $wgResourceBasePath
*
* Below is a description for the $options array:
* @throws MWException
* array(
* // Base path to prepend to all local paths in $options. Defaults to $IP
* 'localBasePath' => [base path],
- * // Base path to prepend to all remote paths in $options. Defaults to $wgScriptPath
+ * // Base path to prepend to all remote paths in $options. Defaults to $wgResourceBasePath
* 'remoteBasePath' => [base path],
* // Equivalent of remoteBasePath, but relative to $wgExtensionAssetsPath
* 'remoteExtPath' => [base path],
* @param string $localBasePath Path to use if not provided in module definition. Defaults
* to $IP
* @param string $remoteBasePath Path to use if not provided in module definition. Defaults
- * to $wgScriptPath
+ * to $wgResourceBasePath
* @return array Array( localBasePath, remoteBasePath )
*/
public static function extractBasePaths(
$localBasePath = null,
$remoteBasePath = null
) {
- global $IP, $wgScriptPath, $wgResourceBasePath;
+ global $IP, $wgResourceBasePath;
// The different ways these checks are done, and their ordering, look very silly,
// but were preserved for backwards-compatibility just in case. Tread lightly.
$localBasePath = $localBasePath === null ? $IP : $localBasePath;
if ( $remoteBasePath === null ) {
- $remoteBasePath = $wgResourceBasePath === null ? $wgScriptPath : $wgResourceBasePath;
+ $remoteBasePath = $wgResourceBasePath;
}
if ( isset( $options['remoteExtPath'] ) ) {
public function getStyles( ResourceLoaderContext $context ) {
$styles = $this->readStyleFiles(
$this->getStyleFiles( $context ),
- $this->getFlip( $context )
+ $this->getFlip( $context ),
+ $context
);
// Collect referenced files
$this->localFileRefs = array_unique( $this->localFileRefs );
*
* @param array $styles List of media type/list of file paths pairs, to read, remap and
* concetenate
- *
* @param bool $flip
+ * @param ResourceLoaderContext $context (optional)
*
* @throws MWException
* @return array List of concatenated and remapped CSS data from $styles,
* keyed by media type
*/
- public function readStyleFiles( array $styles, $flip ) {
+ public function readStyleFiles( array $styles, $flip, $context = null ) {
if ( empty( $styles ) ) {
return array();
}
$uniqueFiles = array_unique( $files, SORT_REGULAR );
$styleFiles = array();
foreach ( $uniqueFiles as $file ) {
- $styleFiles[] = $this->readStyleFile( $file, $flip );
+ $styleFiles[] = $this->readStyleFile( $file, $flip, $context );
}
$styles[$media] = implode( "\n", $styleFiles );
}
*
* @param string $path File path of style file to read
* @param bool $flip
+ * @param ResourceLoaderContext $context (optional)
*
* @return string CSS data in script file
* @throws MWException If the file doesn't exist
*/
- protected function readStyleFile( $path, $flip ) {
+ protected function readStyleFile( $path, $flip, $context = null ) {
$localPath = $this->getLocalPath( $path );
$remotePath = $this->getRemotePath( $path );
if ( !file_exists( $localPath ) ) {
}
if ( $this->getStyleSheetLang( $localPath ) === 'less' ) {
- $style = $this->compileLessFile( $localPath );
+ $compiler = $this->getLessCompiler( $context );
+ $style = $this->compileLessFile( $localPath, $compiler );
$this->hasGeneratedStyles = true;
} else {
$style = file_get_contents( $localPath );
if ( $flip ) {
$style = CSSJanus::transform( $style, true, false );
- } else {
- $style = CSSJanus::nullTransform( $style );
}
$localDir = dirname( $localPath );
$remoteDir = dirname( $remotePath );
* @since 1.22
* @throws Exception If lessc encounters a parse error
* @param string $fileName File path of LESS source
+ * @param lessc $compiler Compiler to use, if not default
* @return string CSS source
*/
- protected function compileLessFile( $fileName ) {
- $compiler = ResourceLoader::getLessCompiler( $this->getConfig() );
+ protected function compileLessFile( $fileName, $compiler = null ) {
+ if ( !$compiler ) {
+ $compiler = $this->getLessCompiler();
+ }
$result = $compiler->compileFile( $fileName );
$this->localFileRefs += array_keys( $compiler->allParsedFiles() );
return $result;
}
+
+ /**
+ * 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() );
+ }
}