diff --git a/TODO b/TODO index 5155c8cc..41973ab0 100644 --- a/TODO +++ b/TODO @@ -17,8 +17,6 @@ UPCOMING RELEASE IMPORTANT - Release candidate, because of the major changes - - Move utility classes for ConfigSchema into HTML Purifier itself: they're - that important DOCUMENTATION - Document new ConfigSchema setup and format; dev-includes.txt is a base @@ -31,21 +29,21 @@ IMPORTANT FEATURES - Factor generate-schema-cache.php into a class, so that the maintenance script is as small as possible - Factor out command line parser into its own class, and unit test it - - Optimize ConfigSchema by only caching things necessary for runtime + - Optimize ConfigSchema by making our runtime class only contain entries for + things necessary for operation (NOT descriptions). CONFIGDOC - - Properly integrate new ConfigSchema system into configdoc (Configdoc + - Properly integrate new ConfigSchema system into configdoc. DESCRIPTIONS + ARE CURRENTLY BROKEN AND NEED TO BE FIXED!!! (Configdoc should directly read the configuration files, or at the very least should not use static functions) - - Reduce code duplication between Serializer and Adapter/ReverseAdapter - (we probably want to use ReverseAdapter for the long haul) + - Deprecate Serializer in favor of ReverseAdapter - Have configdoc use version and deprecated information (hide deprecated info, for example) - - Implement file sniffing for configdoc, so we can easily figure out - which files use what configuration + - Implement source code sniffing for configdoc, so we can easily figure out + which files use what configuration (we'll rely on the $config convention) IF IT AIN'T BROKE... - - Simplify merge library script by removing recursion? (or other things) - Perhaps replace types with integer identifiers in ConfigSchema? (would be smaller, but not by much). diff --git a/extras/HTMLPurifierExtras.php b/extras/HTMLPurifierExtras.php index 10d5b6df..27437a2a 100644 --- a/extras/HTMLPurifierExtras.php +++ b/extras/HTMLPurifierExtras.php @@ -16,8 +16,7 @@ class HTMLPurifierExtras public static function getPath($class) { if ( - strncmp('FSTools', $class, 7) !== 0 && - strncmp('ConfigSchema', $class, 12) !== 0 + strncmp('FSTools', $class, 7) !== 0 ) return false; // Custom implementations can go here // Standard implementation: diff --git a/extras/README b/extras/README index ded43216..6ed42151 100644 --- a/extras/README +++ b/extras/README @@ -28,12 +28,3 @@ the filesystem. It currently consists of two classes: method imaginable one would need. Check the files themselves for more information. - - -ConfigSchema ------------- - -ConfigSchema is the next-generation configuration validation system for -HTML Purifier, built off of the original HTMLPurifier_ConfigSchema. When -complete, it will be used to generate schema files which will then be used -to enforce values set to HTMLPurifier_Config. diff --git a/library/HTMLPurifier.includes.php b/library/HTMLPurifier.includes.php index 0db45a35..8d37999a 100644 --- a/library/HTMLPurifier.includes.php +++ b/library/HTMLPurifier.includes.php @@ -121,6 +121,10 @@ require 'HTMLPurifier/ChildDef/Table.php'; require 'HTMLPurifier/ConfigDef/Directive.php'; require 'HTMLPurifier/ConfigDef/DirectiveAlias.php'; require 'HTMLPurifier/ConfigDef/Namespace.php'; +require 'HTMLPurifier/ConfigSchema/StringHash.php'; +require 'HTMLPurifier/ConfigSchema/StringHashAdapter.php'; +require 'HTMLPurifier/ConfigSchema/StringHashParser.php'; +require 'HTMLPurifier/ConfigSchema/StringHashReverseAdapter.php'; require 'HTMLPurifier/DefinitionCache/Decorator.php'; require 'HTMLPurifier/DefinitionCache/Null.php'; require 'HTMLPurifier/DefinitionCache/Serializer.php'; diff --git a/extras/ConfigSchema/StringHash.php b/library/HTMLPurifier/ConfigSchema/StringHash.php similarity index 93% rename from extras/ConfigSchema/StringHash.php rename to library/HTMLPurifier/ConfigSchema/StringHash.php index d14d0495..280a1bbe 100644 --- a/extras/ConfigSchema/StringHash.php +++ b/library/HTMLPurifier/ConfigSchema/StringHash.php @@ -8,7 +8,7 @@ * of PHP 5, you must not use the $hash[$key] syntax; if you do * our version of offsetGet is never called. */ -class ConfigSchema_StringHash extends ArrayObject +class HTMLPurifier_ConfigSchema_StringHash extends ArrayObject { protected $accessed = array(); diff --git a/extras/ConfigSchema/StringHashAdapter.php b/library/HTMLPurifier/ConfigSchema/StringHashAdapter.php similarity index 92% rename from extras/ConfigSchema/StringHashAdapter.php rename to library/HTMLPurifier/ConfigSchema/StringHashAdapter.php index 1aa6f775..06cb5fcc 100644 --- a/extras/ConfigSchema/StringHashAdapter.php +++ b/library/HTMLPurifier/ConfigSchema/StringHashAdapter.php @@ -2,9 +2,9 @@ /** * Takes an array of keys to strings, probably generated by - * ConfigSchema_StringHashParser + * HTMLPurifier_ConfigSchema_StringHashParser */ -class ConfigSchema_StringHashAdapter +class HTMLPurifier_ConfigSchema_StringHashAdapter { /** @@ -13,8 +13,8 @@ class ConfigSchema_StringHashAdapter */ public function adapt($hash, $schema) { - if (! $hash instanceof ConfigSchema_StringHash) { - $hash = new ConfigSchema_StringHash($hash); + if (! $hash instanceof HTMLPurifier_ConfigSchema_StringHash) { + $hash = new HTMLPurifier_ConfigSchema_StringHash($hash); } if (!isset($hash['ID'])) { diff --git a/extras/ConfigSchema/StringHashParser.php b/library/HTMLPurifier/ConfigSchema/StringHashParser.php similarity index 86% rename from extras/ConfigSchema/StringHashParser.php rename to library/HTMLPurifier/ConfigSchema/StringHashParser.php index 4aa32100..fe136fed 100644 --- a/extras/ConfigSchema/StringHashParser.php +++ b/library/HTMLPurifier/ConfigSchema/StringHashParser.php @@ -26,19 +26,18 @@ * Put this in its own class hierarchy or something; this class * is usage agnostic. */ -class ConfigSchema_StringHashParser +class HTMLPurifier_ConfigSchema_StringHashParser { public $default = 'ID'; public function parseFile($file) { - if (is_string($file)) $file = new FSTools_File($file); - if (!$file->exists()) throw new Exception('File does not exist'); - $file->open('r'); + if (!file_exists($file)) throw new Exception('File does not exist'); + $fh = fopen($file, 'r'); $state = false; $single = false; $ret = array(); - while (($line = $file->getLine()) !== false) { + while (($line = fgets($fh)) !== false) { $line = rtrim($line, "\n\r"); if (!$state && $line === '') continue; if (strncmp('--', $line, 2) === 0) { @@ -64,7 +63,7 @@ class ConfigSchema_StringHashParser $ret[$state] .= "$line\n"; } } - $file->close(); + fclose($fh); return $ret; } diff --git a/extras/ConfigSchema/StringHashReverseAdapter.php b/library/HTMLPurifier/ConfigSchema/StringHashReverseAdapter.php similarity index 98% rename from extras/ConfigSchema/StringHashReverseAdapter.php rename to library/HTMLPurifier/ConfigSchema/StringHashReverseAdapter.php index c9d513a5..2eb1fb2e 100644 --- a/extras/ConfigSchema/StringHashReverseAdapter.php +++ b/library/HTMLPurifier/ConfigSchema/StringHashReverseAdapter.php @@ -4,7 +4,7 @@ * Converts HTMLPurifier_ConfigSchema into a StringHash which can be * easily saved to a file. */ -class ConfigSchema_StringHashReverseAdapter +class HTMLPurifier_ConfigSchema_StringHashReverseAdapter { protected $schema; diff --git a/maintenance/generate-schema-cache.php b/maintenance/generate-schema-cache.php index 2677e394..2f94ae2c 100644 --- a/maintenance/generate-schema-cache.php +++ b/maintenance/generate-schema-cache.php @@ -21,7 +21,7 @@ $namespaces = array(); $directives = array(); // Generate string hashes -$parser = new ConfigSchema_StringHashParser(); +$parser = new HTMLPurifier_ConfigSchema_StringHashParser(); foreach ($files as $file) { $hash = $parser->parseFile($file); if (strpos($hash['ID'], '.') === false) { @@ -31,7 +31,7 @@ foreach ($files as $file) { } } -$adapter = new ConfigSchema_StringHashAdapter(); +$adapter = new HTMLPurifier_ConfigSchema_StringHashAdapter(); $schema = new HTMLPurifier_ConfigSchema(); foreach ($namespaces as $hash) $adapter->adapt($hash, $schema); diff --git a/maintenance/old-extract-schema.php b/maintenance/old-extract-schema.php index e1283362..67d67698 100644 --- a/maintenance/old-extract-schema.php +++ b/maintenance/old-extract-schema.php @@ -58,7 +58,7 @@ function saveHash($hash) { } $schema = HTMLPurifier_ConfigSchema::instance(); -$adapter = new ConfigSchema_StringHashReverseAdapter($schema); +$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($schema); foreach ($schema->info as $ns => $ns_array) { saveHash($adapter->get($ns)); diff --git a/tests/ConfigSchema/StringHashAdapterTest.php b/tests/HTMLPurifier/ConfigSchema/StringHashAdapterTest.php similarity index 96% rename from tests/ConfigSchema/StringHashAdapterTest.php rename to tests/HTMLPurifier/ConfigSchema/StringHashAdapterTest.php index 3a930897..1e7c8460 100644 --- a/tests/ConfigSchema/StringHashAdapterTest.php +++ b/tests/HTMLPurifier/ConfigSchema/StringHashAdapterTest.php @@ -1,6 +1,6 @@ expectAt($called[$func]++, $func, $params); } - $adapter = new ConfigSchema_StringHashAdapter(); + $adapter = new HTMLPurifier_ConfigSchema_StringHashAdapter(); $adapter->adapt($input, $schema); } diff --git a/tests/ConfigSchema/StringHashParser/AppendMultiline.txt b/tests/HTMLPurifier/ConfigSchema/StringHashParser/AppendMultiline.txt similarity index 100% rename from tests/ConfigSchema/StringHashParser/AppendMultiline.txt rename to tests/HTMLPurifier/ConfigSchema/StringHashParser/AppendMultiline.txt diff --git a/tests/ConfigSchema/StringHashParser/Default.txt b/tests/HTMLPurifier/ConfigSchema/StringHashParser/Default.txt similarity index 100% rename from tests/ConfigSchema/StringHashParser/Default.txt rename to tests/HTMLPurifier/ConfigSchema/StringHashParser/Default.txt diff --git a/tests/ConfigSchema/StringHashParser/OverrideSingle.txt b/tests/HTMLPurifier/ConfigSchema/StringHashParser/OverrideSingle.txt similarity index 100% rename from tests/ConfigSchema/StringHashParser/OverrideSingle.txt rename to tests/HTMLPurifier/ConfigSchema/StringHashParser/OverrideSingle.txt diff --git a/tests/ConfigSchema/StringHashParser/Simple.txt b/tests/HTMLPurifier/ConfigSchema/StringHashParser/Simple.txt similarity index 100% rename from tests/ConfigSchema/StringHashParser/Simple.txt rename to tests/HTMLPurifier/ConfigSchema/StringHashParser/Simple.txt diff --git a/tests/ConfigSchema/StringHashParserTest.php b/tests/HTMLPurifier/ConfigSchema/StringHashParserTest.php similarity index 89% rename from tests/ConfigSchema/StringHashParserTest.php rename to tests/HTMLPurifier/ConfigSchema/StringHashParserTest.php index 6e0c0014..5e6af5d9 100644 --- a/tests/ConfigSchema/StringHashParserTest.php +++ b/tests/HTMLPurifier/ConfigSchema/StringHashParserTest.php @@ -3,7 +3,7 @@ /** * @note Sample input files are located in the StringHashParser/ directory. */ -class ConfigSchema_StringHashParserTest extends UnitTestCase +class HTMLPurifier_ConfigSchema_StringHashParserTest extends UnitTestCase { /** @@ -12,7 +12,7 @@ class ConfigSchema_StringHashParserTest extends UnitTestCase protected $parser; function setup() { - $this->parser = new ConfigSchema_StringHashParser(); + $this->parser = new HTMLPurifier_ConfigSchema_StringHashParser(); } /** diff --git a/tests/ConfigSchema/StringHashReverseAdapterTest.php b/tests/HTMLPurifier/ConfigSchema/StringHashReverseAdapterTest.php similarity index 82% rename from tests/ConfigSchema/StringHashReverseAdapterTest.php rename to tests/HTMLPurifier/ConfigSchema/StringHashReverseAdapterTest.php index f33ed100..852e2144 100644 --- a/tests/ConfigSchema/StringHashReverseAdapterTest.php +++ b/tests/HTMLPurifier/ConfigSchema/StringHashReverseAdapterTest.php @@ -1,6 +1,6 @@ makeSchema()); + $adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema()); $result = $adapter->get('Ns'); $expect = array( 'ID' => 'Ns', @@ -27,14 +27,14 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase } function testBadNamespace() { - $adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema()); + $adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema()); $this->expectError("Namespace 'BadNs' doesn't exist in schema"); $adapter->get('BadNs'); } function testDirective() { - $adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema()); + $adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema()); $result = $adapter->get('Ns', 'Dir'); $expect = array( @@ -53,13 +53,13 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase } function testBadDirective() { - $adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema()); + $adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema()); $this->expectError("Directive 'BadNs.BadDir' doesn't exist in schema"); $adapter->get('BadNs', 'BadDir'); } function assertMethod($func, $input, $expect) { - $adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema()); + $adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema()); $result = $adapter->$func($input); $this->assertIdentical($result, $expect); } @@ -85,7 +85,7 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase } function assertExtraction($desc, $expect_desc, $expect_version) { - $adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema()); + $adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema()); list($result_desc, $result_version) = $adapter->extractVersion($desc); $this->assertIdentical($result_desc, $expect_desc); $this->assertIdentical($result_version, $expect_version); diff --git a/tests/ConfigSchema/StringHashTest.php b/tests/HTMLPurifier/ConfigSchema/StringHashTest.php similarity index 75% rename from tests/ConfigSchema/StringHashTest.php rename to tests/HTMLPurifier/ConfigSchema/StringHashTest.php index e49ba65c..ce3ddd60 100644 --- a/tests/ConfigSchema/StringHashTest.php +++ b/tests/HTMLPurifier/ConfigSchema/StringHashTest.php @@ -1,10 +1,10 @@ 'value', 'key2' => 'value2' )); diff --git a/tests/test_files.php b/tests/test_files.php index 90b71de2..207bd27f 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -64,6 +64,10 @@ $test_files[] = 'HTMLPurifier/ChildDef/RequiredTest.php'; $test_files[] = 'HTMLPurifier/ChildDef/StrictBlockquoteTest.php'; $test_files[] = 'HTMLPurifier/ChildDef/TableTest.php'; $test_files[] = 'HTMLPurifier/ConfigSchemaTest.php'; +$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashAdapterTest.php'; +$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashReverseAdapterTest.php'; +$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashParserTest.php'; +$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashTest.php'; $test_files[] = 'HTMLPurifier/ConfigTest.php'; $test_files[] = 'HTMLPurifier/ContextTest.php'; $test_files[] = 'HTMLPurifier/DefinitionCacheFactoryTest.php'; @@ -136,13 +140,6 @@ if ($csstidy_location) { $test_files[] = 'FSTools/FileTest.php'; -// ConfigSchema auxiliary library - -$test_files[] = 'ConfigSchema/StringHashAdapterTest.php'; -$test_files[] = 'ConfigSchema/StringHashReverseAdapterTest.php'; -$test_files[] = 'ConfigSchema/StringHashParserTest.php'; -$test_files[] = 'ConfigSchema/StringHashTest.php'; - } // end if ($AC['only-phpt']) // PHPT tests