3 * ResourceLoader module for skin stylesheets.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 class ResourceLoaderSkinModule
extends ResourceLoaderFileModule
{
26 * All skins are assumed to be compatible with mobile
28 public $targets = [ 'desktop', 'mobile' ];
31 * @param ResourceLoaderContext $context
34 public function getStyles( ResourceLoaderContext
$context ) {
35 $logo = $this->getLogo( $this->getConfig() );
36 $styles = parent
::getStyles( $context );
37 $this->normalizeStyles( $styles );
39 $default = !is_array( $logo ) ?
$logo : $logo['1x'];
40 $styles['all'][] = '.mw-wiki-logo { background-image: ' .
41 CSSMin
::buildUrlValue( $default ) .
44 if ( is_array( $logo ) ) {
45 if ( isset( $logo['1.5x'] ) ) {
47 '(-webkit-min-device-pixel-ratio: 1.5), ' .
48 '(min--moz-device-pixel-ratio: 1.5), ' .
49 '(min-resolution: 1.5dppx), ' .
50 '(min-resolution: 144dpi)'
51 ][] = '.mw-wiki-logo { background-image: ' .
52 CSSMin
::buildUrlValue( $logo['1.5x'] ) . ';' .
53 'background-size: 135px auto; }';
55 if ( isset( $logo['2x'] ) ) {
57 '(-webkit-min-device-pixel-ratio: 2), ' .
58 '(min--moz-device-pixel-ratio: 2),' .
59 '(min-resolution: 2dppx), ' .
60 '(min-resolution: 192dpi)'
61 ][] = '.mw-wiki-logo { background-image: ' .
62 CSSMin
::buildUrlValue( $logo['2x'] ) . ';' .
63 'background-size: 135px auto; }';
71 * Ensure all media keys use array values.
73 * Normalises arrays returned by the ResourceLoaderFileModule::getStyles() method.
75 * @param array &$styles Associative array, keys are strings (media queries),
76 * values are strings or arrays
78 private function normalizeStyles( &$styles ) {
79 foreach ( $styles as $key => $val ) {
80 if ( !is_array( $val ) ) {
81 $styles[$key] = [ $val ];
88 * @return string|array Single url if no variants are defined
89 * or array of logo urls keyed by dppx in form "<float>x".
90 * Key "1x" is always defined.
92 public static function getLogo( Config
$conf ) {
93 $logo = $conf->get( 'Logo' );
94 $logoHD = $conf->get( 'LogoHD' );
96 $logo1Url = OutputPage
::transformResourcePath( $conf, $logo );
106 // Only 1.5x and 2x are supported
107 if ( isset( $logoHD['1.5x'] ) ) {
108 $logoUrls['1.5x'] = OutputPage
::transformResourcePath(
113 if ( isset( $logoHD['2x'] ) ) {
114 $logoUrls['2x'] = OutputPage
::transformResourcePath(
124 * @param ResourceLoaderContext $context
127 public function isKnownEmpty( ResourceLoaderContext
$context ) {
128 // Regardless of whether the files are specified, we always
129 // provide mw-wiki-logo styles.
133 public function getDefinitionSummary( ResourceLoaderContext
$context ) {
134 $summary = parent
::getDefinitionSummary( $context );
136 'logo' => $this->getConfig()->get( 'Logo' ),
137 'logoHD' => $this->getConfig()->get( 'LogoHD' ),