Merge "RCFilters: Change tooltip messages for view buttons"
[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 * All skins are assumed to be compatible with mobile
27 */
28 public $targets = [ 'desktop', 'mobile' ];
29
30 /**
31 * @param ResourceLoaderContext $context
32 * @return array
33 */
34 public function getStyles( ResourceLoaderContext $context ) {
35 $logo = $this->getLogo( $this->getConfig() );
36 $styles = parent::getStyles( $context );
37
38 $default = !is_array( $logo ) ? $logo : $logo['1x'];
39 $styles['all'][] = '.mw-wiki-logo { background-image: ' .
40 CSSMin::buildUrlValue( $default ) .
41 '; }';
42
43 if ( is_array( $logo ) ) {
44 if ( isset( $logo['1.5x'] ) ) {
45 $styles[
46 '(-webkit-min-device-pixel-ratio: 1.5), ' .
47 '(min--moz-device-pixel-ratio: 1.5), ' .
48 '(min-resolution: 1.5dppx), ' .
49 '(min-resolution: 144dpi)'
50 ][] = '.mw-wiki-logo { background-image: ' .
51 CSSMin::buildUrlValue( $logo['1.5x'] ) . ';' .
52 'background-size: 135px auto; }';
53 }
54 if ( isset( $logo['2x'] ) ) {
55 $styles[
56 '(-webkit-min-device-pixel-ratio: 2), ' .
57 '(min--moz-device-pixel-ratio: 2),' .
58 '(min-resolution: 2dppx), ' .
59 '(min-resolution: 192dpi)'
60 ][] = '.mw-wiki-logo { background-image: ' .
61 CSSMin::buildUrlValue( $logo['2x'] ) . ';' .
62 'background-size: 135px auto; }';
63 }
64 }
65
66 return $styles;
67 }
68
69 /**
70 * @param Config $conf
71 * @return string|array Single url if no variants are defined
72 * or array of logo urls keyed by dppx in form "<float>x".
73 * Key "1x" is always defined.
74 */
75 public static function getLogo( Config $conf ) {
76 $logo = $conf->get( 'Logo' );
77 $logoHD = $conf->get( 'LogoHD' );
78
79 $logo1Url = OutputPage::transformResourcePath( $conf, $logo );
80
81 if ( !$logoHD ) {
82 return $logo1Url;
83 }
84
85 $logoUrls = [
86 '1x' => $logo1Url,
87 ];
88
89 // Only 1.5x and 2x are supported
90 if ( isset( $logoHD['1.5x'] ) ) {
91 $logoUrls['1.5x'] = OutputPage::transformResourcePath(
92 $conf,
93 $logoHD['1.5x']
94 );
95 }
96 if ( isset( $logoHD['2x'] ) ) {
97 $logoUrls['2x'] = OutputPage::transformResourcePath(
98 $conf,
99 $logoHD['2x']
100 );
101 }
102
103 return $logoUrls;
104 }
105
106 /**
107 * @param ResourceLoaderContext $context
108 * @return bool
109 */
110 public function isKnownEmpty( ResourceLoaderContext $context ) {
111 // Regardless of whether the files are specified, we always
112 // provide mw-wiki-logo styles.
113 return false;
114 }
115
116 public function getDefinitionSummary( ResourceLoaderContext $context ) {
117 $summary = parent::getDefinitionSummary( $context );
118 $summary[] = [
119 'logo' => $this->getConfig()->get( 'Logo' ),
120 'logoHD' => $this->getConfig()->get( 'LogoHD' ),
121 ];
122 return $summary;
123 }
124 }