]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - configurator.php
All options which are currently covered now have input means appropriate to the data...
[SourceForge/phpwiki.git] / configurator.php
1 <?php printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", 'iso-8859-1'); ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
5 <head>
6 <!-- $Id: configurator.php,v 1.3 2002-02-26 01:05:10 carstenklapp Exp $ -->
7 <head>
8 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
9 <title>Configuration tool for PhpWiki 1.3.x</title>
10 </head>
11 <body>
12
13 <h1>Configuration tool for PhpWiki 1.3.x</h1>
14
15 <p>This tool is provided for testing purposes only. It's not finished so don't try to use it to configure your server yet.</p>
16
17 <?php
18 /**
19  * The Configurator is a php script to aid in the configuration of PhpWiki.
20  * Parts of this file are based on PHPWeather's configurator.php file.
21  * http://sourceforge.net/projects/phpweather/
22  *
23  *
24  * TO CHANGE THE CONFIGURATION OF YOUR PHPWIKI, DO *NOT* MODIFY THIS FILE!
25  * more instructions go here
26  *
27  * 
28  * An index.php will be generated for you which you can also modify later if you wish.
29  */
30
31
32 //////////////////////////////
33 // begin configuration options
34
35
36 /**
37  * Notes for the description parameter of $property:
38  *
39  * - Descriptive text will be changed into comments (preceeded by //)
40  *   for the final output to index.php.
41  *
42  * - Only a limited set of html is allowed: pre, dl dt dd; it will be
43  *   stripped from the final output.
44  *
45  * - Line breaks and spacing will be preserved for the final output.
46  *
47  * - Double line breaks are automatically converted to paragraphs
48  *   for the html version of the descriptive text.
49  *
50  * - Double-quotes and dollar signs in the descriptive text must be
51  *   escaped: \" and \$. Instead of escaping double-quotes you can use 
52  *   single (') quotes for the enclosing quotes. 
53  *
54  * - Special characters like < and > must use html entities,
55  *   they will be converted back to characters for the final output.
56  */
57
58 $SEPARATOR = "///////////////////////////////////////////////////////////////////";
59
60 $copyright = '
61 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam = array(
62 "Steve Wainstead", "Clifford A. Adams", "Lawrence Akka", 
63 "Scott R. Anderson", "Jon Åslund", "Neil Brown", "Jeff Dairiki",
64 "Stéphane Gourichon", "Jan Hidders", "Arno Hollosi", "John Jorgensen",
65 "Antti Kaihola", "Jeremie Kass", "Carsten Klapp", "Marco Milanesi",
66 "Grant Morgan", "Jan Nieuwenhuizen", "Aredridel Niothke", 
67 "Pablo Roca Rozas", "Sandino Araico Sánchez", "Joel Uckelman", 
68 "Reini Urban", "Tim Voght");
69
70 This file is part of PhpWiki.
71
72 PhpWiki is free software; you can redistribute it and/or modify
73 it under the terms of the GNU General Public License as published by
74 the Free Software Foundation; either version 2 of the License, or
75 (at your option) any later version.
76
77 PhpWiki is distributed in the hope that it will be useful,
78 but WITHOUT ANY WARRANTY; without even the implied warranty of
79 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
80 GNU General Public License for more details.
81
82 You should have received a copy of the GNU General Public License
83 along with PhpWiki; if not, write to the Free Software
84 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
85 ';
86
87
88
89 $preamble = "
90   This is the starting file for PhpWiki. All this file does is set
91   configuration options, and at the end of the file it includes() the
92   file lib/main.php, where the real action begins.
93
94   This file is divided into six parts: Parts Zero, One, Two, Three,
95   Four and Five. Each one has different configuration settings you can
96   change; in all cases the default should work on your system,
97   however, we recommend you tailor things to your particular setting.
98 ";
99
100
101
102 $properties['Part Zero'] =
103 new part('part0', false, "
104 Part Zero: If PHP needs help in finding where you installed the
105 rest of the PhpWiki code, you can set the include_path here.");
106
107
108
109 $properties['PHP include_path'] =
110 new _ini_set('include_path', "\$include_path", "
111 NOTE: phpwiki uses the PEAR library of php code for SQL database
112 access. Your PHP is probably already configured to set
113 include_path so that PHP can find the pear code. If not (or if you
114 change include_path here) make sure you include the path to the
115 PEAR code in include_path. (To find the PEAR code on your system,
116 search for a file named 'PEAR.php'. Some common locations are:
117 <pre>
118   Unixish systems:
119     /usr/share/php
120     /usr/local/share/php
121   Mac OS X:
122     /System/Library/PHP
123 </pre>
124 The above examples are already included by PhpWiki. You shouldn't
125 have to change this unless you see a WikiFatalError:
126 <pre>
127     lib/FileFinder.php:82: Fatal[256]: DB.php: file not found
128 </pre>
129 Define the include path for this wiki: pear plus the phpwiki path
130 <pre>
131 $include_path = '.:/Apache/php/pear:/prog/php/phpwiki';
132 </pre>
133 Windows needs ';' as path delimiter. cygwin, mac and unix ':'
134 <pre>
135 if (substr(PHP_OS,0,3) == 'WIN') {
136     $include_path = implode(';',explode(':',$include_path));
137 } elseif (substr(PHP_OS,0,6) == 'CYGWIN') {
138     $include_path = '.:/usr/local/lib/php/pear:/usr/src/php/phpwiki';
139 } else {
140     ;
141 }</pre>");
142
143
144
145 $properties['Part Null'] =
146 new part('partnullheader', "", "
147 Part Null: Don't touch this!");
148
149
150
151 $properties['Part Null Settings'] =
152 new unchangeable_variable('partnullsettings', "
153 define ('PHPWIKI_VERSION', '1.3.3-jeffs-hacks');
154 require \"lib/prepend.php\";
155 rcs_id('\$Id: configurator.php,v 1.3 2002-02-26 01:05:10 carstenklapp Exp $');", "");
156
157
158
159 $properties['Part One'] =
160 new part('partone', $SEPARATOR."\n", "
161
162 Part One:
163 Authentication and security settings:
164 ");
165
166
167
168 $properties['Wiki Name'] =
169 new _define('WIKI_NAME', ''/*'PhpWiki'*/, "
170 The name of your wiki.
171 This is used to generate a keywords meta tag in the HTML templates,
172 in bookmark titles for any bookmarks made to pages in your wiki,
173 and during RSS generation for the title of the RSS channel.");
174
175
176
177 $properties['Reverse DNS'] =
178 new boolean_define('ENABLE_REVERSE_DNS',
179                     array('true'  => 'perform additional reverse dns lookups',
180                           'false' => 'just record the address as given by the httpd server'), "
181 If set, we will perform reverse dns lookups to try to convert the
182 users IP number to a host name, even if the http server didn't do
183 it for us.");
184
185
186
187 $properties['Admin Username'] =
188 new _define('ADMIN_USER', "", "
189 Username and password of administrator.
190 Set these to your preferences. For heaven's sake
191 pick a good password!");
192 $properties['Admin Password'] =
193 new _define_password('ADMIN_PASSWD', "", "");
194
195
196
197 $properties['ZIPdump Authentication'] =
198 new boolean_define('ZIPDUMP_AUTH', 
199                     array('false' => 'everyone may download zip dumps',
200                           'true'  => 'only admin may download zip dumps'), "
201 If true, only the admin user can make zip dumps, else zip dumps
202 require no authentication.");
203
204
205
206 $properties['Strict Mailable Pagedumps'] =
207 new boolean_define('STRICT_MAILABLE_PAGEDUMPS', 
208                     array('false' => 'binary',
209                           'true'  => 'quoted-printable'), "
210 If you define this to true, (MIME-type) page-dumps (either zip dumps,
211 or \"dumps to directory\" will be encoded using the quoted-printable
212 encoding.  If you're actually thinking of mailing the raw page dumps,
213 then this might be useful, since (among other things,) it ensures
214 that all lines in the message body are under 80 characters in length.
215
216 Also, setting this will cause a few additional mail headers
217 to be generated, so that the resulting dumps are valid
218 RFC 2822 e-mail messages.
219
220 Probably, you can just leave this set to false, in which case you get
221 raw ('binary' content-encoding) page dumps.");
222
223
224
225 $properties['Maximum Upload Size'] =
226 new numeric_define('MAX_UPLOAD_SIZE', "16 * 1024 * 1024", "
227 The maximum file upload size.");
228
229
230
231 $properties['Minor Edit Timeout'] =
232 new numeric_define('MINOR_EDIT_TIMEOUT', "7 * 24 * 3600", "
233 If the last edit is older than MINOR_EDIT_TIMEOUT seconds, the
234 default state for the \"minor edit\" checkbox on the edit page form
235 will be off.");
236
237
238
239 $properties['Disabled Actions'] =
240 new array_variable('DisabledActions', array(), "
241 Actions listed in this array will not be allowed. Actions are:
242 browse, diff, dumphtml, dumpserial, edit, loadfile, lock, remove, 
243 unlock, upload, viewsource, zip, ziphtml");
244
245
246
247 $properties['Access Log'] =
248 new _define('ACCESS_LOG', "", "
249 PhpWiki can generate an access_log (in \"NCSA combined log\" format)
250 for you. If you want one, define this to the name of the log file,
251 such as /tmp/wiki_access_log.");
252
253
254
255 $properties['Strict Login'] =
256 new boolean_define('ALLOW_BOGO_LOGIN',
257                     array('true'  => 'Users may Sign In with any WikiWord',
258                           'false' => 'Only admin may Sign In'), "
259 If ALLOW_BOGO_LOGIN is true, users are allowed to login (with
260 any/no password) using any userid which: 1) is not the ADMIN_USER,
261 2) is a valid WikiWord (matches \$WikiNameRegexp.)");
262
263
264
265 $properties['Require Sign In Before Editing'] =
266 new boolean_define('REQUIRE_SIGNIN_BEFORE_EDIT',
267                     array('false' => 'Do not require Sign In',
268                           'true'  => 'Require Sign In'), "
269 If set, then if an anonymous user attempts to edit a page he will
270 be required to sign in.  (If ALLOW_BOGO_LOGIN is true, of course,
271 no password is required, but the user must still sign in under
272 some sort of BogoUserId.)");
273
274
275
276 $properties['Path for PHP Session Support'] =
277 new _ini_set('session.save_path', 'some_other_directory', "
278 The login code now uses PHP's session support. Usually, the default
279 configuration of PHP is to store the session state information in
280 /tmp. That probably will work fine, but fails e.g. on clustered
281 servers where each server has their own distinct /tmp (this is the
282 case on SourceForge's project web server.) You can specify an
283 alternate directory in which to store state information like so
284 (whatever user your httpd runs as must have read/write permission
285 in this directory):");
286
287
288
289 $properties['Disable PHP Transparent Session ID'] =
290 new unchangeable_variable('session.use_trans_sid', "@ini_set('session.use_trans_sid', 0);", "
291 If your php was compiled with --enable-trans-sid it tries to
292 add a PHPSESSID query argument to all URL strings when cookie
293 support isn't detected in the client browser.  For reasons
294 which aren't entirely clear (PHP bug) this screws up the URLs
295 generated by PhpWiki.  Therefore, transparent session ids
296 should be disabled.  This next line does that.
297
298 (At the present time, you will not be able to log-in to PhpWiki,
299 or set any user preferences, unless your browser supports cookies.)");
300
301
302
303 $properties['Part Two'] =
304 new part('parttwo', $SEPARATOR."\n", "
305
306 Part Two:
307 Database Selection
308 ");
309
310
311
312 // MORE CONFIG OPTIONS GO IN HERE
313
314
315
316 $properties['Page Revisions'] =
317 new part('parttworevisions', "
318 ", "
319
320 The next section controls how many old revisions of each page are
321 kept in the database.
322
323 There are two basic classes of revisions: major and minor. Which
324 class a revision belongs in is determined by whether the author
325 checked the \"this is a minor revision\" checkbox when they saved the
326 page.
327  
328 There is, additionally, a third class of revisions: author
329 revisions. The most recent non-mergable revision from each distinct
330 author is and author revision.
331
332 The expiry parameters for each of those three classes of revisions
333 can be adjusted seperately. For each class there are five
334 parameters (usually, only two or three of the five are actually
335 set) which control how long those revisions are kept in the
336 database.
337 <dl>
338    <dt>max_keep:</dt> <dd>If set, this specifies an absolute maximum for the
339             number of archived revisions of that class. This is
340             meant to be used as a safety cap when a non-zero
341             min_age is specified. It should be set relatively high,
342             and it's purpose is to prevent malicious or accidental
343             database overflow due to someone causing an
344             unreasonable number of edits in a short period of time.</dd>
345
346   <dt>min_age:</dt>  <dd>Revisions younger than this (based upon the supplanted
347             date) will be kept unless max_keep is exceeded. The age
348             should be specified in days. It should be a
349             non-negative, real number,</dd>
350
351   <dt>min_keep:</dt> <dd>At least this many revisions will be kept.</dd>
352
353   <dt>keep:</dt>     <dd>No more than this many revisions will be kept.</dd>
354
355   <dt>max_age:</dt>  <dd>No revision older than this age will be kept.</dd>
356 </dl>
357 Supplanted date: Revisions are timestamped at the instant that they
358 cease being the current revision. Revision age is computed using
359 this timestamp, not the edit time of the page.
360
361 Merging: When a minor revision is deleted, if the preceding
362 revision is by the same author, the minor revision is merged with
363 the preceding revision before it is deleted. Essentially: this
364 replaces the content (and supplanted timestamp) of the previous
365 revision with the content after the merged minor edit, the rest of
366 the page metadata for the preceding version (summary, mtime, ...)
367 is not changed.
368 ");
369
370
371
372 // MORE CONFIG OPTIONS GO IN HERE
373
374
375
376 $properties['Part Three'] =
377 new part('partthree', $SEPARATOR."\n", "
378
379 Part Three:
380 Page appearance and layout
381 ");
382
383
384
385 $properties['Theme'] =
386 new _define_selection('THEME',
387               array('default'  => 'default',
388                     'Hawaiian' => 'Hawaiian',
389                     'MacOSX'   => 'MacOSX',
390                     'Portland' => 'Portland',
391                     'Sidebar'  => 'Sidebar',
392                     'SpaceWiki' => 'SpaceWiki'), "
393 THEME
394
395 Most of the page appearance is controlled by files in the theme
396 subdirectory.
397
398 There are a number of pre-defined themes shipped with PhpWiki.
399 Or you may create your own (e.g. by copying and then modifying one of
400 stock themes.)
401
402 Pick one.
403 <pre>
404 define('THEME', 'default');
405 define('THEME', 'Hawaiian');
406 define('THEME', 'MacOSX');
407 define('THEME', 'Portland');
408 define('THEME', 'Sidebar');
409 define('THEME', 'SpaceWiki');</pre>");
410
411
412
413
414 $properties['Character Set'] =
415 new _define('CHARSET', 'iso-8859-1', "
416 Select a valid charset name to be inserted into the xml/html pages, 
417 and to reference links to the stylesheets (css). For more info see: 
418 http://www.iana.org/assignments/character-sets. Note that PhpWiki 
419 has been extensively tested only with the latin1 (iso-8859-1) 
420 character set.
421
422 If you change the default from iso-8859-1 PhpWiki may not work 
423 properly and it will require code modifications. However, character 
424 sets similar to iso-8859-1 may work with little or no modification 
425 depending on your setup. The database must also support the same 
426 charset, and of course the same is true for the web browser. (Some 
427 work is in progress hopefully to allow more flexibility in this 
428 area in the future).");
429
430
431
432 $properties['Language'] =
433 new _variable_selection('LANG',
434               array('C'  => 'English',
435                     'nl' => 'Nederlands',
436                     'es' => 'Español',
437                     'fr' => 'Français',
438                     'de' => 'Deutsch',
439                     'sv' => 'Svenska',
440                     'it' => 'Italiano',
441                     ''   => 'none'), "
442 Select your language/locale - default language is \"C\" for English.
443 Other languages available:<pre>
444 English \"C\"  (English    - HomePage)
445 Dutch   \"nl\" (Nederlands - ThuisPagina)
446 Spanish \"es\" (Español    - PáginaPrincipal)
447 French  \"fr\" (Français   - Accueil)
448 German  \"de\" (Deutsch    - StartSeite)
449 Swedish \"sv\" (Svenska    - Framsida)
450 Italian \"it\" (Italiano   - PaginaPrincipale)
451 </pre>
452 If you set \$LANG to the empty string, your systems default language
453 (as determined by the applicable environment variables) will be
454 used.
455
456 Note that on some systems, apprently using these short forms for
457 the locale won't work. On my home system 'LANG=de' won't result in
458 german pages. Somehow the system must recognize the locale as a
459 valid locale before gettext() will work, i.e., use 'de_DE', 'nl_NL'.");
460
461
462
463 // MORE CONFIG OPTIONS GO IN HERE
464
465
466
467 $properties['Part Four'] =
468 new part('partfour', $SEPARATOR."\n", "
469
470 Part Four:
471 Mark-up options.
472 ");
473
474
475
476 $properties['Allowed Protocols'] =
477 new list_variable('AllowedProtocols', "http|https|mailto|ftp|news|nntp|ssh|gopher", "
478 allowed protocols for links - be careful not to allow \"javascript:\"
479 URL of these types will be automatically linked.
480 within a named link [name|uri] one more protocol is defined: phpwiki");
481
482
483
484 $properties['Inline Images'] =
485 new list_variable('InlineImages', "png|jpg|gif", "
486 URLs ending with the following extension should be inlined as images");
487
488
489
490 $properties['WikiName Regexp'] =
491 new _variable('WikiNameRegexp', "(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])", "
492 Perl regexp for WikiNames (\"bumpy words\")
493 (?&lt;!..) & (?!...) used instead of '\b' because \b matches '_' as well");
494
495
496
497 $properties['InterWiki Map File'] =
498 new _define('INTERWIKI_MAP_FILE', "lib/interwiki.map", "
499 InterWiki linking -- wiki-style links to other wikis on the web
500
501 The map will be taken from a page name InterWikiMap.
502 If that page is not found (or is not locked), or map
503 data can not be found in it, then the file specified
504 by INTERWIKI_MAP_FILE (if any) will be used.");
505
506
507
508 $properties['Part Five'] =
509 new part('partfive', $SEPARATOR."\n", "
510
511 Part Five:
512 URL options -- you can probably skip this section.
513 ");
514
515
516
517 // MORE CONFIG OPTIONS GO IN HERE
518
519
520
521 $end = "
522
523 $SEPARATOR
524 // Okay... fire up the code:
525 $SEPARATOR
526
527 include \"lib/main.php\";
528
529 // (c-file-style: \"gnu\")
530 // Local Variables:
531 // mode: php
532 // tab-width: 8
533 // c-basic-offset: 4
534 // c-hanging-comment-ender-p: nil
535 // indent-tabs-mode: nil
536 // End:   
537 ?>
538 ";
539
540
541
542 // end of configuration options
543 ///////////////////////////////
544 // begin class definitions
545
546 /**
547  * A basic index.php configuration line in the form of a variable.
548  *
549  * Produces a string in the form "$name = value;"
550  * e.g.:
551  * $WikiNameRegexp = "value";
552  */
553 class _variable {
554
555     var $config_item_name;
556     var $default_value;
557     var $description;
558
559     function _variable($config_item_name, $default_value, $description) {
560         $this->config_item_name = $config_item_name;
561         $this->description = $description;
562         $this->default_value = $default_value;
563     }
564
565     function get_config_item_name() {
566         return $this->config_item_name;
567     }
568
569     function get_description() {
570         return $this->description;
571     }
572
573     function get_config_line($posted_value) {
574         return "\n\$" . $this->get_config_item_name() . " = \"" . $posted_value . "\";";
575     }
576     function get_config($posted_value) {
577         $d = stripHtml($this->get_description());
578         $d = str_replace("\n", "\n// ", $d) . $this->get_config_line($posted_value) ."\n";
579         return $d;
580     }
581
582     function get_instructions($title) {
583         $i = "<p><b><h3>" . $title . "</h3></b></p>\n    " . nl2p($this->get_description()) . "\n";
584         return "<tr>\n<td>\n" . $i . "</td>\n";
585     }
586
587     function get_html() {
588         return get_class($this)."<br />\n"."<input type=\"text\" name=\"" . $this->get_config_item_name() . "\" value=\"" . $this->default_value . "\">";
589     }
590 }
591
592 class unchangeable_variable extends _variable {
593     function get_html() {
594         return "";
595     }
596     function get_config_line($posted_value) {
597         if ($this->description)
598             $n = "\n";
599         return "${n}".$this->default_value;
600     }
601     function get_instructions($title) {
602         $i = "<p><b><h3>" . $title . "</h3></b></p>\n    " . nl2p($this->get_description()) . "\n";
603         $i = $i ."<em>Not editable.</em><br />\n<pre>" . $this->default_value."</pre>";
604         return "<tr>\n<td colspan=\"2\">\n" .$i ."</td></tr>\n";
605     }
606
607 }
608
609 class _variable_selection extends _variable {
610     function get_html() {
611         $output = '<select name="' . $this->get_config_item_name() . "\">\n";
612         /* The first option is the default */
613         while(list($option, $label) = each($this->default_value)) {
614             $output .= "  <option value=\"$option\">$label</option>\n";
615         }
616         $output .= "    </select>\n  </td>\n";
617         return get_class($this)."<br />\n".$output;
618     }
619 }
620
621
622 class _define extends _variable {
623     function get_config_line($posted_value) {
624         if ($this->description)
625             $n = "\n";
626         if ($posted_value == '')
627             return "${n}//define('".$this->get_config_item_name()."', \"\");";
628         else
629             return "${n}define('".$this->get_config_item_name()."', '$posted_value');";
630     }
631 }
632
633 class _define_selection extends _variable_selection {
634     function get_config_line($posted_value) {
635         return _define::get_config_line($posted_value);
636     }
637     function get_html() {
638         return get_class($this)."<br />\n"._variable_selection::get_html();
639     }
640 }
641
642 class _define_password extends _define {
643     function get_config_line($posted_value) {
644         if ($this->description)
645             $n = "\n";
646         if ($posted_value == '') {
647             $p = "${n}//define('".$this->get_config_item_name()."', \"\");";
648             $p = $p . "\n// If you used the passencrypt.php utility to encode the password";
649             $p = $p . "\n// then uncomment this line:";
650             $p = $p . "\n//define('ENCRYPTED_PASSWD', true);";
651             return $p;
652         } else {
653             if (function_exists('crypt')) {
654                 $salt_length = max(CRYPT_SALT_LENGTH,
655                                     2 * CRYPT_STD_DES,
656                                     9 * CRYPT_EXT_DES,
657                                     12 * CRYPT_MD5,
658                                     16 * CRYPT_BLOWFISH);
659                 // generate an encrypted password
660                 $crypt_pass = crypt($posted_value, rand_ascii($salt_length));
661                 $p = "${n}define('".$this->get_config_item_name()."', '$crypt_pass');";
662                 $p = $p . "\n// If you used the passencrypt.php utility to encode the password";
663                 $p = $p . "\n// then uncomment this line:";
664                 return $p . "\ndefine('ENCRYPTED_PASSWD', true);";
665             } else {
666                 $p = "${n}define('".$this->get_config_item_name()."', '$posted_value');";
667                 $p = $p . "\n// If you used the passencrypt.php utility to encode the password";
668                 $p = $p . "\n// then uncomment this line:";
669                 $p = $p . "\n//define('ENCRYPTED_PASSWD', true);";
670                 $p = $p . "\n// Encrypted passwords cannot be used:";
671                 $p = $p . "\n// 'function crypt()' not available in this version of php";
672                 return $p;
673             }
674         }
675     }
676     function get_html() {
677         return get_class($this)."<br />\n"."<input type=\"password\" name=\"" . $this->get_config_item_name() . "\" value=\"" . $this->default_value . "\">";
678     }
679 }
680
681
682 class numeric_define extends _define {
683     function get_config_line($posted_value) {
684         if ($this->description)
685             $n = "\n";
686         if ($posted_value == '')
687             return "${n}//define('".$this->get_config_item_name()."', 0);";
688         else
689             return "${n}define('".$this->get_config_item_name()."', $posted_value);";
690     }
691 }
692
693 class list_variable extends _variable {
694     function get_config_line($posted_value) {
695         // split the phrase by any number of commas or space characters,
696         // which include " ", \r, \t, \n and \f
697         $list_values = preg_split("/[\s,]+/", $posted_value, -1, PREG_SPLIT_NO_EMPTY);
698         $list_values = join("|", $list_values);
699         return _variable::get_config_line($list_values);
700     }
701     function get_html() {
702         $list_values = explode("|", $this->default_value);
703         $cols = max(3, count($this->default_value) +1);
704         $list_values = join("\n", $list_values);
705         $ta = "<textarea cols=\"10\" rows=\"". $cols ."\" name=\"".$this->get_config_item_name()."\">";
706         $ta .= $list_values . "</textarea>";
707         return get_class($this)."<br />\n".$ta;
708     }
709 }
710
711 class array_variable extends _variable {
712     function get_config_line($posted_value) {
713         // split the phrase by any number of commas or space characters,
714         // which include " ", \r, \t, \n and \f
715         $list_values = preg_split("/[\s,]+/", $posted_value, -1, PREG_SPLIT_NO_EMPTY);
716         if (!empty($list_values)) {
717             $list_values = "'".join("', '", $list_values)."'";
718             $list_values = "array(".$list_values.")";
719             return "\n\$" . $this->get_config_item_name() . " = " . $list_values . ";";
720         } else
721             return "\n//\$" . $this->get_config_item_name() . " = array();";
722     }
723     function get_html() {
724         $list_values = join("\n", $this->default_value);
725         $cols = max(3, count($this->default_value) +1);
726         $ta = "<textarea cols=\"10\" rows=\"". $cols ."\" name=\"".$this->get_config_item_name()."\">";
727         $ta .= $list_values . "</textarea>";
728         return get_class($this)."<br />\n".$ta;
729     }
730
731 }
732
733 class _ini_set extends _variable {
734     function get_config_line($posted_value) {
735         if ($posted_value && ! $posted_value == $this->default_value)
736             return "\nini_set('".$this->get_config_item_name()."', '$posted_value');";
737         else
738             return "\n//ini_set('".$this->get_config_item_name()."', '".$this->default_value."');";
739     }
740 }
741
742 class boolean_define extends _define {
743     function get_config_line($posted_value) {
744         if ($this->description)
745             $n = "\n";
746         return "${n}define('".$this->get_config_item_name()."', $posted_value);";
747     }
748     function get_html() {
749         $output = '<select name="' . $this->get_config_item_name() . "\">\n";
750         /* The first option is the default */
751         list($option, $label) = each($this->default_value);
752         $output .= "  <option value=\"$option\" selected>$label</option>\n";
753         /* There can only be two options */
754         list($option, $label) = each($this->default_value);
755         $output .= "  <option value=\"$option\">$label</option>\n";
756         $output .= "</select>\n  </td>\n";
757         return get_class($this)."<br />\n".$output;
758     }
759 }
760
761 class part extends _variable {
762     function get_config($posted_value) {
763         $d = stripHtml($this->get_description());
764         global $SEPARATOR;
765         return "\n".$SEPARATOR . str_replace("\n", "\n// ", $d) ."\n$this->default_value";
766     }
767     function get_instructions($title) {
768         $i = "<p><b><h2>" . $title . "</h2></b></p>\n    " . nl2p($this->get_description()) ."\n";
769         return "<tr>\n<td colspan=\"2\" bgcolor=\"#eee\">\n" .$i ."</td></tr>\n";
770     }
771     function get_html() {
772         return "";
773     }
774 }
775 function nl2p($text) {
776     return "<p>" . str_replace("\n\n", "</p>\n<p>", $text) . "</p>";
777 }
778
779 function stripHtml($text) {
780         $d = str_replace("<pre>", "", $text);
781         $d = str_replace("</pre>", "", $d);
782         $d = str_replace("<dl>", "", $d);
783         $d = str_replace("</dl>", "", $d);
784         $d = str_replace("<dt>", "", $d);
785         $d = str_replace("</dt>", "", $d);
786         $d = str_replace("<dd>", "", $d);
787         $d = str_replace("</dd>", "", $d);
788         //restore html entities into characters
789         // http://www.php.net/manual/en/function.htmlentities.php
790         $trans = get_html_translation_table (HTML_ENTITIES);
791         $trans = array_flip ($trans);
792         $d = strtr($d, $trans);
793         return $d;
794 }
795
796 /**
797  * Seed the random number generator.
798  *
799  * better_srand() ensures the randomizer is seeded only once.
800  * 
801  * How random do you want it? See:
802  * http://www.php.net/manual/en/function.srand.php
803  * http://www.php.net/manual/en/function.mt-srand.php
804  */
805 function better_srand($seed = '') {
806     static $wascalled = FALSE;
807     if (!$wascalled) {
808         $seed = $seed === '' ? (double) microtime() * 1000000 : $seed;
809         srand($seed);
810         $wascalled = TRUE;
811         //trigger_error("new random seed", E_USER_NOTICE); //debugging
812     }
813 }
814
815 function rand_ascii($length = 1) {
816     better_srand();
817    //srand((double) microtime() * 1000000);
818    $s = "";
819    for ($i = 1; $i <= $length; $i++) {
820        $s .= chr(rand(40, 126)); // return only typeable 7 bit ascii
821    }
822    return $s;
823 }
824
825 function printArray($a) {
826     echo "<hr />\n<pre>\n";
827     print_r($a);
828     echo "\n</pre>\n<hr />\n";
829 }
830
831 // end of class definitions
832 /////////////////////////////
833 // begin auto generation code
834
835 if ($action == 'make_config') {
836
837   $timestamp = date ('dS of F, Y H:i:s');
838
839     $config = "<?php
840 /* This is a local configuration file for PhpWiki.
841  * It was automatically generated by the configurator script
842  * on the $timestamp.
843  */
844
845 /*$copyright*/
846
847 /////////////////////////////////////////////////////////////////////
848 /*$preamble*/
849 ";
850
851     $posted = $GLOBALS['HTTP_POST_VARS'];
852
853 printArray($GLOBALS['HTTP_POST_VARS']);
854 /*
855
856 */
857
858     foreach($properties as $option_name => $a) {
859         $posted_value = $posted[$a->config_item_name];
860         $config .= $properties[$option_name]->get_config($posted_value);
861     }
862
863     $diemsg = "The configurator.php is provided for testing purposes only.\nYou can't use this file with your PhpWiki server yet!!";
864     $config .= "\ndie(\"$diemsg\");\n";
865     $config .= $end;
866
867     /* We first check if the config-file exists. */
868     if (file_exists('defaults.php')) {
869         /* We make a backup copy of the file */
870         $new_filename = 'defaults.' . time() . '.php';
871         if (@copy('defaults.php', $new_filename)) {
872             $fp = @fopen('defaults.php', 'w');
873         }
874     } else {
875         $fp = @fopen('defaults.php', 'w');
876     }
877
878     if ($fp) {
879         fputs($fp, $config);
880         fclose($fp);
881         echo "<p>The configuration was written to <code><b>defaults.php</b></code>. A backup was made to <code><b>$new_filename</b></code>.</p>\n";
882     } else {
883         echo "<p>A configuration file could <b>not</b> be written. You should copy the above configuration to a file, and manually save it as <code><b>defaults.php</b></code>.</p>\n";
884     }
885
886     echo "<hr />\n<p>Here's the configuration file based on your answers:</p>\n<pre>\n";
887     echo htmlentities($config);
888     echo "</pre>\n<hr />\n";
889
890     echo "<!--If she can stand it, I can. Play it!-->\n";
891     echo "<p>Would you like to <a href=\"configurator.php\">play again</a>?</p>\n";
892
893     } else {
894         /* No action has been specified - we make a form. */
895
896         echo '
897         <form action="configurator.php" method="post">
898         <table border="1" cellpadding="4" cellspacing="0">
899         <input type="hidden" name="action" value="make_config">
900         ';
901
902         while(list($property, $obj) = each($properties)) {
903             echo $obj->get_instructions($property);
904             if ($h = $obj->get_html())
905                 echo "<td>".$h."</td>\n";
906         }
907
908         echo '
909             </table>
910             <p><input type="submit" value="Make config-file"> <input type="reset" value="Clear"></p>
911             </form>
912             ';
913
914     }
915 ?>
916 </body>
917 </html>