MediaWiki  1.34.0
ResourceLoaderOOUIIconPackModule.php
Go to the documentation of this file.
1 <?php
28  public function __construct( $options = [], $localBasePath = null ) {
29  parent::__construct( $options, $localBasePath );
30 
31  if ( !isset( $this->definition['icons'] ) || !$this->definition['icons'] ) {
32  throw new InvalidArgumentException( "Parameter 'icons' must be given." );
33  }
34 
35  // A few things check for the "icons" prefix on this value, so specify it even though
36  // we don't use it for actually loading the data, like in the other modules.
37  $this->definition['themeImages'] = 'icons';
38  }
39 
40  private function getIcons() {
41  return $this->definition['icons'];
42  }
43 
44  protected function loadOOUIDefinition( $theme, $unused ) {
45  // This is shared between instances of this class, so we only have to load the JSON files once
46  static $data = [];
47 
48  if ( !isset( $data[$theme] ) ) {
49  $data[$theme] = [];
50  // Load and merge the JSON data for all "icons-foo" modules
51  foreach ( self::$knownImagesModules as $module ) {
52  if ( substr( $module, 0, 5 ) === 'icons' ) {
53  $moreData = $this->readJSONFile( $this->getThemeImagesPath( $theme, $module ) );
54  if ( $moreData ) {
55  $data[$theme] = array_replace_recursive( $data[$theme], $moreData );
56  }
57  }
58  }
59  }
60 
61  $definition = $data[$theme];
62 
63  // Filter out the data for all other icons, leaving only the ones we want for this module
64  $iconsNames = $this->getIcons();
65  foreach ( array_keys( $definition['images'] ) as $iconName ) {
66  if ( !in_array( $iconName, $iconsNames ) ) {
67  unset( $definition['images'][$iconName] );
68  }
69  }
70 
71  return $definition;
72  }
73 
74  public static function extractLocalBasePath( $options, $localBasePath = null ) {
75  global $IP;
76  if ( $localBasePath === null ) {
78  }
79  // Ignore any 'localBasePath' present in $options, this always refers to files in MediaWiki core
80  return $localBasePath;
81  }
82 }
ResourceLoaderOOUIIconPackModule\__construct
__construct( $options=[], $localBasePath=null)
Constructs a new module from an options array.
Definition: ResourceLoaderOOUIIconPackModule.php:28
ResourceLoaderOOUIIconPackModule
Allows loading arbitrary sets of OOUI icons.
Definition: ResourceLoaderOOUIIconPackModule.php:27
ResourceLoaderImageModule\$localBasePath
string $localBasePath
Local base path, see __construct()
Definition: ResourceLoaderImageModule.php:37
ResourceLoaderOOUIImageModule\readJSONFile
readJSONFile( $dataPath)
Read JSON from a file, and transform all paths in it to be relative to the module's base path.
Definition: ResourceLoaderOOUIImageModule.php:121
$IP
$IP
Definition: update.php:3
$knownImagesModules
static $knownImagesModules
Definition: ResourceLoaderOOUIModule.php:30
ResourceLoaderOOUIImageModule
Loads the module definition from JSON files in the format that OOUI uses, converting it to the format...
Definition: ResourceLoaderOOUIImageModule.php:27
ResourceLoaderOOUIIconPackModule\extractLocalBasePath
static extractLocalBasePath( $options, $localBasePath=null)
Extract a local base path from module definition information.
Definition: ResourceLoaderOOUIIconPackModule.php:74
ResourceLoaderImageModule\$definition
array null $definition
Definition: ResourceLoaderImageModule.php:31
getThemeImagesPath
getThemeImagesPath( $theme, $module)
Definition: ResourceLoaderOOUIModule.php:170
ResourceLoaderOOUIIconPackModule\getIcons
getIcons()
Definition: ResourceLoaderOOUIIconPackModule.php:40
ResourceLoaderOOUIIconPackModule\loadOOUIDefinition
loadOOUIDefinition( $theme, $unused)
Load the module definition from the JSON file(s) for the given theme and module.
Definition: ResourceLoaderOOUIIconPackModule.php:44