ApiMessage: Use a trait to avoid code duplication
[mediawiki.git] / resources / ResourcesOOUI.php
blob647efa23e4aaf41d92069305e6f5cf739c6c08d7
1 <?php
2 /**
3 * Definition of OOjs UI ResourceLoader modules.
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.
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.
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
20 * @file
23 if ( !defined( 'MEDIAWIKI' ) ) {
24 die( 'Not an entry point.' );
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 $themes = ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
31 // We only use the theme names for file names, and they are lowercase
32 $themes = array_map( 'strtolower', $themes );
33 $themes['default'] = 'mediawiki';
35 // Helper function to generate paths to files used in 'skinStyles' and 'skinScripts'.
36 $getSkinSpecific = function ( $module, $ext = 'css' ) use ( $themes ) {
37 return array_combine(
38 array_keys( $themes ),
39 array_map( function ( $theme ) use ( $module, $ext ) {
40 $module = $module ? "$module-" : '';
41 // TODO Allow extensions to specify this path somehow
42 return "resources/lib/oojs-ui/oojs-ui-$module$theme.$ext";
43 }, array_values( $themes ) )
47 $modules = array();
49 // Omnibus module.
50 $modules['oojs-ui'] = array(
51 'dependencies' => array(
52 'oojs-ui-core',
53 'oojs-ui-widgets',
54 'oojs-ui-toolbars',
55 'oojs-ui-windows',
57 'targets' => array( 'desktop', 'mobile' ),
60 // The core JavaScript library.
61 $modules['oojs-ui-core'] = array(
62 'scripts' => array(
63 'resources/lib/oojs-ui/oojs-ui-core.js',
64 'resources/src/oojs-ui-local.js',
66 'skinScripts' => $getSkinSpecific( null, 'js' ),
67 'dependencies' => array(
68 'es5-shim',
69 'oojs',
70 'oojs-ui.styles',
71 'oojs-ui.styles.icons',
72 'oojs-ui.styles.indicators',
73 'oojs-ui.styles.textures',
74 'mediawiki.language',
76 'targets' => array( 'desktop', 'mobile' ),
78 // This contains only the styles required by core widgets.
79 $modules['oojs-ui-core.styles'] = array(
80 'position' => 'top',
81 'styles' => 'resources/src/oojs-ui-local.css', // HACK, see inside the file
82 'skinStyles' => $getSkinSpecific( 'core' ),
83 'targets' => array( 'desktop', 'mobile' ),
86 // Deprecated old name for the module 'oojs-ui-core.styles'.
87 $modules['oojs-ui.styles'] = $modules['oojs-ui-core.styles'];
89 // Additional widgets and layouts module.
90 $modules['oojs-ui-widgets'] = array(
91 'scripts' => 'resources/lib/oojs-ui/oojs-ui-widgets.js',
92 'skinStyles' => $getSkinSpecific( 'widgets' ),
93 'dependencies' => 'oojs-ui-core',
94 'messages' => array(
95 'ooui-outline-control-move-down',
96 'ooui-outline-control-move-up',
97 'ooui-outline-control-remove',
98 'ooui-selectfile-button-select',
99 'ooui-selectfile-dragdrop-placeholder',
100 'ooui-selectfile-not-supported',
101 'ooui-selectfile-placeholder',
103 'targets' => array( 'desktop', 'mobile' ),
105 // Toolbar and tools module.
106 $modules['oojs-ui-toolbars'] = array(
107 'scripts' => 'resources/lib/oojs-ui/oojs-ui-toolbars.js',
108 'skinStyles' => $getSkinSpecific( 'toolbars' ),
109 'dependencies' => 'oojs-ui-core',
110 'messages' => array(
111 'ooui-toolbar-more',
112 'ooui-toolgroup-collapse',
113 'ooui-toolgroup-expand',
115 'targets' => array( 'desktop', 'mobile' ),
117 // Windows and dialogs module.
118 $modules['oojs-ui-windows'] = array(
119 'scripts' => 'resources/lib/oojs-ui/oojs-ui-windows.js',
120 'skinStyles' => $getSkinSpecific( 'windows' ),
121 'dependencies' => 'oojs-ui-core',
122 'messages' => array(
123 'ooui-dialog-message-accept',
124 'ooui-dialog-message-reject',
125 'ooui-dialog-process-continue',
126 'ooui-dialog-process-dismiss',
127 'ooui-dialog-process-error',
128 'ooui-dialog-process-retry',
130 'targets' => array( 'desktop', 'mobile' ),
133 $imageSets = array(
134 // Comments for greppability
135 'icons', // oojs-ui.styles.icons
136 'indicators', // oojs-ui.styles.indicators
137 'textures', // oojs-ui.styles.textures
138 'icons-accessibility', // oojs-ui.styles.icons-accessibility
139 'icons-alerts', // oojs-ui.styles.icons-alerts
140 'icons-content', // oojs-ui.styles.icons-content
141 'icons-editing-advanced', // oojs-ui.styles.icons-editing-advanced
142 'icons-editing-core', // oojs-ui.styles.icons-editing-core
143 'icons-editing-list', // oojs-ui.styles.icons-editing-list
144 'icons-editing-styling', // oojs-ui.styles.icons-editing-styling
145 'icons-interactions', // oojs-ui.styles.icons-interactions
146 'icons-layout', // oojs-ui.styles.icons-layout
147 'icons-location', // oojs-ui.styles.icons-location
148 'icons-media', // oojs-ui.styles.icons-media
149 'icons-moderation', // oojs-ui.styles.icons-moderation
150 'icons-movement', // oojs-ui.styles.icons-movement
151 'icons-user', // oojs-ui.styles.icons-user
152 'icons-wikimedia', // oojs-ui.styles.icons-wikimedia
154 $rootPath = 'resources/lib/oojs-ui/themes';
156 foreach ( $imageSets as $name ) {
157 $module = array(
158 'position' => 'top',
159 'class' => 'ResourceLoaderOOUIImageModule',
160 'name' => $name,
161 'rootPath' => $rootPath,
164 if ( substr( $name, 0, 5 ) === 'icons' ) {
165 $module['selectorWithoutVariant'] = '.oo-ui-icon-{name}, .mw-ui-icon-{name}:before';
166 $module['selectorWithVariant'] = '
167 .oo-ui-image-{variant}.oo-ui-icon-{name}, .mw-ui-icon-{name}-{variant}:before,
168 /* Hack for Flow, see T110051 */
169 .mw-ui-hovericon:hover .mw-ui-icon-{name}-{variant}-hover:before,
170 .mw-ui-hovericon.mw-ui-icon-{name}-{variant}-hover:hover:before';
173 $modules["oojs-ui.styles.$name"] = $module;
176 return $modules;
177 } );