Esempio n. 1
0
 /**
  * This tests basic functionality of CSSMin::remap. testRemapRemapping tests funky parameters.
  *
  * @dataProvider provideRemapRemappingCases
  * @covers CSSMin::remap
  */
 public function testRemapRemapping($message, $input, $expectedOutput)
 {
     $localPath = __DIR__ . '/../../data/cssmin/';
     $remotePath = 'http://localhost/w/';
     $realOutput = CSSMin::remap($input, $localPath, $remotePath);
     $this->assertEquals($expectedOutput, $realOutput, "CSSMin::remap: {$message}");
 }
Esempio n. 2
0
 /**
  * This tests basic functionality of CSSMin::remap. testRemapRemapping tests funky parameters.
  *
  * @dataProvider provideRemapRemappingCases
  * @covers CSSMin::remap
  */
 public function testRemapRemapping($message, $input, $expectedOutput)
 {
     $localPath = __DIR__ . '/../../data/cssmin/';
     $remotePath = 'http://localhost/w/';
     $realOutput = CSSMin::remap($input, $localPath, $remotePath);
     $this->assertEquals($expectedOutput, preg_replace('/\\d+-\\d+-\\d+T\\d+:\\d+:\\d+Z/', 'timestamp', $realOutput), "CSSMin::remap: {$message}");
 }
Esempio n. 3
0
 public function minimizeFiles($files)
 {
     $css_out = '';
     $webroot = (string) OC::$WEBROOT;
     foreach ($files as $file_info) {
         $file = $file_info[0] . '/' . $file_info[2];
         $css_out .= '/* ' . $file . ' */' . "\n";
         $css = file_get_contents($file);
         $in_root = false;
         foreach (OC::$APPSROOTS as $app_root) {
             if (strpos($file, $app_root['path'] . '/') === 0) {
                 $in_root = rtrim($webroot . $app_root['url'], '/');
                 break;
             }
         }
         if ($in_root !== false) {
             $css = str_replace('%appswebroot%', $in_root, $css);
             $css = str_replace('%webroot%', $webroot, $css);
         }
         $remote = $file_info[1];
         $remote .= '/';
         $remote .= dirname($file_info[2]);
         $css_out .= CSSMin::remap($css, dirname($file), $remote, true);
     }
     if (!defined('DEBUG') || !DEBUG) {
         $css_out = CSSMin::minify($css_out);
     }
     return $css_out;
 }
 /**
  * @param $context ResourceLoaderContext
  * @return array
  */
 public function getStyles(ResourceLoaderContext $context)
 {
     global $wgScriptPath;
     $styles = array();
     foreach ($this->getPages($context) as $titleText => $options) {
         if ($options['type'] !== 'style') {
             continue;
         }
         $title = Title::newFromText($titleText);
         if (!$title || $title->isRedirect()) {
             continue;
         }
         $media = isset($options['media']) ? $options['media'] : 'all';
         $style = $this->getContent($title);
         if (strval($style) === '') {
             continue;
         }
         if ($this->getFlip($context)) {
             $style = CSSJanus::transform($style, true, false);
         }
         $style = CSSMin::remap($style, false, $wgScriptPath, true);
         if (!isset($styles[$media])) {
             $styles[$media] = array();
         }
         if (strpos($titleText, '*/') === false) {
             $style = "/* {$titleText} */\n" . $style;
         }
         $styles[$media][] = $style;
     }
     return $styles;
 }
 /**
  * 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);
 }
 /**
  * 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
     $localFileRefs = CSSMin::getAllLocalFileReferences($style, $localDir);
     foreach ($localFileRefs as $file) {
         if (file_exists($file)) {
             $this->localFileRefs[] = $file;
         } else {
             $this->missingLocalFileRefs[] = $file;
         }
     }
     return CSSMin::remap($style, $localDir, $remoteDir, true);
 }
 /**
  * @param ResourceLoaderContext $context
  * @return array
  */
 public function getStyles(ResourceLoaderContext $context)
 {
     $styles = array();
     foreach ($this->getPages($context) as $titleText => $options) {
         if ($options['type'] !== 'style') {
             continue;
         }
         $media = isset($options['media']) ? $options['media'] : 'all';
         $style = $this->getContent($titleText);
         if (strval($style) === '') {
             continue;
         }
         if ($this->getFlip($context)) {
             $style = CSSJanus::transform($style, true, false);
         }
         $style = CSSMin::remap($style, false, $this->getConfig()->get('ScriptPath'), true);
         if (!isset($styles[$media])) {
             $styles[$media] = array();
         }
         $style = ResourceLoader::makeComment($titleText) . $style;
         $styles[$media][] = $style;
     }
     return $styles;
 }
Esempio n. 10
0
 /**
  * Get the raw vector CSS, flipping if needed
  *
  * @todo Possibly get rid of this function and use ResourceLoader in the manner it was
  *   designed to be used in, rather than just grabbing a list of filenames from it,
  *   and not properly handling such details as media types in module definitions.
  *
  * @param string $dir 'ltr' or 'rtl'
  * @return String
  */
 public function getCSS($dir)
 {
     // All CSS files these modules reference will be concatenated in sequence
     // and loaded as one file.
     $moduleNames = array('mediawiki.legacy.shared', 'skins.common.interface', 'skins.vector.styles', 'mediawiki.legacy.config');
     $prepend = '';
     $css = '';
     $resourceLoader = new ResourceLoader();
     foreach ($moduleNames as $moduleName) {
         /** @var ResourceLoaderFileModule $module */
         $module = $resourceLoader->getModule($moduleName);
         $cssFileNames = $module->getAllStyleFiles();
         wfSuppressWarnings();
         foreach ($cssFileNames as $cssFileName) {
             if (!file_exists($cssFileName)) {
                 $prepend .= ResourceLoader::makeComment("Unable to find {$cssFileName}.");
                 continue;
             }
             if (!is_readable($cssFileName)) {
                 $prepend .= ResourceLoader::makeComment("Unable to read {$cssFileName}. " . "Please check file permissions.");
                 continue;
             }
             try {
                 if (preg_match('/\\.less$/', $cssFileName)) {
                     // Run the LESS compiler for *.less files (bug 55589)
                     $compiler = ResourceLoader::getLessCompiler();
                     $cssFileContents = $compiler->compileFile($cssFileName);
                 } else {
                     // Regular CSS file
                     $cssFileContents = file_get_contents($cssFileName);
                 }
                 if ($cssFileContents) {
                     // Rewrite URLs, though don't bother embedding images. While static image
                     // files may be cached, CSS returned by this function is definitely not.
                     $cssDirName = dirname($cssFileName);
                     $css .= CSSMin::remap($cssFileContents, $cssDirName, '..' . str_replace(array($GLOBALS['IP'], DIRECTORY_SEPARATOR), array('', '/'), $cssDirName), false);
                 } else {
                     $prepend .= ResourceLoader::makeComment("Unable to read {$cssFileName}.");
                 }
             } catch (Exception $e) {
                 $prepend .= ResourceLoader::formatException($e);
             }
             $css .= "\n";
         }
         wfRestoreWarnings();
     }
     $css = $prepend . $css;
     if ($dir == 'rtl') {
         $css = CSSJanus::transform($css, true);
     }
     return $css;
 }
 /**
  * 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);
 }