4 chdir(dirname(__FILE__
));
5 require_once 'common.php';
6 require_once '../library/HTMLPurifier.auto.php';
11 * Renames a configuration directive. This involves renaming the file,
12 * adding an alias, and then regenerating the cache. You still have to
13 * manually go through and fix any calls to the directive.
14 * @warning This script doesn't handle multi-stringhash files.
17 $argv = $_SERVER['argv'];
18 if (count($argv) < 3) {
19 echo "Usage: {$argv[0]} OldName NewName\n";
23 chdir('../library/HTMLPurifier/ConfigSchema/schema');
28 if (!file_exists("$old.txt")) {
29 echo "Cannot move undefined configuration directive $old\n";
34 echo "Attempting to move to self, aborting\n";
38 if (file_exists("$new.txt")) {
39 echo "Cannot move to already defined directive $new\n";
44 $builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
45 $interchange = new HTMLPurifier_ConfigSchema_Interchange();
46 $builder->buildFile($interchange, $file);
47 $contents = file_get_contents($file);
49 if (strpos($contents, "\r\n") !== false) {
51 } elseif (strpos($contents, "\r") !== false) {
57 // replace name with new name
58 $contents = str_replace($old, $new, $contents);
60 if ($interchange->directives
[$old]->aliases
) {
61 $pos_alias = strpos($contents, 'ALIASES:');
62 $pos_ins = strpos($contents, $nl, $pos_alias);
63 if ($pos_ins === false) $pos_ins = strlen($contents);
65 substr($contents, 0, $pos_ins) . ", $old" . substr($contents, $pos_ins);
66 file_put_contents($file, $contents);
68 $lines = explode($nl, $contents);
70 foreach ($lines as $n => $line) {
71 if (strncmp($line, '--', 2) === 0) {
77 $lines[] = "ALIASES: $old";
79 array_splice($lines, $insert, 0, "ALIASES: $old");
81 file_put_contents($file, implode($nl, $lines));
84 rename("$old.txt", "$new.txt") ||
exit(1);