wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / resourceloader / ResourceLoaderOOUIImageModule.php
blob8493f9fdc3f40940054307027fc6b0b3504f1442
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.
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
18 * @file
21 /**
22 * Secret special sauce.
24 * @since 1.26
26 class ResourceLoaderOOUIImageModule extends ResourceLoaderImageModule {
27 protected function loadFromDefinition() {
28 if ( $this->definition === null ) {
29 return;
32 // Core default themes
33 $themes = array( 'default' => 'mediawiki' );
34 $themes += ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
36 $name = $this->definition['name'];
37 $rootPath = $this->definition['rootPath'];
39 $definition = array();
40 foreach ( $themes as $skin => $theme ) {
41 // TODO Allow extensions to specify this path somehow
42 $dataPath = $this->localBasePath . '/' . $rootPath . '/' . $theme . '/' . $name . '.json';
44 if ( file_exists( $dataPath ) ) {
45 $data = json_decode( file_get_contents( $dataPath ), true );
46 $fixPath = function ( &$path ) use ( $rootPath, $theme ) {
47 // TODO Allow extensions to specify this path somehow
48 $path = $rootPath . '/' . $theme . '/' . $path;
50 array_walk( $data['images'], function ( &$value ) use ( $fixPath ) {
51 if ( is_string( $value['file'] ) ) {
52 $fixPath( $value['file'] );
53 } elseif ( is_array( $value['file'] ) ) {
54 array_walk_recursive( $value['file'], $fixPath );
56 } );
57 } else {
58 $data = array();
61 foreach ( $data as $key => $value ) {
62 switch ( $key ) {
63 case 'images':
64 case 'variants':
65 $definition[$key][$skin] = $data[$key];
66 break;
68 default:
69 if ( !isset( $definition[$key] ) ) {
70 $definition[$key] = $data[$key];
71 } elseif ( $definition[$key] !== $data[$key] ) {
72 throw new Exception(
73 "Mismatched OOUI theme definitions are not supported: trying to load $key of $theme theme"
76 break;
81 // Fields from definition silently override keys from JSON files
82 $this->definition += $definition;
84 parent::loadFromDefinition();