5740925d2a4585dbd564b827993b177bbdd108e3
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderSkinModule.php
1 <?php
2 /**
3 * ResourceLoader module for skin stylesheets.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Timo Tijhof
22 */
23
24 class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
25
26 /**
27 * @param ResourceLoaderContext $context
28 * @return array
29 */
30 public function getStyles( ResourceLoaderContext $context ) {
31 $logo = $this->getLogo( $this->getConfig() );
32 $styles = parent::getStyles( $context );
33
34 $default = !is_array( $logo ) ? $logo : $logo['1x'];
35 $styles['all'][] = '.mw-wiki-logo { background-image: ' .
36 CSSMin::buildUrlValue( $default ) .
37 '; }';
38
39 if ( is_array( $logo ) ) {
40 if ( isset( $logo['1.5x'] ) ) {
41 $styles[
42 '(-webkit-min-device-pixel-ratio: 1.5), ' .
43 '(min--moz-device-pixel-ratio: 1.5), ' .
44 '(min-resolution: 1.5dppx), ' .
45 '(min-resolution: 144dpi)'
46 ][] = '.mw-wiki-logo { background-image: ' .
47 CSSMin::buildUrlValue( $logo['1.5x'] ) . ';' .
48 'background-size: 135px auto; }';
49 }
50 if ( isset( $logo['2x'] ) ) {
51 $styles[
52 '(-webkit-min-device-pixel-ratio: 2), ' .
53 '(min--moz-device-pixel-ratio: 2),' .
54 '(min-resolution: 2dppx), ' .
55 '(min-resolution: 192dpi)'
56 ][] = '.mw-wiki-logo { background-image: ' .
57 CSSMin::buildUrlValue( $logo['2x'] ) . ';' .
58 'background-size: 135px auto; }';
59 }
60 }
61
62 return $styles;
63 }
64
65 /**
66 * @param Config $conf
67 * @return string|array Single url if no variants are defined
68 * or array of logo urls keyed by dppx in form "<float>x".
69 * Key "1x" is always defined.
70 */
71 public static function getLogo( Config $conf ) {
72 $logo = $conf->get( 'Logo' );
73 $logoHD = $conf->get( 'LogoHD' );
74
75 $logo1Url = OutputPage::transformResourcePath( $conf, $logo );
76
77 if ( !$logoHD ) {
78 return $logo1Url;
79 }
80
81 $logoUrls = [
82 '1x' => $logo1Url,
83 ];
84
85 // Only 1.5x and 2x are supported
86 if ( isset( $logoHD['1.5x'] ) ) {
87 $logoUrls['1.5x'] = OutputPage::transformResourcePath(
88 $conf,
89 $logoHD['1.5x']
90 );
91 }
92 if ( isset( $logoHD['2x'] ) ) {
93 $logoUrls['2x'] = OutputPage::transformResourcePath(
94 $conf,
95 $logoHD['2x']
96 );
97 }
98
99 return $logoUrls;
100 }
101
102 /**
103 * @param ResourceLoaderContext $context
104 * @return bool
105 */
106 public function isKnownEmpty( ResourceLoaderContext $context ) {
107 // Regardless of whether the files are specified, we always
108 // provide mw-wiki-logo styles.
109 return false;
110 }
111
112 public function getDefinitionSummary( ResourceLoaderContext $context ) {
113 $summary = parent::getDefinitionSummary( $context );
114 $summary[] = [
115 'logo' => $this->getConfig()->get( 'Logo' ),
116 'logoHD' => $this->getConfig()->get( 'LogoHD' ),
117 ];
118 return $summary;
119 }
120 }