mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateStyles
synced 2024-11-27 17:50:29 +00:00
Allow the default source namespace to be changed
This adds a config option so that the src attribute of the <templatestyles> tag can be set to default namespace other than Template. Bug: T290250 Change-Id: Iec4f5d630d025e0bacba05d40cd74fc9312fcae2
This commit is contained in:
parent
042c5e6a73
commit
cf7225f127
|
@ -114,6 +114,10 @@
|
|||
"TemplateStylesMaxStylesheetSize": {
|
||||
"description": "The maximum size of a stylesheet, in bytes. Set null if you don't want to impose a limit.",
|
||||
"value": 102400
|
||||
},
|
||||
"TemplateStylesDefaultNamespace": {
|
||||
"description": "The default namespace for the src attribute of the <templatestyles> tag. The value 10 corresponds to NS_TEMPLATE.",
|
||||
"value": 10
|
||||
}
|
||||
},
|
||||
"ConfigRegistry": {
|
||||
|
|
|
@ -193,7 +193,6 @@ class TemplateStylesHooks {
|
|||
*/
|
||||
public static function onParserFirstCallInit( Parser $parser ) {
|
||||
$parser->setHook( 'templatestyles', [ __CLASS__, 'handleTag' ] );
|
||||
/** @phan-suppress-next-line PhanUndeclaredProperty */
|
||||
$parser->extTemplateStylesCache = new MapCacheLRU( 100 ); // 100 is arbitrary
|
||||
}
|
||||
|
||||
|
@ -243,7 +242,6 @@ class TemplateStylesHooks {
|
|||
* @param Parser $parser
|
||||
*/
|
||||
public static function onParserClearState( Parser $parser ) {
|
||||
/** @phan-suppress-next-line PhanUndeclaredProperty */
|
||||
$parser->extTemplateStylesCache->clear();
|
||||
}
|
||||
|
||||
|
@ -257,7 +255,8 @@ class TemplateStylesHooks {
|
|||
* @suppress SecurityCheck-XSS
|
||||
*/
|
||||
public static function handleTag( $text, $params, $parser, $frame ) {
|
||||
if ( self::getConfig()->get( 'TemplateStylesDisable' ) ) {
|
||||
$config = self::getConfig();
|
||||
if ( $config->get( 'TemplateStylesDisable' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -277,7 +276,7 @@ class TemplateStylesHooks {
|
|||
// situation. We can't allow for subpage syntax like src="/styles.css"
|
||||
// or the like, though, because stuff like substing and Parsoid would
|
||||
// wind up wanting to make that relative to the wrong page.
|
||||
$title = Title::newFromText( $params['src'], NS_TEMPLATE );
|
||||
$title = Title::newFromText( $params['src'], $config->get( 'TemplateStylesDefaultNamespace' ) );
|
||||
if ( !$title ) {
|
||||
return self::formatTagError( $parser, [ 'templatestyles-invalid-src' ] );
|
||||
}
|
||||
|
@ -332,9 +331,7 @@ class TemplateStylesHooks {
|
|||
}
|
||||
|
||||
// Already cached?
|
||||
/** @phan-suppress-next-line PhanUndeclaredProperty */
|
||||
if ( $parser->extTemplateStylesCache->has( $cacheKey ) ) {
|
||||
/** @phan-suppress-next-line PhanUndeclaredProperty */
|
||||
return $parser->extTemplateStylesCache->get( $cacheKey );
|
||||
}
|
||||
|
||||
|
@ -376,7 +373,6 @@ class TemplateStylesHooks {
|
|||
$ret = Html::inlineStyle( $marker, 'all', [
|
||||
'data-mw-deduplicate' => "TemplateStyles:$cacheKey",
|
||||
] );
|
||||
/** @phan-suppress-next-line PhanUndeclaredProperty */
|
||||
$parser->extTemplateStylesCache->set( $cacheKey, $ret );
|
||||
return $ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue