ResourcesOOUI.php 5.7 KB

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