/** Associative array mapping module name to info associative array */
protected $moduleInfos = array();
-
+
/** Associative array mapping framework ids to a list of names of test suite modules */
/** like array( 'qunit' => array( 'mediawiki.tests.qunit.suites', 'ext.foo.tests', .. ), .. ) */
protected $testModuleNames = array();
$wgResourceLoaderMinifierStatementsOnOwnLine,
$wgResourceLoaderMinifierMaxLineLength
);
- $result .= "\n\n/* cache key: $key */\n";
+ $result .= "\n/* cache key: $key */";
break;
case 'minify-css':
$result = CSSMin::minify( $data );
- $result .= "\n\n/* cache key: $key */\n";
+ $result .= "\n/* cache key: $key */";
break;
}
*
* @param $id Mixed: source ID (string), or array( id1 => props1, id2 => props2, ... )
* @param $properties Array: source properties
+ * @throws MWException
*/
public function addSource( $id, $properties = null) {
// Allow multiple sources to be registered in one call
public function getModuleNames() {
return array_keys( $this->moduleInfos );
}
-
+
/**
* Get a list of test module names for one (or all) frameworks.
* If the given framework id is unknkown, or if the in-object variable is not an array,
$scripts = $module->getScriptURLsForDebug( $context );
} else {
$scripts = $module->getScript( $context );
- if ( is_string( $scripts ) ) {
+ if ( is_string( $scripts ) && strlen( $scripts ) && substr( $scripts, -1 ) !== ';' ) {
// bug 27054: Append semicolon to prevent weird bugs
// caused by files not terminating their statements right
$scripts .= ";\n";
// 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() ) {
- $styles = $module->getStyleURLsForDebug( $context );
+ $styles = array(
+ 'url' => $module->getStyleURLsForDebug( $context )
+ );
} else {
// Minify CSS before embedding in mw.loader.implement call
// (unless in debug mode)
if ( !$context->getDebug() ) {
foreach ( $stylePairs as $media => $style ) {
- if ( is_string( $style ) ) {
+ // Can be either a string or an array of strings.
+ if ( is_array( $style ) ) {
+ $stylePairs[$media] = array();
+ foreach ( $style as $cssText ) {
+ if ( is_string( $cssText ) ) {
+ $stylePairs[$media][] = $this->filter( 'minify-css', $cssText );
+ }
+ }
+ } elseif ( is_string( $style ) ) {
$stylePairs[$media] = $this->filter( 'minify-css', $style );
}
}
}
- // Combine styles into @media groups as one big string
- $styles = array( '' => self::makeCombinedStyles( $stylePairs ) );
+ // Wrap styles into @media groups as needed and flatten into a numerical array
+ $styles = array(
+ 'css' => self::makeCombinedStyles( $stylePairs )
+ );
}
}
}
}
break;
case 'styles':
- // We no longer seperate into media, they are all concatenated now with
- // custom media type groups into @media .. {} sections.
- // Module returns either an empty array or an array with '' (no media type) as
- // only key.
- $out .= isset( $styles[''] ) ? $styles[''] : '';
+ // We no longer seperate into media, they are all combined now with
+ // custom media type groups into @media .. {} sections as part of the css string.
+ // Module returns either an empty array or a numerical array with css strings.
+ $out .= isset( $styles['css'] ) ? implode( '', $styles['css'] ) : '';
break;
case 'messages':
$out .= self::makeMessageSetScript( new XmlJsCode( $messagesBlob ) );
* associative array mapping message key to value, or a JSON-encoded message blob containing
* the same data, wrapped in an XmlJsCode object.
*
+ * @throws MWException
* @return string
*/
public static function makeLoaderImplementScript( $name, $scripts, $styles, $messages ) {
* Combines an associative array mapping media type to CSS into a
* single stylesheet with "@media" blocks.
*
- * @param $styles Array: List of CSS strings keyed by media type
+ * @param $stylePairs Array: Array keyed by media type containing (arrays of) CSS strings.
*
- * @return string
+ * @return Array
*/
- public static function makeCombinedStyles( array $styles ) {
- $out = '';
- foreach ( $styles as $media => $style ) {
- // Transform the media type based on request params and config
- // The way that this relies on $wgRequest to propagate request params is slightly evil
- $media = OutputPage::transformCssMedia( $media );
-
- if ( $media === null ) {
- // Skip
- } elseif ( $media === '' || $media == 'all' ) {
- // Don't output invalid or frivolous @media statements
- $out .= "$style\n";
- } else {
- $out .= "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "\n}\n";
+ private static function makeCombinedStyles( array $stylePairs ) {
+ $out = array();
+ foreach ( $stylePairs as $media => $styles ) {
+ // ResourceLoaderFileModule::getStyle can return the styles
+ // as a string or an array of strings. This is to allow separation in
+ // the front-end.
+ $styles = (array) $styles;
+ foreach ( $styles as $style ) {
+ $style = trim( $style );
+ // Don't output an empty "@media print { }" block (bug 40498)
+ if ( $style !== '' ) {
+ // Transform the media type based on request params and config
+ // The way that this relies on $wgRequest to propagate request params is slightly evil
+ $media = OutputPage::transformCssMedia( $media );
+
+ if ( $media === '' || $media == 'all' ) {
+ $out[] = $style;
+ } else if ( is_string( $media ) ) {
+ $out[] = "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "}";
+ }
+ // else: skip
+ }
}
}
return $out;