MediaWiki master
OOUIFileModule.php
Go to the documentation of this file.
1<?php
22
31 use OOUIModule;
32
34 private $themeStyles = [];
35
36 public function __construct( array $options = [] ) {
37 if ( isset( $options['themeScripts'] ) ) {
38 $skinScripts = $this->getSkinSpecific( $options['themeScripts'], 'scripts' );
39 $options['skinScripts'] = $this->extendSkinSpecific( $options['skinScripts'] ?? [], $skinScripts );
40 }
41 if ( isset( $options['themeStyles'] ) ) {
42 $this->themeStyles = $this->getSkinSpecific( $options['themeStyles'], 'styles' );
43 }
44
45 parent::__construct( $options );
46 }
47
48 public function setSkinStylesOverride( array $moduleSkinStyles ): void {
49 parent::setSkinStylesOverride( $moduleSkinStyles );
50
51 $this->skinStyles = $this->extendSkinSpecific( $this->skinStyles, $this->themeStyles );
52 }
53
62 private function getSkinSpecific( $module, $which ): array {
63 $themes = self::getSkinThemeMap();
64
65 return array_combine(
66 array_keys( $themes ),
67 array_map( function ( $theme ) use ( $module, $which ) {
68 if ( $which === 'scripts' ) {
69 return $this->getThemeScriptsPath( $theme, $module );
70 } else {
71 return $this->getThemeStylesPath( $theme, $module );
72 }
73 }, array_values( $themes ) )
74 );
75 }
76
96 private function extendSkinSpecific( array $skinSpecific, array $themeSpecific ): array {
97 // If the module or skin already set skinStyles/skinScripts, prepend ours
98 foreach ( $skinSpecific as $skin => $files ) {
99 if ( !is_array( $files ) ) {
100 $files = [ $files ];
101 }
102 if ( isset( $themeSpecific[$skin] ) ) {
103 $skinSpecific[$skin] = array_merge( [ $themeSpecific[$skin] ], $files );
104 } elseif ( isset( $themeSpecific['default'] ) ) {
105 $skinSpecific[$skin] = array_merge( [ $themeSpecific['default'] ], $files );
106 }
107 }
108 // If the module has no skinStyles/skinScripts for a skin, then set ours
109 foreach ( $themeSpecific as $skin => $file ) {
110 if ( !isset( $skinSpecific[$skin] ) ) {
111 $skinSpecific[$skin] = [ $file ];
112 }
113 }
114 return $skinSpecific;
115 }
116}
Module based on local JavaScript/CSS files.
array< string, array< int, string|FilePath > > $skinScripts
Lists of JavaScript files by skin name.
Module which magically loads the right skinScripts and skinStyles for every skin, using the specified...
setSkinStylesOverride(array $moduleSkinStyles)
Provide overrides for skinStyles to modules that support that.
trait OOUIModule
Convenience methods for dealing with OOUI themes and their relations to MW skins.
getThemeStylesPath( $theme, $module)
static getSkinThemeMap()
Return a map of skin names (in lowercase) to OOUI theme names, defining which theme a given skin shou...
getThemeScriptsPath( $theme, $module)