]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - config/migrate-phpwiki-config
add PLUGIN_MARKUP_MAP
[SourceForge/phpwiki.git] / config / migrate-phpwiki-config
1 #!/usr/bin/perl -w
2 #
3 # phpwiki configuration file migration script
4 # index.php => config.ini
5 #
6 # Author:   Matt Brown <matt@mattb.net.nz>,
7 #           Reini Urban <rurban@x-ray.at>
8 # Version:  $Id: migrate-phpwiki-config,v 1.1 2006-05-17 17:27:34 rurban Exp $
9 #
10 # Run this script without any arguments for usage information.
11 #
12 # This script is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # PhpWiki is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with PhpWiki; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26 # Store the values
27 # In the form $values{$varname} = (value, comment_state)
28 # Where value is the value in index.php and comment_state indicates
29 # whether the line was commented or not
30 use strict;
31 use warnings;
32
33 my %values = ();
34
35 # Check we got a index.php to read from
36 if ($#ARGV < 0) {
37   print "Usage: ./phpwiki-migrate-config <../path/to/index.php>\n\n";
38   print "Takes an old style (<= 1.3.9) index.php configuration file\n";
39   print "for phpwiki and outputs a new style (>= 1.3.10) ./config.ini\n";
40   print "configuration file for phpwiki, based on a set of\n";
41   print "./config-{dist,default}.ini files.\n";
42   print "\n";
43   print "The values extracted from the old config file will be\n";
44   print "substituted into a new config.ini file as necessary. Commented\n";
45   print "directives in index.php will remain commented in config.ini\n";
46
47   exit 1;
48 }
49
50 # Read in values from index.php
51 my $infile = shift;
52 open INDEXPHP, "< $infile" or die "Cannot read $infile: $!\n";
53 my $inifile     = "config.ini";
54 my $distfile    = "config-dist.ini";
55 my $defaultfile = "config-default.ini";
56 die "$inifile already exists.\n" if -e $inifile;
57
58 # Write out config.ini, substituting values as needed
59 open OUT, "> $inifile"
60   or die "Failed to write $inifile. $!\n";
61 open CONFDIST, "< $distfile"
62   or die "Failed to open $distfile: $!\n";
63 open CONFDEFAULT, "< $defaultfile"
64   or die "Failed to open $defaultfile: $!\n";
65
66 my $epmaj = 0;
67 my $epmin = 0;
68
69 while (<INDEXPHP>) {
70   my ($name, $value) = ('','');
71   # Check if the line starts with a comment (# or / char)
72   my $is_comment = /^[#\/]/;
73   if (!$is_comment) {
74     $is_comment = 0;
75   }
76
77   # Process expire parameters
78   if (/'keep'/) {
79     ($value) = (/'keep'\s*=>\s*(.*)\)/);
80     if ($epmaj) {
81       $name = "MAJOR_KEEP";
82     } elsif ($epmin) {
83       $name = "MINOR_KEEP";
84     }
85   }
86   $epmaj = 0;
87   $epmin = 0;
88
89   # Skip some known bad options
90   if (/ALLOW_LDAP_LOGIN/) {
91     next;
92   } elsif (/ALLOW_IMAP_LOGIN/) {
93     next;
94
95     # Process defined values
96   } elsif (/define\s*\(/) {
97     # Extract the name of the define and the value of it
98     ($name, $value) = (/define\s*\(\s*['"](.*)['"]\s*,\s*['"]*([^'"]*)['"]*\s*\)/);
99
100     # Process PHP variable values
101   } elsif (/HTML_DUMP_SUFFIX\s*=/) {
102     ($name, $value) = (/\$(\w*)\s*=\s*['"](.*)['"];\s*/);
103   } elsif (/AllowedProtocols\s*=/) {
104     ($value) = (/\$\w*\s*=\s*(.*);\s*/);
105     $name = "ALLOWED_PROTOCOLS";
106   } elsif (/InlineImages\s*=/) {
107     ($value) = (/\$\w*\s*=\s*(.*);\s*/);
108     $name = "INLINE_IMAGES";
109   } elsif (/WikiNameRegexp\s*=/) {
110     ($value) = (/\$\w*\s*=\s*(.*);\s*/);
111     $name = "WIKI_NAME_REGEXP";
112
113     # Process arrays that need to be converted
114   } elsif (/GenericPages\s*=/) {
115     ($value) = (/\$\w*\s*=\s*array\((.*)\)/);
116     $name = "DEFAULT_WIKI_PAGES";
117     $value =~ s/[" ]//g;
118     $value =~ s/,/:/g;
119     $value = "\"$value\""
120   } elsif (/keywords\s*=/) {
121     ($value) = (/\$\w*\s*=\s*array\((.*)\)/);
122     $name = "KEYWORDS";
123     $value =~ s/[" ]//g;
124     $value =~ s/,/:/g;
125     $value = "\"$value\""
126
127       # Process database paramters
128   } elsif (/'dbtype'\s*=>/) {
129     ($value) = (/'dbtype'\s*=>\s*['"](.*)['"]/);
130     $name = "DATABASE_TYPE";
131   } elsif (/'dsn'\s*=>/) {
132     ($value) = (/'dsn'\s*=>\s*['"](.*)['"]/);
133     $name = "DATABASE_DSN";
134   } elsif (/'timeout'\s*=>/) {
135     ($value) = (/'timeout'\s*=>\s*(.*)\s*,/);
136     $name = "DATABASE_TIMEOUT";
137   } elsif (/'db_session_table'\s*=>/) {
138     ($value) = (/'db_session_table'\s*=>\s*['"](.*)['"]/);
139     $name = "DATABASE_SESSION_TABLE";
140   } elsif (/'prefix'\s*=>/) {
141     ($value) = (/'prefix'\s*=>\s*['"](.*)['"]/);
142     $name = "DATABASE_PREFIX";
143   } elsif (/'directory'\s*=>/) {
144     ($value) = (/'directory'\s*=>\s*['"](.*)['"]/);
145     $name = "DATABASE_DIRECTORY";
146   } elsif (/'dba_handler'\s*=>/) {
147     ($value) = (/'dba_handler'\s*=>\s*['"](.*)['"]/);
148     $name = "DATABASE_DBA_HANDLER";
149
150     # Process Expire Parameters
151   } elsif (/\$ExpireParams\['major'\]\s*=/) {
152     ($value) = (/'max_age'\s*=>\s*(.*),/);
153     $name = "MAJOR_MAX_AGE";
154     $epmaj = 1;
155   } elsif (/\$ExpireParams\['minor'\]\s*=/) {
156     ($value) = (/'max_age'\s*=>\s*(.*),/);
157     $name = "MINOR_MAX_AGE";
158     $epmin = 1;
159
160     # Process include path
161   } elsif (/ini_set.*include_path'/) {
162     ($value) = (/ini_set.*include_path'\s*,\s*(.*)\s*\)/);
163     $name = "INCLUDE_PATH";
164
165   }
166   if ($name =~ /^$/) {
167     next;
168   }
169
170   # Put it into the array
171   if (exists $values{$name} && $is_comment) {
172     # If we already have a value and this one is commented, skip it
173     next;
174   }
175   #print "$name => $value ($is_comment)\n";
176   $values{$name} = [$value, $is_comment];
177 }
178
179 close INDEXPHP;
180
181 # Print values we got
182 #for my $name ( keys %values ) {
183 #    ($value, $is_comment) = @{$values{$name}};
184 #    print "$name => $value";
185 #    if ($is_comment) { print " (commented)"; }
186 #    print "\n";
187 #}
188
189 select OUT;
190 # Write out migration header
191 print "; phpwiki 1.3.x configuration automatically generated from $infile\n";
192 print "; by migrate-phpwiki-config script\n\n";
193
194 while (<CONFDIST>) {
195   # Look for config var lines
196   if (!/\w* = /) {
197     print $_;
198     next;
199   }
200   my ($name, $value, $is_comment);
201   ($name) = (/(\w*) = /);
202   if (!exists $values{$name}) {
203     print $_;
204     next;
205   }
206   ($value, $is_comment) = @{$values{$name}};
207   if ($is_comment) {
208     print "; $name = $value\n";
209   } else {
210     print "$name = $value\n";
211   }
212 }
213
214 close OUT;
215 close CONFDIST;
216 close CONFDEFAULT;
217 #!/usr/bin/perl -w
218 #
219 # phpwiki configuration file migration script
220 # index.php => config.ini
221 #
222 # Author:   Matt Brown <matt@mattb.net.nz>,
223 #           Reini Urban <rurban@x-ray.at>
224 # Version:  $Id: migrate-phpwiki-config,v 1.1 2006-05-17 17:27:34 rurban Exp $
225 #
226 # Run this script without any arguments for usage information.
227 #
228 # This script is free software; you can redistribute it and/or modify
229 # it under the terms of the GNU General Public License as published by
230 # the Free Software Foundation; either version 2 of the License, or
231 # (at your option) any later version.
232 #
233 # PhpWiki is distributed in the hope that it will be useful,
234 # but WITHOUT ANY WARRANTY; without even the implied warranty of
235 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
236 # GNU General Public License for more details.
237 #
238 # You should have received a copy of the GNU General Public License
239 # along with PhpWiki; if not, write to the Free Software
240 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
241
242 # Store the values
243 # In the form $values{$varname} = (value, comment_state)
244 # Where value is the value in index.php and comment_state indicates
245 # whether the line was commented or not
246 use strict;
247 use warnings;
248
249 my %values = ();
250
251 # Check we got a index.php to read from
252 if ($#ARGV < 0) {
253   print "Usage: ./phpwiki-migrate-config <../path/to/index.php>\n\n";
254   print "Takes an old style (<= 1.3.9) index.php configuration file\n";
255   print "for phpwiki and outputs a new style (>= 1.3.10) ./config.ini\n";
256   print "configuration file for phpwiki, based on a set of\n";
257   print "./config-{dist,default}.ini files.\n";
258   print "\n";
259   print "The values extracted from the old config file will be\n";
260   print "substituted into a new config.ini file as necessary. Commented\n";
261   print "directives in index.php will remain commented in config.ini\n";
262
263   exit 1;
264 }
265
266 # Read in values from index.php
267 my $infile = shift;
268 open INDEXPHP, "< $infile" or die "Cannot read $infile: $!\n";
269 my $inifile     = "config.ini";
270 my $distfile    = "config-dist.ini";
271 my $defaultfile = "config-default.ini";
272 die "$inifile already exists.\n" if -e $inifile;
273
274 # Write out config.ini, substituting values as needed
275 open OUT, "> $inifile"
276   or die "Failed to write $inifile. $!\n";
277 open CONFDIST, "< $distfile"
278   or die "Failed to open $distfile: $!\n";
279 open CONFDEFAULT, "< $defaultfile"
280   or die "Failed to open $defaultfile: $!\n";
281
282 my $epmaj = 0;
283 my $epmin = 0;
284
285 while (<INDEXPHP>) {
286   my ($name, $value) = ('','');
287   # Check if the line starts with a comment (# or / char)
288   my $is_comment = /^[#\/]/;
289   if (!$is_comment) {
290     $is_comment = 0;
291   }
292
293   # Process expire parameters
294   if (/'keep'/) {
295     ($value) = (/'keep'\s*=>\s*(.*)\)/);
296     if ($epmaj) {
297       $name = "MAJOR_KEEP";
298     } elsif ($epmin) {
299       $name = "MINOR_KEEP";
300     }
301   }
302   $epmaj = 0;
303   $epmin = 0;
304
305   # Skip some known bad options
306   if (/ALLOW_LDAP_LOGIN/) {
307     next;
308   } elsif (/ALLOW_IMAP_LOGIN/) {
309     next;
310
311     # Process defined values
312   } elsif (/define\s*\(/) {
313     # Extract the name of the define and the value of it
314     ($name, $value) = (/define\s*\(\s*['"](.*)['"]\s*,\s*['"]*([^'"]*)['"]*\s*\)/);
315
316     # Process PHP variable values
317   } elsif (/HTML_DUMP_SUFFIX\s*=/) {
318     ($name, $value) = (/\$(\w*)\s*=\s*['"](.*)['"];\s*/);
319   } elsif (/AllowedProtocols\s*=/) {
320     ($value) = (/\$\w*\s*=\s*(.*);\s*/);
321     $name = "ALLOWED_PROTOCOLS";
322   } elsif (/InlineImages\s*=/) {
323     ($value) = (/\$\w*\s*=\s*(.*);\s*/);
324     $name = "INLINE_IMAGES";
325   } elsif (/WikiNameRegexp\s*=/) {
326     ($value) = (/\$\w*\s*=\s*(.*);\s*/);
327     $name = "WIKI_NAME_REGEXP";
328
329     # Process arrays that need to be converted
330   } elsif (/GenericPages\s*=/) {
331     ($value) = (/\$\w*\s*=\s*array\((.*)\)/);
332     $name = "DEFAULT_WIKI_PAGES";
333     $value =~ s/[" ]//g;
334     $value =~ s/,/:/g;
335     $value = "\"$value\""
336   } elsif (/keywords\s*=/) {
337     ($value) = (/\$\w*\s*=\s*array\((.*)\)/);
338     $name = "KEYWORDS";
339     $value =~ s/[" ]//g;
340     $value =~ s/,/:/g;
341     $value = "\"$value\""
342
343       # Process database paramters
344   } elsif (/'dbtype'\s*=>/) {
345     ($value) = (/'dbtype'\s*=>\s*['"](.*)['"]/);
346     $name = "DATABASE_TYPE";
347   } elsif (/'dsn'\s*=>/) {
348     ($value) = (/'dsn'\s*=>\s*['"](.*)['"]/);
349     $name = "DATABASE_DSN";
350   } elsif (/'timeout'\s*=>/) {
351     ($value) = (/'timeout'\s*=>\s*(.*)\s*,/);
352     $name = "DATABASE_TIMEOUT";
353   } elsif (/'db_session_table'\s*=>/) {
354     ($value) = (/'db_session_table'\s*=>\s*['"](.*)['"]/);
355     $name = "DATABASE_SESSION_TABLE";
356   } elsif (/'prefix'\s*=>/) {
357     ($value) = (/'prefix'\s*=>\s*['"](.*)['"]/);
358     $name = "DATABASE_PREFIX";
359   } elsif (/'directory'\s*=>/) {
360     ($value) = (/'directory'\s*=>\s*['"](.*)['"]/);
361     $name = "DATABASE_DIRECTORY";
362   } elsif (/'dba_handler'\s*=>/) {
363     ($value) = (/'dba_handler'\s*=>\s*['"](.*)['"]/);
364     $name = "DATABASE_DBA_HANDLER";
365
366     # Process Expire Parameters
367   } elsif (/\$ExpireParams\['major'\]\s*=/) {
368     ($value) = (/'max_age'\s*=>\s*(.*),/);
369     $name = "MAJOR_MAX_AGE";
370     $epmaj = 1;
371   } elsif (/\$ExpireParams\['minor'\]\s*=/) {
372     ($value) = (/'max_age'\s*=>\s*(.*),/);
373     $name = "MINOR_MAX_AGE";
374     $epmin = 1;
375
376     # Process include path
377   } elsif (/ini_set.*include_path'/) {
378     ($value) = (/ini_set.*include_path'\s*,\s*(.*)\s*\)/);
379     $name = "INCLUDE_PATH";
380
381   }
382   if ($name =~ /^$/) {
383     next;
384   }
385
386   # Put it into the array
387   if (exists $values{$name} && $is_comment) {
388     # If we already have a value and this one is commented, skip it
389     next;
390   }
391   #print "$name => $value ($is_comment)\n";
392   $values{$name} = [$value, $is_comment];
393 }
394
395 close INDEXPHP;
396
397 # Print values we got
398 #for my $name ( keys %values ) {
399 #    ($value, $is_comment) = @{$values{$name}};
400 #    print "$name => $value";
401 #    if ($is_comment) { print " (commented)"; }
402 #    print "\n";
403 #}
404
405 select OUT;
406 # Write out migration header
407 print "; phpwiki 1.3.x configuration automatically generated from $infile\n";
408 print "; by migrate-phpwiki-config script\n\n";
409
410 while (<CONFDIST>) {
411   # Look for config var lines
412   if (!/\w* = /) {
413     print $_;
414     next;
415   }
416   my ($name, $value, $is_comment);
417   ($name) = (/(\w*) = /);
418   if (!exists $values{$name}) {
419     print $_;
420     next;
421   }
422   ($value, $is_comment) = @{$values{$name}};
423   if ($is_comment) {
424     print "; $name = $value\n";
425   } else {
426     print "$name = $value\n";
427   }
428 }
429
430 close OUT;
431 close CONFDIST;
432 close CONFDEFAULT;
433