MediaWiki  1.30.0
ResourceLoaderSkinModule.php
Go to the documentation of this file.
1 <?php
28  public $targets = [ 'desktop', 'mobile' ];
29 
35  $logo = $this->getLogo( $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['1.5x'] ) ) {
46  $styles[
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; }';
54  }
55  if ( isset( $logo['2x'] ) ) {
56  $styles[
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; }';
64  }
65  }
66 
67  return $styles;
68  }
69 
78  private function normalizeStyles( &$styles ) {
79  foreach ( $styles as $key => $val ) {
80  if ( !is_array( $val ) ) {
81  $styles[$key] = [ $val ];
82  }
83  }
84  }
85 
92  public static function getLogo( Config $conf ) {
93  $logo = $conf->get( 'Logo' );
94  $logoHD = $conf->get( 'LogoHD' );
95 
96  $logo1Url = OutputPage::transformResourcePath( $conf, $logo );
97 
98  if ( !$logoHD ) {
99  return $logo1Url;
100  }
101 
102  $logoUrls = [
103  '1x' => $logo1Url,
104  ];
105 
106  // Only 1.5x and 2x are supported
107  if ( isset( $logoHD['1.5x'] ) ) {
108  $logoUrls['1.5x'] = OutputPage::transformResourcePath(
109  $conf,
110  $logoHD['1.5x']
111  );
112  }
113  if ( isset( $logoHD['2x'] ) ) {
114  $logoUrls['2x'] = OutputPage::transformResourcePath(
115  $conf,
116  $logoHD['2x']
117  );
118  }
119 
120  return $logoUrls;
121  }
122 
128  // Regardless of whether the files are specified, we always
129  // provide mw-wiki-logo styles.
130  return false;
131  }
132 
134  $summary = parent::getDefinitionSummary( $context );
135  $summary[] = [
136  'logo' => $this->getConfig()->get( 'Logo' ),
137  'logoHD' => $this->getConfig()->get( 'LogoHD' ),
138  ];
139  return $summary;
140  }
141 }
ResourceLoaderContext
Object passed around to modules which contains information about the state of a specific loader reque...
Definition: ResourceLoaderContext.php:32
ResourceLoaderFileModule\$styles
array $styles
List of paths to CSS files to always include.
Definition: ResourceLoaderFileModule.php:83
CSSMin\buildUrlValue
static buildUrlValue( $url)
Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters) and esc...
Definition: CSSMin.php:211
$context
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:2581
ResourceLoaderSkinModule\getDefinitionSummary
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
Definition: ResourceLoaderSkinModule.php:133
php
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:35
ResourceLoaderFileModule
ResourceLoader module based on local JavaScript/CSS files.
Definition: ResourceLoaderFileModule.php:28
Config
Interface for configuration instances.
Definition: Config.php:28
Config\get
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
ResourceLoaderSkinModule\normalizeStyles
normalizeStyles(&$styles)
Ensure all media keys use array values.
Definition: ResourceLoaderSkinModule.php:78
ResourceLoaderSkinModule\getLogo
static getLogo(Config $conf)
Definition: ResourceLoaderSkinModule.php:92
ResourceLoaderSkinModule\getStyles
getStyles(ResourceLoaderContext $context)
Definition: ResourceLoaderSkinModule.php:34
as
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
Definition: distributors.txt:9
ResourceLoaderSkinModule\isKnownEmpty
isKnownEmpty(ResourceLoaderContext $context)
Definition: ResourceLoaderSkinModule.php:127
ResourceLoaderSkinModule
Definition: ResourceLoaderSkinModule.php:24
ResourceLoaderModule\getConfig
getConfig()
Definition: ResourceLoaderModule.php:188
ResourceLoaderSkinModule\$targets
$targets
All skins are assumed to be compatible with mobile.
Definition: ResourceLoaderSkinModule.php:28
OutputPage\transformResourcePath
static transformResourcePath(Config $config, $path)
Transform path to web-accessible static resource.
Definition: OutputPage.php:3777