// Group of module
protected $group;
+ // Whether to enable variable expansion (e.g. "{skin}")
+ protected $allowVariables = false;
+
/**
* @param array $options For back-compat, this can be omitted in favour of overwriting getPages.
*/
case 'scripts':
case 'group':
case 'targets':
+ case 'allowVariables':
$this->{$member} = $option;
break;
}
// Filter out pages from origins not allowed by the current wiki configuration.
if ( $config->get( 'UseSiteJs' ) ) {
foreach ( $this->scripts as $script ) {
- $pages[$script] = [ 'type' => 'script' ];
+ $page = $this->expandVariables( $context, $script );
+ $pages[$page] = [ 'type' => 'script' ];
}
}
if ( $config->get( 'UseSiteCss' ) ) {
foreach ( $this->styles as $style ) {
- $pages[$style] = [ 'type' => 'style' ];
+ $page = $this->expandVariables( $context, $style );
+ $pages[$page] = [ 'type' => 'style' ];
}
}
return $pages;
}
+ private function expandVariables( ResourceLoaderContext $context, $pageName ) {
+ if ( !$this->allowVariables ) {
+ return $pageName;
+ }
+ return strtr( $pageName, [
+ '{skin}' => $context->getSkin()
+ ] );
+ }
+
/**
* Get group name
*
// For ResourceLoader::inDebugMode since it doesn't have context
'ResourceLoaderDebug' => true,
+ // For ResourceLoaderContext::newDummyContext()
+ 'DefaultSkin' => 'vector',
+
// Avoid influence from wgInvalidateCacheOnLocalSettingsChange
'CacheEpoch' => '20140101000000',
'scripts' => [ 'MediaWiki:Common.js' ],
];
+ $variableParams = [
+ 'allowVariables' => true,
+ 'styles' => [ 'MediaWiki:Common.css', 'MediaWiki:{skin}.css' ],
+ 'scripts' => [ 'MediaWiki:Common.js', 'MediaWiki:{skin}.js' ],
+ ];
+
return [
[ [], new HashConfig( $settings ), [] ],
[ $params, new HashConfig( $settings ), [
),
[]
],
+ [ $variableParams, new HashConfig( $settings ), [
+ 'MediaWiki:Common.js' => [ 'type' => 'script' ],
+ 'MediaWiki:vector.js' => [ 'type' => 'script' ],
+ 'MediaWiki:Common.css' => [ 'type' => 'style' ],
+ 'MediaWiki:vector.css' => [ 'type' => 'style' ]
+ ] ],
];
}