Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
OOUIIconPackModule | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
getIcons | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadOOUIDefinition | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
56 | |||
extractLocalBasePath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\ResourceLoader; |
22 | |
23 | use InvalidArgumentException; |
24 | |
25 | /** |
26 | * Allows loading arbitrary sets of OOUI icons. |
27 | * |
28 | * @ingroup ResourceLoader |
29 | * @since 1.34 |
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 | // A few things check for the "icons" prefix on this value, so specify it even though |
40 | // we don't use it for actually loading the data, like in the other modules. |
41 | $this->definition['themeImages'] = 'icons'; |
42 | } |
43 | |
44 | private function getIcons(): array { |
45 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable Checked in the constructor |
46 | return $this->definition['icons']; |
47 | } |
48 | |
49 | protected function loadOOUIDefinition( $theme, $unused ): array { |
50 | // This is shared between instances of this class, so we only have to load the JSON files once |
51 | static $data = []; |
52 | |
53 | if ( !isset( $data[$theme] ) ) { |
54 | $data[$theme] = []; |
55 | // Load and merge the JSON data for all "icons-foo" modules |
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 | // Filter out the data for all other icons, leaving only the ones we want for this module |
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 | // Ignore any 'localBasePath' present in $options, this always refers to files in MediaWiki core |
82 | return $localBasePath ?? $IP; |
83 | } |
84 | } |