ResourcesOOUI.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. if ( !defined( 'MEDIAWIKI' ) ) {
  23. die( 'Not an entry point.' );
  24. }
  25. // WARNING: OOjs-UI is NOT TESTED with older browsers and is likely to break
  26. // if loaded in browsers that don't support ES5
  27. return call_user_func( function () {
  28. $themes = ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
  29. // We only use the theme names for file names, and they are lowercase
  30. $themes = array_map( 'strtolower', $themes );
  31. $themes['default'] = 'mediawiki';
  32. // Helper function to generate paths to files used in 'skinStyles' and 'skinScripts'.
  33. $getSkinSpecific = function ( $module, $ext = 'css' ) use ( $themes ) {
  34. return array_combine(
  35. array_keys( $themes ),
  36. array_map( function ( $theme ) use ( $module, $ext ) {
  37. $module = $module ? "$module-" : '';
  38. // TODO Allow extensions to specify this path somehow
  39. return "resources/lib/oojs-ui/oojs-ui-$module$theme.$ext";
  40. }, array_values( $themes ) )
  41. );
  42. };
  43. $modules = [];
  44. // Omnibus module.
  45. $modules['oojs-ui'] = [
  46. 'dependencies' => [
  47. 'oojs-ui-core',
  48. 'oojs-ui-widgets',
  49. 'oojs-ui-toolbars',
  50. 'oojs-ui-windows',
  51. ],
  52. 'targets' => [ 'desktop', 'mobile' ],
  53. ];
  54. // The core JavaScript library.
  55. $modules['oojs-ui-core'] = [
  56. 'scripts' => [
  57. 'resources/lib/oojs-ui/oojs-ui-core.js',
  58. 'resources/src/oojs-ui-local.js',
  59. ],
  60. 'skinScripts' => $getSkinSpecific( null, 'js' ),
  61. 'dependencies' => [
  62. 'es5-shim',
  63. 'oojs',
  64. 'oojs-ui-core.styles',
  65. 'mediawiki.language',
  66. ],
  67. 'targets' => [ 'desktop', 'mobile' ],
  68. ];
  69. // This contains only the styles required by core widgets.
  70. $modules['oojs-ui-core.styles'] = [
  71. 'position' => 'top',
  72. 'styles' => 'resources/src/oojs-ui-local.css', // HACK, see inside the file
  73. 'skinStyles' => $getSkinSpecific( 'core' ),
  74. 'targets' => [ 'desktop', 'mobile' ],
  75. // ResourceLoaderImageModule doesn't support 'skipFunction', so instead we set this up so that
  76. // this module is skipped together with its dependencies. Nothing else depends on these modules.
  77. 'dependencies' => [
  78. 'oojs-ui.styles.icons',
  79. 'oojs-ui.styles.indicators',
  80. 'oojs-ui.styles.textures',
  81. ],
  82. 'skipFunction' => 'resources/src/oojs-ui-styles-skip.js',
  83. ];
  84. // Deprecated old name for the module 'oojs-ui-core.styles'.
  85. $modules['oojs-ui.styles'] = $modules['oojs-ui-core.styles'];
  86. // Additional widgets and layouts module.
  87. $modules['oojs-ui-widgets'] = [
  88. 'scripts' => 'resources/lib/oojs-ui/oojs-ui-widgets.js',
  89. 'skinStyles' => $getSkinSpecific( 'widgets' ),
  90. 'dependencies' => 'oojs-ui-core',
  91. 'messages' => [
  92. 'ooui-outline-control-move-down',
  93. 'ooui-outline-control-move-up',
  94. 'ooui-outline-control-remove',
  95. 'ooui-selectfile-button-select',
  96. 'ooui-selectfile-dragdrop-placeholder',
  97. 'ooui-selectfile-not-supported',
  98. 'ooui-selectfile-placeholder',
  99. ],
  100. 'targets' => [ 'desktop', 'mobile' ],
  101. ];
  102. // Toolbar and tools module.
  103. $modules['oojs-ui-toolbars'] = [
  104. 'scripts' => 'resources/lib/oojs-ui/oojs-ui-toolbars.js',
  105. 'skinStyles' => $getSkinSpecific( 'toolbars' ),
  106. 'dependencies' => 'oojs-ui-core',
  107. 'messages' => [
  108. 'ooui-toolbar-more',
  109. 'ooui-toolgroup-collapse',
  110. 'ooui-toolgroup-expand',
  111. ],
  112. 'targets' => [ 'desktop', 'mobile' ],
  113. ];
  114. // Windows and dialogs module.
  115. $modules['oojs-ui-windows'] = [
  116. 'scripts' => 'resources/lib/oojs-ui/oojs-ui-windows.js',
  117. 'skinStyles' => $getSkinSpecific( 'windows' ),
  118. 'dependencies' => 'oojs-ui-core',
  119. 'messages' => [
  120. 'ooui-dialog-message-accept',
  121. 'ooui-dialog-message-reject',
  122. 'ooui-dialog-process-continue',
  123. 'ooui-dialog-process-dismiss',
  124. 'ooui-dialog-process-error',
  125. 'ooui-dialog-process-retry',
  126. ],
  127. 'targets' => [ 'desktop', 'mobile' ],
  128. ];
  129. $imageSets = [
  130. // Comments for greppability
  131. 'icons', // oojs-ui.styles.icons
  132. 'indicators', // oojs-ui.styles.indicators
  133. 'textures', // oojs-ui.styles.textures
  134. 'icons-accessibility', // oojs-ui.styles.icons-accessibility
  135. 'icons-alerts', // oojs-ui.styles.icons-alerts
  136. 'icons-content', // oojs-ui.styles.icons-content
  137. 'icons-editing-advanced', // oojs-ui.styles.icons-editing-advanced
  138. 'icons-editing-core', // oojs-ui.styles.icons-editing-core
  139. 'icons-editing-list', // oojs-ui.styles.icons-editing-list
  140. 'icons-editing-styling', // oojs-ui.styles.icons-editing-styling
  141. 'icons-interactions', // oojs-ui.styles.icons-interactions
  142. 'icons-layout', // oojs-ui.styles.icons-layout
  143. 'icons-location', // oojs-ui.styles.icons-location
  144. 'icons-media', // oojs-ui.styles.icons-media
  145. 'icons-moderation', // oojs-ui.styles.icons-moderation
  146. 'icons-movement', // oojs-ui.styles.icons-movement
  147. 'icons-user', // oojs-ui.styles.icons-user
  148. 'icons-wikimedia', // oojs-ui.styles.icons-wikimedia
  149. ];
  150. $rootPath = 'resources/lib/oojs-ui/themes';
  151. foreach ( $imageSets as $name ) {
  152. $module = [
  153. 'position' => 'top',
  154. 'class' => 'ResourceLoaderOOUIImageModule',
  155. 'name' => $name,
  156. 'rootPath' => $rootPath,
  157. ];
  158. if ( substr( $name, 0, 5 ) === 'icons' ) {
  159. $module['selectorWithoutVariant'] = '.oo-ui-icon-{name}, .mw-ui-icon-{name}:before';
  160. $module['selectorWithVariant'] = '
  161. .oo-ui-image-{variant}.oo-ui-icon-{name}, .mw-ui-icon-{name}-{variant}:before,
  162. /* Hack for Flow, see T110051 */
  163. .mw-ui-hovericon:hover .mw-ui-icon-{name}-{variant}-hover:before,
  164. .mw-ui-hovericon.mw-ui-icon-{name}-{variant}-hover:hover:before';
  165. }
  166. $modules["oojs-ui.styles.$name"] = $module;
  167. }
  168. return $modules;
  169. } );