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