/** * Reads a style file. * * This method can be used as a callback for array_map() * * @param $path String: File path of style file to read * @param $flip bool * * @return String: CSS data in script file * @throws MWException if the file doesn't exist */ protected function readStyleFile($path, $flip) { $localPath = $this->getLocalPath($path); if (!file_exists($localPath)) { $msg = __METHOD__ . ": style file not found: \"{$localPath}\""; wfDebugLog('resourceloader', $msg); throw new MWException($msg); } $style = file_get_contents($localPath); if ($flip) { $style = CSSJanus::transform($style, true, false); } $dirname = dirname($path); if ($dirname == '.') { // If $path doesn't have a directory component, don't prepend a dot $dirname = ''; } $dir = $this->getLocalPath($dirname); $remoteDir = $this->getRemotePath($dirname); // Get and register local file references $this->localFileRefs = array_merge($this->localFileRefs, CSSMin::getLocalFileReferences($style, $dir)); return CSSMin::remap($style, $dir, $remoteDir, true); }
/** * Reads a style file. * * This method can be used as a callback for array_map() * * @param string $path File path of style file to read * @param bool $flip * @param ResourceLoaderContext $context * * @return string CSS data in script file * @throws MWException If the file doesn't exist */ protected function readStyleFile($path, $flip, $context) { $localPath = $this->getLocalPath($path); $remotePath = $this->getRemotePath($path); if (!file_exists($localPath)) { $msg = __METHOD__ . ": style file not found: \"{$localPath}\""; wfDebugLog('resourceloader', $msg); throw new MWException($msg); } if ($this->getStyleSheetLang($localPath) === 'less') { $style = $this->compileLessFile($localPath, $context); $this->hasGeneratedStyles = true; } else { $style = file_get_contents($localPath); } if ($flip) { $style = CSSJanus::transform($style, true, false); } $localDir = dirname($localPath); $remoteDir = dirname($remotePath); // Get and register local file references $localFileRefs = CSSMin::getLocalFileReferences($style, $localDir); foreach ($localFileRefs as $file) { if (file_exists($file)) { $this->localFileRefs[] = $file; } else { $this->missingLocalFileRefs[] = $file; } } // Don't cache this call. remap() ensures data URIs embeds are up to date, // and urls contain correct content hashes in their query string. (T128668) return CSSMin::remap($style, $localDir, $remoteDir, true); }
/** * Reads a style file. * * This method can be used as a callback for array_map() * * @param $path String: File path of style file to read * @param $flip bool * * @return String: CSS data in script file * @throws MWException if the file doesn't exist */ protected function readStyleFile($path, $flip, ResourceLoaderContext $context) { $localPath = $this->getLocalPath($path); if (!file_exists($localPath)) { throw new MWException(__METHOD__ . ": style file not found: \"{$localPath}\""); } // Wikia - change begin - @author: wladek $style = self::getFileContents($localPath, $context); // Wikia - change end if ($flip) { $style = CSSJanus::transform($style, true, false); } $dirname = dirname($path); if ($dirname == '.') { // If $path doesn't have a directory component, don't prepend a dot $dirname = ''; } $dir = $this->getLocalPath($dirname); $remoteDir = $this->getRemotePath($dirname, $context); // Get and register local file references $this->localFileRefs = array_merge($this->localFileRefs, CSSMin::getLocalFileReferences($style, $dir)); return CSSMin::remap($style, $dir, $remoteDir, true, $this->localBasePath); }
/** * CSSMin::getLocalFileReferences should ignore url(...) expressions * that have been commented out. */ public function testCommentedLocalFileReferences() { $basepath = __DIR__ . '/../data/css/'; $css = file_get_contents($basepath . 'comments.css'); $files = CSSMin::getLocalFileReferences($css, $basepath); $expected = [$basepath . 'not-commented.gif']; $this->assertArrayEquals($expected, $files, 'Url(...) expression in comment should be omitted.'); }
/** * Reads a style file. * * This method can be used as a callback for array_map() * * @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, $context = null) { $localPath = $this->getLocalPath($path); $remotePath = $this->getRemotePath($path); if (!file_exists($localPath)) { $msg = __METHOD__ . ": style file not found: \"{$localPath}\""; wfDebugLog('resourceloader', $msg); throw new MWException($msg); } if ($this->getStyleSheetLang($localPath) === 'less') { $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); } $localDir = dirname($localPath); $remoteDir = dirname($remotePath); // Get and register local file references $this->localFileRefs = array_merge($this->localFileRefs, CSSMin::getLocalFileReferences($style, $localDir)); return CSSMin::remap($style, $localDir, $remoteDir, true); }
/** * Reads a style file. * * This method can be used as a callback for array_map() * * @param $path String: File path of script file to read * @return String: CSS data in script file */ protected function readStyleFile($path, $flip) { $localPath = $this->getLocalPath($path); $style = file_get_contents($localPath); if ($style === false) { throw new MWException(__METHOD__ . ": style file not found: \"{$localPath}\""); } if ($flip) { $style = CSSJanus::transform($style, true, false); } $dir = $this->getLocalPath(dirname($path)); $remoteDir = $this->getRemotePath(dirname($path)); // Get and register local file references $this->localFileRefs = array_merge($this->localFileRefs, CSSMin::getLocalFileReferences($style, $dir)); return CSSMin::remap($style, $dir, $remoteDir, true); }