}
/**
- * 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.
+ * Get the stylesheet of the MediaWiki skin.
*
* @return string
*/
public function getCSS() {
- // All CSS files these modules reference will be concatenated in sequence
- // and loaded as one file.
$moduleNames = array(
+ // See SkinTemplate::setupSkinUserCss
'mediawiki.legacy.shared',
+ // See Vector::setupSkinUserCss
'mediawiki.skinning.interface',
'skins.vector.styles',
+
'mediawiki.legacy.config',
);
- $prepend = '';
$css = '';
$resourceLoader = new ResourceLoader();
+ $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( array(
+ 'debug' => 'true',
+ 'lang' => $this->getLanguageCode(),
+ 'only' => 'styles',
+ 'skin' => 'vector',
+ ) ) );
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(
- /* source */ $cssFileContents,
- /* local */ $cssDirName,
- /* remote */ '..' . str_replace(
- array( $GLOBALS['IP'], DIRECTORY_SEPARATOR ),
- array( '', '/' ),
- $cssDirName
- ),
- /* embedData */ false
- );
- } else {
- $prepend .= ResourceLoader::makeComment( "Unable to read $cssFileName." );
- }
- } catch ( Exception $e ) {
- $prepend .= ResourceLoader::formatException( $e );
- }
-
- $css .= "\n";
- }
- wfRestoreWarnings();
- }
- $css = $prepend . $css;
+ // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
+ $styles = ResourceLoader::makeCombinedStyles( $module->readStyleFiles(
+ $module->getStyleFiles( $rlContext ),
+ $module->getFlip( $rlContext )
+ ) );
- if ( $this->getDir() == 'rtl' ) {
- $css = CSSJanus::transform( $css, true );
+ $css .= implode( "\n", $styles );
}
return $css;
// Don't create empty stylesheets like array( '' => '' ) for modules
// that don't *have* any stylesheets (bug 38024).
$stylePairs = $module->getStyles( $context );
- if ( count ( $stylePairs ) ) {
+ if ( count( $stylePairs ) ) {
// If we are in debug mode without &only= set, we'll want to return an array of URLs
// See comment near shouldIncludeScripts() for more details
if ( $context->getDebug() && !$context->getOnly() && $module->supportsURLLoading() ) {
* @param array $stylePairs Array keyed by media type containing (arrays of) CSS strings
* @return array
*/
- private static function makeCombinedStyles( array $stylePairs ) {
+ public static function makeCombinedStyles( array $stylePairs ) {
$out = array();
foreach ( $stylePairs as $media => $styles ) {
// ResourceLoaderFileModule::getStyle can return the styles
}
/**
- * Gets loader script.
+ * Get loader script.
*
- * @return string JavaScript code to be added to startup module
+ * @return string|false JavaScript code to be added to startup module
*/
public function getLoaderScript() {
- if ( count( $this->loaderScripts ) == 0 ) {
+ if ( count( $this->loaderScripts ) === 0 ) {
return false;
}
return $this->readScriptFiles( $this->loaderScripts );
}
/**
- * Gets all styles for a given context concatenated together.
+ * Get all styles for a given context.
*
- * @param ResourceLoaderContext $context Context in which to generate styles
- * @return string CSS code for $context
+ * @param ResourceLoaderContext $context
+ * @return array CSS code for $context as an associative array mapping media type to CSS text.
*/
public function getStyles( ResourceLoaderContext $context ) {
$styles = $this->readStyleFiles(
}
/**
- * Gets a list of element that match a key, optionally using a fallback key.
+ * Get a list of element that match a key, optionally using a fallback key.
*
* @param array $list List of lists to select from
* @param string $key Key to look for in $map
* @param string $fallback Key to look for in $list if $key doesn't exist
* @return array List of elements from $map which matched $key or $fallback,
- * or an empty list in case of no match
+ * or an empty list in case of no match
*/
protected static function tryForKey( array $list, $key, $fallback = null ) {
if ( isset( $list[$key] ) && is_array( $list[$key] ) ) {
}
/**
- * Gets a list of file paths for all scripts in this module, in order of propper execution.
+ * Get a list of file paths for all scripts in this module, in order of proper execution.
*
* @param ResourceLoaderContext $context
* @return array List of file paths
}
/**
- * Gets a list of file paths for all styles in this module, in order of propper inclusion.
+ * Get a list of file paths for all styles in this module, in order of proper inclusion.
*
* @param ResourceLoaderContext $context
* @return array List of file paths
*/
- protected function getStyleFiles( ResourceLoaderContext $context ) {
+ public function getStyleFiles( ResourceLoaderContext $context ) {
return array_merge_recursive(
self::collateFilePathListByOption( $this->styles, 'media', 'all' ),
self::collateFilePathListByOption(
* @return array List of concatenated and remapped CSS data from $styles,
* keyed by media type
*/
- protected function readStyleFiles( array $styles, $flip ) {
+ public function readStyleFiles( array $styles, $flip ) {
if ( empty( $styles ) ) {
return array();
}