setCssWideKeywordsMatcher( new Juxtaposition( [ Quantifier::optional( new AnythingMatcher() ), new WhitespaceMatcher( [ 'significant' => false ] ), Quantifier::plus( new FunctionMatcher( 'var', new Juxtaposition( [ new WhitespaceMatcher( [ 'significant' => false ] ), new VarNameMatcher(), new WhitespaceMatcher( [ 'significant' => false ] ), ] ) ), ), new WhitespaceMatcher( [ 'significant' => false ] ), Quantifier::optional( new AnythingMatcher() ), Quantifier::optional( new KeywordMatcher( [ '!important' ] ) ) ] ), ); } /** * Adds the image-rendering matcher * T222678 * * @param StylePropertySanitizer $propertySanitizer */ public function addImageRendering( StylePropertySanitizer $propertySanitizer ): void { try { $propertySanitizer->addKnownProperties( [ 'image-rendering' => new KeywordMatcher( [ 'auto', 'crisp-edges', 'pixelated', 'inherit', 'initial', 'unset', ] ) ] ); } catch ( InvalidArgumentException $e ) { // Fail silently } } /** * Adds the ruby-position and ruby-align matcher * T277755 * * @param StylePropertySanitizer $propertySanitizer */ public function addRuby( StylePropertySanitizer $propertySanitizer ): void { try { $propertySanitizer->addKnownProperties( [ 'ruby-position' => new KeywordMatcher( [ 'start', 'center', 'space-between', 'space-around', 'inherit', 'initial', 'unset', ] ) ] ); $propertySanitizer->addKnownProperties( [ 'ruby-align' => new KeywordMatcher( [ 'over', 'under', 'inter-character', 'inherit', 'initial', 'unset', ] ) ] ); } catch ( InvalidArgumentException $e ) { // Fail silently } } /** * Adds scroll-margin-* and scroll-padding-* matcher * TODO: This is not well tested * T271598 * * @param StylePropertySanitizer $propertySanitizer * @param MatcherFactory $factory */ public function addScrollMarginProperties( $propertySanitizer, $factory ): void { $suffixes = [ 'margin-block-end', 'margin-block-start', 'margin-block', 'margin-bottom', 'margin-inline-end', 'margin-inline-start', 'margin-inline', 'margin-left', 'margin-right', 'margin-top', 'margin', 'padding-block-end', 'padding-block-start', 'padding-block', 'padding-bottom', 'padding-inline-end', 'padding-inline-start', 'padding-inline', 'padding-left', 'padding-right', 'padding-top', 'padding', ]; foreach ( $suffixes as $suffix ) { try { $propertySanitizer->addKnownProperties( [ sprintf( 'scroll-%s', $suffix ) => new Alternative( [ $factory->length() ] ) ] ); } catch ( InvalidArgumentException $e ) { // Fail silently } } } /** * Loads a config value for a given key from the main config * Returns null on if an ConfigException was thrown * * @param string $key The config key * @param null $default * @return mixed|null */ public static function getConfigValue( string $key, $default = null ) { try { $value = MediaWikiServices::getInstance()->getMainConfig()->get( $key ); } catch ( ConfigException $e ) { wfLogWarning( sprintf( 'Could not get config for "$wg%s". %s', $key, $e->getMessage() ) ); return $default; } return $value; } }