mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateStyles
synced 2024-11-28 10:10:42 +00:00
37fc1df457
SPDX released version 3 of their license list (<https://spdx.org/licenses/>), which changed the FSF licenses to explicitly end in -only or -or-later instead of relying on an easy to miss + symbol. Bug: T183858 Change-Id: Ic9accb2eb34bc32d455f48dfe81a91d23a2d5f5e
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* @file
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
|
|
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"
|
|
$this->propertySanitizer->setKnownProperties( [
|
|
'font-family' => new Alternative( [
|
|
new TokenMatcher( Token::T_STRING, function ( Token $t ) {
|
|
return substr( $t->value(), 0, 14 ) === 'TemplateStyles';
|
|
} ),
|
|
new Juxtaposition( [
|
|
new TokenMatcher( Token::T_IDENT, function ( Token $t ) {
|
|
return substr( $t->value(), 0, 14 ) === 'TemplateStyles';
|
|
} ),
|
|
Quantifier::star( $matcherFactory->ident() ),
|
|
] ),
|
|
] ),
|
|
] + $this->propertySanitizer->getKnownProperties() );
|
|
}
|
|
}
|