MediaWiki master
OOUIFileModule.php
Go to the documentation of this file.
1<?php
8
17 use OOUIModule;
18
20 private $themeStyles = [];
21
22 public function __construct( array $options = [] ) {
23 if ( isset( $options['themeScripts'] ) ) {
24 $skinScripts = $this->getSkinSpecific( $options['themeScripts'], 'scripts' );
25 $options['skinScripts'] = $this->extendSkinSpecific( $options['skinScripts'] ?? [], $skinScripts );
26 }
27 if ( isset( $options['themeStyles'] ) ) {
28 $this->themeStyles = $this->getSkinSpecific( $options['themeStyles'], 'styles' );
29 }
30
31 parent::__construct( $options );
32 }
33
34 public function setSkinStylesOverride( array $moduleSkinStyles ): void {
35 parent::setSkinStylesOverride( $moduleSkinStyles );
36
37 $this->skinStyles = $this->extendSkinSpecific( $this->skinStyles, $this->themeStyles );
38 }
39
48 private function getSkinSpecific( $module, $which ): array {
49 $themes = self::getSkinThemeMap();
50
51 return array_combine(
52 array_keys( $themes ),
53 array_map( function ( $theme ) use ( $module, $which ) {
54 if ( $which === 'scripts' ) {
55 return $this->getThemeScriptsPath( $theme, $module );
56 } else {
57 return $this->getThemeStylesPath( $theme, $module );
58 }
59 }, array_values( $themes ) )
60 );
61 }
62
82 private function extendSkinSpecific( array $skinSpecific, array $themeSpecific ): array {
83 // If the module or skin already set skinStyles/skinScripts, prepend ours
84 foreach ( $skinSpecific as $skin => &$files ) {
85 $prepend = $themeSpecific[$skin] ?? $themeSpecific['default'] ?? null;
86 if ( $prepend !== null ) {
87 if ( !is_array( $files ) ) {
88 $files = [ $files ];
89 }
90 array_unshift( $files, $prepend );
91 }
92 }
93 // If the module has no skinStyles/skinScripts for a skin, then set ours
94 foreach ( $themeSpecific as $skin => $file ) {
95 $skinSpecific[$skin] ??= [ $file ];
96 }
97 return $skinSpecific;
98 }
99}
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)