MediaWiki REL1_33
ResourceLoaderSkinModule.php
Go to the documentation of this file.
1<?php
28 public $targets = [ 'desktop', 'mobile' ];
29
35 $logo = $this->getLogoData( $this->getConfig() );
36 $styles = parent::getStyles( $context );
37 $this->normalizeStyles( $styles );
38
39 $default = !is_array( $logo ) ? $logo : $logo['1x'];
40 $styles['all'][] = '.mw-wiki-logo { background-image: ' .
41 CSSMin::buildUrlValue( $default ) .
42 '; }';
43
44 if ( is_array( $logo ) ) {
45 if ( isset( $logo['svg'] ) ) {
46 $styles['all'][] = '.mw-wiki-logo { ' .
47 'background-image: -webkit-linear-gradient(transparent, transparent), ' .
48 CSSMin::buildUrlValue( $logo['svg'] ) . '; ' .
49 'background-image: linear-gradient(transparent, transparent), ' .
50 CSSMin::buildUrlValue( $logo['svg'] ) . ';' .
51 'background-size: 135px auto; }';
52 } else {
53 if ( isset( $logo['1.5x'] ) ) {
54 $styles[
55 '(-webkit-min-device-pixel-ratio: 1.5), ' .
56 '(min--moz-device-pixel-ratio: 1.5), ' .
57 '(min-resolution: 1.5dppx), ' .
58 '(min-resolution: 144dpi)'
59 ][] = '.mw-wiki-logo { background-image: ' .
60 CSSMin::buildUrlValue( $logo['1.5x'] ) . ';' .
61 'background-size: 135px auto; }';
62 }
63 if ( isset( $logo['2x'] ) ) {
64 $styles[
65 '(-webkit-min-device-pixel-ratio: 2), ' .
66 '(min--moz-device-pixel-ratio: 2), ' .
67 '(min-resolution: 2dppx), ' .
68 '(min-resolution: 192dpi)'
69 ][] = '.mw-wiki-logo { background-image: ' .
70 CSSMin::buildUrlValue( $logo['2x'] ) . ';' .
71 'background-size: 135px auto; }';
72 }
73 }
74 }
75
76 return $styles;
77 }
78
84 return $this->getLogoPreloadlinks();
85 }
86
91 private function getLogoPreloadlinks() {
92 $logo = $this->getLogoData( $this->getConfig() );
93
94 $logosPerDppx = [];
95 $logos = [];
96
97 $preloadLinks = [];
98
99 if ( !is_array( $logo ) ) {
100 // No media queries required if we only have one variant
101 $preloadLinks[$logo] = [ 'as' => 'image' ];
102 return $preloadLinks;
103 }
104
105 if ( isset( $logo['svg'] ) ) {
106 // No media queries required if we only have a 1x and svg variant
107 // because all preload-capable browsers support SVGs
108 $preloadLinks[$logo['svg']] = [ 'as' => 'image' ];
109 return $preloadLinks;
110 }
111
112 foreach ( $logo as $dppx => $src ) {
113 // Keys are in this format: "1.5x"
114 $dppx = substr( $dppx, 0, -1 );
115 $logosPerDppx[$dppx] = $src;
116 }
117
118 // Because PHP can't have floats as array keys
119 uksort( $logosPerDppx, function ( $a, $b ) {
120 $a = floatval( $a );
121 $b = floatval( $b );
122 // Sort from smallest to largest (e.g. 1x, 1.5x, 2x)
123 return $a <=> $b;
124 } );
125
126 foreach ( $logosPerDppx as $dppx => $src ) {
127 $logos[] = [
128 'dppx' => $dppx,
129 'src' => $src
130 ];
131 }
132
133 $logosCount = count( $logos );
134 // Logic must match ResourceLoaderSkinModule:
135 // - 1x applies to resolution < 1.5dppx
136 // - 1.5x applies to resolution >= 1.5dppx && < 2dppx
137 // - 2x applies to resolution >= 2dppx
138 // Note that min-resolution and max-resolution are both inclusive.
139 for ( $i = 0; $i < $logosCount; $i++ ) {
140 if ( $i === 0 ) {
141 // Smallest dppx
142 // min-resolution is ">=" (larger than or equal to)
143 // "not min-resolution" is essentially "<"
144 $media_query = 'not all and (min-resolution: ' . $logos[1]['dppx'] . 'dppx)';
145 } elseif ( $i !== $logosCount - 1 ) {
146 // In between
147 // Media query expressions can only apply "not" to the entire expression
148 // (e.g. can't express ">= 1.5 and not >= 2).
149 // Workaround: Use <= 1.9999 in place of < 2.
150 $upper_bound = floatval( $logos[$i + 1]['dppx'] ) - 0.000001;
151 $media_query = '(min-resolution: ' . $logos[$i]['dppx'] .
152 'dppx) and (max-resolution: ' . $upper_bound . 'dppx)';
153 } else {
154 // Largest dppx
155 $media_query = '(min-resolution: ' . $logos[$i]['dppx'] . 'dppx)';
156 }
157
158 $preloadLinks[$logos[$i]['src']] = [
159 'as' => 'image',
160 'media' => $media_query
161 ];
162 }
163
164 return $preloadLinks;
165 }
166
175 private function normalizeStyles( &$styles ) {
176 foreach ( $styles as $key => $val ) {
177 if ( !is_array( $val ) ) {
178 $styles[$key] = [ $val ];
179 }
180 }
181 }
182
191 protected function getLogoData( Config $conf ) {
192 $logo = $conf->get( 'Logo' );
193 $logoHD = $conf->get( 'LogoHD' );
194
195 $logo1Url = OutputPage::transformResourcePath( $conf, $logo );
196
197 if ( !$logoHD ) {
198 return $logo1Url;
199 }
200
201 $logoUrls = [
202 '1x' => $logo1Url,
203 ];
204
205 if ( isset( $logoHD['svg'] ) ) {
206 $logoUrls['svg'] = OutputPage::transformResourcePath(
207 $conf,
208 $logoHD['svg']
209 );
210 } else {
211 // Only 1.5x and 2x are supported
212 if ( isset( $logoHD['1.5x'] ) ) {
213 $logoUrls['1.5x'] = OutputPage::transformResourcePath(
214 $conf,
215 $logoHD['1.5x']
216 );
217 }
218 if ( isset( $logoHD['2x'] ) ) {
219 $logoUrls['2x'] = OutputPage::transformResourcePath(
220 $conf,
221 $logoHD['2x']
222 );
223 }
224 }
225
226 return $logoUrls;
227 }
228
234 // Regardless of whether the files are specified, we always
235 // provide mw-wiki-logo styles.
236 return false;
237 }
238
240 $summary = parent::getDefinitionSummary( $context );
241 $summary[] = [
242 'logo' => $this->getConfig()->get( 'Logo' ),
243 'logoHD' => $this->getConfig()->get( 'LogoHD' ),
244 ];
245 return $summary;
246 }
247}
static buildUrlValue( $url)
Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters) and esc...
Definition CSSMin.php:217
Object passed around to modules which contains information about the state of a specific loader reque...
ResourceLoader module based on local JavaScript/CSS files.
array $styles
List of paths to CSS files to always include.
$targets
All skins are assumed to be compatible with mobile.
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
normalizeStyles(&$styles)
Ensure all media keys use array values.
getStyles(ResourceLoaderContext $context)
getPreloadLinks(ResourceLoaderContext $context)
isKnownEmpty(ResourceLoaderContext $context)
getLogoPreloadlinks()
Helper method for getPreloadLinks()
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2848
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Interface for configuration instances.
Definition Config.php:28
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".