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.
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.
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
22 * Allows loading arbitrary sets of OOUI icons.
26 class ResourceLoaderOOUIIconPackModule
extends ResourceLoaderOOUIImageModule
{
27 public function __construct( $options = [], $localBasePath = null ) {
28 parent
::__construct( $options, $localBasePath );
30 if ( !isset( $this->definition
['icons'] ) ||
!$this->definition
['icons'] ) {
31 throw new InvalidArgumentException( "Parameter 'icons' must be given." );
34 // A few things check for the "icons" prefix on this value, so specify it even though
35 // we don't use it for actually loading the data, like in the other modules.
36 $this->definition
['themeImages'] = 'icons';
39 private function getIcons() {
40 return $this->definition
['icons'];
43 protected function loadOOUIDefinition( $theme, $unused ) {
44 // This is shared between instances of this class, so we only have to load the JSON files once
47 if ( !isset( $data[$theme] ) ) {
49 // Load and merge the JSON data for all "icons-foo" modules
50 foreach ( self
::$knownImagesModules as $module ) {
51 if ( substr( $module, 0, 5 ) === 'icons' ) {
52 $moreData = $this->readJSONFile( $this->getThemeImagesPath( $theme, $module ) );
54 $data[$theme] = array_replace_recursive( $data[$theme], $moreData );
60 $definition = $data[$theme];
62 // Filter out the data for all other icons, leaving only the ones we want for this module
63 $iconsNames = $this->getIcons();
64 foreach ( array_keys( $definition['images'] ) as $iconName ) {
65 if ( !in_array( $iconName, $iconsNames ) ) {
66 unset( $definition['images'][$iconName] );
73 public static function extractLocalBasePath( $options, $localBasePath = null ) {
75 if ( $localBasePath === null ) {
78 // Ignore any 'localBasePath' present in $options, this always refers to files in MediaWiki core
79 return $localBasePath;