]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - configurator.php
more fixes. this version finally loads fine.
[SourceForge/phpwiki.git] / configurator.php
1 <?php 
2 /*
3  * Todo: 
4  *   * validate input (fix javascript, add POST checks)
5  *   * start this automatically the first time
6  *   * fix include_path
7  *   * eval index-user.php or index.php to get the actual settings.
8  *   * ask to store it in index.php or index-user.php
9  * 
10  * The file index-user.php will be generated which you can use as your index.php.
11  */
12
13 $tdwidth = 700;
14 $config_file = 'index-user.php';
15 $fs_config_file = dirname(__FILE__) . (substr(PHP_OS,0,3) == 'WIN' ? '\\' : "/") . $config_file;
16 if ($HTTP_POST_VARS['create'])  header('Location: configurator.php?create=1#create');
17 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", 'iso-8859-1'); 
18 ?>
19 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
20   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
21 <html xmlns="http://www.w3.org/1999/xhtml">
22 <head>
23 <!-- $Id: configurator.php,v 1.8 2002-09-15 16:30:27 rurban Exp $ -->
24 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
25 <title>Configuration tool for PhpWiki 1.3.x</title>
26 <style type="text/css" media="screen">
27 <!--
28 /* TABLE { border: thin solid black } */
29 body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 80%; }
30 pre { font-size: 120%; }
31 td { border: thin solid black }
32 tr { border: none }
33 td.part { background-color: #eeaaaa; }
34 td.full_instructions { background-color: #eeeeee; }
35 td.instructions { background-color: #ffffee; width: <?php echo $tdwidth ?>; }
36 td.unchangeable_variable_top   { border-bottom: none; background-color: #eeeeee; }
37 td.unchangeable_variable_left  { top-bottom: none; background-color: #eeeeee; }
38 /* td.unchangeable_variable_right { top-bottom: none; background-color: #ffffff; } */
39 -->
40 </style>
41 <script language="JavaScript" type="text/javascript">
42 <!--
43 function update(accepted, error, value, output) {
44   if (accepted) {
45     document.getElementById(output).innerHTML = "<font color=\"green\">Input accepted.</font>";
46   } else {
47     while ((index = error.indexOf("%s")) > -1) {
48       error = error.substring(0, index) + value + error.substring(index+2);
49     }
50     document.getElementById(output).innerHTML = "<font color=\"red\">" + error + "</font>";
51   }
52 }
53
54 function validate(error, value, output, field) {
55   update(field.value == value, error, field.value, output);
56 }
57
58 function validate_ereg(error, ereg, output, field) {
59   regex = new RegExp(ereg);
60   update(regex.test(field.value), error, field.value, output);
61 }
62
63 function validate_range(error, low, high, empty_ok, output, field) {
64   update((empty_ok == 1 && field.value == "") ||
65          (field.value >= low && field.value <= high),
66          error, field.value, output);
67 }
68
69 function toggle_group(id) {
70   group = document.getElementById(id);
71   text = document.getElementById(id + "_text");
72   input = document.getElementById(id + "_input");
73   if (group.style.display == "none") {
74     text.innerHTML = "Hide options.";
75     group.style.display = "block";
76     input.value = 1;
77   } else {
78     text.innerHTML = "Show options.";
79     group.style.display = "none";
80     input.value = 0;
81   }
82 }
83 -->
84 </script>
85 </head>
86 <body>
87
88 <h1>Configuration tool for PhpWiki 1.3.x</h1>
89
90 <?php
91 //define('DEBUG', 1);
92 /**
93  * The Configurator is a php script to aid in the configuration of PhpWiki.
94  * Parts of this file are based on PHPWeather's configurator.php file.
95  * http://sourceforge.net/projects/phpweather/
96  *
97  *
98  * TO CHANGE THE CONFIGURATION OF YOUR PHPWIKI, DO *NOT* MODIFY THIS FILE!
99  * more instructions go here
100  *
101  * Todo: 
102  *   * start this automatically the first time
103  *   * fix include_path
104  *   * eval index.php to get the actual settings.
105  *   * ask to store it in index.php or settings.php
106  * 
107  * The file settings.php will be generated which you can use as your index.php.
108  */
109
110
111 //////////////////////////////
112 // begin configuration options
113
114
115 /**
116  * Notes for the description parameter of $property:
117  *
118  * - Descriptive text will be changed into comments (preceeded by //)
119  *   for the final output to index.php.
120  *
121  * - Only a limited set of html is allowed: pre, dl dt dd; it will be
122  *   stripped from the final output.
123  *
124  * - Line breaks and spacing will be preserved for the final output.
125  *
126  * - Double line breaks are automatically converted to paragraphs
127  *   for the html version of the descriptive text.
128  *
129  * - Double-quotes and dollar signs in the descriptive text must be
130  *   escaped: \" and \$. Instead of escaping double-quotes you can use 
131  *   single (') quotes for the enclosing quotes. 
132  *
133  * - Special characters like < and > must use html entities,
134  *   they will be converted back to characters for the final output.
135  */
136
137 $SEPARATOR = "///////////////////////////////////////////////////////////////////";
138
139 $copyright = '
140 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam = array(
141 "Steve Wainstead", "Clifford A. Adams", "Lawrence Akka", 
142 "Scott R. Anderson", "Jon Åslund", "Neil Brown", "Jeff Dairiki",
143 "Stéphane Gourichon", "Jan Hidders", "Arno Hollosi", "John Jorgensen",
144 "Antti Kaihola", "Jeremie Kass", "Carsten Klapp", "Marco Milanesi",
145 "Grant Morgan", "Jan Nieuwenhuizen", "Aredridel Niothke", 
146 "Pablo Roca Rozas", "Sandino Araico Sánchez", "Joel Uckelman", 
147 "Reini Urban", "Tim Voght");
148
149 This file is part of PhpWiki.
150
151 PhpWiki is free software; you can redistribute it and/or modify
152 it under the terms of the GNU General Public License as published by
153 the Free Software Foundation; either version 2 of the License, or
154 (at your option) any later version.
155
156 PhpWiki is distributed in the hope that it will be useful,
157 but WITHOUT ANY WARRANTY; without even the implied warranty of
158 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
159 GNU General Public License for more details.
160
161 You should have received a copy of the GNU General Public License
162 along with PhpWiki; if not, write to the Free Software
163 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
164 ';
165
166
167
168 $preamble = "
169   This is the starting file for PhpWiki. All this file does is set
170   configuration options, and at the end of the file it includes() the
171   file lib/main.php, where the real action begins.
172
173   If you include this file to override the default settings here, 
174   you must also include lib/main.php.
175
176   This file is divided into seven parts: Parts Zero, One, Two, Three,
177   Four, Five and Six. Each one has different configuration settings you can
178   change; in all cases the default should work on your system,
179   however, we recommend you tailor things to your particular setting.
180 ";
181
182
183
184 $properties["Part Zero"] =
185 new part('_part0', false, "
186 Part Zero: If PHP needs help in finding where you installed the
187 rest of the PhpWiki code, you can set the include_path here.");
188
189 if (substr(PHP_OS,0,3) == 'WIN') {
190     $include_path = ini_get('include_path') . ';' . dirname(__FILE__);
191     if (strchr(ini_get('include_path'),'/'))
192         $include_path = strtr($include_path,'\\','/');
193 } else {
194     $include_path = ini_get('include_path') . ':' . dirname(__FILE__);
195 }
196
197 $properties["PHP include_path"] =
198 new _ini_set('include_path', $include_path, "
199 NOTE: phpwiki uses the PEAR library of php code for SQL database
200 access. Your PHP is probably already configured to set
201 include_path so that PHP can find the pear code. If not (or if you
202 change include_path here) make sure you include the path to the
203 PEAR code in include_path. (To find the PEAR code on your system,
204 search for a file named 'PEAR.php'. Some common locations are:
205 <pre>
206   Unixish systems:
207     /usr/share/php
208     /usr/local/share/php
209   Mac OS X:
210     /System/Library/PHP
211 </pre>
212 The above examples are already included by PhpWiki. You shouldn't
213 have to change this unless you see a WikiFatalError:
214 <pre>
215     lib/FileFinder.php:82: Fatal[256]: 
216     DB.php: file not found
217 </pre>
218 Define the include path for this wiki: pear plus the phpwiki path
219 <pre>
220 \$include_path = '.:/Apache/php/pear:/prog/php/phpwiki';
221 </pre>
222 Windows needs ';' as path delimiter. cygwin, mac and unix ':'
223 <pre>
224 if (substr(PHP_OS,0,3) == 'WIN') {
225   \$include_path = implode(';',explode(':',\$include_path));
226 } elseif (substr(PHP_OS,0,6) == 'CYGWIN') {
227   \$include_path = '.:/usr/local/lib/php/pear'.
228                      ':/usr/src/php/phpwiki';
229 } else {
230   ;
231 }</pre>");
232
233 $properties["Part Null"] =
234 new part('_partnullheader', "", "
235 Part Null: Don't touch this!");
236
237
238
239 $properties["Part Null Settings"] =
240 new unchangeable_variable('_partnullsettings', "
241 define ('PHPWIKI_VERSION', '1.3.4pre');
242 require \"lib/prepend.php\";
243 rcs_id('\$Id: configurator.php,v 1.8 2002-09-15 16:30:27 rurban Exp $');", "");
244
245
246 $properties["Part One"] =
247 new part('_partone', $SEPARATOR."\n", "
248
249 Part One:
250 Authentication and security settings. See Part Three for more.
251 ");
252
253
254
255 $properties["Wiki Name"] =
256 new _define_optional('WIKI_NAME', 'PhpWiki', "
257 The name of your wiki.
258 This is used to generate a keywords meta tag in the HTML templates,
259 in bookmark titles for any bookmarks made to pages in your wiki,
260 and during RSS generation for the title of the RSS channel.");
261
262
263 $properties["Reverse DNS"] =
264 new boolean_define('ENABLE_REVERSE_DNS',
265                     array('true'  => "true. perform additional reverse dns lookups",
266                           'false' => "false. just record the address as given by the httpd server"), "
267 If set, we will perform reverse dns lookups to try to convert the
268 users IP number to a host name, even if the http server didn't do
269 it for us.");
270
271
272
273 $properties["Admin Username"] =
274 new _define_optional('ADMIN_USER', "", "
275 <a name=\"create\">You must set this! Username and password of the administrator.</a>");
276
277 $properties["Admin Password"] =
278 new _define_password_optional('ADMIN_PASSWD', "", "
279 For heaven's sake pick a good password.
280 You can also use our <a target=\"_new\" href=\"passencrypt.php\">passwordencrypter</a> to encrypt an existing password.");
281
282 $properties["Encrypted Password"] = 
283 new boolean_define_optional('ENCRYPTED_PASSWD',
284                     array('true'  => "true. ADMIN_PASSWD is encrypted",
285                           'false' => "false. ADMIN_PASSWD is plaintext. Not recommended!"), "
286 If you used the passencrypt.php utility to encode the password or use an existing unix-crypt password,
287 then set this to true. Recommended!");
288
289 $properties["ZIPdump Authentication"] =
290 new boolean_define_optional('ZIPDUMP_AUTH', 
291                     array('false' => "false. Everyone may download zip dumps",
292                           'true'  => "true. Only admin may download zip dumps"), "
293 If true, only the admin user can make zip dumps, else zip dumps
294 require no authentication.");
295
296 $properties["Enable Plugin RawHtml"] =
297 new boolean_define_optional('ENABLE_RAW_HTML', 
298                     array('false' => "Disabled. Recommended on public sites.",
299                           'true'  => "Enabled"), "
300 Allow < ?plugin RawHtml ...>. Don't do this on a publicly accessable wiki for now.");
301
302 $properties["Strict Mailable Pagedumps"] =
303 new boolean_define('STRICT_MAILABLE_PAGEDUMPS', 
304                     array('false' => "binary",
305                           'true'  => "quoted-printable"), "
306 If you define this to true, (MIME-type) page-dumps (either zip dumps,
307 or \"dumps to directory\" will be encoded using the quoted-printable
308 encoding.  If you're actually thinking of mailing the raw page dumps,
309 then this might be useful, since (among other things,) it ensures
310 that all lines in the message body are under 80 characters in length.
311
312 Also, setting this will cause a few additional mail headers
313 to be generated, so that the resulting dumps are valid
314 RFC 2822 e-mail messages.
315
316 Probably, you can just leave this set to false, in which case you get
317 raw ('binary' content-encoding) page dumps.");
318
319
320
321 $properties["HTML Dump Filename Suffix"] =
322 new _variable('HTML_DUMP_SUFFIX', ".html", "
323 Here you can change the filename suffix used for XHTML page dumps.
324 If you don't want any suffix just comment this out.");
325
326
327
328 $properties["Maximum Upload Size"] =
329 new numeric_define('MAX_UPLOAD_SIZE', "16 * 1024 * 1024", "
330 The maximum file upload size.");
331
332
333
334 $properties["Minor Edit Timeout"] =
335 new numeric_define('MINOR_EDIT_TIMEOUT', "7 * 24 * 3600", "
336 If the last edit is older than MINOR_EDIT_TIMEOUT seconds, the
337 default state for the \"minor edit\" checkbox on the edit page form
338 will be off.");
339
340
341
342 $properties["Disabled Actions"] =
343 new array_variable('DisabledActions', array(), "
344 Actions listed in this array will not be allowed. Actions are:
345 browse, diff, dumphtml, dumpserial, edit, loadfile, lock, remove, 
346 unlock, upload, viewsource, zip, ziphtml");
347
348 $properties["Access Log"] =
349 new _define_commented('ACCESS_LOG', "/var/logs/wiki_access.log", "
350 PhpWiki can generate an access_log (in \"NCSA combined log\" format)
351 for you. If you want one, define this to the name of the log file,
352 such as /tmp/wiki_access_log.");
353
354
355 $properties["Path for PHP Session Support"] =
356 new _ini_set('session.save_path', '/tmp', "
357 The login code now uses PHP's session support. Usually, the default
358 configuration of PHP is to store the session state information in
359 /tmp. That probably will work fine, but fails e.g. on clustered
360 servers where each server has their own distinct /tmp (this is the
361 case on SourceForge's project web server.) You can specify an
362 alternate directory in which to store state information like so
363 (whatever user your httpd runs as must have read/write permission
364 in this directory):");
365
366
367
368 $properties["Disable PHP Transparent Session ID"] =
369 new unchangeable_ini_set('session.use_trans_sid', "@ini_set('session.use_trans_sid', 0);", "
370 If your php was compiled with --enable-trans-sid it tries to
371 add a PHPSESSID query argument to all URL strings when cookie
372 support isn't detected in the client browser.  For reasons
373 which aren't entirely clear (PHP bug) this screws up the URLs
374 generated by PhpWiki.  Therefore, transparent session ids
375 should be disabled.  This next line does that.
376
377 (At the present time, you will not be able to log-in to PhpWiki,
378 or set any user preferences, unless your browser supports cookies.)");
379
380
381
382 ///////// database selection
383
384
385 $properties["Part Two"] =
386 new part('_parttwo', $SEPARATOR."\n", "
387
388 Part Two:
389 Database Selection
390 ");
391
392
393 $properties["Database Type"] =
394 new _variable_selection("DBParams|dbtype",
395               array('dba'   => "dba DBM",
396                     'SQL'   => "SQL PEAR",
397                     'ADODB' => "SQL ADODB",
398                     'cvs'   => "CVS File handler"), "
399 Select the database backend type:
400 Choose ADODB or SQL to use an SQL database with ADODB or PEAR.
401 Choose dba to use one of the standard UNIX dbm libraries.
402 CVS is not yet tested nor supported.
403 Recommended is SQL PEAR.");
404
405 $properties["Filename / Table name Prefix"] =
406 new _variable_commented("DBParams|prefix", "phpwiki_", "
407 Used by all DB types:
408
409 Prefix for filenames or table names
410
411 Currently you MUST EDIT THE SQL file too (in the schemas/
412 directory because we aren't doing on the fly sql generation
413 during the installation.");
414
415
416 $properties["SQL dsn Setup"] =
417 new unchangeable_variable('_sqldsnstuff', "", "
418 For SQL based backends, specify the database as a DSN
419 The most general form of a DSN looks like:
420 <pre>
421   phptype(dbsyntax)://username:password@protocol+hostspec/database
422 </pre>
423 For a MySQL database, the following should work:
424 <pre>
425    mysql://user:password@host/databasename
426 </pre>
427 <dl><dd>FIXME:</dd> <dt>My version Pear::DB seems to be broken enough that there
428         is no way to connect to a mysql server over a socket right now.</dt></dl>
429 <pre>'dsn' => 'mysql://guest@:/var/lib/mysql/mysql.sock/test',
430 'dsn' => 'mysql://guest@localhost/test',
431 'dsn' => 'pgsql://localhost/test',</pre>");
432
433 // Choose ADODB or SQL to use an SQL database with ADODB or PEAR.
434 // Choose dba to use one of the standard UNIX dbm libraries.
435
436 $properties["SQL Type"] =
437 new _variable_selection('_dsn_sqltype',
438               array('mysql' => "MySQL",
439                     'pgsql' => "PostgreSQL"), "
440 SQL DB types");
441
442
443
444 $properties["SQL User"] =
445 new _variable('_dsn_sqluser', "wikiuser", "
446 SQL User Id:");
447
448
449
450 $properties["SQL Password"] =
451 new _variable('_dsn_sqlpass', "", "
452 SQL Password:");
453
454
455
456 $properties["SQL Database Host"] =
457 new _variable('_dsn_sqlhostorsock', "localhost", "
458 SQL Database Hostname:");
459
460
461
462 $properties["SQL Database Name"] =
463 new _variable('_dsn_sqldbname', "phpwiki", "
464 SQL Database Name:");
465
466 list($dsn_sqltype,) = $properties["SQL Type"]->value();
467 $dsn_sqluser = $properties["SQL User"]->value();
468 $dsn_sqlpass = $properties["SQL Password"]->value();
469 $dsn_sqlhostorsock = $properties["SQL Database Host"]->value();
470 $dsn_sqldbname = $properties["SQL Database Name"]->value();
471
472 $properties["SQL dsn"] =
473 new unchangeable_variable("DBParams['dsn']", 
474   "\$DBParams['dsn'] = \"\$_dsn_sqltype://{$dsn_sqluser}:{$dsn_sqlpass}@{$dsn_sqlhostorsock}/{$dsn_sqldbname}\";", "");
475
476 $properties["dba directory"] =
477 new _variable("DBParams|directory", "/tmp", "
478 dba directory:");
479
480
481 $properties["dba handler"] =
482 new _variable_selection('DBParams|dba_handler',
483               array('gdbm' => "Gdbm - GNU database manager",
484                     'dbm'  => "DBM - Redhat default. On sf.net there's dbm and gdbm",
485                     'db2'  => "DB2 - Sleepycat Software's DB2",
486                     'db3'  => "DB3 - Sleepycat Software's DB3. Fine on Windows but not on every Linux"), "
487 Use 'gdbm', 'dbm', 'db2' or 'db3' depending on your DBA handler methods supported:");
488
489 $properties["dba timeout"] =
490 new _variable("DBParams|timeout", "20", "
491 Recommended values are 20 or 5.");
492
493
494
495 ///////////////////
496
497
498
499 $properties["Page Revisions"] =
500 new unchangeable_variable('_parttworevisions', "", "
501
502 The next section controls how many old revisions of each page are
503 kept in the database.
504
505 There are two basic classes of revisions: major and minor. Which
506 class a revision belongs in is determined by whether the author
507 checked the \"this is a minor revision\" checkbox when they saved the
508 page.
509  
510 There is, additionally, a third class of revisions: author
511 revisions. The most recent non-mergable revision from each distinct
512 author is and author revision.
513
514 The expiry parameters for each of those three classes of revisions
515 can be adjusted seperately. For each class there are five
516 parameters (usually, only two or three of the five are actually
517 set) which control how long those revisions are kept in the
518 database.
519 <dl>
520    <dt>max_keep:</dt> <dd>If set, this specifies an absolute maximum for the
521             number of archived revisions of that class. This is
522             meant to be used as a safety cap when a non-zero
523             min_age is specified. It should be set relatively high,
524             and it's purpose is to prevent malicious or accidental
525             database overflow due to someone causing an
526             unreasonable number of edits in a short period of time.</dd>
527
528   <dt>min_age:</dt>  <dd>Revisions younger than this (based upon the supplanted
529             date) will be kept unless max_keep is exceeded. The age
530             should be specified in days. It should be a
531             non-negative, real number,</dd>
532
533   <dt>min_keep:</dt> <dd>At least this many revisions will be kept.</dd>
534
535   <dt>keep:</dt>     <dd>No more than this many revisions will be kept.</dd>
536
537   <dt>max_age:</dt>  <dd>No revision older than this age will be kept.</dd>
538 </dl>
539 Supplanted date: Revisions are timestamped at the instant that they
540 cease being the current revision. Revision age is computed using
541 this timestamp, not the edit time of the page.
542
543 Merging: When a minor revision is deleted, if the preceding
544 revision is by the same author, the minor revision is merged with
545 the preceding revision before it is deleted. Essentially: this
546 replaces the content (and supplanted timestamp) of the previous
547 revision with the content after the merged minor edit, the rest of
548 the page metadata for the preceding version (summary, mtime, ...)
549 is not changed.
550 ");
551
552
553 // For now the expiration parameters are statically inserted as
554 // an unchangeable property. You'll have to edit the resulting
555 // config file if you really want to change these from the default.
556
557 $properties["Expiration Parameters for Major Edits"] =
558 new unchangeable_variable('ExpireParams|major',
559 "\$ExpireParams['major'] = array('max_age' => 32,
560                                'keep'    => 8);", "
561 Keep up to 8 major edits, but keep them no longer than a month.");
562
563 $properties["Expiration Parameters for Minor Edits"] =
564 new unchangeable_variable('ExpireParams|minor',
565 "\$ExpireParams['minor'] = array('max_age' => 7,
566                                'keep'    => 4);", "
567 Keep up to 4 minor edits, but keep them no longer than a week.");
568
569
570
571 $properties["Expiration Parameters by Author"] =
572 new unchangeable_variable('ExpireParams|author',
573 "\$ExpireParams['author'] = array('max_age'  => 365,
574                                 'keep'     => 8,
575                                 'min_age'  => 7,
576                                 'max_keep' => 20);", "
577 Keep the latest contributions of the last 8 authors up to a year.
578 Additionally, (in the case of a particularly active page) try to
579 keep the latest contributions of all authors in the last week (even
580 if there are more than eight of them,) but in no case keep more
581 than twenty unique author revisions.");
582
583 /////////////////////////////////////////////////////////////////////
584
585 $properties["Part Three"] =
586 new part('_partthree', $SEPARATOR."\n", "
587
588 Part Three: (optional)
589 User Authentification
590 ");
591
592 $properties["User Authentication"] =
593 new boolean_define_optional('ALLOW_USER_LOGIN',
594                     array('true'  => "true. Check any defined passwords. (Default)",
595                           'false' => "false. Don't check passwords. Legacy < 1.3.4"), "
596 If ALLOW_USER_LOGIN is true, any defined internal and external
597 authentication method is tried. 
598 If not, we don't care about passwords, but check the next two constants.");
599
600 $properties["HTTP Authentication"] =
601 new boolean_define_optional('ALLOW_HTTP_AUTH_LOGIN',
602                     array('false' => "false. Ignore HTTP Authentication. (Default)",
603                           'true'  => "true. Allow .htpasswd users login automatically."), "
604 The wiki can be optionally be protected by HTTP Auth. Use the username and password 
605 from there, and if this fails, try the other methods also.");
606
607 $properties["Strict Login"] =
608 new boolean_define_optional('ALLOW_BOGO_LOGIN',
609                     array('true'  => "Users may Sign In with any WikiWord",
610                           'false' => "Only admin may Sign In"), "
611 If ALLOW_BOGO_LOGIN is true, users are allowed to login (with
612 any/no password) using any userid which: 1) is not the ADMIN_USER,
613 2) is a valid WikiWord (matches \$WikiNameRegexp.)
614 If true, users may be created by themselves. Otherwise we need seperate auth. 
615 This might be renamed to ALLOW_SELF_REGISTRATION");
616
617 $properties["Require Sign In Before Editing"] =
618 new boolean_define_optional('REQUIRE_SIGNIN_BEFORE_EDIT',
619                     array('false' => "Do not require Sign In",
620                           'true'  => "Require Sign In"), "
621 If set, then if an anonymous user attempts to edit a page he will
622 be required to sign in.  (If ALLOW_BOGO_LOGIN is true, of course,
623 no password is required, but the user must still sign in under
624 some sort of BogoUserId.)");
625
626 if (function_exists('ldap_connect')) {
627 $properties["LDAP Authentication"] =
628   new boolean_define_optional('ALLOW_LDAP_LOGIN',
629                     array('true'  => "Allow LDAP Authentication",
630                           'false' => "Ignore LDAP"), "
631 LDAP Authentication
632 ");
633 $properties["LDAP Host"] =
634   new _define_optional('LDAP_AUTH_HOST', "localhost", "");
635 $properties["LDAP Root Search"] =
636   new _define_optional('LDAP_AUTH_SEARCH', "ou=mycompany.com,o=My Company", 
637   "Give the right LDAP root search information in the next statement.");
638
639 } else {
640
641 $properties["LDAP Authentication"] =
642 new unchangeable_define('ALLOW_LDAP_LOGIN', "
643 if (!defined('ALLOW_LDAP_LOGIN')) define('ALLOW_LDAP_LOGIN', true and function_exists('ldap_connect'));
644 if (!defined('LDAP_AUTH_HOST'))   define('LDAP_AUTH_HOST', 'localhost');
645 // Give the right LDAP root search information in the next statement. 
646 if (!defined('LDAP_AUTH_SEARCH')) define('LDAP_AUTH_SEARCH', 'ou=mycompany.com,o=My Company');
647 ", "
648 Ignored. No LDAP support in this php. configure --with-ldap");
649 }
650
651 if (function_exists('imap_open')) {
652 $properties["IMAP Authentication"] =
653   new boolean_define_optional('ALLOW_IMAP_LOGIN',
654                     array('true'  => "Allow IMAP Authentication",
655                           'false' => "Ignore IMAP"), "
656 IMAP Authentication
657 ");
658 $properties["IMAP Host"] =
659   new _define_optional('IMAP_AUTH_HOST', 'localhost', '');
660 } else {
661 $properties["IMAP Authentication"] =
662   new unchangeable_define('ALLOW_IMAP_LOGIN',"
663 // IMAP auth: check userid/passwords from a imap server, defaults to localhost
664 if (!defined('ALLOW_IMAP_LOGIN')) define('ALLOW_IMAP_LOGIN', true and function_exists('imap_open'));
665 if (!defined('IMAP_AUTH_HOST'))   define('IMAP_AUTH_HOST', 'localhost');
666 ", "Ignored. No IMAP support in this php. configure --with-imap");
667 }
668
669
670 /////////////////////////////////////////////////////////////////////
671
672 $properties["Part Four"] =
673 new part('_partfour', $SEPARATOR."\n", "
674
675 Part Four:
676 Page appearance and layout
677 ");
678
679
680
681 $properties["Theme"] =
682 new _define_selection_optional('THEME',
683               array('default'  => "default",
684                     'Hawaiian' => "Hawaiian",
685                     'MacOSX'   => "MacOSX",
686                     'Portland' => "Portland",
687                     'Sidebar'  => "Sidebar",
688                     'SpaceWiki' => "SpaceWiki"), "
689 THEME
690
691 Most of the page appearance is controlled by files in the theme
692 subdirectory.
693
694 There are a number of pre-defined themes shipped with PhpWiki.
695 Or you may create your own (e.g. by copying and then modifying one of
696 stock themes.)
697
698 Pick one.
699 <pre>
700 define('THEME', 'default');
701 define('THEME', 'Hawaiian');
702 define('THEME', 'MacOSX');
703 define('THEME', 'Portland');
704 define('THEME', 'Sidebar');
705 define('THEME', 'SpaceWiki');</pre>");
706
707
708
709 $properties["Character Set"] =
710 new _define_optional('CHARSET', 'iso-8859-1', "
711 Select a valid charset name to be inserted into the xml/html pages, 
712 and to reference links to the stylesheets (css). For more info see: 
713 http://www.iana.org/assignments/character-sets. Note that PhpWiki 
714 has been extensively tested only with the latin1 (iso-8859-1) 
715 character set.
716
717 If you change the default from iso-8859-1 PhpWiki may not work 
718 properly and it will require code modifications. However, character 
719 sets similar to iso-8859-1 may work with little or no modification 
720 depending on your setup. The database must also support the same 
721 charset, and of course the same is true for the web browser. (Some 
722 work is in progress hopefully to allow more flexibility in this 
723 area in the future).");
724
725
726
727 $properties["Language"] =
728 new _variable_selection_optional('LANG',
729               array('en' => "English",
730                     'nl' => "Nederlands",
731                     'es' => "Español",
732                     'fr' => "Français",
733                     'de' => "Deutsch",
734                     'sv' => "Svenska",
735                     'it' => "Italiano",
736                     ''   => "none"), "
737 Select your language/locale - default language is \"en\" for English.
738 Other languages available:<pre>
739 English \"en\"  (English    - HomePage)
740 Dutch   \"nl\" (Nederlands - ThuisPagina)
741 Spanish \"es\" (Español    - PáginaPrincipal)
742 French  \"fr\" (Français   - Accueil)
743 German  \"de\" (Deutsch    - StartSeite)
744 Swedish \"sv\" (Svenska    - Framsida)
745 Italian \"it\" (Italiano   - PaginaPrincipale)
746 </pre>
747 If you set \$LANG to the empty string, your systems default language
748 (as determined by the applicable environment variables) will be
749 used.");
750
751 $properties["Language Locales"] =
752 new unchangeable_variable('language_locales',
753 "\$language_locales = array('en' => 'C',
754                             'de' => 'de_DE',
755                             'es' => 'es_MX',
756                             'nl' => 'nl_NL',
757                             'fr' => 'fr_FR',
758                             'it' => 'it_IT',
759                             'sv' => 'sv_SV'
760                             );
761 if (empty(\$LC_ALL)) {
762   if (empty(\$language_locales[\$LANG]))
763      \$LC_ALL = \$LANG;
764   else
765      \$LC_ALL = \$language_locales[\$LANG];
766 }
767 putenv(\"LC_TIME=\$LC_ALL\");
768 ", "
769 Setting the LANG environment variable (accomplished above) may or
770 may not be sufficient to cause PhpWiki to produce dates in your
771 native language. (It depends on the configuration of the operating
772 system on your http server.)  The problem is that, e.g. 'de' is
773 often not a valid locale.
774
775 A standard locale name is typically of  the  form
776 language[_territory][.codeset][@modifier],  where  language is
777 an ISO 639 language code, territory is an ISO 3166 country code,
778 and codeset  is  a  character  set or encoding identifier like
779 ISO-8859-1 or UTF-8.
780
781 You can tailor the locale used for time and date formatting by
782 setting the LC_TIME environment variable. You'll have to experiment
783 to find the correct setting.
784 gettext() fix: With setlocale() we must use the long form, 
785 like 'de_DE','nl_NL', 'es_MX', 'es_AR', 'fr_FR'. 
786 For Windows maybe even 'german'. You might fix this accordingly.");
787
788 $properties["Wiki Page Source"] =
789 new _define_optional('WIKI_PGSRC', 'pgsrc', "
790 WIKI_PGSRC -- specifies the source for the initial page contents of
791 the Wiki. The setting of WIKI_PGSRC only has effect when the wiki is
792 accessed for the first time (or after clearing the database.)
793 WIKI_PGSRC can either name a directory or a zip file. In either case
794 WIKI_PGSRC is scanned for files -- one file per page.
795 <pre>
796 // Default (old) behavior:
797 define('WIKI_PGSRC', 'pgsrc'); 
798 // New style:
799 define('WIKI_PGSRC', 'wiki.zip'); 
800 define('WIKI_PGSRC', 
801        '../Logs/Hamwiki/hamwiki-20010830.zip'); 
802 </pre>");
803
804
805
806 $properties["Default Wiki Page Source"] =
807 new _define('DEFAULT_WIKI_PGSRC', 'pgsrc', "
808 DEFAULT_WIKI_PGSRC is only used when the language is *not* the
809 default (English) and when reading from a directory: in that case
810 some English pages are inserted into the wiki as well.
811 DEFAULT_WIKI_PGSRC defines where the English pages reside.
812
813 FIXME: is this really needed?
814 ");
815
816
817
818 $properties["Generic Pages"] =
819 new array_variable('GenericPages', array('ReleaseNotes', 'SteveWainstead', 'TestPage'), "
820 These are the pages which will get loaded from DEFAULT_WIKI_PGSRC.      
821
822 FIXME: is this really needed?  Can't we just copy these pages into
823 the localized pgsrc?
824 ");
825
826
827
828
829 $properties["Part Five"] =
830 new part('_partfive', $SEPARATOR."\n", "
831
832 Part Five:
833 Mark-up options.
834 ");
835
836
837
838 $properties["Allowed Protocols"] =
839 new list_variable('AllowedProtocols', 'http|https|mailto|ftp|news|nntp|ssh|gopher', "
840 allowed protocols for links - be careful not to allow \"javascript:\"
841 URL of these types will be automatically linked.
842 within a named link [name|uri] one more protocol is defined: phpwiki");
843
844
845
846 $properties["Inline Images"] =
847 new list_variable('InlineImages', 'png|jpg|gif', "
848 URLs ending with the following extension should be inlined as images");
849
850
851
852 $properties["WikiName Regexp"] =
853 new _variable('WikiNameRegexp', "(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])", "
854 Perl regexp for WikiNames (\"bumpy words\")
855 (?&lt;!..) & (?!...) used instead of '\b' because \b matches '_' as well");
856
857 $properties["Subpage Separator"] =
858 new _define_optional('SUBPAGE_SEPARATOR', '/', "
859 One character which seperates pages from subpages. Defaults to '/', but '.' or ':' were also used.");
860
861 $properties["InterWiki Map File"] =
862 new _define('INTERWIKI_MAP_FILE', 'lib/interwiki.map', "
863 InterWiki linking -- wiki-style links to other wikis on the web
864
865 The map will be taken from a page name InterWikiMap.
866 If that page is not found (or is not locked), or map
867 data can not be found in it, then the file specified
868 by INTERWIKI_MAP_FILE (if any) will be used.");
869
870 $properties["WARN_NONPUBLIC_INTERWIKIMAP"] =
871 new boolean_define('WARN_NONPUBLIC_INTERWIKIMAP',   
872         array('true'  => "true",
873                           'false' => "false"), "
874 Display a warning if the internal lib/interwiki.map is used, and 
875 not the public InterWikiMap page. This map is not readable from outside.");
876
877
878 $properties["Part Six"] =
879 new part('_partsix', $SEPARATOR."\n", "
880
881 Part Six (optional):
882 URL options -- you can probably skip this section.
883 ");
884
885 $properties["Server Name"] =
886 new _define_commented_optional('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME'], "
887 Canonical name and httpd port of the server on which this PhpWiki
888 resides.");
889
890
891
892 $properties["Server Port"] =
893 new numeric_define_commented('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT'], "");
894
895 $scriptname = preg_replace('/configurator.php/','index.php',$HTTP_SERVER_VARS["SCRIPT_NAME"]);
896
897 $properties["Script Name"] =
898 new _define_commented_optional('SCRIPT_NAME', $scriptname, "
899 Relative URL (from the server root) of the PhpWiki script.");
900
901 $properties["Data Path"] =
902 new _define_commented_optional('DATA_PATH', dirname($scriptname), "
903 URL of the PhpWiki install directory.  (You only need to set this
904 if you've moved index.php out of the install directory.)  This can
905 be either a relative URL (from the directory where the top-level
906 PhpWiki script is) or an absolute one.");
907
908
909
910 $properties["PhpWiki Install Directory"] =
911 new _define_commented_optional('PHPWIKI_DIR', dirname(__FILE__), "
912 Path to the PhpWiki install directory.  This is the local
913 filesystem counterpart to DATA_PATH.  (If you have to set
914 DATA_PATH, your probably have to set this as well.)  This can be
915 either an absolute path, or a relative path interpreted from the
916 directory where the top-level PhpWiki script (normally index.php)
917 resides.");
918
919
920
921 $properties["Use PATH_INFO"] =
922 new boolean_define_commented_optional('USE_PATH_INFO', 
923                     array('true'  => 'use PATH_INFO',
924                           'false' => 'do not use PATH_INFO'), "
925 Define to 'true' to use PATH_INFO to pass the pagenames.
926 e.g. http://www.some.where/index.php/HomePage instead
927 of http://www.some.where/index.php?pagename=HomePage
928 FIXME: more docs (maybe in README). Default: true");
929
930
931
932 $properties["Virtual Path"] =
933 new _define_commented_optional('VIRTUAL_PATH', '/SomeWiki', "
934 VIRTUAL_PATH is the canonical URL path under which your your wiki
935 appears. Normally this is the same as dirname(SCRIPT_NAME), however
936 using, e.g. apaches mod_actions (or mod_rewrite), you can make it
937 something different.
938
939 If you do this, you should set VIRTUAL_PATH here.
940
941 E.g. your phpwiki might be installed at at /scripts/phpwiki/index.php,
942 but you've made it accessible through eg. /wiki/HomePage.
943
944 One way to do this is to create a directory named 'wiki' in your
945 server root. The directory contains only one file: an .htaccess
946 file which reads something like:
947 <pre>
948     Action x-phpwiki-page /scripts/phpwiki/index.php
949     SetHandler x-phpwiki-page
950     DirectoryIndex /scripts/phpwiki/index.php
951 </pre>
952 In that case you should set VIRTUAL_PATH to '/wiki'.
953
954 (VIRTUAL_PATH is only used if USE_PATH_INFO is true.)
955 ");
956
957
958
959 $end = "
960
961 $SEPARATOR
962 // Check if we were included by some other wiki version (getimg, en, ...) 
963 // or not. 
964 // If the server requested this index.php fire up the code by loading lib/main.php.
965 // Parallel wiki scripts can now simply include /index.php for the 
966 // main configuration, extend or redefine some settings and 
967 // load lib/main.php by themselves. 
968 // This overcomes the index as config problem.
969 $SEPARATOR
970
971 // This doesn't work with php as CGI yet!
972 if (defined('VIRTUAL_PATH') and defined('USE_PATH_INFO')) {
973     if (\$HTTP_SERVER_VARS['SCRIPT_NAME'] == VIRTUAL_PATH) {
974         include \"lib/main.php\";
975     }
976 } else {
977     if (defined('SCRIPT_NAME') and 
978         (\$HTTP_SERVER_VARS['SCRIPT_NAME'] == SCRIPT_NAME)) {
979         include \"lib/main.php\";
980     } elseif (strstr(\$HTTP_SERVER_VARS['PHP_SELF'],'index.php')) {
981         include \"lib/main.php\";
982     }
983 }
984
985 // (c-file-style: \"gnu\")
986 // Local Variables:
987 // mode: php
988 // tab-width: 8
989 // c-basic-offset: 4
990 // c-hanging-comment-ender-p: nil
991 // indent-tabs-mode: nil
992 // End:   
993 ?>
994 ";
995
996
997
998 // end of configuration options
999 ///////////////////////////////
1000 // begin class definitions
1001
1002 /**
1003  * A basic index.php configuration line in the form of a variable.
1004  *
1005  * Produces a string in the form "$name = value;"
1006  * e.g.:
1007  * $WikiNameRegexp = "value";
1008  */
1009 class _variable {
1010
1011     var $config_item_name;
1012     var $default_value;
1013     var $description;
1014     var $prefix;
1015
1016     function _variable($config_item_name, $default_value, $description) {
1017         $this->config_item_name = $config_item_name;
1018         $this->description = $description;
1019         $this->default_value = $default_value;
1020         if (preg_match("/variable/i",get_class($this)))
1021             $this->prefix = "\$";
1022         elseif (preg_match("/ini_set/i",get_class($this)))
1023             $this->prefix = "ini_get: ";
1024         else
1025             $this->prefix = "";
1026     }
1027
1028     function value() {
1029       global $HTTP_POST_VARS;
1030       if ($v = $HTTP_POST_VARS[$this->config_item_name])
1031           return $v;
1032       else 
1033           return $this->default_value;
1034     }
1035
1036     function _config_format($value) {
1037         $v = $this->get_config_item_name();
1038         // handle arrays: a|b --> a['b']
1039         if (strpos($v, '|')) {
1040             list($a, $b) = explode('|', $v);
1041             $v = sprintf("%s['%s']", $a, $b);
1042         }
1043         return sprintf("\$%s = \"%s\";", $v, $value);
1044     }
1045
1046     function get_config_item_name() {
1047         return $this->config_item_name;
1048     }
1049
1050     function get_config_item_header() {
1051        if (strchr($this->config_item_name,'|')) {
1052           list($var,$param) = explode('|',$this->config_item_name);
1053           return "<b>" . $this->prefix . $var . "['" . $param . "']</b><br />";
1054        }
1055        elseif ($this->config_item_name[0] != '_')
1056           return "<b>" . $this->prefix . $this->config_item_name . "</b><br />";
1057        else 
1058           return '';
1059     }
1060
1061     function _get_description() {
1062         return $this->description;
1063     }
1064
1065     function _get_config_line($posted_value) {
1066         return "\n" . $this->_config_format($posted_value);
1067     }
1068
1069     function get_config($posted_value) {
1070         $d = stripHtml($this->_get_description());
1071         $d = str_replace("\n", "\n// ", $d) . $this->_get_config_line($posted_value) ."\n";
1072         return $d;
1073     }
1074
1075     function get_instructions($title) {
1076         global $tdwidth;
1077         $i = "<p><b><h3>" . $title . "</h3></b></p>\n    " . nl2p($this->_get_description()) . "\n";
1078         return "<tr>\n<td width=\"$tdwidth\" class=\"instructions\">\n" . $i . "</td>\n";
1079     }
1080
1081     function get_html() {
1082         return $this->get_config_item_header() . 
1083             "<input type=\"text\" size=\"50\" name=\"" . $this->get_config_item_name() . "\" value=\"" . $this->default_value . "\" />";
1084     }
1085 }
1086
1087 class unchangeable_variable
1088 extends _variable {
1089     function _config_format($value) {
1090         return "";
1091     }
1092     // function get_html() { return false; }
1093     function get_html() {
1094         return $this->get_config_item_header() . 
1095         "<em>Not editable.</em>" . 
1096         "<pre>" . $this->default_value."</pre>";
1097     }
1098     function _get_config_line($posted_value) {
1099         if ($this->description)
1100             $n = "\n";
1101         return "${n}".$this->default_value;
1102     }
1103     function get_instructions($title) {
1104         global $tdwidth;
1105         $i = "<p><b><h3>" . $title . "</h3></b></p>\n    " . nl2p($this->_get_description()) . "\n";
1106         // $i = $i ."<em>Not editable.</em><br />\n<pre>" . $this->default_value."</pre>";
1107         return "<tr><td width=\"100%\" class=\"unchangeable_variable_top\" colspan=\"2\">\n".$i ."</td></tr>\n".
1108         "<tr style=\"border-top: none\"><td class=\"unchangeable_variable_left\" width=\"$tdwidth\" bgcolor=\"#eeeeee\">&nbsp;</td>";
1109     }
1110 }
1111
1112 class unchangeable_define
1113 extends unchangeable_variable {
1114     function _config_format($value) {
1115         return "";
1116     }
1117 }
1118 class unchangeable_ini_set
1119 extends unchangeable_variable {
1120     function _config_format($value) {
1121         return "";
1122     }
1123 }
1124
1125
1126 class _variable_selection
1127 extends _variable {
1128     function value() {
1129         global $HTTP_POST_VARS;
1130         if ($v = $HTTP_POST_VARS[$this->config_item_name])
1131             return $v;
1132         else {
1133             list($option, $label) = current($this->default_value);
1134             return $this->$option;
1135         }
1136     }
1137     function get_html() {
1138         $output = $this->get_config_item_header();
1139         $output .= '<select name="' . $this->get_config_item_name() . "\">\n";
1140         /* The first option is the default */
1141         while(list($option, $label) = each($this->default_value)) {
1142             $output .= "  <option value=\"$option\">$label</option>\n";
1143         }
1144         $output .= "</select>\n  </td>\n";
1145         return $output;
1146     }
1147 }
1148
1149
1150 class _define
1151 extends _variable {
1152     function _config_format($value) {
1153         return sprintf("define('%s', '%s');", $this->get_config_item_name(), $value);
1154     }
1155     function _get_config_line($posted_value) {
1156         if ($this->description)
1157             $n = "\n";
1158         if ($posted_value == '')
1159             return "${n}//" . $this->_config_format("");
1160         else
1161             return "${n}" . $this->_config_format($posted_value);
1162     }
1163     function get_html() {
1164         return $this->get_config_item_header() . 
1165             "<input type=\"text\" size=\"50\" name=\"" . $this->get_config_item_name() . "\" value=\"" . $this->default_value . "\" />";
1166     }
1167 }
1168
1169 class _define_commented
1170 extends _define {
1171     function _get_config_line($posted_value) {
1172         if ($this->description)
1173             $n = "\n";
1174         if ($posted_value == $this->default_value)
1175             return "${n}//" . $this->_config_format($posted_value);
1176         else if ($posted_value == '')
1177             return "${n}//" . $this->_config_format("");
1178         else
1179             return "${n}" . $this->_config_format($posted_value);
1180     }
1181 }
1182
1183 class _define_commented_optional
1184 extends _define_commented {
1185     function _config_format($value) {
1186         $name = $this->get_config_item_name();
1187         return sprintf("if (!defined('%s')) define('%s', '%s');", $name, $name, $value);
1188     }
1189 }
1190
1191 class _define_optional
1192 extends _define {
1193     function _config_format($value) {
1194         $name = $this->get_config_item_name();
1195         return sprintf("if (!defined('%s')) define('%s', '%s');", $name, $name, $value);
1196     }
1197 }
1198
1199 class _variable_commented
1200 extends _variable {
1201     function _get_config_line($posted_value) {
1202         if ($this->description)
1203             $n = "\n";
1204         if ($posted_value == $this->default_value)
1205             return "${n}//" . $this->_config_format($posted_value);
1206         else if ($posted_value == '')
1207             return "${n}//" . $this->_config_format("");
1208         else
1209             return "${n}" . $this->_config_format($posted_value);
1210     }
1211 }
1212
1213 class numeric_define_commented
1214 extends _define {
1215     function get_html() {
1216         return numeric_define::get_html();
1217     }
1218     function _get_config_line($posted_value) {
1219         if ($this->description)
1220             $n = "\n";
1221         if ($posted_value == $this->default_value)
1222             return "${n}//" . $this->_config_format($posted_value);
1223         else if ($posted_value == '')
1224             return "${n}//" . $this->_config_format('0');
1225         else
1226             return "${n}" . $this->_config_format($posted_value);
1227     }
1228 }
1229
1230 class _define_selection
1231 extends _variable_selection {
1232     function _config_format($value) {
1233         return sprintf("define('%s', '%s');", $this->get_config_item_name(), $value);
1234     }
1235     function _get_config_line($posted_value) {
1236         return _define::_get_config_line($posted_value);
1237     }
1238     function get_html() {
1239         return _variable_selection::get_html();
1240     }
1241 }
1242
1243 class _define_selection_optional
1244 extends _define_selection {
1245     function _config_format($value) {
1246         $name = $this->get_config_item_name();
1247         return sprintf("if (!defined('%s')) define('%s', '%s');", $name, $name, $value);
1248     }
1249 }
1250
1251 class _variable_selection_optional
1252 extends _variable_selection {
1253     function _config_format($value) {
1254         $v = $this->get_config_item_name();
1255         // handle arrays: a|b --> a['b']
1256         if (strpos($v, '|')) {
1257             list($a, $b) = explode('|', $v);
1258             $v = sprintf("%s['%s']", $a, $b);
1259         }
1260         return sprintf("if (!isset(\$%s)) { \$%s = \"%s\"; }", $v, $v, $value);
1261     }
1262 }
1263
1264 class _define_password
1265 extends _define {
1266     function _get_config_line($posted_value) {
1267         if ($this->description)
1268             $n = "\n";
1269         if ($posted_value == '') {
1270             $p = "${n}//" . $this->_config_format("");
1271             $p = $p . "\n// If you used the passencrypt.php utility to encode the password";
1272             $p = $p . "\n// then uncomment this line:";
1273             $p = $p . "\n//if (!defined('ENCRYPTED_PASSWD')) define('ENCRYPTED_PASSWD', true);";
1274             return $p;
1275         } else {
1276             if (function_exists('crypt')) {
1277                 $salt_length = max(CRYPT_SALT_LENGTH,
1278                                     2 * CRYPT_STD_DES,
1279                                     9 * CRYPT_EXT_DES,
1280                                    12 * CRYPT_MD5,
1281                                    16 * CRYPT_BLOWFISH);
1282                 // generate an encrypted password
1283                 $crypt_pass = crypt($posted_value, rand_ascii($salt_length));
1284                 $p = "${n}" . $this->_config_format($crypt_pass);
1285                 return $p . "\ndefine('ENCRYPTED_PASSWD', true);";
1286             } else {
1287                 $p = "${n}" . $this->_config_format($posted_value);
1288                 $p = $p . "\n// If you used the passencrypt.php utility to encode the password";
1289                 $p = $p . "\n// then uncomment this line:";
1290                 $p = $p . "\n//define('ENCRYPTED_PASSWD', false);";
1291                 $p = $p . "\n// Encrypted passwords cannot be used:";
1292                 $p = $p . "\n// 'function crypt()' not available in this version of php";
1293                 return $p;
1294             }
1295         }
1296     }
1297     function get_html() {
1298         return _variable_password::get_html();
1299     }
1300 }
1301
1302 class _define_password_optional
1303 extends _define_password {
1304     function _config_format($value) {
1305         $name = $this->get_config_item_name();
1306         return sprintf("if (!defined('%s')) define('%s', '%s');", $name, $name, $value);
1307     }
1308 }
1309
1310
1311 class _variable_password
1312 extends _variable {
1313     function get_html() {
1314         global $HTTP_POST_VARS, $HTTP_GET_VARS;
1315         $s = $this->get_config_item_header();
1316         $s .= "<input type=\"password\" name=\"" . $this->get_config_item_name() . "\" value=\"" . $this->default_value . "\" />" . 
1317 "&nbsp;&nbsp;<input type=\"submit\" name=\"create\" value=\"Create Password\" />";
1318         if ($HTTP_POST_VARS['create'] or $HTTP_GET_VARS['create']) {
1319             $new_password = random_good_password();
1320             $this->default_value = $new_password;
1321             $s .= "<br />&nbsp;<br />Created password: <strong>$new_password</strong>";
1322         }
1323         return $s;
1324     }
1325 }
1326
1327 class numeric_define
1328 extends _define {
1329     function _config_format($value) {
1330         return sprintf("define('%s', %s);", $this->get_config_item_name(), $value);
1331     }
1332     function get_html() {
1333         $ori = _define::get_html();
1334         return substr($ori,0,-2) . " onchange=\"validate_ereg('Sorry, \'%s\' is not an integer.', '^[-+]?[0-9]+$', '" . $this->get_config_item_name() . "', this);" . '" />';
1335     }
1336     function _get_config_line($posted_value) {
1337         if ($this->description)
1338             $n = "\n";
1339         if ($posted_value == '')
1340             return "${n}//" . $this->_config_format('0');
1341         else
1342             return "${n}" . $this->_config_format($posted_value);
1343     }
1344 }
1345
1346 class list_variable
1347 extends _variable {
1348     function _get_config_line($posted_value) {
1349         // split the phrase by any number of commas or space characters,
1350         // which include " ", \r, \t, \n and \f
1351         $list_values = preg_split("/[\s,]+/", $posted_value, -1, PREG_SPLIT_NO_EMPTY);
1352         $list_values = join("|", $list_values);
1353         return _variable::_get_config_line($list_values);
1354     }
1355     function get_html() {
1356         $list_values = explode("|", $this->default_value);
1357         $rows = max(3, count($list_values) +1);
1358         $list_values = join("\n", $list_values);
1359         $ta = $this->get_config_item_header();
1360         $ta .= "<textarea cols=\"18\" rows=\"". $rows ."\" name=\"".$this->get_config_item_name()."\">";
1361         $ta .= $list_values . "</textarea>";
1362         return $ta;
1363     }
1364 }
1365
1366 class array_variable
1367 extends _variable {
1368     function _config_format($value) {
1369         return sprintf("\$%s = array(%s);", $this->get_config_item_name(), $value);
1370     }
1371     function _get_config_line($posted_value) {
1372         // split the phrase by any number of commas or space characters,
1373         // which include " ", \r, \t, \n and \f
1374         $list_values = preg_split("/[\s,]+/", $posted_value, -1, PREG_SPLIT_NO_EMPTY);
1375         if (!empty($list_values)) {
1376             $list_values = "'".join("', '", $list_values)."'";
1377             return "\n" . $this->_config_format($list_values);
1378         } else
1379             return "\n//" . $this->_config_format('');
1380     }
1381     function get_html() {
1382         $list_values = join("\n", $this->default_value);
1383         $rows = max(3, count($this->default_value) +1);
1384         $ta = $this->get_config_item_header();
1385         $ta .= "<textarea cols=\"18\" rows=\"". $rows ."\" name=\"".$this->get_config_item_name()."\">";
1386         $ta .= $list_values . "</textarea>";
1387         return $ta;
1388     }
1389
1390 }
1391
1392 class _ini_set
1393 extends _variable {
1394     function value() {
1395         global $HTTP_POST_VARS;
1396         if ($v = $HTTP_POST_VARS[$this->config_item_name])
1397             return $v;
1398         else {
1399             return ini_get($this->get_config_item_name);
1400         }
1401     }
1402     function _config_format($value) {
1403         return sprintf("ini_set('%s', '%s');", $this->get_config_item_name(), $value);
1404     }
1405     function _get_config_line($posted_value) {
1406         if ($posted_value && ! $posted_value == $this->default_value)
1407             return "\n" . $this->_config_format($posted_value);
1408         else
1409             return "\n//" . $this->_config_format($this->default_value);
1410     }
1411 }
1412
1413 class boolean_define
1414 extends _define {
1415     function _get_config_line($posted_value) {
1416         if ($this->description)
1417             $n = "\n";
1418         return "${n}" . $this->_config_format($posted_value);
1419     }
1420     function get_html() {
1421         $output = $this->get_config_item_header();
1422         $output .= '<select name="' . $this->get_config_item_name() . "\">\n";
1423         /* The first option is the default */
1424         list($option, $label) = each($this->default_value);
1425         $output .= "  <option value=\"$option\" selected>$label</option>\n";
1426         /* There can only be two options */
1427         list($option, $label) = each($this->default_value);
1428         $output .= "  <option value=\"$option\">$label</option>\n";
1429         $output .= "</select>\n  </td>\n";
1430         return $output;
1431     }
1432 }
1433
1434 class boolean_define_optional
1435 extends boolean_define {
1436     function _config_format($value) {
1437         $name = $this->get_config_item_name();
1438         return sprintf("if (!defined('%s')) define('%s', '%s');", $name, $name, $value);
1439     }
1440 }
1441
1442 class boolean_define_commented
1443 extends boolean_define {
1444     function _get_config_line($posted_value) {
1445         if ($this->description)
1446             $n = "\n";
1447         list($default_value, $label) = each($this->default_value);
1448         if ($posted_value == $default_value)
1449             return "${n}//" . $this->_config_format($posted_value);
1450         else if ($posted_value == '')
1451             return "${n}//" . $this->_config_format('false');
1452         else
1453             return "${n}" . $this->_config_format($posted_value);
1454     }
1455 }
1456
1457 class boolean_define_commented_optional
1458 extends boolean_define_commented {
1459     function _config_format($value) {
1460         $name = $this->get_config_item_name();
1461         return sprintf("if (!defined('%s')) define('%s', '%s');", $name, $name, $value);
1462     }
1463 }
1464
1465 class part
1466 extends _variable {
1467     function value () { return; }
1468     function get_config($posted_value) {
1469         $d = stripHtml($this->_get_description());
1470         global $SEPARATOR;
1471         return "\n".$SEPARATOR . str_replace("\n", "\n// ", $d) ."\n$this->default_value";
1472     }
1473     function get_instructions($title) {
1474         $group_name = preg_replace("/\W/","",$title);
1475         $i = "<tr>\n<td class=\"part\" width=\"100%\" colspan=\"2\" bgcolor=\"#eeaaaa\">\n";
1476         if ($group_name == 'PartZero') $i = "</dl>" . $i;
1477         $i .= "<p><b><h2>" . $title . "</h2></b></p>\n    " . nl2p($this->_get_description()) ."\n";
1478         $i .= "<input id=\"{$group_name}_input\" type=\"hidden\" name=\"$group_name\" value=\"0\" />";
1479         $i .= "<p><a href=\"javascript:toggle_group('$group_name')\" id=\"{$group_name}_text\">Show options.</a></p>";
1480         return  $i ."</td></tr>\n" . "<dl id=\"$group_name\" style=\"display: none\">";
1481     }
1482     function get_html() {
1483         return "";
1484     }
1485 }
1486
1487 // html utility functions
1488 function nl2p($text) {
1489     return "<p>" . str_replace("\n\n", "</p>\n<p>", $text) . "</p>";
1490 }
1491
1492 function stripHtml($text) {
1493         $d = str_replace("<pre>", "", $text);
1494         $d = str_replace("</pre>", "", $d);
1495         $d = str_replace("<dl>", "", $d);
1496         $d = str_replace("</dl>", "", $d);
1497         $d = str_replace("<dt>", "", $d);
1498         $d = str_replace("</dt>", "", $d);
1499         $d = str_replace("<dd>", "", $d);
1500         $d = str_replace("</dd>", "", $d);
1501         //restore html entities into characters
1502         // http://www.php.net/manual/en/function.htmlentities.php
1503         $trans = get_html_translation_table (HTML_ENTITIES);
1504         $trans = array_flip ($trans);
1505         $d = strtr($d, $trans);
1506         return $d;
1507 }
1508
1509 /**
1510  * Seed the random number generator.
1511  *
1512  * better_srand() ensures the randomizer is seeded only once.
1513  * 
1514  * How random do you want it? See:
1515  * http://www.php.net/manual/en/function.srand.php
1516  * http://www.php.net/manual/en/function.mt-srand.php
1517  */
1518 function better_srand($seed = '') {
1519     static $wascalled = FALSE;
1520     if (!$wascalled) {
1521         if ($seed === '') {
1522             list($usec,$sec)=explode(" ",microtime());
1523             if ($usec > 0.1) 
1524                 $seed = (double) $usec * $sec;
1525             else // once in a while use the combined LCG entropy
1526                 $seed = (double) 1000000 * substr(uniqid("",true),13);
1527         }
1528         if (function_exists('mt_srand')) {
1529             mt_srand($seed); // mersenne twister
1530         } else {
1531             srand($seed);    
1532         }
1533         $wascalled = TRUE;
1534     }
1535 }
1536
1537 function rand_ascii($length = 1) {
1538     better_srand();
1539     $s = "";
1540     for ($i = 1; $i <= $length; $i++) {
1541         // return only typeable 7 bit ascii, avoid quotes
1542         if (function_exists('mt_rand'))
1543             // the usually bad glibc srand()
1544             $s .= chr(mt_rand(40, 126)); 
1545         else
1546             $s .= chr(rand(40, 126));
1547     }
1548     return $s;
1549 }
1550
1551 ////
1552 // Function to create better user passwords (much larger keyspace),
1553 // suitable for user passwords.
1554 // Sequence of random ASCII numbers, letters and some special chars.
1555 // Note: There exist other algorithms for easy-to-remember passwords.
1556 function random_good_password ($minlength = 5, $maxlength = 8) {
1557   $newpass = '';
1558   // assume ASCII ordering (not valid on EBCDIC systems!)
1559   $valid_chars = "!#%&+-.0123456789=@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
1560   $start = ord($valid_chars);
1561   $end   = ord(substr($valid_chars,-1));
1562   better_srand();
1563   if (function_exists('mt_rand')) // mersenne twister
1564       $length = mt_rand($minlength, $maxlength);
1565   else  // the usually bad glibc rand()
1566       $length = rand($minlength, $maxlength);
1567   while ($length > 0) {
1568       if (function_exists('mt_rand'))
1569           $newchar = mt_rand($start, $end);
1570       else
1571           $newchar = rand($start, $end);
1572       if (! strrpos($valid_chars,$newchar) ) continue; // skip holes
1573       $newpass .= sprintf("%c",$newchar);
1574       $length--;
1575   }
1576   return($newpass);
1577 }
1578
1579 // debugging
1580 function printArray($a) {
1581     echo "<hr />\n<pre>\n";
1582     print_r($a);
1583     echo "\n</pre>\n<hr />\n";
1584 }
1585
1586 // end of class definitions
1587 /////////////////////////////
1588 // begin auto generation code
1589
1590 if ($HTTP_POST_VARS['action'] == 'make_config') {
1591
1592     $timestamp = date ('dS of F, Y H:i:s');
1593
1594     $config = "<?php
1595 /* This is a local configuration file for PhpWiki.
1596  * It was automatically generated by the configurator script
1597  * on the $timestamp.
1598  */
1599
1600 /*$copyright*/
1601
1602 /////////////////////////////////////////////////////////////////////
1603 /*$preamble*/
1604 ";
1605
1606     $posted = $GLOBALS['HTTP_POST_VARS'];
1607
1608     if (defined('DEBUG'))
1609         printArray($GLOBALS['HTTP_POST_VARS']);
1610
1611     foreach($properties as $option_name => $a) {
1612         $posted_value = $posted[$a->config_item_name];
1613         $config .= $properties[$option_name]->get_config($posted_value);
1614     }
1615
1616     if (defined('DEBUG')) {
1617         $diemsg = "The configurator.php is provided for testing purposes only.
1618 You can't use this file with your PhpWiki server yet!!";
1619         $config .= "\ndie(\"$diemsg\");\n";
1620     }
1621     $config .= $end;
1622
1623     /* We first check if the config-file exists. */
1624     if (file_exists($fs_config_file)) {
1625         /* We make a backup copy of the file */
1626         // $config_file = 'index-user.php';
1627         $new_filename = preg_replace('/\.php$/', time() . '.php', $fs_config_file);
1628         if (@copy($fs_config_file, $new_filename)) {
1629             $fp = @fopen($fs_config_file, 'w');
1630         }
1631     } else {
1632         $fp = @fopen($fs_config_file, 'w');
1633     }
1634
1635     if ($fp) {
1636         fputs($fp, $config);
1637         fclose($fp);
1638         echo "<p>The configuration was written to <code><b>$config_file</b></code>.</p>\n";
1639         if ($new_filename) {
1640             echo "<p>A backup was made to <code><b>$new_filename</b></code>.</p>\n";
1641         }
1642         echo "<p><strong>You must rename or copy this</strong> <code><b>$config_file</b></code> <strong>file to</strong> <code><b>index.php</b></code>.</p>\n";
1643     } else {
1644         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>index.php</b></code>.</p>\n";
1645     }
1646
1647     echo "<hr />\n<p>Here's the configuration file based on your answers:</p>\n<pre>\n";
1648     echo htmlentities($config);
1649     echo "</pre>\n<hr />\n";
1650
1651     echo "<p>To make any corrections, <a href=\"configurator.php\">edit the settings again</a>.</p>\n";
1652
1653 } else { // first time or create password
1654     $posted = $GLOBALS['HTTP_POST_VARS'];
1655     /* No action has been specified - we make a form. */
1656
1657     echo '
1658 <form action="configurator.php" method="POST">
1659 <table cellpadding="4" cellspacing="0">
1660   <input type="hidden" name="action" value="make_config">
1661 ';
1662
1663     while(list($property, $obj) = each($properties)) {
1664         echo $obj->get_instructions($property);
1665         if ($h = $obj->get_html()) {
1666             if (defined('DEBUG'))  $h = get_class($obj) . "<br />\n" . $h;
1667             echo "<td>".$h."</td>\n";
1668         }
1669         echo '</tr>';
1670     }
1671
1672     echo '
1673 </dl></table>
1674 <p><input type="submit" value="Save ',$config_file,'"> <input type="reset" value="Clear"></p>
1675 </form>
1676 ';
1677 }
1678 ?>
1679 </body>
1680 </html>