Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| TemplateStylesFontFaceAtRuleSanitizer | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\TemplateStyles; |
| 4 | |
| 5 | /** |
| 6 | * @file |
| 7 | * @license GPL-2.0-or-later |
| 8 | */ |
| 9 | |
| 10 | use Wikimedia\CSS\Grammar\Alternative; |
| 11 | use Wikimedia\CSS\Grammar\Juxtaposition; |
| 12 | use Wikimedia\CSS\Grammar\MatcherFactory; |
| 13 | use Wikimedia\CSS\Grammar\Quantifier; |
| 14 | use Wikimedia\CSS\Grammar\TokenMatcher; |
| 15 | use Wikimedia\CSS\Objects\Token; |
| 16 | use Wikimedia\CSS\Sanitizer\FontFaceAtRuleSanitizer; |
| 17 | |
| 18 | /** |
| 19 | * Extend the standard `@font-face` matcher to require a prefix on families. |
| 20 | */ |
| 21 | class TemplateStylesFontFaceAtRuleSanitizer extends FontFaceAtRuleSanitizer { |
| 22 | |
| 23 | public function __construct( MatcherFactory $matcherFactory ) { |
| 24 | parent::__construct( $matcherFactory ); |
| 25 | |
| 26 | // Only allow the font-family if it begins with "TemplateStyles" |
| 27 | $validator = static fn ( Token $t ) => str_starts_with( $t->value(), 'TemplateStyles' ); |
| 28 | $this->propertySanitizer->setKnownProperties( [ |
| 29 | 'font-family' => new Alternative( [ |
| 30 | new TokenMatcher( Token::T_STRING, $validator ), |
| 31 | new Juxtaposition( [ |
| 32 | new TokenMatcher( Token::T_IDENT, $validator ), |
| 33 | Quantifier::star( $matcherFactory->ident() ), |
| 34 | ] ), |
| 35 | ] ), |
| 36 | ] + $this->propertySanitizer->getKnownProperties() ); |
| 37 | } |
| 38 | } |