<?php
require 'vendor/autoload.php'; // Ensure Wikimedia CSS libraries are installed via Composer
use Wikimedia\CSS\Parser\Parser; use Wikimedia\CSS\Sanitizer\StylesheetSanitizer; use Wikimedia\CSS\Util;
$inputFile = "input.css"; // Path to the original CSS file $outputFile = "sanitized.css"; // Path to save the sanitized CSS
// Read the CSS file $cssText = file_get_contents($inputFile); if ($cssText === false) {
die("Error: Could not read CSS file.\n");
}
// Parse the CSS $parser = Parser::newFromString($cssText); $stylesheet = $parser->parseStylesheet();
// Report parser errors foreach ($parser->getParseErrors() as list($code, $line, $pos)) {
echo "Parse error: $code at line $line, character $pos\n";
}
// Sanitize the CSS $sanitizer = StylesheetSanitizer::newDefault(); $newStylesheet = $sanitizer->sanitize($stylesheet);
// Report sanitization errors foreach ($sanitizer->getSanitizationErrors() as list($code, $line, $pos)) {
echo "Sanitization error: $code at line $line, character $pos\n";
}
// Convert sanitized stylesheet back to text $newText = (string)$newStylesheet;
// Save sanitized CSS to a new file if (file_put_contents($outputFile, $newText) !== false) {
echo "Sanitized CSS saved to $outputFile\n";
} else {
echo "Error: Could not write sanitized CSS file.\n";
}
?>
@media screen { html.skin-theme-clientpref-night .infobox { background-color: black; color: white; } } @media screen and (prefers-color-scheme: dark) { html.skin-theme-clientpref-os .infobox { background-color: black; color: white; } }