| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\ResourceLoader; |
| 22 |
|
| 23 |
use InvalidArgumentException; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class OOUIIconPackModule extends OOUIImageModule { |
| 32 |
public function __construct( array $options = [], $localBasePath = null ) { |
| 33 |
parent::__construct( $options, $localBasePath ); |
| 34 |
|
| 35 |
if ( !isset( $this->definition['icons'] ) || !$this->definition['icons'] ) { |
| 36 |
throw new InvalidArgumentException( "Parameter 'icons' must be given." ); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
$this->definition['themeImages'] = 'icons'; |
| 42 |
} |
| 43 |
|
| 44 |
private function getIcons(): array { |
| 45 |
|
| 46 |
return $this->definition['icons']; |
| 47 |
} |
| 48 |
|
| 49 |
protected function loadOOUIDefinition( $theme, $unused ): array { |
| 50 |
|
| 51 |
static $data = []; |
| 52 |
|
| 53 |
if ( !isset( $data[$theme] ) ) { |
| 54 |
$data[$theme] = []; |
| 55 |
|
| 56 |
foreach ( self::$knownImagesModules as $module ) { |
| 57 |
if ( str_starts_with( $module, 'icons' ) ) { |
| 58 |
$moreData = $this->readJSONFile( $this->getThemeImagesPath( $theme, $module ) ); |
| 59 |
if ( $moreData ) { |
| 60 |
$data[$theme] = array_replace_recursive( $data[$theme], $moreData ); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
$definition = $data[$theme]; |
| 67 |
|
| 68 |
|
| 69 |
$iconsNames = $this->getIcons(); |
| 70 |
foreach ( $definition['images'] as $iconName => $_ ) { |
| 71 |
if ( !in_array( $iconName, $iconsNames ) ) { |
| 72 |
unset( $definition['images'][$iconName] ); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
return $definition; |
| 77 |
} |
| 78 |
|
| 79 |
public static function extractLocalBasePath( array $options, $localBasePath = null ) { |
| 80 |
global $IP; |
| 81 |
|
| 82 |
return $localBasePath ?? $IP; |
| 83 |
} |
| 84 |
} |