2 // ease PHP5 source file updates:
3 // each line with the special tag '/*PHP5 patch*/' will be commented or uncommented.
5 function check_php_version ($a = '0', $b = '0', $c = '0') {
7 if(!isset($PHP_VERSION))
8 $PHP_VERSION = substr( str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'), 0, 3);
9 return $PHP_VERSION >= ($a.$b.$c);
11 function patch_into5 ($file) {
12 patch($file,'/^(\s+)(\/\*PHP5 patch\*\/)/',"\$1// \$2",'.php4');
14 function patch_into4 ($file) {
15 patch($file,'/^(\s+)\/\/ (\/\*PHP5 patch\*\/)/',"\$1\$2",'.php5');
17 function patch ($file,$from,$to,$bak='.bak') {
18 $tmpfile = $file.".tmp";
19 $in = fopen($file,"rb");
20 $out = fopen($tmpfile,"wb");
24 $new = preg_replace($from,$to,$s,1);
25 if ($new != $s) $changed++;
31 if (file_exists($file.$bak))
33 rename($file,$file.$bak);
34 rename($tmpfile,$file);
35 echo "successfully patched $file, backup: $file$bak\n";
38 echo "didn't patch $file\n";
42 $dir = dirname(__FILE__);
43 $patchfiles = array("lib/WikiUserNew.php");
45 // patch into which direction?
46 if (check_php_version(5)) $patchfunc = 'patch_into5';
47 else $patchfunc = 'patch_into4';
49 foreach ($patchfiles as $f) {
50 $file = $dir . "/" . $f;
52 trigger_error("File $f not found");