Fix iconv truncation bug.
[htmlpurifier.git] / maintenance / old-extract-schema.php
blobbd55feaa6fdad9f34fb54bcc61ec52be4e59f0d3
1 #!/usr/bin/php
2 <?php
4 chdir(dirname(__FILE__));
5 require_once 'common.php';
6 assertCli();
8 echo "Please do not run this script. It is here for historical purposes only.";
9 exit;
11 /**
12 * @file
13 * Extracts all definitions inside a configuration schema
14 * (HTMLPurifier_ConfigSchema) and exports them as plain text files.
16 * @todo Extract version numbers.
19 define('HTMLPURIFIER_SCHEMA_STRICT', true); // description data needs to be collected
20 require_once dirname(__FILE__) . '/../library/HTMLPurifier.auto.php';
22 // We need includes to ensure all HTMLPurifier_ConfigSchema calls are
23 // performed.
24 require_once 'HTMLPurifier.includes.php';
26 // Also, these extra files will be necessary.
27 require_once 'HTMLPurifier/Filter/ExtractStyleBlocks.php';
29 /**
30 * Takes a hash and saves its contents to library/HTMLPurifier/ConfigSchema/
32 function saveHash($hash) {
33 if ($hash === false) return;
34 $dir = realpath(dirname(__FILE__) . '/../library/HTMLPurifier/ConfigSchema');
35 $name = $hash['ID'] . '.txt';
36 $file = $dir . '/' . $name;
37 if (file_exists($file)) {
38 trigger_error("File already exists; skipped $name");
39 return;
41 $file = new FSTools_File($file);
42 $file->open('w');
43 $multiline = false;
44 foreach ($hash as $key => $value) {
45 $multiline = $multiline || (strpos($value, "\n") !== false);
46 if ($multiline) {
47 $file->put("--$key--" . PHP_EOL);
48 $file->put(str_replace("\n", PHP_EOL, $value) . PHP_EOL);
49 } else {
50 if ($key == 'ID') {
51 $file->put("$value" . PHP_EOL);
52 } else {
53 $file->put("$key: $value" . PHP_EOL);
57 $file->close();
60 $schema = HTMLPurifier_ConfigSchema::instance();
61 $adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($schema);
63 foreach ($schema->info as $ns => $ns_array) {
64 saveHash($adapter->get($ns));
65 foreach ($ns_array as $dir => $x) {
66 saveHash($adapter->get($ns, $dir));
70 // vim: et sw=4 sts=4