ResourcesOOUI.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. 'oojs-ui.styles.icons',
  66. 'oojs-ui.styles.indicators',
  67. 'oojs-ui.styles.textures',
  68. 'mediawiki.language',
  69. ],
  70. 'targets' => [ 'desktop', 'mobile' ],
  71. ];
  72. // This contains only the styles required by core widgets.
  73. $modules['oojs-ui-core.styles'] = [
  74. 'position' => 'top',
  75. 'styles' => 'resources/src/oojs-ui-local.css', // HACK, see inside the file
  76. 'skinStyles' => $getSkinSpecific( 'core' ),
  77. 'targets' => [ 'desktop', 'mobile' ],
  78. ];
  79. // Additional widgets and layouts module.
  80. $modules['oojs-ui-widgets'] = [
  81. 'scripts' => 'resources/lib/oojs-ui/oojs-ui-widgets.js',
  82. 'skinStyles' => $getSkinSpecific( 'widgets' ),
  83. 'dependencies' => 'oojs-ui-core',
  84. 'messages' => [
  85. 'ooui-outline-control-move-down',
  86. 'ooui-outline-control-move-up',
  87. 'ooui-outline-control-remove',
  88. 'ooui-selectfile-button-select',
  89. 'ooui-selectfile-dragdrop-placeholder',
  90. 'ooui-selectfile-not-supported',
  91. 'ooui-selectfile-placeholder',
  92. ],
  93. 'targets' => [ 'desktop', 'mobile' ],
  94. ];
  95. // Toolbar and tools module.
  96. $modules['oojs-ui-toolbars'] = [
  97. 'scripts' => 'resources/lib/oojs-ui/oojs-ui-toolbars.js',
  98. 'skinStyles' => $getSkinSpecific( 'toolbars' ),
  99. 'dependencies' => 'oojs-ui-core',
  100. 'messages' => [
  101. 'ooui-toolbar-more',
  102. 'ooui-toolgroup-collapse',
  103. 'ooui-toolgroup-expand',
  104. ],
  105. 'targets' => [ 'desktop', 'mobile' ],
  106. ];
  107. // Windows and dialogs module.
  108. $modules['oojs-ui-windows'] = [
  109. 'scripts' => 'resources/lib/oojs-ui/oojs-ui-windows.js',
  110. 'skinStyles' => $getSkinSpecific( 'windows' ),
  111. 'dependencies' => 'oojs-ui-core',
  112. 'messages' => [
  113. 'ooui-dialog-message-accept',
  114. 'ooui-dialog-message-reject',
  115. 'ooui-dialog-process-continue',
  116. 'ooui-dialog-process-dismiss',
  117. 'ooui-dialog-process-error',
  118. 'ooui-dialog-process-retry',
  119. ],
  120. 'targets' => [ 'desktop', 'mobile' ],
  121. ];
  122. $imageSets = [
  123. // Comments for greppability
  124. 'icons', // oojs-ui.styles.icons
  125. 'indicators', // oojs-ui.styles.indicators
  126. 'textures', // oojs-ui.styles.textures
  127. 'icons-accessibility', // oojs-ui.styles.icons-accessibility
  128. 'icons-alerts', // oojs-ui.styles.icons-alerts
  129. 'icons-content', // oojs-ui.styles.icons-content
  130. 'icons-editing-advanced', // oojs-ui.styles.icons-editing-advanced
  131. 'icons-editing-core', // oojs-ui.styles.icons-editing-core
  132. 'icons-editing-list', // oojs-ui.styles.icons-editing-list
  133. 'icons-editing-styling', // oojs-ui.styles.icons-editing-styling
  134. 'icons-interactions', // oojs-ui.styles.icons-interactions
  135. 'icons-layout', // oojs-ui.styles.icons-layout
  136. 'icons-location', // oojs-ui.styles.icons-location
  137. 'icons-media', // oojs-ui.styles.icons-media
  138. 'icons-moderation', // oojs-ui.styles.icons-moderation
  139. 'icons-movement', // oojs-ui.styles.icons-movement
  140. 'icons-user', // oojs-ui.styles.icons-user
  141. 'icons-wikimedia', // oojs-ui.styles.icons-wikimedia
  142. ];
  143. $rootPath = 'resources/lib/oojs-ui/themes';
  144. foreach ( $imageSets as $name ) {
  145. $module = [
  146. 'position' => 'top',
  147. 'class' => 'ResourceLoaderOOUIImageModule',
  148. 'name' => $name,
  149. 'rootPath' => $rootPath,
  150. ];
  151. if ( substr( $name, 0, 5 ) === 'icons' ) {
  152. $module['selectorWithoutVariant'] = '.oo-ui-icon-{name}, .mw-ui-icon-{name}:before';
  153. $module['selectorWithVariant'] = '
  154. .oo-ui-image-{variant}.oo-ui-icon-{name}, .mw-ui-icon-{name}-{variant}:before,
  155. /* Hack for Flow, see T110051 */
  156. .mw-ui-hovericon:hover .mw-ui-icon-{name}-{variant}-hover:before,
  157. .mw-ui-hovericon.mw-ui-icon-{name}-{variant}-hover:hover:before';
  158. }
  159. $modules["oojs-ui.styles.$name"] = $module;
  160. }
  161. return $modules;
  162. } );