From cf7225f12756048e7505c4c1205dd845193630e6 Mon Sep 17 00:00:00 2001 From: Porplemontage Date: Fri, 3 Sep 2021 00:55:55 +0000 Subject: [PATCH] Allow the default source namespace to be changed This adds a config option so that the src attribute of the tag can be set to default namespace other than Template. Bug: T290250 Change-Id: Iec4f5d630d025e0bacba05d40cd74fc9312fcae2 --- extension.json | 4 ++++ includes/TemplateStylesHooks.php | 10 +++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/extension.json b/extension.json index eb97754..13a86ba 100644 --- a/extension.json +++ b/extension.json @@ -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 tag. The value 10 corresponds to NS_TEMPLATE.", + "value": 10 } }, "ConfigRegistry": { diff --git a/includes/TemplateStylesHooks.php b/includes/TemplateStylesHooks.php index decc851..2b3c8b4 100644 --- a/includes/TemplateStylesHooks.php +++ b/includes/TemplateStylesHooks.php @@ -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; }