From d7e525b7af26896c586be2ac30e7a51a4773be6b Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Thu, 20 Jul 2023 10:00:43 +0200 Subject: [PATCH 01/13] feat: Implement margin|padding-inline|block In reference to https://www.mediawiki.org/wiki/Topic:Xm7z9eroimlh75co --- includes/Hooks/StylesheetSanitizerHook.php | 1 + includes/StylePropertySanitizerExtender.php | 6 ++-- includes/TemplateStylesExtender.php | 32 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/includes/Hooks/StylesheetSanitizerHook.php b/includes/Hooks/StylesheetSanitizerHook.php index 0e565bd..d46a711 100644 --- a/includes/Hooks/StylesheetSanitizerHook.php +++ b/includes/Hooks/StylesheetSanitizerHook.php @@ -67,6 +67,7 @@ class StylesheetSanitizerHook { $extended->addPointerEvents( $extender ); $extended->addScrollMarginProperties( $extender, $matcherFactory ); $extended->addAspectRatio( $extender, $matcherFactory ); + $extended->addInlineBlockMarginPaddingProperties( $extender, $matcherFactory ); $propertySanitizer->setKnownProperties( $extender->getKnownProperties() ); } diff --git a/includes/StylePropertySanitizerExtender.php b/includes/StylePropertySanitizerExtender.php index 1d75037..ac340e1 100644 --- a/includes/StylePropertySanitizerExtender.php +++ b/includes/StylePropertySanitizerExtender.php @@ -103,7 +103,7 @@ class StylePropertySanitizerExtender extends StylePropertySanitizer { ] ), new Alternative( [ $matcherFactory->color(), - new FunctionMatcher( 'var', new VarNameMatcher() ), + new FunctionMatcher( 'var', new VarNameMatcher() ), ] ) ] ); @@ -112,9 +112,9 @@ class StylePropertySanitizerExtender extends StylePropertySanitizer { Quantifier::hash( UnorderedGroup::allOf( [ Quantifier::optional( new KeywordMatcher( 'inset' ) ), Quantifier::count( $matcherFactory->length(), 2, 4 ), - Quantifier::optional(new Alternative( [ + Quantifier::optional( new Alternative( [ $matcherFactory->color(), - new FunctionMatcher( 'var', new VarNameMatcher() ), + new FunctionMatcher( 'var', new VarNameMatcher() ), ] ) ), ] ) ) ] ); diff --git a/includes/TemplateStylesExtender.php b/includes/TemplateStylesExtender.php index 86b6b58..d432c84 100644 --- a/includes/TemplateStylesExtender.php +++ b/includes/TemplateStylesExtender.php @@ -206,6 +206,38 @@ class TemplateStylesExtender { } } + /** + * Adds padding|margin-inline|block support + * + * @param StylePropertySanitizer $propertySanitizer + * @param MatcherFactory $factory + */ + public function addInlineBlockMarginPaddingProperties( $propertySanitizer, $factory ): void { + $auto = new KeywordMatcher( 'auto' ); + $autoLengthPct = new Alternative( [ $auto, $factory->lengthPercentage() ] ); + + $props = []; + + $props['margin-block-end'] = $autoLengthPct; + $props['margin-block-start'] = $autoLengthPct; + $props['margin-block'] = Quantifier::count( $autoLengthPct, 1, 2 ); + $props['margin-inline-end'] = $autoLengthPct; + $props['margin-inline-start'] = $autoLengthPct; + $props['margin-inline'] = Quantifier::count( $autoLengthPct, 1, 2 ); + $props['padding-block-end'] = $autoLengthPct; + $props['padding-block-start'] = $autoLengthPct; + $props['padding-block'] = Quantifier::count( $autoLengthPct, 1, 2 ); + $props['padding-inline-end'] = $autoLengthPct; + $props['padding-inline-start'] = $autoLengthPct; + $props['padding-inline'] = Quantifier::count( $autoLengthPct, 1, 2 ); + + try { + $propertySanitizer->addKnownProperties( $props ); + } catch ( InvalidArgumentException $e ) { + // Fail silently + } + } + /** * Adds the pointer-events matcher * From b249ebd8019d73d88d288d8acb1a504370bbb37b Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Fri, 4 Aug 2023 10:32:30 +0200 Subject: [PATCH 02/13] feat(Var): Add fallback support for `var()` e.g. `color: var( --color-base, #fff )` --- includes/TemplateStylesExtender.php | 50 +++++++++++++++++------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/includes/TemplateStylesExtender.php b/includes/TemplateStylesExtender.php index d432c84..94832dc 100644 --- a/includes/TemplateStylesExtender.php +++ b/includes/TemplateStylesExtender.php @@ -51,36 +51,44 @@ class TemplateStylesExtender { * @param MatcherFactory $factory */ public function addVarSelector( StylePropertySanitizer $propertySanitizer, MatcherFactory $factory ): void { + $anyProperty = new Alternative( [ + $factory->color(), + $factory->image(), + $factory->length(), + $factory->integer(), + $factory->percentage(), + $factory->number(), + $factory->angle(), + $factory->frequency(), + $factory->resolution(), + $factory->position(), + $factory->cssSingleEasingFunction(), + $factory->comma(), + $factory->cssWideKeywords(), + new KeywordMatcher( [ + 'solid', 'double', 'dotted', 'dashed', 'wavy' + ] ) + ] ); + $var = new FunctionMatcher( 'var', new Juxtaposition( [ new WhitespaceMatcher( [ 'significant' => false ] ), new VarNameMatcher(), new WhitespaceMatcher( [ 'significant' => false ] ), + Quantifier::optional( new Juxtaposition( [ + $factory->comma(), + new WhitespaceMatcher( [ 'significant' => false ] ), + $anyProperty, + ] ) ), + new WhitespaceMatcher( [ 'significant' => false ] ), ] ) ); - $anyProperty = Quantifier::star( - new Alternative( [ - $var, - $factory->color(), - $factory->image(), - $factory->length(), - $factory->integer(), - $factory->percentage(), - $factory->number(), - $factory->angle(), - $factory->frequency(), - $factory->resolution(), - $factory->position(), - $factory->cssSingleEasingFunction(), - $factory->comma(), - $factory->cssWideKeywords(), - new KeywordMatcher( [ - 'solid', 'double', 'dotted', 'dashed', 'wavy' - ] ) - ] ) - ); + $anyProperty = Quantifier::star( new Alternative( [ + $var, + $anyProperty, + ] ) ); // Match anything*\s?[var anything|anything var]+\s?anything*(!important)? // The problem is, that var() can be used more or less anywhere From 81813bca52b7e411d392d3b71786016ba94eef85 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Fri, 11 Aug 2023 09:39:00 +0200 Subject: [PATCH 03/13] refactor: Use DI in hooks --- extension.json | 6 +++++- includes/Hooks/MainHooks.php | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/extension.json b/extension.json index 1212c15..764e09d 100644 --- a/extension.json +++ b/extension.json @@ -48,7 +48,11 @@ }, "HookHandlers": { "MainHooks": { - "class": "MediaWiki\\Extension\\TemplateStylesExtender\\Hooks\\MainHooks" + "class": "MediaWiki\\Extension\\TemplateStylesExtender\\Hooks\\MainHooks", + "services": [ + "PermissionManager", + "UserFactory" + ] } }, "Hooks": { diff --git a/includes/Hooks/MainHooks.php b/includes/Hooks/MainHooks.php index 2c62611..32bb7cd 100644 --- a/includes/Hooks/MainHooks.php +++ b/includes/Hooks/MainHooks.php @@ -6,13 +6,22 @@ use MediaWiki\Extension\TemplateStyles\Hooks; use MediaWiki\Extension\TemplateStylesExtender\TemplateStylesExtender; use MediaWiki\Hook\EditPage__attemptSaveHook; use MediaWiki\Hook\ParserFirstCallInitHook; -use MediaWiki\MediaWikiServices; +use MediaWiki\Permissions\PermissionManager; use MediaWiki\Revision\SlotRecord; +use MediaWiki\User\UserFactory; use MWException; use PermissionsError; class MainHooks implements ParserFirstCallInitHook, EditPage__attemptSaveHook { + private PermissionManager $manager; + private UserFactory $factory; + + public function __construct( PermissionManager $manager, UserFactory $factory ) { + $this->manager = $manager; + $this->factory = $factory; + } + /** * @throws MWException */ @@ -69,13 +78,10 @@ class MainHooks implements ParserFirstCallInitHook, EditPage__attemptSaveHook { $permission = TemplateStylesExtender::getConfigValue( 'TemplateStylesExtenderUnscopingPermission' ); - $permManager = MediaWikiServices::getInstance()->getPermissionManager(); - $user = MediaWikiServices::getInstance() - ->getUserFactory() - ->newFromUserIdentity( $editpage_Obj->getContext()->getUser() ); + $user = $this->factory->newFromUserIdentity( $editpage_Obj->getContext()->getUser() ); - $userCan = $permManager->userHasRight( $user, $permission ) || - $permManager->userCan( $permission, $user, $editpage_Obj->getTitle() ); + $userCan = $this->manager->userHasRight( $user, $permission ) || + $this->manager->userCan( $permission, $user, $editpage_Obj->getTitle() ); if ( strpos( $content->getText(), 'wrapclass' ) !== false && !$userCan ) { throw new PermissionsError( $permission, [ 'templatestylesextender-unscope-no-permisson' ] ); From b66e7c28860e2f1bb0fb5b87a04cea1bfb66dc17 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Tue, 15 Aug 2023 12:49:04 +0200 Subject: [PATCH 04/13] refactor: Raise required php version to >=8.0 --- composer.json | 2 +- extension.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 41914b7..fa4cc20 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ } ], "require": { - "php": ">=7.3.19", + "php": ">=8.0", "ext-json": "*", "composer/installers": ">=1.0.1" }, diff --git a/extension.json b/extension.json index 764e09d..415812b 100644 --- a/extension.json +++ b/extension.json @@ -11,7 +11,7 @@ "requires": { "MediaWiki": ">= 1.39.0", "platform": { - "php": ">=7.3.19" + "php": ">=8.0" }, "extensions": { "TemplateStyles": ">= 1.0" From fccec1e4ee53eb052240b6f64dd066e2755f0071 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Fri, 18 Aug 2023 13:43:20 +0200 Subject: [PATCH 05/13] feat: Add lint jobs --- .github/workflows/lint-check.yml | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/lint-check.yml diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml new file mode 100644 index 0000000..c2be628 --- /dev/null +++ b/.github/workflows/lint-check.yml @@ -0,0 +1,38 @@ +name: Lint Tests +on: + push: + branches: [ master, develop, feature/** ] + pull_request: + branches: [ master ] +jobs: + lint-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Installing PHP + uses: shivammathur/setup-php@master + with: + php-version: '8.0' + - name: Get Composer Cache Directory 2 + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + - uses: actions/cache@v3 + id: actions-cache + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + - name: Cache PHP dependencies + uses: actions/cache@v3 + id: vendor-cache + with: + path: vendor + key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }} + - name: Composer install + if: steps.vendor-cache.outputs.cache-hit != 'true' + run: composer install --no-ansi --no-interaction --no-scripts --no-suggest --prefer-dist + - name: Run Test + run: composer run test From 8b834905f99b80d7a3a7207a451bb15b10045997 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Fri, 18 Aug 2023 14:29:30 +0200 Subject: [PATCH 06/13] refactor: Use $GITHUB_OUTPUT --- .github/workflows/lint-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml index c2be628..7a04f06 100644 --- a/.github/workflows/lint-check.yml +++ b/.github/workflows/lint-check.yml @@ -17,7 +17,7 @@ jobs: - name: Get Composer Cache Directory 2 id: composer-cache run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - uses: actions/cache@v3 id: actions-cache with: From 307aa8909c4f8caec46ee897a0a99ad7fa09ce58 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Fri, 18 Aug 2023 14:36:52 +0200 Subject: [PATCH 07/13] refactor: Make linter happy --- includes/Hooks/MainHooks.php | 29 ++++++++++++++++++++++-- includes/Hooks/PropertySanitizerHook.php | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/includes/Hooks/MainHooks.php b/includes/Hooks/MainHooks.php index 32bb7cd..2516fe8 100644 --- a/includes/Hooks/MainHooks.php +++ b/includes/Hooks/MainHooks.php @@ -2,6 +2,7 @@ namespace MediaWiki\Extension\TemplateStylesExtender\Hooks; +use MediaWiki\EditPage\EditPage; use MediaWiki\Extension\TemplateStyles\Hooks; use MediaWiki\Extension\TemplateStylesExtender\TemplateStylesExtender; use MediaWiki\Hook\EditPage__attemptSaveHook; @@ -10,19 +11,36 @@ use MediaWiki\Permissions\PermissionManager; use MediaWiki\Revision\SlotRecord; use MediaWiki\User\UserFactory; use MWException; +use Parser; use PermissionsError; +use PPFrame; +/** + * phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName + */ class MainHooks implements ParserFirstCallInitHook, EditPage__attemptSaveHook { + /** + * @var PermissionManager + */ private PermissionManager $manager; + + /** + * @var UserFactory + */ private UserFactory $factory; + /** + * @param PermissionManager $manager + * @param UserFactory $factory + */ public function __construct( PermissionManager $manager, UserFactory $factory ) { $this->manager = $manager; $this->factory = $factory; } /** + * @param Parser $parser * @throws MWException */ public function onParserFirstCallInit( $parser ) { @@ -30,7 +48,14 @@ class MainHooks implements ParserFirstCallInitHook, EditPage__attemptSaveHook { } /** - * This is a wrapper for tags, that allows unscoping of css for users with 'editinterface' permissions + * This is a wrapper for tags, + * that allows unscoping of css for users with 'editinterface' permissions + * + * @param string $text + * @param string[] $params + * @param Parser $parser + * @param PPFrame $frame + * @return string * @see Hooks::handleTag() */ public static function handleTag( $text, $params, $parser, $frame ): string { @@ -57,7 +82,7 @@ class MainHooks implements ParserFirstCallInitHook, EditPage__attemptSaveHook { /** * Check if 'wrapclass' was used in the page, if so only users with 'editinterface' permissions may save the page * - * @param $editpage_Obj + * @param EditPage $editpage_Obj * @return true * @throws PermissionsError */ diff --git a/includes/Hooks/PropertySanitizerHook.php b/includes/Hooks/PropertySanitizerHook.php index 5a2ab68..88f1e0a 100644 --- a/includes/Hooks/PropertySanitizerHook.php +++ b/includes/Hooks/PropertySanitizerHook.php @@ -27,7 +27,7 @@ use Wikimedia\CSS\Sanitizer\StylePropertySanitizer; class PropertySanitizerHook { /** - * @param StylePropertySanitizer $propertySanitizer + * @param StylePropertySanitizer &$propertySanitizer * @param TemplateStylesMatcherFactory $matcherFactory */ public static function onSanitize( &$propertySanitizer, $matcherFactory ): void { From c1344759978b2c2d9310411c1bc40ffc0c2ef3ba Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Tue, 10 Oct 2023 09:24:14 +0200 Subject: [PATCH 08/13] feat: Add `inset` support Implements #11 --- includes/Hooks/StylesheetSanitizerHook.php | 1 + includes/TemplateStylesExtender.php | 29 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/includes/Hooks/StylesheetSanitizerHook.php b/includes/Hooks/StylesheetSanitizerHook.php index d46a711..ed2a473 100644 --- a/includes/Hooks/StylesheetSanitizerHook.php +++ b/includes/Hooks/StylesheetSanitizerHook.php @@ -68,6 +68,7 @@ class StylesheetSanitizerHook { $extended->addScrollMarginProperties( $extender, $matcherFactory ); $extended->addAspectRatio( $extender, $matcherFactory ); $extended->addInlineBlockMarginPaddingProperties( $extender, $matcherFactory ); + $extended->addInsetProperties( $extender, $matcherFactory ); $propertySanitizer->setKnownProperties( $extender->getKnownProperties() ); } diff --git a/includes/TemplateStylesExtender.php b/includes/TemplateStylesExtender.php index 94832dc..62c65c7 100644 --- a/includes/TemplateStylesExtender.php +++ b/includes/TemplateStylesExtender.php @@ -246,6 +246,35 @@ class TemplateStylesExtender { } } + /** + * Adds padding|margin-inline|block support + * + * @param StylePropertySanitizer $propertySanitizer + * @param MatcherFactory $factory + */ + public function addInsetProperties( $propertySanitizer, $factory ): void { + $auto = new KeywordMatcher( 'auto' ); + $autoLengthPct = new Alternative( [ $auto, $factory->lengthPercentage() ] ); + + $props = []; + + $props['inset'] = Quantifier::count( $autoLengthPct, 1, 4 ); + + $props['inset-block'] = Quantifier::count( $autoLengthPct, 1, 2 ); + $props['inset-block-end'] = $autoLengthPct; + $props['inset-block-start'] = $autoLengthPct; + + $props['inset-inline'] = Quantifier::count( $autoLengthPct, 1, 2 ); + $props['inset-inline-end'] = $autoLengthPct; + $props['inset-inline-start'] = $autoLengthPct; + + try { + $propertySanitizer->addKnownProperties( $props ); + } catch ( InvalidArgumentException $e ) { + // Fail silently + } + } + /** * Adds the pointer-events matcher * From 746002bcdd7c888fbc8db3e411f6b9e17d2bdf82 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Tue, 10 Oct 2023 09:31:25 +0200 Subject: [PATCH 09/13] feat: Add `RGBA` support Implements #13 --- includes/Hooks/PropertySanitizerHook.php | 2 +- includes/MatcherFactoryExtender.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/includes/Hooks/PropertySanitizerHook.php b/includes/Hooks/PropertySanitizerHook.php index 88f1e0a..5a2ab68 100644 --- a/includes/Hooks/PropertySanitizerHook.php +++ b/includes/Hooks/PropertySanitizerHook.php @@ -27,7 +27,7 @@ use Wikimedia\CSS\Sanitizer\StylePropertySanitizer; class PropertySanitizerHook { /** - * @param StylePropertySanitizer &$propertySanitizer + * @param StylePropertySanitizer $propertySanitizer * @param TemplateStylesMatcherFactory $matcherFactory */ public static function onSanitize( &$propertySanitizer, $matcherFactory ): void { diff --git a/includes/MatcherFactoryExtender.php b/includes/MatcherFactoryExtender.php index ee5be86..c306ffe 100644 --- a/includes/MatcherFactoryExtender.php +++ b/includes/MatcherFactoryExtender.php @@ -53,6 +53,25 @@ class MatcherFactoryExtender extends MatcherFactory { return $this->cache[__METHOD__]; } + /** + * CSS-color extension enabling RGBA + * @see https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color + * @return Matcher + */ + public function color() + { + if ( !isset( $this->cache[__METHOD__] ) ) { + $color = new Alternative( [ + parent::color(), + new TokenMatcher( Token::T_HASH, static function ( Token $t ) { + return preg_match( '/^([0-9a-f]{4})|([0-9a-f]{8})$/i', $t->value() ); + } ), + ]); + $this->cache[__METHOD__] = $color; + } + return $this->cache[__METHOD__]; + } + /** * This is in reality a complete copy of the parent hook with line 68 and 110 extended * This can very easily break if there is an update upstream From 97e51afdad585fbfb8837036268afa714dd453d6 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Tue, 10 Oct 2023 09:42:34 +0200 Subject: [PATCH 10/13] feat: Add color function `var` support Implements #12 --- includes/Hooks/PropertySanitizerHook.php | 2 +- includes/MatcherFactoryExtender.php | 42 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/includes/Hooks/PropertySanitizerHook.php b/includes/Hooks/PropertySanitizerHook.php index 5a2ab68..88f1e0a 100644 --- a/includes/Hooks/PropertySanitizerHook.php +++ b/includes/Hooks/PropertySanitizerHook.php @@ -27,7 +27,7 @@ use Wikimedia\CSS\Sanitizer\StylePropertySanitizer; class PropertySanitizerHook { /** - * @param StylePropertySanitizer $propertySanitizer + * @param StylePropertySanitizer &$propertySanitizer * @param TemplateStylesMatcherFactory $matcherFactory */ public static function onSanitize( &$propertySanitizer, $matcherFactory ): void { diff --git a/includes/MatcherFactoryExtender.php b/includes/MatcherFactoryExtender.php index c306ffe..6eea9c9 100644 --- a/includes/MatcherFactoryExtender.php +++ b/includes/MatcherFactoryExtender.php @@ -21,6 +21,7 @@ declare( strict_types=1 ); namespace MediaWiki\Extension\TemplateStylesExtender; +use MediaWiki\Extension\TemplateStylesExtender\Matcher\VarNameMatcher; use Wikimedia\CSS\Grammar\Alternative; use Wikimedia\CSS\Grammar\AnythingMatcher; use Wikimedia\CSS\Grammar\BlockMatcher; @@ -72,6 +73,47 @@ class MatcherFactoryExtender extends MatcherFactory { return $this->cache[__METHOD__]; } + /** + * Adds `var` support to color functions + * @return Matcher|Matcher[] + */ + protected function colorFuncs() { + if ( !isset( $this->cache[__METHOD__] ) ) { + $var = new FunctionMatcher( 'var', new VarNameMatcher() ); + + $i = $this->integer(); + $iVar = new Alternative([ $var, $i ]); + + $n = $this->number(); + $nVar = new Alternative([ $var, $n ]); + + $p = $this->percentage(); + $pVar = new Alternative([ $var, $p ]); + + $this->cache[__METHOD__] = [ + new FunctionMatcher( 'rgb', new Alternative( [ + Quantifier::hash( $iVar, 3, 3 ), + Quantifier::hash( $pVar, 3, 3 ), + Quantifier::hash( $var, 1, 3 ), + ] ) ), + new FunctionMatcher( 'rgba', new Alternative( [ + new Juxtaposition( [ $iVar, $iVar, $iVar, $nVar ], true ), + new Juxtaposition( [ $pVar, $pVar, $pVar, $nVar ], true ), + Quantifier::hash( $var, 1, 4 ), + ] ) ), + new FunctionMatcher( 'hsl', new Alternative([ + new Juxtaposition( [ $nVar, $pVar, $pVar ], true ), + Quantifier::hash($var, 1, 3), + ]) ), + new FunctionMatcher( 'hsla', new Alternative([ + new Juxtaposition( [ $nVar, $pVar, $pVar, $nVar ], true ), + Quantifier::hash($var, 1, 4), + ]) ), + ]; + } + return $this->cache[__METHOD__]; + } + /** * This is in reality a complete copy of the parent hook with line 68 and 110 extended * This can very easily break if there is an update upstream From b6a62fbfb52184c6f89b27750c1ed099995ed7eb Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Tue, 10 Oct 2023 11:42:34 +0200 Subject: [PATCH 11/13] fix: Fix `rgba` --- includes/MatcherFactoryExtender.php | 1 + includes/StylePropertySanitizerExtender.php | 13 ++++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/includes/MatcherFactoryExtender.php b/includes/MatcherFactoryExtender.php index 6eea9c9..fbcbed4 100644 --- a/includes/MatcherFactoryExtender.php +++ b/includes/MatcherFactoryExtender.php @@ -100,6 +100,7 @@ class MatcherFactoryExtender extends MatcherFactory { new Juxtaposition( [ $iVar, $iVar, $iVar, $nVar ], true ), new Juxtaposition( [ $pVar, $pVar, $pVar, $nVar ], true ), Quantifier::hash( $var, 1, 4 ), + new Juxtaposition( [ Quantifier::hash( $var, 1, 3 ), $nVar ], true ), ] ) ), new FunctionMatcher( 'hsl', new Alternative([ new Juxtaposition( [ $nVar, $pVar, $pVar ], true ), diff --git a/includes/StylePropertySanitizerExtender.php b/includes/StylePropertySanitizerExtender.php index ac340e1..d8505ca 100644 --- a/includes/StylePropertySanitizerExtender.php +++ b/includes/StylePropertySanitizerExtender.php @@ -27,11 +27,9 @@ use Wikimedia\CSS\Grammar\FunctionMatcher; use Wikimedia\CSS\Grammar\KeywordMatcher; use Wikimedia\CSS\Grammar\MatcherFactory; use Wikimedia\CSS\Grammar\Quantifier; -use Wikimedia\CSS\Grammar\TokenMatcher; use Wikimedia\CSS\Grammar\UnorderedGroup; use Wikimedia\CSS\Objects\CSSObject; use Wikimedia\CSS\Objects\Declaration; -use Wikimedia\CSS\Objects\Token; use Wikimedia\CSS\Sanitizer\StylePropertySanitizer; class StylePropertySanitizerExtender extends StylePropertySanitizer { @@ -42,6 +40,10 @@ class StylePropertySanitizerExtender extends StylePropertySanitizer { private static $extendedCssSizing3 = false; private static $extendedCss1Masking = false; + public function __construct( MatcherFactory $matcherFactory ) { + parent::__construct( new MatcherFactoryExtender() ); + } + /** * @inheritDoc * Allow overflow-wrap: anywhere @@ -87,13 +89,6 @@ class StylePropertySanitizerExtender extends StylePropertySanitizer { $props = parent::cssBorderBackground3( $matcherFactory ); - $props['background-color'] = new Alternative( [ - $matcherFactory->color(), - new TokenMatcher( Token::T_HASH, function ( Token $t ) { - return preg_match( '/^([0-9a-f]{3}|[0-9a-f]{8})$/i', $t->value() ); - } ), - ] ); - $props['border'] = UnorderedGroup::someOf( [ new KeywordMatcher( [ 'none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset' From 823336d2b51c3cab429cb7b1b7bb9f02072006b9 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Thu, 14 Dec 2023 09:21:34 +0100 Subject: [PATCH 12/13] nit: Make linter happy --- includes/StylePropertySanitizerExtender.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/StylePropertySanitizerExtender.php b/includes/StylePropertySanitizerExtender.php index d8505ca..810e4e0 100644 --- a/includes/StylePropertySanitizerExtender.php +++ b/includes/StylePropertySanitizerExtender.php @@ -40,6 +40,9 @@ class StylePropertySanitizerExtender extends StylePropertySanitizer { private static $extendedCssSizing3 = false; private static $extendedCss1Masking = false; + /** + * @param MatcherFactory $matcherFactory + */ public function __construct( MatcherFactory $matcherFactory ) { parent::__construct( new MatcherFactoryExtender() ); } From 473f840d82e42197e548ce0794e08884b0f2eee9 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Thu, 14 Dec 2023 14:48:49 +0100 Subject: [PATCH 13/13] dist: Bump version to 1.2.0 --- composer.json | 2 +- extension.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index fa4cc20..6044fe5 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "octfx/template-styles-extender", - "version": "1.1.8", + "version": "1.2.0", "type": "mediawiki-extension", "description": "Extends TemplateStyles with new CSS properties", "homepage": "http://www.mediawiki.org/wiki/Extension:TemplateStylesExtender", diff --git a/extension.json b/extension.json index 415812b..a9bd57f 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "TemplateStylesExtender", - "version": "1.1.8", + "version": "1.2.0", "author": [ "[https://www.mediawiki.org/wiki/User:Octfx Octfx]" ],