MediaWiki  master
Go to the documentation of this file.
1 <?php
30  protected function loadFromDefinition() {
31  if ( $this->definition === null ) {
32  // Do nothing if definition was already processed
33  return;
34  }
36  $themes = self::getSkinThemeMap();
38  // For backwards-compatibility, allow missing 'themeImages'
39  $module = $this->definition['themeImages'] ?? '';
41  $definition = [];
42  foreach ( $themes as $skin => $theme ) {
43  $data = $this->loadOOUIDefinition( $theme, $module );
45  if ( !$data ) {
46  // If there's no file for this module of this theme, that's okay, it will just use the defaults
47  continue;
48  }
50  // Convert into a definition compatible with the parent vanilla ResourceLoaderImageModule
51  foreach ( $data as $key => $value ) {
52  switch ( $key ) {
53  // Images and color variants are defined per-theme, here converted to per-skin
54  case 'images':
55  case 'variants':
56  $definition[$key][$skin] = $data[$key];
57  break;
59  // Other options must be identical for each theme (or only defined in the default one)
60  default:
61  if ( !isset( $definition[$key] ) ) {
62  $definition[$key] = $data[$key];
63  } elseif ( $definition[$key] !== $data[$key] ) {
64  throw new Exception(
65  "Mismatched OOUI theme images definition: " .
66  "key '$key' of theme '$theme' for module '$module' " .
67  "does not match other themes"
68  );
69  }
70  break;
71  }
72  }
73  }
75  // Extra selectors to allow using the same icons for old-style MediaWiki UI code
76  if ( substr( $module, 0, 5 ) === 'icons' ) {
77  $definition['selectorWithoutVariant'] = '.oo-ui-icon-{name}, .mw-ui-icon-{name}:before';
78  $definition['selectorWithVariant'] = '.oo-ui-image-{variant}.oo-ui-icon-{name}, ' .
79  '.mw-ui-icon-{name}-{variant}:before';
80  }
82  // Fields from module definition silently override keys from JSON files
83  $this->definition += $definition;
85  parent::loadFromDefinition();
86  }
96  protected function loadOOUIDefinition( $theme, $module ) {
97  // Find the path to the JSON file which contains the actual image definitions for this theme
98  if ( $module ) {
99  $dataPath = $this->getThemeImagesPath( $theme, $module );
100  if ( !$dataPath ) {
101  return false;
102  }
103  } else {
104  // Backwards-compatibility for things that probably shouldn't have used this class...
105  $dataPath =
106  $this->definition['rootPath'] . '/' .
107  strtolower( $theme ) . '/' .
108  $this->definition['name'] . '.json';
109  }
111  return $this->readJSONFile( $dataPath );
112  }
121  protected function readJSONFile( $dataPath ) {
122  $localDataPath = $this->getLocalPath( $dataPath );
124  if ( !file_exists( $localDataPath ) ) {
125  return false;
126  }
128  $data = json_decode( file_get_contents( $localDataPath ), true );
130  // Expand the paths to images (since they are relative to the JSON file that defines them, not
131  // our base directory)
132  $fixPath = function ( &$path ) use ( $dataPath ) {
133  if ( $dataPath instanceof ResourceLoaderFilePath ) {
134  $path = new ResourceLoaderFilePath(
135  dirname( $dataPath->getPath() ) . '/' . $path,
136  $dataPath->getLocalBasePath(),
137  $dataPath->getRemoteBasePath()
138  );
139  } else {
140  $path = dirname( $dataPath ) . '/' . $path;
141  }
142  };
143  array_walk( $data['images'], function ( &$value ) use ( $fixPath ) {
144  if ( is_string( $value['file'] ) ) {
145  $fixPath( $value['file'] );
146  } elseif ( is_array( $value['file'] ) ) {
147  array_walk_recursive( $value['file'], $fixPath );
148  }
149  } );
151  return $data;
152  }
153 }
static static static getSkinThemeMap()
Return a map of skin names (in lowercase) to OOUI theme names, defining which theme a given skin shou...
ResourceLoader module for generated and embedded images.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getThemeImagesPath( $theme, $module)
readJSONFile( $dataPath)
Read JSON from a file, and transform all paths in it to be relative to the module&#39;s base path...
loadOOUIDefinition( $theme, $module)
Load the module definition from the JSON file(s) for the given theme and module.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition: hooks.txt:1971
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
Loads the module definition from JSON files in the format that OOUI uses, converting it to the format...
An object to represent a path to a JavaScript/CSS file, along with a remote and local base path...
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
trait ResourceLoaderOOUIModule
Convenience methods for dealing with OOUI themes and their relations to MW skins. ...
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this definition