2017-03-17 01:32:59 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2019-09-14 04:32:54 +00:00
|
|
|
* Module which magically loads the right skinScripts and skinStyles for every
|
2017-03-17 01:32:59 +00:00
|
|
|
* skin, using the specified OOUI theme for each.
|
|
|
|
|
*
|
2019-09-14 04:32:54 +00:00
|
|
|
* @ingroup ResourceLoader
|
|
|
|
|
* @internal
|
2017-03-17 01:32:59 +00:00
|
|
|
*/
|
|
|
|
|
class ResourceLoaderOOUIFileModule extends ResourceLoaderFileModule {
|
|
|
|
|
use ResourceLoaderOOUIModule;
|
|
|
|
|
|
resourceloader: Fix prepending of OOUI theme skinStyles
== Background
Prior to 1367e356e76e:
* Module definition is registered (may have skinStyles).
* If the module already has skinStyles, skip this step.
Otherwise, skin-provided ResourceModuleSkinStyles are merged
into the module def, where '+module' means defaults are kept,
and 'module' replaces the defaults.
* When the module is constructed for bundling,
OOUIFileModule prepends theme-specific resources to skinStyles.
For OOUI and MonoBook that meant:
* oojs-ui-core.styles has no own skinStyles.
* MonoBook/skin.json defines additive (+module) styles,
which are set into an otherwise empty skinStyles array.
* OOUIFileModule sees skinStyles[monobook] and prepends to it.
After 1367e356e76e, it works like this:
* Module definition is registered.
* The module is constructed, and OOUIFileModule sets
skinStyles[monobook] as new key.
* Skin-provided ResourceModuleSkinStyles is ignored because by design
these are not allowed if the module has skinStyles[monobook] set
itself.
This refactor changed nothing for most module classes, but did for
OOUIFileModule.
== Fix
We can move the OOUIFileModule logic up to where the new abstraction
is, or we can move it down toward run-time methods like getStyleFiles
(as SkinModule currently does).
I'm choosing the former as otherwise we lose automatic versioning,
caching, and inclusion in PHPUnit structure tests for file existence
and Less syntax etc.
Bug: T290013
Change-Id: Id7c258841d7816e710961a1f7c7f7c99764cf59a
2021-08-31 19:57:04 +00:00
|
|
|
/** @var array<string,string|ResourceLoaderFilePath> */
|
|
|
|
|
private $themeStyles = [];
|
|
|
|
|
|
2019-10-07 05:22:02 +00:00
|
|
|
public function __construct( array $options = [] ) {
|
2019-04-06 12:48:39 +00:00
|
|
|
if ( isset( $options['themeScripts'] ) ) {
|
|
|
|
|
$skinScripts = $this->getSkinSpecific( $options['themeScripts'], 'scripts' );
|
2017-06-05 17:32:23 +00:00
|
|
|
if ( !isset( $options['skinScripts'] ) ) {
|
|
|
|
|
$options['skinScripts'] = [];
|
|
|
|
|
}
|
|
|
|
|
$this->extendSkinSpecific( $options['skinScripts'], $skinScripts );
|
2017-03-17 01:32:59 +00:00
|
|
|
}
|
2019-04-06 12:48:39 +00:00
|
|
|
if ( isset( $options['themeStyles'] ) ) {
|
resourceloader: Fix prepending of OOUI theme skinStyles
== Background
Prior to 1367e356e76e:
* Module definition is registered (may have skinStyles).
* If the module already has skinStyles, skip this step.
Otherwise, skin-provided ResourceModuleSkinStyles are merged
into the module def, where '+module' means defaults are kept,
and 'module' replaces the defaults.
* When the module is constructed for bundling,
OOUIFileModule prepends theme-specific resources to skinStyles.
For OOUI and MonoBook that meant:
* oojs-ui-core.styles has no own skinStyles.
* MonoBook/skin.json defines additive (+module) styles,
which are set into an otherwise empty skinStyles array.
* OOUIFileModule sees skinStyles[monobook] and prepends to it.
After 1367e356e76e, it works like this:
* Module definition is registered.
* The module is constructed, and OOUIFileModule sets
skinStyles[monobook] as new key.
* Skin-provided ResourceModuleSkinStyles is ignored because by design
these are not allowed if the module has skinStyles[monobook] set
itself.
This refactor changed nothing for most module classes, but did for
OOUIFileModule.
== Fix
We can move the OOUIFileModule logic up to where the new abstraction
is, or we can move it down toward run-time methods like getStyleFiles
(as SkinModule currently does).
I'm choosing the former as otherwise we lose automatic versioning,
caching, and inclusion in PHPUnit structure tests for file existence
and Less syntax etc.
Bug: T290013
Change-Id: Id7c258841d7816e710961a1f7c7f7c99764cf59a
2021-08-31 19:57:04 +00:00
|
|
|
$this->themeStyles = $this->getSkinSpecific( $options['themeStyles'], 'styles' );
|
2017-03-17 01:32:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent::__construct( $options );
|
|
|
|
|
}
|
|
|
|
|
|
resourceloader: Fix prepending of OOUI theme skinStyles
== Background
Prior to 1367e356e76e:
* Module definition is registered (may have skinStyles).
* If the module already has skinStyles, skip this step.
Otherwise, skin-provided ResourceModuleSkinStyles are merged
into the module def, where '+module' means defaults are kept,
and 'module' replaces the defaults.
* When the module is constructed for bundling,
OOUIFileModule prepends theme-specific resources to skinStyles.
For OOUI and MonoBook that meant:
* oojs-ui-core.styles has no own skinStyles.
* MonoBook/skin.json defines additive (+module) styles,
which are set into an otherwise empty skinStyles array.
* OOUIFileModule sees skinStyles[monobook] and prepends to it.
After 1367e356e76e, it works like this:
* Module definition is registered.
* The module is constructed, and OOUIFileModule sets
skinStyles[monobook] as new key.
* Skin-provided ResourceModuleSkinStyles is ignored because by design
these are not allowed if the module has skinStyles[monobook] set
itself.
This refactor changed nothing for most module classes, but did for
OOUIFileModule.
== Fix
We can move the OOUIFileModule logic up to where the new abstraction
is, or we can move it down toward run-time methods like getStyleFiles
(as SkinModule currently does).
I'm choosing the former as otherwise we lose automatic versioning,
caching, and inclusion in PHPUnit structure tests for file existence
and Less syntax etc.
Bug: T290013
Change-Id: Id7c258841d7816e710961a1f7c7f7c99764cf59a
2021-08-31 19:57:04 +00:00
|
|
|
public function setSkinStylesOverride( array $moduleSkinStyles ): void {
|
|
|
|
|
parent::setSkinStylesOverride( $moduleSkinStyles );
|
|
|
|
|
|
|
|
|
|
$this->extendSkinSpecific( $this->skinStyles, $this->themeStyles );
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 01:32:59 +00:00
|
|
|
/**
|
|
|
|
|
* Helper function to generate values for 'skinStyles' and 'skinScripts'.
|
|
|
|
|
*
|
|
|
|
|
* @param string $module Module to generate skinStyles/skinScripts for:
|
|
|
|
|
* 'core', 'widgets', 'toolbars', 'windows'
|
|
|
|
|
* @param string $which 'scripts' or 'styles'
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
private function getSkinSpecific( $module, $which ): array {
|
2017-03-17 01:32:59 +00:00
|
|
|
$themes = self::getSkinThemeMap();
|
|
|
|
|
|
|
|
|
|
return array_combine(
|
|
|
|
|
array_keys( $themes ),
|
|
|
|
|
array_map( function ( $theme ) use ( $module, $which ) {
|
|
|
|
|
if ( $which === 'scripts' ) {
|
|
|
|
|
return $this->getThemeScriptsPath( $theme, $module );
|
|
|
|
|
} else {
|
|
|
|
|
return $this->getThemeStylesPath( $theme, $module );
|
|
|
|
|
}
|
|
|
|
|
}, array_values( $themes ) )
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-06-05 17:32:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepend the $extraSkinSpecific assoc. array to the $skinSpecific assoc. array.
|
|
|
|
|
* Both of them represent a 'skinScripts' or 'skinStyles' definition.
|
|
|
|
|
*
|
|
|
|
|
* @param array &$skinSpecific
|
|
|
|
|
* @param array $extraSkinSpecific
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
private function extendSkinSpecific( array &$skinSpecific, array $extraSkinSpecific ): void {
|
2017-06-05 17:32:23 +00:00
|
|
|
// For each skin where skinStyles/skinScripts are defined, add our ones at the beginning
|
|
|
|
|
foreach ( $skinSpecific as $skin => $files ) {
|
|
|
|
|
if ( !is_array( $files ) ) {
|
|
|
|
|
$files = [ $files ];
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $extraSkinSpecific[$skin] ) ) {
|
|
|
|
|
$skinSpecific[$skin] = array_merge( [ $extraSkinSpecific[$skin] ], $files );
|
|
|
|
|
} elseif ( isset( $extraSkinSpecific['default'] ) ) {
|
|
|
|
|
$skinSpecific[$skin] = array_merge( [ $extraSkinSpecific['default'] ], $files );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Add our remaining skinStyles/skinScripts for skins that did not have them defined
|
|
|
|
|
foreach ( $extraSkinSpecific as $skin => $file ) {
|
|
|
|
|
if ( !isset( $skinSpecific[$skin] ) ) {
|
resourceloader: Fix prepending of OOUI theme skinStyles
== Background
Prior to 1367e356e76e:
* Module definition is registered (may have skinStyles).
* If the module already has skinStyles, skip this step.
Otherwise, skin-provided ResourceModuleSkinStyles are merged
into the module def, where '+module' means defaults are kept,
and 'module' replaces the defaults.
* When the module is constructed for bundling,
OOUIFileModule prepends theme-specific resources to skinStyles.
For OOUI and MonoBook that meant:
* oojs-ui-core.styles has no own skinStyles.
* MonoBook/skin.json defines additive (+module) styles,
which are set into an otherwise empty skinStyles array.
* OOUIFileModule sees skinStyles[monobook] and prepends to it.
After 1367e356e76e, it works like this:
* Module definition is registered.
* The module is constructed, and OOUIFileModule sets
skinStyles[monobook] as new key.
* Skin-provided ResourceModuleSkinStyles is ignored because by design
these are not allowed if the module has skinStyles[monobook] set
itself.
This refactor changed nothing for most module classes, but did for
OOUIFileModule.
== Fix
We can move the OOUIFileModule logic up to where the new abstraction
is, or we can move it down toward run-time methods like getStyleFiles
(as SkinModule currently does).
I'm choosing the former as otherwise we lose automatic versioning,
caching, and inclusion in PHPUnit structure tests for file existence
and Less syntax etc.
Bug: T290013
Change-Id: Id7c258841d7816e710961a1f7c7f7c99764cf59a
2021-08-31 19:57:04 +00:00
|
|
|
$skinSpecific[$skin] = [ $file ];
|
2017-06-05 17:32:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-17 01:32:59 +00:00
|
|
|
}
|