From e616f077394341661104b400210e1e88135bf215 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 22 Apr 2008 05:38:03 +0000 Subject: [PATCH] [3.1.0] Implement file sniffing of $config, for TRUE feature parity! Also add some really silly multi-column code in the XSLT. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1668 48356398-32a2-884e-a903-53898d9a118a --- TODO | 4 - configdoc/styles/plain.css | 27 ++- configdoc/styles/plain.xsl | 99 ++++++++-- configdoc/usage.xml | 346 +++++++++++++++++++++++++++++++++ maintenance/config-scanner.php | 138 +++++++++++++ maintenance/flush.php | 1 + 6 files changed, 585 insertions(+), 30 deletions(-) create mode 100644 configdoc/usage.xml create mode 100644 maintenance/config-scanner.php diff --git a/TODO b/TODO index 479b4ed9..5fedfa70 100644 --- a/TODO +++ b/TODO @@ -26,10 +26,6 @@ IMPORTANT FEATURES - Factor out command line parser into its own class, and unit test it - Figure out autoload and PEAR -CONFIGDOC - - Implement source code sniffing for configdoc, so we can easily figure out - which files use what configuration (we'll rely on the $config convention) - NICE FEATURES - Factor demo.php into a set of Printer classes, and then create a stub file for users here (inside the actual HTML Purifier library) diff --git a/configdoc/styles/plain.css b/configdoc/styles/plain.css index 44378edd..44ab105f 100644 --- a/configdoc/styles/plain.css +++ b/configdoc/styles/plain.css @@ -1,16 +1,30 @@ -body {margin:1em 4em;} +body {margin:0;padding:0;} +#content { + margin:1em auto; + max-width: 47em; + width: expression(document.body.clientWidth > + 85 * parseInt(document.body.currentStyle.fontSize) ? + "54em": "auto"); +} table {border-collapse:collapse;} table td, table th {padding:0.2em;} table.constraints {margin:0 0 1em;} -table.constraints th {text-align:left;padding-left:0.4em;} -table.constraints td {padding-right:0.4em;} +table.constraints th { + text-align:right;padding-left:0.4em;padding-right:0.4em;background:#EEE; + width:8em;vertical-align:top;} +table.constraints td {padding-right:0.4em; padding-left: 1em;} +table.constraints td ul {padding:0; margin:0; list-style:none;} table.constraints td pre {margin:0;} -#toc {list-style-type:none; font-weight:bold;} -#toc ul {list-style-type:disc; font-weight:normal;} +#tocContainer {position:relative;} +#toc {list-style-type:none; font-weight:bold; font-size:1em; margin-bottom:1em;} +#toc li {position:relative; line-height: 1.2em;} +#toc .col-2 {margin-left:50%;} +#toc .col-l {float:left;} +#toc ul {list-style-type:disc; font-weight:normal; padding-bottom:1.2em;} .description p {margin-top:0;margin-bottom:1em;} @@ -19,9 +33,10 @@ table.constraints td pre {margin:0;} #library {font-size:1em;} h1 {margin-top:0;} h2 {border-bottom:1px solid #CCC; font-family:sans-serif; font-weight:normal; - font-size:1.3em;} + font-size:1.3em; clear:both;} h3 {font-family:sans-serif; font-size:1.1em; font-weight:bold; } h4 {font-family:sans-serif; font-size:0.9em; font-weight:bold; } .deprecated {color: #CCC;} +.deprecated table.constraints th {background:#FFF;} .deprecated-notice {color: #000; text-align:center; margin-bottom: 1em;} diff --git a/configdoc/styles/plain.xsl b/configdoc/styles/plain.xsl index f769da48..c98bcc2f 100644 --- a/configdoc/styles/plain.xsl +++ b/configdoc/styles/plain.xsl @@ -15,7 +15,11 @@ - + + + + + @@ -25,31 +29,58 @@ -
-

-

Table of Contents

-
    - -
- +
+
+

+
+

Table of Contents

+
    + + + +
+
+ +
+ + +
  • + + + col-2 + + + margin-top:-em + +
      - + + +
    + +
    +
  • + + + -
  • +
  • + +
  • @@ -74,14 +105,19 @@
    - directive deprecated - - + directive deprecated + + +
    + -

    +

    @@ -91,16 +127,18 @@ + +
    - Aliases: + Aliases , @@ -116,24 +154,45 @@
    + Warning: This directive was deprecated in version . % should be used instead.
    + + + Used in + +
      + +
    + + +
    + +
  • + on lines + + + , + + +
  • +
    - Version: + Version added - Type: + Type type type- - + (or null) @@ -142,7 +201,7 @@ - Allowed values: + Allowed values , @@ -153,7 +212,7 @@ - Default: + Default
    diff --git a/configdoc/usage.xml b/configdoc/usage.xml new file mode 100644 index 00000000..dc666a0d --- /dev/null +++ b/configdoc/usage.xml @@ -0,0 +1,346 @@ + + + + + 130 + + + 93 + + + 50 + 62 + 327 + + + 44 + + + + + 201 + + + + + 205 + + + + + 209 + + + + + 261 + + + + + 49 + + + + + 83 + + + + + 85 + + + + + 88 + + + + + 93 + + + + + 267 + 285 + + + + + 269 + 290 + + + + + 287 + + + + + 81 + + + 90 + + + 45 + + + + + 40 + + + + + 61 + + + + + 86 + + + + + 213 + + + + + 221 + + + + + 238 + + + + + 239 + + + + + 242 + + + + + 198 + + + 245 + + + 34 + + + + + 205 + + + + + 206 + + + + + 220 + + + + + 26 + + + + + 85 + + + + + 78 + + + + + 237 + + + + + 57 + + + 8 + + + + + 58 + + + + + 65 + + + + + 42 + + + + + 43 + + + + + 24 + + + + + 78 + + + + + 12 + + + 12 + + + + + 15 + + + + + 20 + + + + + 26 + + + + + 28 + 31 + + + + + 54 + + + + + 13 + + + + + 18 + + + 20 + + + + + 19 + + + + + 27 + + + + + 55 + + + + + 91 + + + + + 69 + + + + + 127 + + + + + 45 + + + + + 49 + + + + + 50 + + + + + 15 + + + + + 44 + + + + + 59 + + + + + 22 + + + 19 + + + + + 22 + + + + + 23 + + + + + 8 + + + diff --git a/maintenance/config-scanner.php b/maintenance/config-scanner.php new file mode 100644 index 00000000..fb786b02 --- /dev/null +++ b/maintenance/config-scanner.php @@ -0,0 +1,138 @@ +#!/usr/bin/php +globr('.', '*.php'); +$files = array(); +foreach ($raw_files as $file) { + $file = substr($file, 2); // rm leading './' + if (strncmp('standalone/', $file, 11) === 0) continue; // rm generated files + if (substr_count($file, '.') > 1) continue; // rm meta files + $files[] = $file; +} + +/** + * Moves the $i cursor to the next non-whitespace token + */ +function consumeWhitespace($tokens, &$i) { + do {$i++;} while (is_array($tokens[$i]) && $tokens[$i][0] === T_WHITESPACE); +} + +/** + * Tests whether or not a token is a particular type. There are three run-cases: + * - ($token, $expect_token): tests if the token is $expect_token type; + * - ($token, $expect_value): tests if the token is the string $expect_value; + * - ($token, $expect_token, $expect_value): tests if token is $expect_token type, and + * its string representation is $expect_value + */ +function testToken($token, $value_or_token, $value = null) { + if (is_null($value)) { + if (is_int($value_or_token)) return is_array($token) && $token[0] === $value_or_token; + else return $token === $value_or_token; + } else { + return is_array($token) && $token[0] === $value_or_token && $token[1] === $value; + } +} + +$counter = 0; +$full_counter = 0; +$tracker = array(); + +foreach ($files as $file) { + $tokens = token_get_all(file_get_contents($file)); + $file = str_replace('\\', '/', $file); + for ($i = 0, $c = count($tokens); $i < $c; $i++) { + if (!testToken($tokens[$i], T_VARIABLE, '$config')) continue; + $ok = false; + for($i++; $i < $c; $i++) { + if ($tokens[$i] === ',' || $tokens[$i] === ')' || $tokens[$i] === ';') { + break; + } + if (is_string($tokens[$i])) continue; + if ($tokens[$i][0] === T_OBJECT_OPERATOR) { + $ok = true; + break; + } + } + if (!$ok) continue; + + $line = $tokens[$i][2]; + + consumeWhitespace($tokens, $i); + if (!testToken($tokens[$i], T_STRING, 'get')) continue; + + consumeWhitespace($tokens, $i); + if (!testToken($tokens[$i], '(')) continue; + + $full_counter++; + + // The T_CONSTANT_ENCAPSED_STRING may hide some more obscure use-cases; + // it may be useful to log these. + consumeWhitespace($tokens, $i); + if (!testToken($tokens[$i], T_CONSTANT_ENCAPSED_STRING)) continue; + $namespace = substr($tokens[$i][1], 1, -1); + + consumeWhitespace($tokens, $i); + if (!testToken($tokens[$i], ',')) continue; + + consumeWhitespace($tokens, $i); + if (!testToken($tokens[$i], T_CONSTANT_ENCAPSED_STRING)) continue; + $directive = substr($tokens[$i][1], 1, -1); + + $counter++; + + $id = "$namespace.$directive"; + if (!isset($tracker[$id])) $tracker[$id] = array(); + if (!isset($tracker[$id][$file])) $tracker[$id][$file] = array(); + $tracker[$id][$file][] = $line; + + // echo "$file:$line uses $namespace.$directive\n"; + } +} + +echo "\n$counter/$full_counter instances of \$config found in source code.\n"; + +echo "Generating XML... "; + +$xw = new XMLWriter(); +$xw->openURI('../configdoc/usage.xml'); +$xw->setIndent(true); +$xw->startDocument('1.0', 'UTF-8'); +$xw->startElement('usage'); +foreach ($tracker as $id => $files) { + $xw->startElement('directive'); + $xw->writeAttribute('id', $id); + foreach ($files as $file => $lines) { + $xw->startElement('file'); + $xw->writeAttribute('name', $file); + foreach ($lines as $line) { + $xw->writeElement('line', $line); + } + $xw->endElement(); + } + $xw->endElement(); +} +$xw->endElement(); +$xw->flush(); + +echo "done!\n"; diff --git a/maintenance/flush.php b/maintenance/flush.php index 9f2c2b8d..93f0e766 100644 --- a/maintenance/flush.php +++ b/maintenance/flush.php @@ -25,3 +25,4 @@ e($php . ' generate-includes.php'); e($php . ' generate-schema-cache.php'); e($php . ' flush-definition-cache.php'); e($php . ' generate-standalone.php'); +e($php . ' config-scanner.php');