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