OOUI theme support
[lhc/web/wiklou.git] / resources / ResourcesOOUI.php
1 <?php
2 /**
3 * Definition of OOjs UI ResourceLoader modules.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 if ( !defined( 'MEDIAWIKI' ) ) {
24 die( 'Not an entry point.' );
25 }
26
27 // WARNING: OOjs-UI is NOT TESTED with older browsers and is likely to break
28 // if loaded in browsers that don't support ES5
29 return call_user_func( function () {
30 // Core default themes
31 $themes = array( 'default' => 'mediawiki' );
32 $themes += ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
33 $modules = array();
34
35 $modules['oojs-ui'] = array(
36 'scripts' => array(
37 'resources/lib/oojs-ui/oojs-ui.js',
38 ),
39 'skinScripts' => array_combine(
40 array_keys( $themes ),
41 array_map( function ( $theme ) {
42 // TODO Allow extensions to specify this path somehow
43 return "resources/lib/oojs-ui/oojs-ui-$theme.js";
44 }, array_values( $themes ) )
45 ),
46 'dependencies' => array(
47 'es5-shim',
48 'oojs',
49 'oojs-ui.styles',
50 'oojs-ui.styles.icons',
51 'oojs-ui.styles.indicators',
52 'oojs-ui.styles.textures',
53 ),
54 'messages' => array(
55 'ooui-dialog-message-accept',
56 'ooui-dialog-message-reject',
57 'ooui-dialog-process-continue',
58 'ooui-dialog-process-dismiss',
59 'ooui-dialog-process-error',
60 'ooui-dialog-process-retry',
61 'ooui-outline-control-move-down',
62 'ooui-outline-control-move-up',
63 'ooui-outline-control-remove',
64 'ooui-toolbar-more',
65 'ooui-toolgroup-collapse',
66 'ooui-toolgroup-expand',
67 ),
68 'targets' => array( 'desktop', 'mobile' ),
69 );
70 $modules['oojs-ui.styles'] = array(
71 'position' => 'top',
72 'styles' => 'resources/src/oojs-ui-local.css', // HACK, see inside the file
73 'skinStyles' => array_combine(
74 array_keys( $themes ),
75 array_map( function ( $theme ) {
76 // TODO Allow extensions to specify this path somehow
77 return "resources/lib/oojs-ui/oojs-ui-$theme-noimages.css";
78 }, array_values( $themes ) )
79 ),
80 'targets' => array( 'desktop', 'mobile' ),
81 );
82
83 $imageSets = array(
84 // Comments for greppability
85 'icons', // oojs-ui.styles.icons
86 'indicators', // oojs-ui.styles.indicators
87 'textures', // oojs-ui.styles.textures
88 'icons-alerts', // oojs-ui.styles.icons-alerts
89 'icons-content', // oojs-ui.styles.icons-content
90 'icons-editing-advanced', // oojs-ui.styles.icons-editing-advanced
91 'icons-editing-core', // oojs-ui.styles.icons-editing-core
92 'icons-editing-list', // oojs-ui.styles.icons-editing-list
93 'icons-editing-styling', // oojs-ui.styles.icons-editing-styling
94 'icons-interactions', // oojs-ui.styles.icons-interactions
95 'icons-layout', // oojs-ui.styles.icons-layout
96 'icons-location', // oojs-ui.styles.icons-location
97 'icons-media', // oojs-ui.styles.icons-media
98 'icons-moderation', // oojs-ui.styles.icons-moderation
99 'icons-movement', // oojs-ui.styles.icons-movement
100 'icons-user', // oojs-ui.styles.icons-user
101 'icons-wikimedia', // oojs-ui.styles.icons-wikimedia
102 );
103 $rootPath = 'resources/lib/oojs-ui/themes';
104
105 foreach ( $imageSets as $name ) {
106 $module = array(
107 'position' => 'top',
108 'class' => 'ResourceLoaderOOUIImageModule',
109 'name' => $name,
110 'rootPath' => $rootPath,
111 );
112
113 if ( substr( $name, 0, 5 ) === 'icons' ) {
114 $module['selectorWithoutVariant'] = '.oo-ui-icon-{name}, .mw-ui-icon-{name}:before';
115 $module['selectorWithVariant'] = '.oo-ui-image-{variant} .oo-ui-icon-{name}, .oo-ui-image-{variant}.oo-ui-icon-{name}, .mw-ui-icon-{name}-{variant}:before, .mw-ui-hovericon:hover .mw-ui-icon-{name}-{variant}-hover:before, .mw-ui-hovericon.mw-ui-icon-{name}-{variant}-hover:hover:before';
116 }
117
118 $modules[ "oojs-ui.styles.$name" ] = $module;
119 }
120
121 return $modules;
122 } );