MediaWiki  master
ResourceLoaderOOUIIconPackModule.php
Go to the documentation of this file.
1 <?php
28  public function __construct( array $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() : array {
41  // @phan-suppress-next-line PhanTypeArraySuspiciousNullable Checked in the constructor
42  return $this->definition['icons'];
43  }
44 
45  protected function loadOOUIDefinition( $theme, $unused ) : array {
46  // This is shared between instances of this class, so we only have to load the JSON files once
47  static $data = [];
48 
49  if ( !isset( $data[$theme] ) ) {
50  $data[$theme] = [];
51  // Load and merge the JSON data for all "icons-foo" modules
52  foreach ( self::$knownImagesModules as $module ) {
53  if ( substr( $module, 0, 5 ) === 'icons' ) {
54  $moreData = $this->readJSONFile( $this->getThemeImagesPath( $theme, $module ) );
55  if ( $moreData ) {
56  $data[$theme] = array_replace_recursive( $data[$theme], $moreData );
57  }
58  }
59  }
60  }
61 
62  $definition = $data[$theme];
63 
64  // Filter out the data for all other icons, leaving only the ones we want for this module
65  $iconsNames = $this->getIcons();
66  foreach ( array_keys( $definition['images'] ) as $iconName ) {
67  if ( !in_array( $iconName, $iconsNames ) ) {
68  unset( $definition['images'][$iconName] );
69  }
70  }
71 
72  return $definition;
73  }
74 
75  public static function extractLocalBasePath( array $options, $localBasePath = null ) {
76  global $IP;
77  if ( $localBasePath === null ) {
79  }
80  // Ignore any 'localBasePath' present in $options, this always refers to files in MediaWiki core
81  return $localBasePath;
82  }
83 }
ResourceLoaderImageModule\$definition
array $definition
Definition: ResourceLoaderImageModule.php:30
ResourceLoaderOOUIIconPackModule
Allows loading arbitrary sets of OOUI icons.
Definition: ResourceLoaderOOUIIconPackModule.php:27
ResourceLoaderImageModule\$localBasePath
string $localBasePath
Local base path, see __construct()
Definition: ResourceLoaderImageModule.php:36
ResourceLoaderOOUIIconPackModule\__construct
__construct(array $options=[], $localBasePath=null)
Constructs a new module from an options array.
Definition: ResourceLoaderOOUIIconPackModule.php:28
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:122
$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(array $options, $localBasePath=null)
Extract a local base path from module definition information.
Definition: ResourceLoaderOOUIIconPackModule.php:75
getThemeImagesPath
getThemeImagesPath( $theme, $module)
Definition: ResourceLoaderOOUIModule.php:170
ResourceLoaderOOUIIconPackModule\getIcons
getIcons()
Definition: ResourceLoaderOOUIIconPackModule.php:40
$IP
$IP
Definition: WebStart.php:49
ResourceLoaderOOUIIconPackModule\loadOOUIDefinition
loadOOUIDefinition( $theme, $unused)
Load the module definition from the JSON file(s) for the given theme and module.
Definition: ResourceLoaderOOUIIconPackModule.php:45