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() {
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( array $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 }
$IP
Definition: WebStart.php:41
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...
static $knownImagesModules
string $localBasePath
Local base path, see __construct()
static extractLocalBasePath(array $options, $localBasePath=null)
Loads the module definition from JSON files in the format that OOUI uses, converting it to the format...
__construct(array $options=[], $localBasePath=null)
Allows loading arbitrary sets of OOUI icons.