Merge "objectcache: add getMultiWithUnionSetCallback() method"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderOOUIFileModule.php
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 /**
22 * ResourceLoaderFileModule which magically loads the right skinScripts and skinStyles for every
23 * skin, using the specified OOUI theme for each.
24 *
25 * @since 1.30
26 */
27 class ResourceLoaderOOUIFileModule extends ResourceLoaderFileModule {
28 use ResourceLoaderOOUIModule;
29
30 public function __construct( $options = [] ) {
31 if ( isset( $options[ 'themeScripts' ] ) ) {
32 $options['skinScripts'] = $this->getSkinSpecific( $options[ 'themeScripts' ], 'scripts' );
33 }
34 if ( isset( $options[ 'themeStyles' ] ) ) {
35 $options['skinStyles'] = $this->getSkinSpecific( $options[ 'themeStyles' ], 'styles' );
36 }
37
38 parent::__construct( $options );
39 }
40
41 /**
42 * Helper function to generate values for 'skinStyles' and 'skinScripts'.
43 *
44 * @param string $module Module to generate skinStyles/skinScripts for:
45 * 'core', 'widgets', 'toolbars', 'windows'
46 * @param string $which 'scripts' or 'styles'
47 * @return array
48 */
49 private function getSkinSpecific( $module, $which ) {
50 $themes = self::getSkinThemeMap();
51
52 return array_combine(
53 array_keys( $themes ),
54 array_map( function ( $theme ) use ( $module, $which ) {
55 if ( $which === 'scripts' ) {
56 return $this->getThemeScriptsPath( $theme, $module );
57 } else {
58 return $this->getThemeStylesPath( $theme, $module );
59 }
60 }, array_values( $themes ) )
61 );
62 }
63 }