2017-02-20 04:33:24 +00:00
|
|
|
<?php
|
2022-02-06 14:39:49 +00:00
|
|
|
|
|
|
|
namespace MediaWiki\Extension\TemplateStyles;
|
|
|
|
|
2017-02-20 04:33:24 +00:00
|
|
|
/**
|
|
|
|
* @file
|
2018-03-02 23:43:40 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2017-02-20 04:33:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
use Wikimedia\CSS\Grammar\Alternative;
|
|
|
|
use Wikimedia\CSS\Grammar\Juxtaposition;
|
|
|
|
use Wikimedia\CSS\Grammar\MatcherFactory;
|
|
|
|
use Wikimedia\CSS\Grammar\Quantifier;
|
|
|
|
use Wikimedia\CSS\Grammar\TokenMatcher;
|
|
|
|
use Wikimedia\CSS\Objects\Token;
|
|
|
|
use Wikimedia\CSS\Sanitizer\FontFaceAtRuleSanitizer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the standard `@font-face` matcher to require a prefix on families.
|
|
|
|
*/
|
|
|
|
class TemplateStylesFontFaceAtRuleSanitizer extends FontFaceAtRuleSanitizer {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param MatcherFactory $matcherFactory
|
|
|
|
*/
|
|
|
|
public function __construct( MatcherFactory $matcherFactory ) {
|
|
|
|
parent::__construct( $matcherFactory );
|
|
|
|
|
|
|
|
// Only allow the font-family if it begins with "TemplateStyles"
|
2024-11-07 10:05:46 +00:00
|
|
|
$validator = static fn ( Token $t ) => str_starts_with( $t->value(), 'TemplateStyles' );
|
2017-02-20 04:33:24 +00:00
|
|
|
$this->propertySanitizer->setKnownProperties( [
|
|
|
|
'font-family' => new Alternative( [
|
2024-11-07 10:05:46 +00:00
|
|
|
new TokenMatcher( Token::T_STRING, $validator ),
|
2017-02-20 04:33:24 +00:00
|
|
|
new Juxtaposition( [
|
2024-11-07 10:05:46 +00:00
|
|
|
new TokenMatcher( Token::T_IDENT, $validator ),
|
2017-02-20 04:33:24 +00:00
|
|
|
Quantifier::star( $matcherFactory->ident() ),
|
|
|
|
] ),
|
|
|
|
] ),
|
|
|
|
] + $this->propertySanitizer->getKnownProperties() );
|
|
|
|
}
|
|
|
|
}
|