* 'selectorWithVariant' => [CSS selector template, variables: {prefix} {name} {variant}],
* // List of variants that may be used for the image files
* 'variants' => [
- * [theme name] => [
+ * // This level of nesting can be omitted if you use the same images for every skin
+ * [skin name (or 'default')] => [
* [variant name] => [
* 'color' => [color string, e.g. '#ffff00'],
* 'global' => [boolean, if true, this variant is available
* ],
* // List of image files and their options
* 'images' => [
- * [theme name] => [
+ * // This level of nesting can be omitted if you use the same images for every skin
+ * [skin name (or 'default')] => [
* [icon name] => [
* 'file' => [file path string or array whose values are file path strings
* and whose keys are 'default', 'ltr', 'rtl', a single
$selectors = $this->getSelectors();
foreach ( $this->getImages( $context ) as $name => $image ) {
- $declarations = $this->getCssDeclarations(
- $image->getDataUri( $context, null, 'original' ),
- $image->getUrl( $context, $script, null, 'rasterized' )
- );
- $declarations = implode( "\n\t", $declarations );
+ $declarations = $this->getStyleDeclarations( $context, $image, $script );
$selector = strtr(
$selectors['selectorWithoutVariant'],
[
$rules[] = "$selector {\n\t$declarations\n}";
foreach ( $image->getVariants() as $variant ) {
- $declarations = $this->getCssDeclarations(
- $image->getDataUri( $context, $variant, 'original' ),
- $image->getUrl( $context, $script, $variant, 'rasterized' )
- );
- $declarations = implode( "\n\t", $declarations );
+ $declarations = $this->getStyleDeclarations( $context, $image, $script, $variant );
$selector = strtr(
$selectors['selectorWithVariant'],
[
return [ 'all' => $style ];
}
+ /**
+ * @param ResourceLoaderContext $context
+ * @param ResourceLoaderImage $image Image to get the style for
+ * @param string $script URL to load.php
+ * @param string|null $variant Variant to get the style for
+ * @return string
+ */
+ private function getStyleDeclarations(
+ ResourceLoaderContext $context,
+ ResourceLoaderImage $image,
+ $script,
+ $variant = null
+ ) {
+ $imageDataUri = $image->getDataUri( $context, $variant, 'original' );
+ $primaryUrl = $imageDataUri ?: $image->getUrl( $context, $script, $variant, 'original' );
+ $declarations = $this->getCssDeclarations(
+ $primaryUrl,
+ $image->getUrl( $context, $script, $variant, 'rasterized' )
+ );
+ return implode( "\n\t", $declarations );
+ }
+
/**
* SVG support using a transparent gradient to guarantee cross-browser
* compatibility (browsers able to understand gradient syntax support also SVG).
* @return string[] CSS declarations to use given URIs as background-image
*/
protected function getCssDeclarations( $primary, $fallback ) {
+ $primaryUrl = CSSMin::buildUrlValue( $primary );
+ $fallbackUrl = CSSMin::buildUrlValue( $fallback );
return [
- "background-image: url($fallback);",
- "background-image: linear-gradient(transparent, transparent), url($primary);",
+ "background-image: $fallbackUrl;",
+ "background-image: linear-gradient(transparent, transparent), $primaryUrl;",
// Do not serve SVG to Opera 12, bad rendering with border-radius or background-size (T87504)
- "background-image: -o-linear-gradient(transparent, transparent), url($fallback);",
+ "background-image: -o-linear-gradient(transparent, transparent), $fallbackUrl;",
];
}
/**
* Helper method for getDefinitionSummary.
+ * @param ResourceLoaderContext $context
+ * @return array
*/
protected function getFileHashes( ResourceLoaderContext $context ) {
$this->loadFromDefinition();