From 4bc7abb0ac31c105d4e419ef5f939c5c79457a63 Mon Sep 17 00:00:00 2001 From: MGChecker Date: Thu, 18 Oct 2018 15:37:23 +0200 Subject: [PATCH] Set "TemplateSandboxEditNamespaces" in extension.json If TemplateStyles installed, then enable it in the Module namespace by default. This change is analogous to I96d9601ff80c2d3eb052c01. Since both extensions use the ContentHandlerDefaultModelFor hook, Scribunto will check if the sanitized-css model has already been set, and if so, not override it. If the page is in NS_MODULE, it will set the content model to Scribunto, but allow further hooks to override it, in which case it is expected that TemplateStyles would set it to sanitized-css. Bug: T200914 Depends-On: I2fa9b822ee39bcc5f95a293c8c4aad4d53ede30a Change-Id: I7a9b445accde35e4a5e7d13100c646f211d21afe --- extension.json | 3 +++ includes/common/Hooks.php | 6 +++++- tests/phpunit/common/HooksTest.php | 10 ++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/extension.json b/extension.json index 6da32373..bc608e42 100644 --- a/extension.json +++ b/extension.json @@ -164,5 +164,8 @@ "TemplateSandboxEditNamespaces": [ 828 ], + "TemplateStylesNamespaces": [ + 828 + ], "manifest_version": 1 } diff --git a/includes/common/Hooks.php b/includes/common/Hooks.php index 43ca6587..10534903 100644 --- a/includes/common/Hooks.php +++ b/includes/common/Hooks.php @@ -261,9 +261,13 @@ class ScribuntoHooks { * @return bool */ public static function contentHandlerDefaultModelFor( Title $title, &$model ) { + if ( $model === 'sanitized-css' ) { + // Let TemplateStyles override Scribunto + return true; + } if ( $title->getNamespace() == NS_MODULE && !Scribunto::isDocPage( $title ) ) { $model = CONTENT_MODEL_SCRIBUNTO; - return false; + return true; } return true; } diff --git a/tests/phpunit/common/HooksTest.php b/tests/phpunit/common/HooksTest.php index 55233c4c..d6002543 100644 --- a/tests/phpunit/common/HooksTest.php +++ b/tests/phpunit/common/HooksTest.php @@ -4,10 +4,10 @@ class ScribuntoHooksTest extends MediaWikiLangTestCase { public function provideContentHandlerDefaultModelFor() { return [ - [ 'Module:Foo', CONTENT_MODEL_SCRIBUNTO, false ], + [ 'Module:Foo', CONTENT_MODEL_SCRIBUNTO, true ], [ 'Module:Foo/doc', null, true ], + [ 'Module:Foo/styles.css', 'sanitized-css', true, 'sanitized-css' ], [ 'Main Page', null, true ], - ]; } @@ -15,9 +15,11 @@ class ScribuntoHooksTest extends MediaWikiLangTestCase { * @covers ScribuntoHooks::contentHandlerDefaultModelFor * @dataProvider provideContentHandlerDefaultModelFor */ - public function testContentHandlerDefaultModelFor( $name, $expected, $retVal ) { + public function testContentHandlerDefaultModelFor( $name, $expected, + $retVal, $before = null + ) { $title = Title::newFromText( $name ); - $model = null; + $model = $before; $ret = ScribuntoHooks::contentHandlerDefaultModelFor( $title, $model ); $this->assertSame( $retVal, $ret ); $this->assertSame( $expected, $model );