]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - configurator.php
ENABLE_MARKUP_TEMPLATE removed, it had to be true so that Wikicreole syntax for image...
[SourceForge/phpwiki.git] / configurator.php
1 <?php // -*-php-*- $Id$
2 /*
3  * Copyright 2002,2003,2005 $ThePhpWikiProgrammingTeam
4  * Copyright 2002 Martin Geisler <gimpster@gimpster.com> 
5  * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  * Parts of this file were based on PHPWeather's configurator.php file.
9  *   http://sourceforge.net/projects/phpweather/
10  *
11  * PhpWiki is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * PhpWiki is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with PhpWiki; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26 /**
27  * Starts automatically the first time by IniConfig("config/config.ini") 
28  * if it doesn't exist.
29  *
30  * DONE:
31  * o Initial expand ?show=_part1 (the part id)
32  * o read config-default.ini and use this as default_values
33  * o commented / optional: non-default values should not be commented!
34  *                         default values if optional can be omitted.
35  * o validate input (fix javascript, add POST checks)
36  * o start this automatically the first time
37  * o fix include_path
38  *
39  * 1.3.11 TODO: (or 1.3.12?)
40  * o parse_ini_file("config-dist.ini") for the commented vars
41  * o check automatically for commented and optional vars
42  * o fix _optional, to ignore existing config.ini and only use config-default.ini values
43  * o mixin class for commented 
44  * o fix SQL quotes, AUTH_ORDER quotes and file forward slashes
45  * o posted values validation, extend js validation for sane DB values
46  * o read config-dist.ini into sections, comments, and optional/required settings
47  *
48  * A file config/config.ini will be automatically generated, if writable.
49  *
50  * NOTE: If you have a starterscript outside PHPWIKI_DIR but no 
51  * config/config.ini yet (very unlikely!), you must define DATA_PATH in the 
52  * starterscript, otherwise the webpath to configurator is unknown, and 
53  * subsequent requests will fail. (POST to save the INI)
54  */
55
56 global $HTTP_SERVER_VARS, $HTTP_POST_VARS, $tdwidth;
57 if (empty($_SERVER))    $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
58 if (empty($_GET))       $_GET    =& $GLOBALS['HTTP_GET_VARS'];
59 if (empty($_ENV))       $_ENV    =& $GLOBALS['HTTP_ENV_VARS'];
60 if (empty($_POST))      $_POST   =& $GLOBALS['HTTP_POST_VARS'];
61
62 if (empty($configurator))
63     $configurator = "configurator.php";
64 if (!strstr($_SERVER["SCRIPT_NAME"], $configurator) and defined('DATA_PATH'))
65     $configurator = DATA_PATH . "/" . $configurator;
66 $scriptname = str_replace('configurator.php', 'index.php', $_SERVER["SCRIPT_NAME"]);
67 if (strstr($_SERVER["SCRIPT_NAME"],"/php")) {  // cgi got this different
68     if (defined('DATA_PATH'))
69         $scriptname = DATA_PATH . "/index.php";
70     else
71         $scriptname = str_replace('configurator.php', 'index.php', $_SERVER["PHP_SELF"]);
72 }
73
74 $tdwidth = 700;
75 $config_file = (substr(PHP_OS,0,3) == 'WIN') ? 'config\\config.ini' : 'config/config.ini';
76 $fs_config_file = dirname(__FILE__) . (substr(PHP_OS,0,3) == 'WIN' ? '\\' : '/') . $config_file;
77 if (isset($_POST['create']))  header('Location: '.$configurator.'?show=_part1&create=1#create');
78
79 // helpers from lib/WikiUser/HttpAuth.php
80 if (!function_exists('_http_user')) {
81     function _http_user() {
82         if (!isset($_SERVER))
83             $_SERVER = $GLOBALS['HTTP_SERVER_VARS'];
84         if (!empty($_SERVER['PHP_AUTH_USER']))
85             return array($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
86         if (!empty($_SERVER['REMOTE_USER']))
87             return array($_SERVER['REMOTE_USER'], $_SERVER['PHP_AUTH_PW']);
88         if (!empty($GLOBALS['HTTP_ENV_VARS']['REMOTE_USER']))
89             return array($GLOBALS['HTTP_ENV_VARS']['REMOTE_USER'], 
90                          $GLOBALS['HTTP_ENV_VARS']['PHP_AUTH_PW']);
91         if (!empty($GLOBALS['REMOTE_USER']))
92             return array($GLOBALS['REMOTE_USER'], $GLOBALS['PHP_AUTH_PW']);
93             
94         // MsWindows IIS:
95         if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
96             list($userid, $passwd) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
97             return array($userid, $passwd);
98         }
99         return array('','');
100     }
101     function _http_logout() {
102         if (!isset($_SERVER))
103             $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
104         // maybe we should random the realm to really force a logout. but the next login will fail.
105         // better_srand(); $realm = microtime().rand();
106         header('WWW-Authenticate: Basic realm="'.WIKI_NAME.'"');
107         if (strstr(php_sapi_name(), 'apache'))
108             header('HTTP/1.0 401 Unauthorized'); 
109         else    
110             header("Status: 401 Access Denied"); //IIS and CGI need that
111         unset($GLOBALS['REMOTE_USER']);
112         unset($_SERVER['PHP_AUTH_USER']);
113         unset($_SERVER['PHP_AUTH_PW']);
114
115         trigger_error("Permission denied. Require ADMIN_USER.", E_USER_ERROR);
116         exit();
117     }
118 }
119
120 // If config.ini exists, we require ADMIN_USER access by faking HttpAuth. 
121 // So nobody can see or reset the password(s).
122 if (file_exists($fs_config_file)) {
123     // Require admin user
124     if (!defined('ADMIN_USER') or !defined('ADMIN_PASSWD')) {
125         if (!function_exists("IniConfig")) {
126             include_once("lib/prepend.php");
127             include_once("lib/IniConfig.php");
128         }
129         IniConfig($fs_config_file);
130     }
131     if (!defined('ADMIN_USER') or ADMIN_USER == '') {
132         trigger_error("Configuration problem:\nADMIN_USER not defined in \"$fs_config_file\".\n"
133                       . "Cannot continue: You have to fix that manually.", E_USER_ERROR);
134         exit();
135     }
136
137     list($admin_user, $admin_pw) = _http_user();
138     //$required_user = ADMIN_USER;
139     if (empty($admin_user) or $admin_user != ADMIN_USER)
140     {
141         _http_logout();
142     }
143     // check password
144     if (ENCRYPTED_PASSWD and function_exists('crypt')) {
145         if (crypt($admin_pw, ADMIN_PASSWD) != ADMIN_PASSWD) 
146             _http_logout();
147     } elseif ($admin_pw != ADMIN_PASSWD) {
148         _http_logout();
149     }
150 } else {
151     if (!function_exists("IniConfig")) {
152         include_once("lib/prepend.php");
153         include_once("lib/IniConfig.php");
154     }
155     $def_file = (substr(PHP_OS,0,3) == 'WIN') ? 'config\\config-default.ini' : 'config/config-default.ini';
156     $fs_def_file = dirname(__FILE__) . (substr(PHP_OS,0,3) == 'WIN' ? '\\' : '/') . $def_file;
157     IniConfig($fs_def_file);
158 }
159
160 echo '<','?xml version="1.0" encoding="iso-8859-1"?',">\n";
161 ?>
162 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
163   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
164 <html xmlns="http://www.w3.org/1999/xhtml">
165 <head>
166 <!-- $Id$ -->
167 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
168 <title>Configuration tool for PhpWiki <?php echo $config_file ?></title>
169 <style type="text/css" media="screen">
170 <!--
171 /* TABLE { border: thin solid black } */
172 body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 80%; }
173 pre { font-size: 120%; }
174 td { border: thin solid black }
175 tr { border: none }
176 div.hint { border: thin solid red, background-color: #eeeeee; }
177 tr.hidden { border: none; display: none; }
178 td.part { background-color: #eeeeee; color: inherit; }
179 td.instructions { background-color: #ffffee; width: <?php echo $tdwidth ?>px; color: inherit; }
180 td.unchangeable-variable-top   { border-bottom: none; background-color: #ffffee; color:inherit; }
181 td.unchangeable-variable-left  { border-top: none; background-color: #ffffee; color:inherit; }
182 -->
183 </style>
184 <script language="JavaScript" type="text/javascript">
185 <!--
186 function update(accepted, error, value, output) {
187   var msg = document.getElementById(output);
188   if (accepted) {
189     /* MSIE 5.0 fails here */
190     if (msg && msg.innerHTML) { msg.innerHTML = "<font color=\"green\">Input accepted.</font>"; }
191   } else {
192     while ((index = error.indexOf("%s")) > -1) {
193       error = error.substring(0, index) + value + error.substring(index+2);
194     }
195     if (msg) { msg.innerHTML = "<font color=\"red\">" + error + "</font>"; }
196   }
197   if (submit = document.getElementById('submit')) submit.disabled = accepted ? false : true;
198 }
199
200 function validate(error, value, output, field) {
201   update(field.value == value, error, field.value, output);
202 }
203
204 function validate_ereg(error, ereg, output, field) {
205   regex = new RegExp(ereg);
206   update(regex.test(field.value), error, field.value, output);
207 }
208
209 function validate_range(error, low, high, empty_ok, output, field) {
210   update((empty_ok == 1 && field.value == "") ||
211          (field.value >= low && field.value <= high),
212          error, field.value, output);
213 }
214
215 function toggle_group(id) {
216   var text = document.getElementById(id + "_text");
217   var do_hide = false;
218   if (text.innerHTML == "Hide options.") {
219     do_hide = true;
220     text.innerHTML = "Show options.";
221   } else {
222     text.innerHTML = "Hide options.";
223   }
224
225   var rows = document.getElementsByTagName('tr');
226   var i = 0;
227   for (i = 0; i < rows.length; i++) {
228     var tr = rows[i];
229     if (tr.className == 'header' && tr.id == id) {
230       i++;
231       break;
232     }
233   }
234   for (; i < rows.length; i++) {
235     var tr = rows[i];
236     if (tr.className == 'header')
237       break;
238     tr.className = do_hide ? 'hidden': 'nonhidden';
239   }
240 }
241
242 function do_init() {
243   // Hide all groups.  We do this via JavaScript to avoid
244   // hiding the groups if JavaScript is not supported...
245   var rows = document.getElementsByTagName('tr');
246   var show = '<?php echo $_GET["show"] ?>';
247   for (var i = 0; i < rows.length; i++) {
248     var tr = rows[i];
249     if (tr.className == 'header')
250         if (!show || tr.id != show)
251             toggle_group(tr.id);
252   }
253
254   // Select text in textarea upon focus
255   var area = document.getElementById('config-output');
256   if (area) {
257     listener = { handleEvent: function (e) { area.select(); } };
258     area.addEventListener('focus', listener, false);
259   }
260 }
261   
262 -->
263 </script>
264 </head>
265 <body onload="do_init();">
266
267       <h1>Configuration for PhpWiki <?php echo $config_file ?></h1>
268
269 <div class="hint">
270     Using this configurator.php is experimental!<br />
271     On any configuration problems, please edit the resulting config.ini manually.
272 </div>
273
274 <?php
275 //define('DEBUG', 1);
276 /**
277  * The Configurator is a php script to aid in the configuration of PhpWiki.
278  * Parts of this file were based on PHPWeather's configurator.php file.
279  *   http://sourceforge.net/projects/phpweather/
280  *
281  * TO CHANGE THE CONFIGURATION OF YOUR PHPWIKI, DO *NOT* MODIFY THIS FILE!
282  * more instructions go here
283  *
284  * Todo: 
285  *   * fix include_path
286  *   * eval config.ini to get the actual settings.
287  */
288
289 //////////////////////////////
290 // begin configuration options
291
292 /**
293  * Notes for the description parameter of $property:
294  *
295  * - Descriptive text will be changed into comments (preceeded by ; )
296  *   for the final output to config.ini.
297  *
298  * - Only a limited set of html is allowed: pre, dl dt dd; it will be
299  *   stripped from the final output.
300  *
301  * - Line breaks and spacing will be preserved for the final output.
302  *
303  * - Double line breaks are automatically converted to paragraphs
304  *   for the html version of the descriptive text.
305  *
306  * - Double-quotes and dollar signs in the descriptive text must be
307  *   escaped: \" and \$. Instead of escaping double-quotes you can use 
308  *   single (') quotes for the enclosing quotes. 
309  *
310  * - Special characters like < and > must use html entities,
311  *   they will be converted back to characters for the final output.
312  */
313
314 $SEPARATOR = ";=========================================================================";
315
316 $preamble = "
317 ; This is the main configuration file for PhpWiki in INI-style format.
318 ; Note that certain characters are used as comment char and therefore 
319 ; these entries must be in double-quotes. Such as \":\", \";\", \",\" and \"|\"
320 ; Take special care for DBAUTH_ sql statements. (Part 3a)
321 ;
322 ; This file is divided into several parts: Each one has different configuration 
323 ; settings you can change; in all cases the default should work on your system,
324 ; however, we recommend you tailor things to your particular setting.
325 ; Here undefined definitions get defined by config-default.ini settings.
326 ";
327
328 // Detect not here listed configs:
329 // for x in `perl -ne 'print $1,"\n" if /^;(\w+) =/' config/config-dist.ini`; do \
330 //   grep \'$x\' configurator.php >/dev/null || echo $x ; done
331
332 $properties["Part Zero"] =
333 new part('_part0', $SEPARATOR."\n", "
334 Part Zero: (optional)
335 Latest Development and Tricky Options");
336
337 if (defined('INCLUDE_PATH'))
338     $include_path = INCLUDE_PATH;
339 else {
340   if (substr(PHP_OS,0,3) == 'WIN') {
341       $include_path = dirname(__FILE__) . ';' . ini_get('include_path');
342       if (strchr(ini_get('include_path'),'/'))
343           $include_path = strtr($include_path,'\\','/');
344   } else {
345     $include_path = dirname(__FILE__) . ':' . ini_get('include_path');
346   }
347 }
348
349 $properties["PHP include_path"] =
350 new _define('INCLUDE_PATH', $include_path);
351
352 // TODO: Convert this to a checkbox row as in tests/unit/test.php
353 $properties["DEBUG"] =
354 new numeric_define_optional('DEBUG', DEBUG);
355
356 $properties["ENABLE_EDIT_TOOLBAR"] =
357 new boolean_define_commented_optional('ENABLE_EDIT_TOOLBAR');
358
359 $properties["JS_SEARCHREPLACE"] =
360 new boolean_define_commented_optional('JS_SEARCHREPLACE');
361
362 // TESTME: use config-default:  = false
363 $properties["ENABLE_DOUBLECLICKEDIT"] =
364 new boolean_define_commented_optional('ENABLE_DOUBLECLICKEDIT');
365
366 $properties["ENABLE_WYSIWYG"] =
367 new boolean_define_commented_optional('ENABLE_WYSIWYG');
368
369 $properties["WYSIWYG_BACKEND"] =
370 new _define_selection(
371 'WYSIWYG_BACKEND', 
372 array('Wikiwyg'   => 'Wikiwyg',
373       'tinymce'   => 'tinymce',
374       'FCKeditor' => 'FCKeditor', 
375       'spaw'      => 'spaw', 
376       'htmlarea3' => 'htmlarea3', 
377       'htmlarea2' => 'htmlarea2',
378 ));
379
380 $properties["WYSIWYG_DEFAULT_PAGETYPE_HTML"] =
381 new boolean_define_commented_optional('WYSIWYG_DEFAULT_PAGETYPE_HTML');
382
383 $properties["UPLOAD_USERDIR"] =
384 new boolean_define_commented_optional('UPLOAD_USERDIR');
385
386 $properties["DISABLE_UNITS"] =
387 new boolean_define_commented_optional('DISABLE_UNITS');
388
389 $properties["UNITS_EXE"] =
390 new _define_commented_optional('UNITS_EXE');
391
392 $properties["ENABLE_XHTML_XML"] =
393 new boolean_define_commented_optional('ENABLE_XHTML_XML');
394
395 $properties["ENABLE_SPAMASSASSIN"] =
396 new boolean_define_commented_optional('ENABLE_SPAMASSASSIN');
397
398 $properties["ENABLE_SPAMBLOCKLIST"] =
399 new boolean_define_optional('ENABLE_SPAMBLOCKLIST');
400
401 $properties["NUM_SPAM_LINKS"] =
402 new numeric_define_optional('NUM_SPAM_LINKS');
403
404 $properties["GOOGLE_LINKS_NOFOLLOW"] =
405 new boolean_define_commented_optional('GOOGLE_LINKS_NOFOLLOW');
406
407 $properties["ENABLE_LIVESEARCH"] =
408 new boolean_define_commented_optional('ENABLE_LIVESEARCH');
409
410 $properties["ENABLE_ACDROPDOWN"] =
411 new boolean_define_commented_optional('ENABLE_ACDROPDOWN');
412
413 $properties["ENABLE_DISCUSSION_LINK"] =
414 new boolean_define_commented_optional('ENABLE_DISCUSSION_LINK');
415
416 $properties["ENABLE_CAPTCHA"] =
417 new boolean_define_commented_optional('ENABLE_CAPTCHA');
418
419 $properties["USE_CAPTCHA_RANDOM_WORD"] =
420 new boolean_define_commented_optional('USE_CAPTCHA_RANDOM_WORD');
421
422 $properties["USE_SAFE_DBSESSION"] =
423 new boolean_define_commented_optional('USE_SAFE_DBSESSION');
424
425 $properties["BLOG_DEFAULT_EMPTY_PREFIX"] =
426 new boolean_define_commented_optional('BLOG_DEFAULT_EMPTY_PREFIX');
427
428 $properties["ENABLE_SEARCHHIGHLIGHT"] =
429 new boolean_define_commented_optional('ENABLE_SEARCHHIGHLIGHT');
430
431 $properties["Part One"] =
432 new part('_part1', $SEPARATOR."\n", "
433 Part One: Authentication and security settings. See Part Three for more.");
434
435 $properties["Wiki Name"] =
436 new _define_optional('WIKI_NAME', WIKI_NAME);
437
438 $properties["Admin Username"] =
439 new _define_notempty('ADMIN_USER', ADMIN_USER, "
440 You must set this! Username and password of the administrator.",
441 "onchange=\"validate_ereg('Sorry, ADMIN_USER cannot be empty.', '^.+$', 'ADMIN_USER', this);\"");
442
443 $properties["Admin Password"] =
444 new _define_password('ADMIN_PASSWD', ADMIN_PASSWD, "
445 You must set this! 
446 For heaven's sake pick a good password.
447
448 If your version of PHP supports encrypted passwords, your password will be
449 automatically encrypted within the generated config file. 
450 Use the \"Create Random Password\" button to create a good (random) password.
451
452 ADMIN_PASSWD is ignored on HttpAuth",
453 "onchange=\"validate_ereg('Sorry, ADMIN_PASSWD must be at least 4 chars long.', '^....+$', 'ADMIN_PASSWD', this);\"");
454
455 $properties["Encrypted Passwords"] =
456 new boolean_define
457 ('ENCRYPTED_PASSWD',
458  array('true'  => "true.  use crypt for all passwords",
459        'false' => "false. use plaintest passwords (not recommended)"));
460
461 $properties["Reverse DNS"] =
462 new boolean_define_optional
463 ('ENABLE_REVERSE_DNS',
464  array('true'  => "true. perform additional reverse dns lookups",
465        'false' => "false. just record the address as given by the httpd server"));
466
467 $properties["ZIP Dump Authentication"] =
468 new boolean_define_optional('ZIPDUMP_AUTH', 
469                     array('false' => "false. Everyone may download zip dumps",
470                           'true'  => "true. Only admin may download zip dumps"));
471
472 $properties["Enable RawHtml Plugin"] =
473 new boolean_define_commented_optional('ENABLE_RAW_HTML');
474
475 $properties["Allow RawHtml Plugin only on locked pages"] =
476 new boolean_define_commented_optional('ENABLE_RAW_HTML_LOCKEDONLY');
477
478 $properties["Allow RawHtml Plugin if safe HTML code"] =
479     new boolean_define_commented_optional('ENABLE_RAW_HTML_SAFE','', "
480 If this is set, all unsafe html code is stripped automatically (experimental!)
481 See <a href=\"http://chxo.com/scripts/safe_html-test.php\" target=\"_new\">chxo.com/scripts/safe_html-test.php</a>
482 ");
483
484 $properties["Maximum Upload Size"] =
485 new numeric_define_optional('MAX_UPLOAD_SIZE', MAX_UPLOAD_SIZE);
486
487 $properties["Minor Edit Timeout"] =
488 new numeric_define_optional('MINOR_EDIT_TIMEOUT', MINOR_EDIT_TIMEOUT);
489
490 $properties["Disabled Actions"] =
491 new array_define('DISABLED_ACTIONS', DISABLED_ACTIONS /*array()*/);
492
493 $properties["Moderate all Pagechanges"] =
494 new boolean_define_commented_optional('ENABLE_MODERATEDPAGE_ALL');
495
496 $properties["Access Log File"] =
497 new _define_commented_optional('ACCESS_LOG', ACCESS_LOG);
498
499 $properties["Access Log SQL"] =
500 new _define_selection(
501 'ACCESS_LOG_SQL', 
502 array('0' => 'disabled',
503       '1' => 'read only',
504       '2' => 'read + write'));
505
506 $properties["Compress Output"] =
507 new boolean_define_commented_optional
508 ( 'COMPRESS_OUTPUT', 
509   array(''      => 'undefined - GZIP compress when appropriate.',
510         'false' => 'Never compress output.',
511         'true'  => 'Always try to compress output.'));
512
513 $properties["HTTP Cache Control"] =
514 new _define_selection_optional
515 ('CACHE_CONTROL',
516  array('LOOSE' => 'LOOSE',
517        'STRICT' => 'STRICT',
518        'NO_CACHE' => 'NO_CACHE',
519        'ALLOW_STALE' => 'ALLOW_STALE'),
520 "
521 HTTP CACHE_CONTROL
522
523 This controls how PhpWiki sets the HTTP cache control
524 headers (Expires: and Cache-Control:) 
525
526 Choose one of:
527 <dl>
528 <dt>NO_CACHE</dt>
529 <dd>This is roughly the old (pre 1.3.4) behaviour.  PhpWiki will
530     instruct proxies and browsers never to cache PhpWiki output.</dd>
531 <dt>STRICT</dt>
532 <dd>Cached pages will be invalidated whenever the database global
533     timestamp changes.  This should behave just like NONE (modulo
534     bugs in PhpWiki and your proxies and browsers), except that
535     things will be slightly more efficient.</dd>
536 <dt>LOOSE</dt>
537 <dd>Cached pages will be invalidated whenever they are edited,
538     or, if the pages include plugins, when the plugin output could
539     concievably have changed.
540     <p>Behavior should be much like STRICT, except that sometimes
541        wikilinks will show up as undefined (with the question mark)
542        when in fact they refer to (recently) created pages.
543        (Hitting your browsers reload or perhaps shift-reload button
544        should fix the problem.)</p></dd>
545 <dt>ALLOW_STALE</dt>
546 <dd>Proxies and browsers will be allowed to used stale pages.
547     (The timeout for stale pages is controlled by CACHE_CONTROL_MAX_AGE.)
548     <p>This setting will result in quirky behavior.  When you edit a
549        page your changes may not show up until you shift-reload the
550        page, etc...</p>
551     <p>This setting is generally not advisable, however it may be useful
552        in certain cases (e.g. if your wiki gets lots of page views,
553        and few edits by knowledgable people who won't freak over the quirks.)</p>
554 </dd>
555 </dl>
556 The default is currently LOOSE.");
557
558 $properties["HTTP Cache Control Max Age"] =
559 new numeric_define_optional('CACHE_CONTROL_MAX_AGE', CACHE_CONTROL_MAX_AGE);
560
561 $properties["Markup Caching"] =
562 new boolean_define_commented_optional
563 ('WIKIDB_NOCACHE_MARKUP',
564  array('false' => 'Enable markup cache',
565        'true'  => 'Disable markup cache'));
566
567 $properties["COOKIE_EXPIRATION_DAYS"] =
568 new numeric_define_optional('COOKIE_EXPIRATION_DAYS', COOKIE_EXPIRATION_DAYS);
569
570 $properties["COOKIE_DOMAIN"] =
571 new _define_commented_optional('COOKIE_DOMAIN', COOKIE_DOMAIN);
572
573 $properties["Path for PHP Session Support"] =
574 new _define_optional('SESSION_SAVE_PATH', defined('SESSION_SAVE_PATH') ? SESSION_SAVE_PATH : ini_get('session.save_path'));
575
576 $properties["Force PHP Database Sessions"] =
577 new boolean_define_commented_optional
578 ('USE_DB_SESSION', 
579  array('false' => 'Disable database sessions, use files',
580        'true'  => 'Enable database sessions'));
581
582 ///////// database selection
583
584 $properties["Part Two"] =
585 new part('_part2', $SEPARATOR."\n", "
586
587 Part Two:
588 Database Configuration
589 ");
590
591 $properties["Database Type"] =
592 new _define_selection("DATABASE_TYPE",
593               array('dba'   => "dba",
594                     'SQL'   => "SQL PEAR",
595                     'ADODB' => "SQL ADODB",
596                     'PDO'   => "PDO (php5 only)",
597                     'file'   => "flatfile",
598                     'cvs'   => "CVS File handler")/*, "
599 Select the database backend type:
600 Choose dba (default) to use one of the standard UNIX dba libraries. This is the fastest.
601 Choose ADODB or SQL to use an SQL database with ADODB or PEAR.
602 Choose PDO on php5 to use an SQL database. (experimental, no paging yet)
603 flatfile is simple and slow.
604 CVS is highly experimental and slow.
605 Recommended is dba or SQL: PEAR or ADODB."*/);
606
607 $properties["SQL DSN Setup"] =
608 new unchangeable_variable('_sqldsnstuff', "", "
609 For SQL based backends, specify the database as a DSN
610 The most general form of a DSN looks like:
611 <pre>
612   phptype(dbsyntax)://username:password@protocol+hostspec/database?option=value
613 </pre>
614 For a MySQL database, the following should work:
615 <pre>
616    mysql://user:password@host/databasename
617 </pre>
618 To connect over a unix socket, use something like
619 <pre>
620    mysql://user:password@unix(/path/to/socket)/databasename
621 </pre>
622 <pre>
623   DATABASE_DSN = mysql://guest@:/var/lib/mysql/mysql.sock/phpwiki
624   DATABASE_DSN = mysql://guest@localhost/phpwiki
625   DATABASE_DSN = pgsql://localhost/user_phpwiki
626 </pre>");
627
628 // Choose ADODB or SQL to use an SQL database with ADODB or PEAR.
629 // Choose dba to use one of the standard UNIX dbm libraries.
630
631 $properties["SQL Type"] =
632 new _variable_selection('_dsn_sqltype',
633               array('mysql'  => "MySQL",
634                     'pgsql'  => "PostgreSQL",
635                     'mssql'  => "Microsoft SQL Server",
636                     'oci8'   => "Oracle 8",
637                     'mysqli' => "mysqli (only ADODB)",
638                     'mysqlt' => "mysqlt (only ADODB)",
639                     'ODBC'   => "ODBC (only ADODB or PDO)",
640                     'firebird' => "Firebird (only PDO)",
641                     'oracle'  => "Oracle (only PDO)",
642 ), "
643 SQL DB types. The DSN hosttype.");
644
645 $properties["SQL User"] =
646 new _variable('_dsn_sqluser', "wikiuser", "
647 SQL User Id:");
648
649 $properties["SQL Password"] =
650 new _variable('_dsn_sqlpass', "", "
651 SQL Password:");
652
653 $properties["SQL Database Host"] =
654 new _variable('_dsn_sqlhostorsock', "localhost", "
655 SQL Database Hostname:
656
657 To connect over a local named socket, use something like
658 <pre>
659   unix(/var/lib/mysql/mysql.sock)
660 </pre>
661 here. 
662 mysql on Windows via named pipes might need 127.0.0.1");
663
664 $properties["SQL Database Name"] =
665 new _variable('_dsn_sqldbname', "phpwiki", "
666 SQL Database Name:");
667
668 $dsn_sqltype = $properties["SQL Type"]->value();
669 $dsn_sqluser = $properties["SQL User"]->value();
670 $dsn_sqlpass = $properties["SQL Password"]->value();
671 $dsn_sqlhostorsock = $properties["SQL Database Host"]->value();
672 $dsn_sqldbname = $properties["SQL Database Name"]->value();
673 $dsn_sqlstring = $dsn_sqltype."://{$dsn_sqluser}:{$dsn_sqlpass}@{$dsn_sqlhostorsock}/{$dsn_sqldbname}";
674
675 $properties["SQL dsn"] =
676 new unchangeable_define("DATABASE_DSN", 
677                         $dsn_sqlstring, "
678 Calculated from the settings above:");
679
680 $properties["Filename / Table name Prefix"] =
681 new _define_commented('DATABASE_PREFIX', DATABASE_PREFIX, "
682 Used by all DB types:
683
684 Prefix for filenames or table names, e.g. \"phpwiki_\"
685
686 Currently <b>you MUST EDIT THE SQL file too!</b> (in the schemas/
687 directory because we aren't doing on the fly sql generation
688 during the installation.
689
690 Note: This prefix is NOT prepended to the default DBAUTH_
691       tables user, pref and member!
692 ");
693
694 $properties["DATABASE_PERSISTENT"] =
695 new boolean_define_commented_optional
696 ('DATABASE_PERSISTENT', 
697  array('false' => "Disabled",
698        'true'  => "Enabled"));
699
700 $properties["DB Session table"] =
701 new _define_optional("DATABASE_SESSION_TABLE", DATABASE_SESSION_TABLE, "
702 Tablename to store session information. Only supported by SQL backends.
703
704 A word of warning - any prefix defined above will be prepended to whatever is given here.
705 ");
706
707 //TODO: $TEMP
708 $temp = !empty($_ENV['TEMP']) ? $_ENV['TEMP'] : "/tmp";
709 $properties["dba directory"] =
710 new _define("DATABASE_DIRECTORY", $temp);
711
712 // TODO: list the available methods
713 $properties["dba handler"] =
714 new _define_selection('DATABASE_DBA_HANDLER',
715               array('gdbm' => "gdbm - GNU database manager (not recommended anymore)",
716                     'dbm'  => "DBM - Redhat default. On sf.net there's dbm and not gdbm anymore",
717                     'db2'  => "DB2 - BerkeleyDB (Sleepycat) DB2",
718                     'db3'  => "DB3 - BerkeleyDB (Sleepycat) DB3. Default on Windows but not on every Linux",
719                     'db4'  => "DB4 - BerkeleyDB (Sleepycat) DB4."), "
720 Use 'gdbm', 'dbm', 'db2', 'db3' or 'db4' depending on your DBA handler methods supported: <br />  "
721                       . (function_exists("dba_handlers") ? join(", ",dba_handlers()) : "")
722                       . "\n\nBetter not use other hacks such as inifile, flatfile or cdb");
723
724 $properties["dba timeout"] =
725 new numeric_define("DATABASE_TIMEOUT", DATABASE_TIMEOUT, "
726 Recommended values are 10-20 seconds. The more load the server has, the higher the timeout.");
727
728 $properties["DATABASE_OPTIMISE_FREQUENCY"] =
729 new numeric_define_optional('DATABASE_OPTIMISE_FREQUENCY', DATABASE_OPTIMISE_FREQUENCY);
730
731 $properties["DBADMIN_USER"] =
732 new _define_optional('DBADMIN_USER', DBADMIN_USER);
733
734 $properties["DBADMIN_PASSWD"] =
735 new _define_password_optional('DBADMIN_PASSWD', DBADMIN_PASSWD);
736
737 $properties["USECACHE"] =
738 new boolean_define_commented_optional('USECACHE');
739
740 ///////////////////
741
742 $properties["Page Revisions"] =
743 new unchangeable_variable('_parttworevisions', "", "
744
745 Section 2a: Archive Cleanup
746 The next section controls how many old revisions of each page are kept in the database.
747
748 There are two basic classes of revisions: major and minor. Which
749 class a revision belongs in is determined by whether the author
750 checked the \"this is a minor revision\" checkbox when they saved the
751 page.
752  
753 There is, additionally, a third class of revisions: author
754 revisions. The most recent non-mergable revision from each distinct
755 author is and author revision.
756
757 The expiry parameters for each of those three classes of revisions
758 can be adjusted seperately. For each class there are five
759 parameters (usually, only two or three of the five are actually
760 set) which control how long those revisions are kept in the
761 database.
762 <dl>
763    <dt>max_keep:</dt> <dd>If set, this specifies an absolute maximum for the
764             number of archived revisions of that class. This is
765             meant to be used as a safety cap when a non-zero
766             min_age is specified. It should be set relatively high,
767             and it's purpose is to prevent malicious or accidental
768             database overflow due to someone causing an
769             unreasonable number of edits in a short period of time.</dd>
770
771   <dt>min_age:</dt>  <dd>Revisions younger than this (based upon the supplanted
772             date) will be kept unless max_keep is exceeded. The age
773             should be specified in days. It should be a
774             non-negative, real number,</dd>
775
776   <dt>min_keep:</dt> <dd>At least this many revisions will be kept.</dd>
777
778   <dt>keep:</dt>     <dd>No more than this many revisions will be kept.</dd>
779
780   <dt>max_age:</dt>  <dd>No revision older than this age will be kept.</dd>
781 </dl>
782 Supplanted date: Revisions are timestamped at the instant that they
783 cease being the current revision. Revision age is computed using
784 this timestamp, not the edit time of the page.
785
786 Merging: When a minor revision is deleted, if the preceding
787 revision is by the same author, the minor revision is merged with
788 the preceding revision before it is deleted. Essentially: this
789 replaces the content (and supplanted timestamp) of the previous
790 revision with the content after the merged minor edit, the rest of
791 the page metadata for the preceding version (summary, mtime, ...)
792 is not changed.
793 ");
794
795 // For now the expiration parameters are statically inserted as
796 // an unchangeable property. You'll have to edit the resulting
797 // config file if you really want to change these from the default.
798
799 $properties["Major Edits: keep minimum days"] =
800     new numeric_define('MAJOR_MIN_KEEP', MAJOR_MIN_KEEP, "
801 Default: Keep for unlimited time. 
802 Set to 0 to enable archive cleanup");
803 $properties["Minor Edits: keep minumum days"] =
804     new numeric_define('MINOR_MIN_KEEP', MINOR_MIN_KEEP, "
805 Default: Keep for unlimited time. 
806 Set to 0 to enable archive cleanup");
807
808 $properties["Major Edits: how many"] =
809     new numeric_define('MAJOR_KEEP', MAJOR_KEEP, "
810 Keep up to 8 major edits");
811 $properties["Major Edits: how many days"] =
812     new numeric_define('MAJOR_MAX_AGE', MAJOR_MAX_AGE, "
813 keep them no longer than a month");
814
815 $properties["Minor Edits: how many"] =
816     new numeric_define("MINOR_KEEP", MINOR_KEEP, "
817 Keep up to 4 minor edits");
818 $properties["Minor Edits: how many days"] =
819     new numeric_define("MINOR_MAX_AGE", "7", "
820 keep them no longer than a week");
821
822 $properties["per Author: how many"] =
823     new numeric_define("AUTHOR_KEEP", "8", "
824 Keep the latest contributions of the last 8 authors,");
825 $properties["per Author: how many days"] =
826     new numeric_define("AUTHOR_MAX_AGE", "365", "
827 up to a year.");
828 $properties["per Author: keep minumum days"] =
829     new numeric_define("AUTHOR_MIN_AGE", "7", "
830 Additionally, (in the case of a particularly active page) try to
831 keep the latest contributions of all authors in the last week (even if there are more than eight of them,)");
832 $properties["per Author: max revisions"] =
833     new numeric_define("AUTHOR_MAX_KEEP", "20", "
834 but in no case keep more than twenty unique author revisions.");
835
836 /////////////////////////////////////////////////////////////////////
837
838 $properties["Part Three"] =
839 new part('_part3', $SEPARATOR."\n", "
840
841 Part Three: (optional)
842 Basic User Authentication Setup
843 ");
844
845 $properties["Publicly viewable"] =
846 new boolean_define_optional('ALLOW_ANON_USER',
847                     array('true'  => "true. Permit anonymous view. (Default)",
848                           'false' => "false. Force login even on view (strictly private)"), "
849 If ALLOW_ANON_USER is false, you have to login before viewing any page or doing any other action on a page.");
850
851 $properties["Allow anonymous edit"] =
852 new boolean_define_optional('ALLOW_ANON_EDIT',
853                     array('true'  => "true. Permit anonymous users to edit. (Default)",
854                           'false' => "false. Force login on edit (moderately locked)"), "
855 If ALLOW_ANON_EDIT is false, you have to login before editing or changing any page. See below.");
856
857 $properties["Allow Bogo Login"] =
858 new boolean_define_optional('ALLOW_BOGO_LOGIN',
859                     array('true'  => "true. Users may Sign In with any WikiWord, without password. (Default)",
860                           'false' => "false. Require stricter authentication."), "
861 If ALLOW_BOGO_LOGIN is false, you may not login with any wikiword username and empty password. 
862 If true, users are allowed to create themselves with any WikiWord username. See below.");
863
864 $properties["Allow User Passwords"] =
865 new boolean_define_optional('ALLOW_USER_PASSWORDS',
866                     array('true'  => "True user authentication with password checking. (Default)",
867                           'false' => "false. Ignore authentication settings below."), "
868 If ALLOW_USER_PASSWORDS is true, the authentication settings below define where and how to 
869 check against given username/passwords. For completely security disable BOGO_LOGIN and ANON_EDIT above.");
870
871 $properties["User Authentication Methods"] =
872     new array_define('USER_AUTH_ORDER', array("PersonalPage", "Db"), "
873 Many different methods can be used to check user's passwords. 
874 Try any of these in the given order:
875 <dl>
876 <dt>BogoLogin</dt>
877         <dd>WikiWord username, with no *actual* password checking,
878         although the user will still have to enter one.</dd>
879 <dt>PersonalPage</dt>
880         <dd>Store passwords in the users homepage metadata (simple)</dd>
881 <dt>Db</dt>
882         <dd>Use DBAUTH_AUTH_* (see below) with PearDB or ADODB only.</dd>
883 <dt>LDAP</dt>
884         <dd>Authenticate against LDAP_AUTH_HOST with LDAP_BASE_DN.</dd>
885 <dt>IMAP</dt>
886         <dd>Authenticate against IMAP_AUTH_HOST (email account)</dd>
887 <dt>POP3</dt>
888         <dd>Authenticate against POP3_AUTH_HOST (email account)</dd>
889 <dt>Session</dt>
890         <dd>Get username and level from a PHP session variable. (e.g. for gforge)</dd>
891 <dt>File</dt>
892         <dd>Store username:crypted-passwords in .htaccess like files. 
893          Use Apache's htpasswd to manage this file.</dd>
894 <dt>HttpAuth</dt>
895         <dd>Use the protection by the webserver (.htaccess/.htpasswd) (experimental)
896         Enforcing HTTP Auth not yet. Note that the ADMIN_USER should exist also.
897         Using HttpAuth disables all other methods and no userauth sessions are used.</dd>
898 </dl>
899
900 Several of these methods can be used together, in the manner specified by
901 USER_AUTH_POLICY, below.  To specify multiple authentication methods,
902 separate the name of each one with colons.
903 <pre>
904   USER_AUTH_ORDER = 'PersonalPage : Db'
905   USER_AUTH_ORDER = 'BogoLogin : PersonalPage'
906 </pre>");
907
908 $properties["PASSWORD_LENGTH_MINIMUM"] =
909 new numeric_define('PASSWORD_LENGTH_MINIMUM', PASSWORD_LENGTH_MINIMUM);
910
911 $properties["USER_AUTH_POLICY"] =
912 new _define_selection('USER_AUTH_POLICY',
913               array('first-only' => "first-only - use only the first method in USER_AUTH_ORDER",
914                     'old'       => "old - ignore USER_AUTH_ORDER (legacy)",
915                     'strict'    => "strict - check all methods for userid + password (recommended)",
916                     'stacked'   => "stacked - check all methods for userid, and if found for password"), "
917 The following policies are available for user authentication:
918 <dl>
919 <dt>first-only</dt>
920         <dd>use only the first method in USER_AUTH_ORDER</dd>
921 <dt>old</dt>
922         <dd>ignore USER_AUTH_ORDER and try to use all available 
923         methods as in the previous PhpWiki releases (slow)</dd>
924 <dt>strict</dt>
925         <dd>check if the user exists for all methods: 
926         on the first existing user, try the password. 
927         dont try the other methods on failure then</dd>
928 <dt>stacked</dt>
929         <dd>check the given user - password combination for all
930         methods and return true on the first success.</dd></dl>");
931
932 $properties["ENABLE_USER_NEW"] =
933 new boolean_define_commented_optional('ENABLE_USER_NEW');
934
935 $properties["ENABLE_PAGEPERM"] =
936 new boolean_define_commented_optional('ENABLE_PAGEPERM');
937
938 ///////////////////
939
940 $properties["Part Three A"] =
941 new part('_part3a', $SEPARATOR."\n", "
942
943 Part Three A: (optional)
944 Group Membership");
945
946 $properties["Group membership"] =
947 new _define_selection("GROUP_METHOD",
948               array('WIKIPAGE' => "WIKIPAGE - List at \"CategoryGroup\". (Slowest, but easiest to maintain)",
949                     '"NONE"'   => "NONE - Disable group membership (Fastest)",
950                     'DB'       => "DB - SQL Database, Optionally external. See USERS/GROUPS queries",
951                     'FILE'     => "Flatfile. See AUTH_GROUP_FILE below.",
952                     'LDAP'     => "LDAP - See \"LDAP authentication options\" above. (Experimental)"), "
953 Group membership.  PhpWiki supports defining permissions for a group as
954 well as for individual users.  This defines how group membership information
955 is obtained.  Supported values are:
956 <dl>
957 <dt>\"NONE\"</dt>
958           <dd>Disable group membership (Fastest). Note the required quoting.</dd>
959 <dt>WIKIPAGE</dt>
960           <dd>Define groups as list at \"CategoryGroup\". (Slowest, but easiest to maintain)</dd>
961 <dt>DB</dt>
962           <dd>Stored in an SQL database. Optionally external. See USERS/GROUPS queries</dd>
963 <dt>FILE</dt>
964           <dd>Flatfile. See AUTH_GROUP_FILE below.</dd>
965 <dt>LDAP</dt>
966           <dd>LDAP groups. See \"LDAP authentication options\" above and 
967           lib/WikiGroup.php. (experimental)</dd></dl>");
968
969 $properties["CATEGORY_GROUP_PAGE"] =
970   new _define_optional('CATEGORY_GROUP_PAGE', _("CategoryGroup"), "
971 If GROUP_METHOD = WIKIPAGE:
972
973 Page where all groups are listed.");
974
975 $properties["AUTH_GROUP_FILE"] =
976   new _define_optional('AUTH_GROUP_FILE', _("/etc/groups"), "
977 For GROUP_METHOD = FILE, the file given below is referenced to obtain
978 group membership information.  It should be in the same format as the
979 standard unix /etc/groups(5) file.");
980
981 $properties["Part Three B"] =
982 new part('_part3b', $SEPARATOR."\n", "
983
984 Part Three B: (optional)
985 External database authentication and authorization.
986
987 If USER_AUTH_ORDER includes Db, or GROUP_METHOD = DB, the options listed
988 below define the SQL queries used to obtain the information out of the
989 database, and (optionally) store the information back to the DB.");
990
991 $properties["DBAUTH_AUTH_DSN"] =
992   new _define_optional('DBAUTH_AUTH_DSN', $dsn_sqlstring, "
993 A database DSN to connect to.  Defaults to the DSN specified for the Wiki as a whole.");
994
995 $properties["User Exists Query"] =
996   new _define('DBAUTH_AUTH_USER_EXISTS', "SELECT userid FROM user WHERE userid='\$userid'", "
997 USER/PASSWORD queries:
998
999 For USER_AUTH_POLICY=strict and the Db method is required");
1000
1001 $properties["Check Query"] =
1002   new _define_optional('DBAUTH_AUTH_CHECK', "SELECT IF(passwd='\$password',1,0) AS ok FROM user WHERE userid='\$userid'", "
1003
1004 Check to see if the supplied username/password pair is OK
1005
1006 Plaintext passwords: (DBAUTH_AUTH_CRYPT_METHOD = plain)<br />
1007 ; DBAUTH_AUTH_CHECK = \"SELECT IF(passwd='\$password',1,0) AS ok FROM user WHERE userid='\$userid'\"
1008
1009 database-hashed passwords (more secure):<br />
1010 ; DBAUTH_AUTH_CHECK = \"SELECT IF(passwd=PASSWORD('\$password'),1,0) AS ok FROM user WHERE userid='\$userid'\"");
1011
1012 $properties["Crypt Method"] =
1013 new _define_selection_optional
1014 ('DBAUTH_AUTH_CRYPT_METHOD',
1015  array('plain' => 'plain',
1016        'crypt' => 'crypt'), "
1017 If you want to use Unix crypt()ed passwords, you can use DBAUTH_AUTH_CHECK
1018 to get the password out of the database with a simple SELECT query, and
1019 specify DBAUTH_AUTH_USER_EXISTS and DBAUTH_AUTH_CRYPT_METHOD:
1020
1021 ; DBAUTH_AUTH_CHECK = \"SELECT passwd FROM user where userid='\$userid'\" <br />
1022 ; DBAUTH_AUTH_CRYPT_METHOD = crypt");
1023
1024 $properties["Update the user's authentication credential"] =
1025     new _define('DBAUTH_AUTH_UPDATE', "UPDATE user SET passwd='\$password' WHERE userid='\$userid'", "
1026 If this is not defined but DBAUTH_AUTH_CHECK is, then the user will be unable to update their
1027 password.
1028
1029 Plaintext passwords:<br />
1030   DBAUTH_AUTH_UPDATE = \"UPDATE user SET passwd='\$password' WHERE userid='\$userid'\"<br />
1031 Database-hashed passwords:<br />
1032   DBAUTH_AUTH_UPDATE = \"UPDATE user SET passwd=PASSWORD('\$password') WHERE userid='\$userid'\"");
1033
1034 $properties["Allow the user to create their own account"] =
1035     new _define_optional('DBAUTH_AUTH_CREATE', "INSERT INTO user SET passwd=PASSWORD('\$password'),userid='\$userid'", "
1036 If this is empty, Db users cannot subscribe by their own.");
1037
1038 $properties["USER/PREFERENCE queries"] =
1039     new _define_optional('DBAUTH_PREF_SELECT', "SELECT prefs FROM user WHERE userid='\$userid'", "
1040 If you choose to store your preferences in an external database, enable
1041 the following queries.  Note that if you choose to store user preferences
1042 in the 'user' table, only registered users get their prefs from the database,
1043 self-created users do not.  Better to use the special 'pref' table.
1044
1045 The prefs field stores the serialized form of the user's preferences array,
1046 to ease the complication of storage.
1047 <pre>
1048   DBAUTH_PREF_SELECT = \"SELECT prefs FROM user WHERE userid='\$userid'\"
1049   DBAUTH_PREF_SELECT = \"SELECT prefs FROM pref WHERE userid='\$userid'\"
1050 </pre>");
1051
1052 $properties["Update the user's preferences"] =
1053     new _define_optional('DBAUTH_PREF_UPDATE', "UPDATE user SET prefs='\$pref_blob' WHERE userid='\$userid'", "
1054 Note that REPLACE works only with mysql and destroy all other columns!
1055
1056 Mysql: DBAUTH_PREF_UPDATE = \"REPLACE INTO pref SET prefs='\$pref_blob',userid='\$userid'\"");
1057
1058 $properties["Create new user's preferences"] =
1059     new _define_optional('DBAUTH_PREF_INSERT', "INSERT INTO pref (userid,prefs) VALUES ('\$userid','\$pref_blob')", "
1060 Define this if new user can be create by themselves.
1061 ");
1062
1063 $properties["USERS/GROUPS queries"] =
1064     new _define_optional('DBAUTH_IS_MEMBER', "SELECT user FROM user WHERE user='\$userid' AND group='\$groupname'", "
1065 You can define 1:n or n:m user<=>group relations, as you wish.
1066
1067 Sample configurations:
1068
1069 only one group per user (1:n):<br />
1070    DBAUTH_IS_MEMBER = \"SELECT user FROM user WHERE user='\$userid' AND group='\$groupname'\"<br />
1071    DBAUTH_GROUP_MEMBERS = \"SELECT user FROM user WHERE group='\$groupname'\"<br />
1072    DBAUTH_USER_GROUPS = \"SELECT group FROM user WHERE user='\$userid'\"<br />
1073 multiple groups per user (n:m):<br />
1074    DBAUTH_IS_MEMBER = \"SELECT userid FROM member WHERE userid='\$userid' AND groupname='\$groupname'\"<br />
1075    DBAUTH_GROUP_MEMBERS = \"SELECT DISTINCT userid FROM member WHERE groupname='\$groupname'\"<br />
1076    DBAUTH_USER_GROUPS = \"SELECT groupname FROM member WHERE userid='\$userid'\"<br />");
1077 $properties["DBAUTH_GROUP_MEMBERS"] =
1078     new _define_optional('DBAUTH_GROUP_MEMBERS', "SELECT user FROM user WHERE group='\$groupname'", "");
1079 $properties["DBAUTH_USER_GROUPS"] =
1080     new _define_optional('DBAUTH_USER_GROUPS', "SELECT group FROM user WHERE user='\$userid'", "");
1081
1082 if (function_exists('ldap_connect')) {
1083
1084 $properties["LDAP AUTH Host"] =
1085   new _define_optional('LDAP_AUTH_HOST', "ldap://localhost:389", "
1086 If USER_AUTH_ORDER contains Ldap:
1087
1088 The LDAP server to connect to.  Can either be a hostname, or a complete
1089 URL to the server (useful if you want to use ldaps or specify a different
1090 port number).");
1091
1092 $properties["LDAP BASE DN"] =
1093   new _define_optional('LDAP_BASE_DN', "ou=mycompany.com,o=My Company", "
1094 The organizational or domain BASE DN: e.g. \"dc=mydomain,dc=com\".
1095
1096 Note: ou=Users and ou=Groups are used for GroupLdap Membership
1097 Better use LDAP_OU_USERS and LDAP_OU_GROUP with GROUP_METHOD=LDAP.");
1098
1099 $properties["LDAP SET OPTION"] =
1100     new _define_optional('LDAP_SET_OPTION', "LDAP_OPT_PROTOCOL_VERSION=3:LDAP_OPT_REFERRALS=0", "
1101 Some LDAP servers need some more options, such as the Windows Active
1102 Directory Server.  Specify the options (as allowed by the PHP LDAP module)
1103 and their values as NAME=value pairs separated by colons.");
1104
1105 $properties["LDAP AUTH USER"] =
1106     new _define_optional('LDAP_AUTH_USER', "CN=ldapuser,ou=Users,o=Development,dc=mycompany.com", "
1107 DN to initially bind to the LDAP server as. This is needed if the server doesn't 
1108 allow anonymous queries. (Windows Active Directory Server)");
1109
1110 $properties["LDAP AUTH PASSWORD"] =
1111     new _define_optional('LDAP_AUTH_PASSWORD', "secret", "
1112 Password to use to initially bind to the LDAP server, as the DN 
1113 specified in the LDAP_AUTH_USER option (above).");
1114
1115 $properties["LDAP SEARCH FIELD"] =
1116     new _define_optional('LDAP_SEARCH_FIELD', "uid", "
1117 If you want to match usernames against an attribute other than uid,
1118 specify it here. Default: uid
1119
1120 e.g.: LDAP_SEARCH_FIELD = sAMAccountName");
1121
1122 $properties["LDAP OU USERS"] =
1123     new _define_optional('LDAP_OU_USERS', "ou=Users", "
1124 If you have an organizational unit for all users, define it here.
1125 This narrows the search, and is needed for LDAP group membership (if GROUP_METHOD=LDAP)
1126 Default: ou=Users");
1127
1128 $properties["LDAP OU GROUP"] =
1129     new _define_optional('LDAP_OU_GROUP', "ou=Groups", "
1130 If you have an organizational unit for all groups, define it here.
1131 This narrows the search, and is needed for LDAP group membership (if GROUP_METHOD=LDAP)
1132 The entries in this ou must have a gidNumber and cn attribute.
1133 Default: ou=Groups");
1134
1135 } else { // function_exists('ldap_connect')
1136
1137 $properties["LDAP Authentication"] =
1138 new unchangeable_variable('LDAP Authentication', "
1139 ; If USER_AUTH_ORDER contains Ldap:
1140
1141 ; The LDAP server to connect to.  Can either be a hostname, or a complete
1142 ; URL to the server (useful if you want to use ldaps or specify a different
1143 ; port number).
1144 ;LDAP_AUTH_HOST = \"ldap://localhost:389\"
1145
1146 ; The organizational or domain BASE DN: e.g. \"dc=mydomain,dc=com\".
1147 ;
1148 ; Note: ou=Users and ou=Groups are used for GroupLdap Membership
1149 ; Better use LDAP_OU_USERS and LDAP_OU_GROUP with GROUP_METHOD=LDAP.
1150 ;LDAP_BASE_DN = \"ou=Users,o=Development,dc=mycompany.com\"
1151
1152 ; Some LDAP servers need some more options, such as the Windows Active
1153 ; Directory Server.  Specify the options (as allowed by the PHP LDAP module)
1154 ; and their values as NAME=value pairs separated by colons.
1155 ; LDAP_SET_OPTION = \"LDAP_OPT_PROTOCOL_VERSION=3:LDAP_OPT_REFERRALS=0\"
1156
1157 ; DN to initially bind to the LDAP server as. This is needed if the server doesn't 
1158 ; allow anonymous queries. (Windows Active Directory Server)
1159 ; LDAP_AUTH_USER = \"CN=ldapuser,ou=Users,o=Development,dc=mycompany.com\"
1160
1161 ; Password to use to initially bind to the LDAP server, as the DN 
1162 ; specified in the LDAP_AUTH_USER option (above).
1163 ; LDAP_AUTH_PASSWORD = secret
1164
1165 ; If you want to match usernames against an attribute other than uid,
1166 ; specify it here. Default: uid
1167 ; LDAP_SEARCH_FIELD = sAMAccountName
1168
1169 ; If you have an organizational unit for all users, define it here.
1170 ; This narrows the search, and is needed for LDAP group membership (if GROUP_METHOD=LDAP)
1171 ; Default: ou=Users
1172 ; LDAP_OU_USERS = ou=Users
1173
1174 ; If you have an organizational unit for all groups, define it here.
1175 ; This narrows the search, and is needed for LDAP group membership (if GROUP_METHOD=LDAP)
1176 ; The entries in this ou must have a gidNumber and cn attribute.
1177 ; Default: ou=Groups
1178 ; LDAP_OU_GROUP = ou=Groups", "
1179 ; Ignored. No LDAP support in this php. configure --with-ldap");
1180 }
1181
1182 if (function_exists('imap_open')) {
1183
1184 $properties["IMAP Auth Host"] =
1185   new _define_optional('IMAP_AUTH_HOST', 'localhost:143/imap/notls', "
1186 If USER_AUTH_ORDER contains IMAP:
1187
1188 The IMAP server to check usernames from. Defaults to localhost.
1189
1190 Some IMAP_AUTH_HOST samples:
1191   localhost, localhost:143/imap/notls, 
1192   localhost:993/imap/ssl/novalidate-cert (SuSE refuses non-SSL conections)");
1193
1194 } else { // function_exists('imap_open')
1195
1196 $properties["IMAP Authentication"] =
1197   new unchangeable_variable('IMAP_AUTH_HOST',"
1198 ; If USER_AUTH_ORDER contains IMAP:
1199 ; The IMAP server to check usernames from. Defaults to localhost.
1200
1201 ; Some IMAP_AUTH_HOST samples:
1202 ;   localhost, localhost:143/imap/notls, 
1203 ;   localhost:993/imap/ssl/novalidate-cert (SuSE refuses non-SSL conections)
1204 ;IMAP_AUTH_HOST = localhost:143/imap/notls", "
1205 Ignored. No IMAP support in this php. configure --with-imap");
1206
1207 }
1208
1209 $properties["POP3 Authentication"] =
1210   new _define_optional('POP3_AUTH_HOST', 'localhost:110', "
1211 If USER_AUTH_ORDER contains POP3:
1212
1213 The POP3 mail server to check usernames and passwords against.");
1214 $properties["File Authentication"] =
1215   new _define_optional('AUTH_USER_FILE', '/etc/shadow', "
1216 If USER_AUTH_ORDER contains File:
1217
1218 File to read for authentication information.
1219 Popular choices are /etc/shadow and /etc/httpd/.htpasswd");
1220
1221 $properties["File Storable?"] =
1222 new boolean_define_commented_optional('AUTH_USER_FILE_STORABLE');
1223
1224 $properties["Session Auth USER"] =
1225   new _define_optional('AUTH_SESS_USER', 'userid', "
1226 If USER_AUTH_ORDER contains Session:
1227
1228 Name of the session variable which holds the already authenticated username.
1229 Sample: 'userid', 'user[username]', 'user->username'");
1230
1231 $properties["Session Auth LEVEL"] =
1232   new numeric_define('AUTH_SESS_LEVEL', '2', "
1233 Which level will the user be? 1 = Bogo or 2 = Pass");
1234
1235 /////////////////////////////////////////////////////////////////////
1236
1237 $properties["Part Four"] =
1238 new part('_part4', $SEPARATOR."\n", "
1239
1240 Part Four:
1241 Page appearance and layout");
1242
1243 $properties["Theme"] =
1244 new _define_selection_optional('THEME',
1245               array('default'  => "default",
1246                     'MacOSX'   => "MacOSX",
1247                     'smaller'  => 'smaller',
1248                     'Wordpress'=> 'Wordpress',
1249                     'Portland' => "Portland",
1250                     'Sidebar'  => "Sidebar",
1251                     'Crao'     => 'Crao',
1252                     'wikilens' => 'wikilens (Ratings)',
1253                     'shamino_com' => 'shamino_com',
1254                     'SpaceWiki' => "SpaceWiki",
1255                     'Hawaiian' => "Hawaiian",
1256                     'MonoBook'  => 'MonoBook [experimental]',
1257                     'blog'      => 'blog [experimental]',
1258                     ), "
1259 THEME
1260
1261 Most of the page appearance is controlled by files in the theme
1262 subdirectory.
1263
1264 There are a number of pre-defined themes shipped with PhpWiki.
1265 Or you may create your own, e.g. by copying and then modifying one of
1266 stock themes.
1267 <pre>
1268   THEME = default
1269   THEME = MacOSX
1270   THEME = MonoBook (WikiPedia)
1271   THEME = smaller
1272   THEME = Wordpress
1273   THEME = Portland
1274   THEME = Sidebar
1275   THEME = Crao
1276   THEME = wikilens (with Ratings)
1277   THEME = Hawaiian
1278   THEME = SpaceWiki
1279   THEME = Hawaiian
1280 </pre>
1281   
1282 Problems:
1283 <pre>
1284   THEME = blog     (Kubrick)   [experimental. Several links missing]
1285 </pre>");
1286
1287 $properties["Character Set"] =
1288     new _define_optional('CHARSET', 'iso-8859-1');
1289
1290 $properties["Ignore Charset Not Supported Warning"] =
1291     new _define_optional('IGNORE_CHARSET_NOT_SUPPORTED_WARNING');
1292
1293 $properties["Language"] =
1294 new _define_selection_optional('DEFAULT_LANGUAGE',
1295                array('en' => "English",
1296                      ''   => "&lt;empty&gt; (user-specific)",
1297                      'fr' => "Français",
1298                      'de' => "Deutsch",
1299                      'nl' => "Nederlands",
1300                      'es' => "Español",
1301                      'sv' => "Svenska",
1302                      'it' => "Italiano",
1303                      'ja' => "Japanese",
1304                      'zh' => "Chinese"), "
1305 Select your language/locale - default language is \"en\" for English.
1306 Other languages available:<pre>
1307 English  \"en\" (English    - HomePage)
1308 German   \"de\" (Deutsch    - StartSeite)
1309 French   \"fr\" (Français   - Accueil)
1310 Dutch    \"nl\" (Nederlands - ThuisPagina)
1311 Spanish  \"es\" (Español    - PáginaPrincipal)
1312 Swedish  \"sv\" (Svenska    - Framsida)
1313 Italian  \"it\" (Italiano   - PaginaPrincipale)
1314 Japanese \"ja\" (Japanese   - ホームページ)
1315 Chinese  \"zh\" (Chinese    - 首頁)
1316 </pre>
1317 If you set DEFAULT_LANGUAGE to the empty string, your systems default language
1318 (as determined by the applicable environment variables) will be
1319 used.");
1320
1321 $properties["Wiki Page Source"] =
1322 new _define_optional('WIKI_PGSRC', 'pgsrc', "
1323 WIKI_PGSRC -- specifies the source for the initial page contents of
1324 the Wiki. The setting of WIKI_PGSRC only has effect when the wiki is
1325 accessed for the first time (or after clearing the database.)
1326 WIKI_PGSRC can either name a directory or a zip file. In either case
1327 WIKI_PGSRC is scanned for files -- one file per page.
1328 <pre>
1329 // Default (old) behavior:
1330 define('WIKI_PGSRC', 'pgsrc'); 
1331 // New style:
1332 define('WIKI_PGSRC', 'wiki.zip'); 
1333 define('WIKI_PGSRC', 
1334        '../Logs/Hamwiki/hamwiki-20010830.zip'); 
1335 </pre>");
1336
1337 $properties["Default Wiki Page Source"] =
1338 new _define('DEFAULT_WIKI_PGSRC', 'pgsrc', "
1339 DEFAULT_WIKI_PGSRC is only used when the language is *not* the
1340 default (English) and when reading from a directory: in that case
1341 some English pages are inserted into the wiki as well.
1342 DEFAULT_WIKI_PGSRC defines where the English pages reside.
1343 ");
1344
1345 $properties["Generic Pages"] =
1346 new array_variable('DEFAULT_WIKI_PAGES', array('ReleaseNotes', 'SteveWainstead', 'TestPage'), "
1347 These are ':'-seperated pages which will get loaded untranslated from DEFAULT_WIKI_PGSRC.
1348 ");
1349
1350 ///////////////////
1351
1352 $properties["Part Five"] =
1353 new part('_part5', $SEPARATOR."\n", "
1354
1355 Part Five:
1356 Mark-up options");
1357
1358 $properties["Allowed Protocols"] =
1359 new list_define('ALLOWED_PROTOCOLS', 'http|https|mailto|ftp|news|nntp|ssh|gopher', "
1360 Allowed protocols for links - be careful not to allow \"javascript:\"
1361 URL of these types will be automatically linked.
1362 within a named link [name|uri] one more protocol is defined: phpwiki");
1363
1364 $properties["Inline Images"] =
1365     new list_define('INLINE_IMAGES', 'png|jpg|jpeg|gif');
1366
1367 $properties["WikiName Regexp"] =
1368 new _define('WIKI_NAME_REGEXP', "(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])", "
1369 Perl regexp for WikiNames (\"bumpy words\")
1370 (?&lt;!..) &amp; (?!...) used instead of '\b' because \b matches '_' as well");
1371
1372 $properties["Subpage Separator"] =
1373 new _define_optional('SUBPAGE_SEPARATOR', '"/"', "
1374 One character which seperates pages from subpages. Defaults to '/', but '.' or ':' were also used.",
1375 "onchange=\"validate_ereg('Sorry, \'%s\' must be a single character. Currently only :, / or .', '^[/:.]$', 'SUBPAGE_SEPARATOR', this);\""
1376 );
1377
1378 $properties["InterWiki Map File"] =
1379 new _define('INTERWIKI_MAP_FILE', 'lib/interwiki.map', "
1380 InterWiki linking -- wiki-style links to other wikis on the web
1381
1382 The map will be taken from a page name InterWikiMap.
1383 If that page is not found (or is not locked), or map
1384 data can not be found in it, then the file specified
1385 by INTERWIKI_MAP_FILE (if any) will be used.");
1386
1387 $properties["WARN_NONPUBLIC_INTERWIKIMAP"] =
1388 new boolean_define('WARN_NONPUBLIC_INTERWIKIMAP');
1389
1390 $properties["Keyword Link Regexp"] =
1391 new _define_optional('KEYWORDS', '\"Category* OR Topic*\"', "
1392 Search term used for automatic page classification by keyword extraction.
1393
1394 Any links on a page to pages whose names match this search 
1395 will be used keywords in the keywords html meta tag. This is an aid to
1396 classification by search engines. The value of the match is
1397 used as the keyword.
1398
1399 The default behavior is to match Category* or Topic* links.");
1400
1401 $properties["Author and Copyright Site Navigation Links"] =
1402 new _define_commented_optional('COPYRIGHTPAGE_TITLE', "GNU General Public License", "
1403
1404 These will be inserted as &lt;link rel&gt; tags in the html header of
1405 every page, for search engines and for browsers like Mozilla which
1406 take advantage of link rel site navigation.
1407
1408 If you have your own copyright and contact information pages change
1409 these as appropriate.");
1410
1411 $properties["COPYRIGHTPAGE URL"] =
1412 new _define_commented_optional('COPYRIGHTPAGE_URL', "http://www.gnu.org/copyleft/gpl.html#SEC1", "
1413
1414 Other useful alternatives to consider:
1415 <pre>
1416  COPYRIGHTPAGE_TITLE = \"GNU Free Documentation License\"
1417  COPYRIGHTPAGE_URL = \"http://www.gnu.org/copyleft/fdl.html\"
1418  COPYRIGHTPAGE_TITLE = \"Creative Commons License 2.0\"
1419  COPYRIGHTPAGE_URL = \"http://creativecommons.org/licenses/by/2.0/\"</pre>
1420 See http://creativecommons.org/learn/licenses/ for variations");
1421
1422 $properties["AUTHORPAGE_TITLE"] =
1423     new _define_commented_optional('AUTHORPAGE_TITLE', "The PhpWiki Programming Team", "
1424 Default Author Names");
1425 $properties["AUTHORPAGE_URL"] =
1426     new _define_commented_optional('AUTHORPAGE_URL', "http://phpwiki.org/ThePhpWikiProgrammingTeam", "
1427 Default Author URL");
1428
1429 $properties["TOC_FULL_SYNTAX"] =
1430 new boolean_define_optional('TOC_FULL_SYNTAX');
1431
1432 $properties["ENABLE_MARKUP_COLOR"] =
1433 new boolean_define_optional('ENABLE_MARKUP_COLOR');
1434
1435 $properties["DISABLE_MARKUP_WIKIWORD"] =
1436 new boolean_define_optional('DISABLE_MARKUP_WIKIWORD');
1437
1438 $properties["ENABLE_MARKUP_DIVSPAN" ] = 
1439 new boolean_define_optional('ENABLE_MARKUP_DIVSPAN');
1440
1441 ///////////////////
1442
1443 $properties["Part Six"] =
1444 new part('_part6', $SEPARATOR."\n", "
1445
1446 Part Six (optional):
1447 URL options -- you can probably skip this section.
1448
1449 For a pretty wiki (no index.php in the url) set a seperate DATA_PATH.");
1450
1451 $properties["Server Name"] =
1452     new _define_commented_optional('SERVER_NAME', $_SERVER['SERVER_NAME'], "
1453 Canonical name of the server on which this PhpWiki resides.");
1454
1455 $properties["Server Port"] =
1456     new numeric_define_commented('SERVER_PORT', $_SERVER['SERVER_PORT'], "
1457 Canonical httpd port of the server on which this PhpWiki resides.",
1458 "onchange=\"validate_ereg('Sorry, \'%s\' is no valid port number.', '^[0-9]+$', 'SERVER_PORT', this);\"");
1459
1460 $properties["Server Protocol"] =
1461     new _define_selection_optional_commented('SERVER_PROTOCOL', 
1462                     array('http'  => 'http',
1463                           'https' => 'https'));
1464
1465 $properties["Script Name"] =
1466     new _define_commented_optional('SCRIPT_NAME', $scriptname);
1467
1468 $properties["Data Path"] =
1469     new _define_commented_optional('DATA_PATH', dirname($scriptname));
1470
1471 $properties["PhpWiki Install Directory"] =
1472 new _define_commented_optional('PHPWIKI_DIR', dirname(__FILE__));
1473
1474 $properties["Use PATH_INFO"] =
1475 new _define_selection_optional_commented('USE_PATH_INFO', 
1476                     array(''      => 'automatic',
1477                           'true'  => 'use PATH_INFO',
1478                           'false' => 'do not use PATH_INFO'), "
1479 PhpWiki will try to use short urls to pages, eg 
1480 http://www.example.com/index.php/HomePage
1481 If you want to use urls like 
1482 http://www.example.com/index.php?pagename=HomePage
1483 then define 'USE_PATH_INFO' as false by uncommenting the line below.
1484 NB:  If you are using Apache >= 2.0.30, then you may need to to use
1485 the directive \"AcceptPathInfo On\" in your Apache configuration file
1486 (or in an appropriate <.htaccess> file) for the short urls to work:  
1487 See http://httpd.apache.org/docs-2.0/mod/core.html#acceptpathinfo
1488
1489 See also http://phpwiki.sourceforge.net/phpwiki/PrettyWiki for more ideas
1490 on prettifying your urls.
1491
1492 Default: PhpWiki will try to divine whether use of PATH_INFO
1493 is supported in by your webserver/PHP configuration, and will
1494 use PATH_INFO if it thinks that is possible.");
1495
1496 $properties["Virtual Path"] =
1497 new _define_commented_optional('VIRTUAL_PATH', '/SomeWiki', "
1498 VIRTUAL_PATH is the canonical URL path under which your your wiki
1499 appears. Normally this is the same as dirname(SCRIPT_NAME), however
1500 using e.g. seperate starter scripts, apaches mod_actions (or mod_rewrite), 
1501 you can make it something different.
1502
1503 If you do this, you should set VIRTUAL_PATH here or in the starter scripts.
1504
1505 E.g. your phpwiki might be installed at at /scripts/phpwiki/index.php,
1506 but you've made it accessible through eg. /wiki/HomePage.
1507
1508 One way to do this is to create a directory named 'wiki' in your
1509 server root. The directory contains only one file: an .htaccess
1510 file which reads something like:
1511 <pre>
1512     Action x-phpwiki-page /scripts/phpwiki/index.php
1513     SetHandler x-phpwiki-page
1514     DirectoryIndex /scripts/phpwiki/index.php
1515 </pre>
1516 In that case you should set VIRTUAL_PATH to '/wiki'.
1517
1518 (VIRTUAL_PATH is only used if USE_PATH_INFO is true.)
1519 ");
1520
1521 $upload_file_path = defined('UPLOAD_FILE_PATH') ? UPLOAD_FILE_PATH : getUploadFilePath();
1522 new _define_optional('UPLOAD_FILE_PATH', $temp);
1523
1524 $upload_data_path = defined('UPLOAD_DATA_PATH') ? UPLOAD_DATA_PATH : getUploadDataPath();
1525 new _define_optional('UPLOAD_DATA_PATH', $temp);
1526
1527 $temp = !empty($_ENV['TEMP']) ? $_ENV['TEMP'] : "/tmp";
1528 $properties["TEMP_DIR"] =
1529 new _define_optional('TEMP_DIR', $temp);
1530
1531 ///////////////////
1532
1533 $properties["Part Seven"] =
1534 new part('_part7', $SEPARATOR."\n", "
1535
1536 Part Seven:
1537
1538 Miscellaneous settings
1539 ");
1540
1541 $properties["Strict Mailable Pagedumps"] =
1542     new boolean_define_optional('STRICT_MAILABLE_PAGEDUMPS', 
1543      array('false' => "binary",
1544            'true'  => "quoted-printable"));
1545
1546 $properties["Default local Dump Directory"] =
1547     new _define_optional('DEFAULT_DUMP_DIR');
1548
1549 $properties["Default local HTML Dump Directory"] =
1550     new _define_optional('HTML_DUMP_DIR');
1551
1552 $properties["HTML Dump Filename Suffix"] =
1553     new _define_optional('HTML_DUMP_SUFFIX');
1554
1555 $properties["Pagename of Recent Changes"] =
1556     new _define_optional('RECENT_CHANGES', 
1557                          "RecentChanges");
1558
1559 $properties["Disable HTTP Redirects"] =
1560     new boolean_define_commented_optional('DISABLE_HTTP_REDIRECT');
1561
1562 $properties["Disable GETIMAGESIZE"] =
1563     new boolean_define_commented_optional('DISABLE_GETIMAGESIZE');
1564
1565 $properties["EDITING_POLICY"] =
1566     new _define_optional('EDITING_POLICY');
1567
1568 $properties["TOOLBAR_PAGELINK_PULLDOWN"] =
1569     new _define_commented_optional('TOOLBAR_PAGELINK_PULLDOWN');
1570 $properties["TOOLBAR_TEMPLATE_PULLDOWN"] =
1571     new _define_commented_optional('TOOLBAR_TEMPLATE_PULLDOWN');
1572 $properties["TOOLBAR_IMAGE_PULLDOWN"] =
1573     new _define_commented_optional('TOOLBAR_IMAGE_PULLDOWN');
1574 $properties["FULLTEXTSEARCH_STOPLIST"] =
1575     new _define_commented_optional('FULLTEXTSEARCH_STOPLIST');
1576
1577 $properties["Part Seven A"] =
1578     new part('_part7a', $SEPARATOR."\n", "
1579
1580 Part Seven A:
1581
1582 Optional Plugin Settings and external executables
1583 ");
1584
1585 $properties["FORTUNE_DIR"] =
1586   new _define_commented_optional('FORTUNE_DIR', "/usr/share/fortune");
1587 $properties["USE_EXTERNAL_HTML2PDF"] =
1588     new _define_commented_optional('USE_EXTERNAL_HTML2PDF', "htmldoc --quiet --format pdf14 --no-toc --no-title %s");
1589 $properties["EXTERNAL_HTML2PDF_PAGELIST"] =
1590     new _define_commented_optional('EXTERNAL_HTML2PDF_PAGELIST');
1591 $properties["BABYCART_PATH"] =
1592     new _define_commented_optional('BABYCART_PATH', "/usr/local/bin/babycart");
1593 $properties["GOOGLE_LICENSE_KEY"] =
1594   new _define_commented_optional('GOOGLE_LICENSE_KEY');
1595 $properties["RATEIT_IMGPREFIX"] =
1596     new _define_commented_optional('RATEIT_IMGPREFIX'); //BStar
1597 $properties["GRAPHVIZ_EXE"] =
1598     new _define_commented_optional('GRAPHVIZ_EXE'); // /usr/local/bin/dot
1599
1600 if (PHP_OS == "Darwin") // Mac OS X
1601     $ttfont   = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf";
1602 elseif (isWindows()) {
1603     $ttfont = $_ENV['windir'].'\Fonts\Arial.ttf';
1604 } else {
1605     $ttfont = 'luximr'; // This is the only what sourceforge offered.
1606     //$ttfont = 'Helvetica';
1607 }
1608 $properties["TTFONT"] =
1609     new _define_commented_optional('TTFONT',$ttfont);
1610 $properties["VISUALWIKIFONT"] =
1611     new _define_commented_optional('VISUALWIKIFONT'); // Arial
1612 $properties["VISUALWIKI_ALLOWOPTIONS"] =
1613     new boolean_define_commented_optional('VISUALWIKI_ALLOWOPTIONS'); // false
1614 $properties["PLOTICUS_EXE"] =
1615     new _define_commented_optional('PLOTICUS_EXE'); // /usr/local/bin/pl
1616 $properties["PLOTICUS_PREFABS"] =
1617     new _define_commented_optional('PLOTICUS_PREFABS'); // /usr/share/ploticus
1618 $properties["MY_JABBER_ID"] =
1619     new _define_commented_optional('MY_JABBER_ID'); //
1620 $properties["PHPWEATHER_BASE_DIR"] =
1621     new _define_commented_optional('PHPWEATHER_BASE_DIR'); //
1622 $properties["HIGHLIGHT_EXE"] =
1623     new _define_commented_optional('HIGHLIGHT_EXE'); // /usr/local/bin/highlight
1624 $properties["HIGHLIGHT_DATA_DIR"] =
1625     new _define_commented_optional('HIGHLIGHT_DATA_DIR'); // /usr/share/highlight
1626
1627
1628 $properties["Part Eight"] =
1629 new part('_part8', $SEPARATOR."\n", "
1630
1631 Part Eight:
1632
1633 Cached Plugin Settings. (pear Cache)
1634 ");
1635
1636 $properties["pear Cache USECACHE"] =
1637 new boolean_define_optional('PLUGIN_CACHED_USECACHE', 
1638                     array('true'  => 'Enabled',
1639                           'false' => 'Disabled'), "
1640 Enable or disable pear caching of plugins.");
1641 $properties["pear Cache Database Container"] =
1642 new _define_selection_optional('PLUGIN_CACHED_DATABASE', 
1643                                array('file' => 'file'), "
1644 Curently only file is supported. 
1645 db, trifile and imgfile might be supported, but you must hack that by yourself.");
1646
1647 $properties["pear Cache cache directory"] =
1648 new _define_commented_optional('PLUGIN_CACHED_CACHE_DIR', "/tmp/cache", "
1649 Should be writable to the webserver.");
1650 $properties["pear Cache Filename Prefix"] =
1651 new _define_optional('PLUGIN_CACHED_FILENAME_PREFIX', "phpwiki", "");
1652 $properties["pear Cache HIGHWATER"] =
1653 new numeric_define_optional('PLUGIN_CACHED_HIGHWATER', "4194304", "
1654 Garbage collection parameter.");
1655 $properties["pear Cache LOWWATER"] =
1656 new numeric_define_optional('PLUGIN_CACHED_LOWWATER', "3145728", "
1657 Garbage collection parameter.");
1658 $properties["pear Cache MAXLIFETIME"] =
1659 new numeric_define_optional('PLUGIN_CACHED_MAXLIFETIME', "2592000", "
1660 Garbage collection parameter.");
1661 $properties["pear Cache MAXARGLEN"] =
1662 new numeric_define_optional('PLUGIN_CACHED_MAXARGLEN', "1000", "
1663 max. generated url length.");
1664 $properties["pear Cache FORCE_SYNCMAP"] =
1665 new boolean_define_optional('PLUGIN_CACHED_FORCE_SYNCMAP', 
1666                     array('true'  => 'Enabled',
1667                           'false' => 'Disabled'), "");
1668 $properties["pear Cache IMGTYPES"] =
1669 new list_define('PLUGIN_CACHED_IMGTYPES', "png|gif|gd|gd2|jpeg|wbmp|xbm|xpm", "
1670 Handle those image types via GD handles. Check your GD supported image types.");
1671
1672 $end = "\n".$SEPARATOR."\n";
1673
1674 // performance hack
1675 text_from_dist("_MAGIC_CLOSE_FILE");
1676
1677 // end of configuration options
1678 ///////////////////////////////
1679 // begin class definitions
1680
1681 /**
1682  * A basic config-dist.ini configuration line in the form of a variable. 
1683  * (not needed anymore, we have only defines)
1684  *
1685  * Produces a string in the form "$name = value;"
1686  * e.g.:
1687  * $WikiNameRegexp = "value";
1688  */
1689 class _variable {
1690
1691     var $config_item_name;
1692     var $default_value;
1693     var $description;
1694     var $prefix;
1695     var $jscheck;
1696
1697     function _variable($config_item_name, $default_value='', $description = '', $jscheck = '') {
1698         $this->config_item_name = $config_item_name;
1699         if (!$description)
1700             $description = text_from_dist($config_item_name);
1701         $this->description = $description;
1702         if (defined($config_item_name) 
1703             and !preg_match("/(selection|boolean)/", get_class($this))
1704             and !preg_match("/^(SCRIPT_NAME|VIRTUAL_PATH|TEMP_DIR)$/", $config_item_name))
1705             $this->default_value = constant($config_item_name); // ignore given default value
1706         elseif ($config_item_name == $default_value)
1707             $this->default_value = '';
1708         else
1709             $this->default_value = $default_value;
1710         $this->jscheck = $jscheck;
1711         if (preg_match("/variable/i", get_class($this)))
1712             $this->prefix = "\$";
1713         elseif (preg_match("/ini_set/i", get_class($this)))
1714             $this->prefix = "ini_get: ";
1715         else
1716             $this->prefix = "";
1717     }
1718
1719     function value() {
1720       global $HTTP_POST_VARS;
1721       if (isset($HTTP_POST_VARS[$this->config_item_name]))
1722           return $HTTP_POST_VARS[$this->config_item_name];
1723       else 
1724           return $this->default_value;
1725     }
1726
1727     function _config_format($value) {
1728         return '';
1729         $v = $this->get_config_item_name();
1730         // handle arrays: a|b --> a['b']
1731         if (strpos($v, '|')) {
1732             list($a, $b) = explode('|', $v);
1733             $v = sprintf("%s['%s']", $a, $b);
1734         }
1735         if (preg_match("/[\"']/", $value))
1736             $value = '"' . $value . '"';
1737         return sprintf("%s = \"%s\"", $v, $value);
1738     }
1739
1740     function get_config_item_name() {
1741         return $this->config_item_name;
1742     }
1743
1744     function get_config_item_id() {
1745         return str_replace('|', '-', $this->config_item_name);
1746     }
1747
1748     function get_config_item_header() {
1749        if (strchr($this->config_item_name,'|')) {
1750           list($var,$param) = explode('|',$this->config_item_name);
1751           return "<b>" . $this->prefix . $var . "['" . $param . "']</b><br />";
1752        }
1753        elseif ($this->config_item_name[0] != '_')
1754           return "<b>" . $this->prefix . $this->config_item_name . "</b><br />";
1755        else 
1756           return '';
1757     }
1758
1759     function _get_description() {
1760         return $this->description;
1761     }
1762
1763     function _get_config_line($posted_value) {
1764         return "\n" . $this->_config_format($posted_value);
1765     }
1766
1767     function get_config($posted_value) {
1768         $d = stripHtml($this->_get_description());
1769         $d = str_replace("\n", "\n; ", $d) . $this->_get_config_line($posted_value) ."\n";
1770         return $d;
1771     }
1772
1773     function get_instructions($title) {
1774         global $tdwidth;
1775         $i = "<h3>" . $title . "</h3>\n    " . nl2p($this->_get_description()) . "\n";
1776         return "<tr>\n<td width=\"$tdwidth\" class=\"instructions\">\n" . $i . "</td>\n";
1777     }
1778
1779     function get_html() {
1780         $size = strlen($this->default_value) > 45 ? 90 : 50;
1781         return $this->get_config_item_header() . 
1782             "<input type=\"text\" size=\"$50\" name=\"" . $this->get_config_item_name() . "\" value=\"" . htmlspecialchars($this->default_value) . "\" " . 
1783             $this->jscheck . " />" . "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: green\">Input accepted.</p>";
1784     }
1785 }
1786
1787 class unchangeable_variable
1788 extends _variable {
1789     function _config_format($value) {
1790         return "";
1791     }
1792     // function get_html() { return false; }
1793     function get_html() {
1794         return $this->get_config_item_header() . 
1795         "<em>Not editable.</em>" . 
1796         "<pre>" . $this->default_value."</pre>";
1797     }
1798     function _get_config_line($posted_value) {
1799         if ($this->description)
1800             $n = "\n";
1801         return "${n}".$this->default_value;
1802     }
1803     function get_instructions($title) {
1804         global $tdwidth;
1805         $i = "<h3>" . $title . "</h3>\n    " . nl2p($this->_get_description()) . "\n";
1806         // $i .= "<em>Not editable.</em><br />\n<pre>" . $this->default_value."</pre>";
1807         return '<tr><td width="100%" class="unchangeable-variable-top" colspan="2">'."\n".$i."</td></tr>\n" 
1808         . '<tr style="border-top: none;"><td class="unchangeable-variable-left" width="'.$tdwidth.'">&nbsp;</td>';
1809     }
1810 }
1811
1812 class unchangeable_define
1813 extends unchangeable_variable {
1814     function _get_config_line($posted_value) {
1815         if ($this->description)
1816             $n = "\n";
1817         if (!$posted_value)
1818             $posted_value = $this->default_value;
1819         return "${n}".$this->_config_format($posted_value);
1820     }
1821     function _config_format($value) {
1822         return sprintf("%s = \"%s\"", $this->get_config_item_name(), $value);
1823     }
1824 }
1825 class unchangeable_ini_set
1826 extends unchangeable_variable {
1827     function _config_format($value) {
1828         return "";
1829     }
1830 }
1831
1832 class _variable_selection
1833 extends _variable {
1834     function value() {
1835         global $HTTP_POST_VARS;
1836         if (!empty($HTTP_POST_VARS[$this->config_item_name]))
1837             return $HTTP_POST_VARS[$this->config_item_name];
1838         else {
1839             list($option, $label) = each($this->default_value);
1840             return $option;
1841         }
1842     }
1843     function get_html() {
1844         $output = $this->get_config_item_header();
1845         $output .= '<select name="' . $this->get_config_item_name() . "\">\n";
1846         /* The first option is the default */
1847         $values = $this->default_value;
1848         if (defined($this->get_config_item_name()))
1849             $this->default_value = constant($this->get_config_item_name());
1850         else
1851             $this->default_value = null;
1852         while(list($option, $label) = each($values)) {
1853             if (!is_null($this->default_value) and $this->default_value === $option)
1854                 $output .= "  <option value=\"$option\" selected=\"selected\">$label</option>\n";
1855             else
1856                 $output .= "  <option value=\"$option\">$label</option>\n";
1857         }
1858         $output .= "</select>\n";
1859         return $output;
1860     }
1861 }
1862
1863
1864 class _define
1865 extends _variable {
1866     function _config_format($value) {
1867         return sprintf("%s = \"%s\"", $this->get_config_item_name(), $value);
1868     }
1869     function _get_config_line($posted_value) {
1870         if ($this->description)
1871             $n = "\n";
1872         if ($posted_value == '')
1873             return "${n};" . $this->_config_format("");
1874         else
1875             return "${n}" . $this->_config_format($posted_value);
1876     }
1877     function get_html() {
1878         $size = strlen($this->default_value) > 45 ? 90 : 50;
1879         return $this->get_config_item_header() 
1880             . "<input type=\"text\" size=\"$size\" name=\"" . htmlentities($this->get_config_item_name()) 
1881             . "\" value=\"" . htmlentities($this->default_value) . "\" {$this->jscheck} />" 
1882             . "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: green\">Input accepted.</p>";
1883     }
1884 }
1885
1886 class _define_commented
1887 extends _define {
1888     function _get_config_line($posted_value) {
1889         if ($this->description)
1890             $n = "\n";
1891         if ($posted_value == $this->default_value)
1892             return "${n};" . $this->_config_format($posted_value);
1893         elseif ($posted_value == '')
1894             return "${n};" . $this->_config_format("");
1895         else
1896             return "${n}" . $this->_config_format($posted_value);
1897     }
1898 }
1899
1900 /** 
1901  * We don't use _optional anymore, because INI-style config's don't need that. 
1902  * IniConfig.php does the optional logic now.
1903  * But we use _optional for config-default.ini options
1904  */
1905 class _define_commented_optional
1906 extends _define_commented { }
1907
1908 class _define_optional
1909 extends _define { }
1910
1911 class _define_notempty
1912 extends _define {
1913     function get_html() {
1914         $s = $this->get_config_item_header() 
1915             . "<input type=\"text\" size=\"50\" name=\"" . $this->get_config_item_name() 
1916             . "\" value=\"" . $this->default_value . "\" {$this->jscheck} />";
1917         if (empty($this->default_value))
1918             return $s . "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: red\">Cannot be empty.</p>";
1919         else
1920             return $s . "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: green\">Input accepted.</p>";
1921     }
1922 }
1923
1924 class _variable_commented
1925 extends _variable {
1926     function _get_config_line($posted_value) {
1927         if ($this->description)
1928             $n = "\n";
1929         if ($posted_value == $this->default_value)
1930             return "${n};" . $this->_config_format($posted_value);
1931         elseif ($posted_value == '')
1932             return "${n};" . $this->_config_format("");
1933         else
1934             return "${n}" . $this->_config_format($posted_value);
1935     }
1936 }
1937
1938 class numeric_define
1939 extends _define {
1940
1941     function numeric_define($config_item_name, $default_value='', $description = '', $jscheck = '') {
1942         $this->_define($config_item_name, $default_value, $description, $jscheck);
1943         if (!$jscheck)
1944             $this->jscheck = "onchange=\"validate_ereg('Sorry, \'%s\' is not an integer.', '^[-+]?[0-9]+$', '" . $this->get_config_item_name() . "', this);\"";
1945     }
1946     function _config_format($value) {
1947         //return sprintf("define('%s', %s);", $this->get_config_item_name(), $value);
1948         return sprintf("%s = %s", $this->get_config_item_name(), $value);
1949     }
1950     function _get_config_line($posted_value) {
1951         if ($this->description)
1952             $n = "\n";
1953         if ($posted_value == '')
1954             return "${n};" . $this->_config_format('0');
1955         else
1956             return "${n}" . $this->_config_format($posted_value);
1957     }
1958 }
1959
1960 class numeric_define_optional
1961 extends numeric_define {}
1962
1963 class numeric_define_commented
1964 extends numeric_define {
1965     function _get_config_line($posted_value) {
1966         if ($this->description)
1967             $n = "\n";
1968         if ($posted_value == $this->default_value)
1969             return "${n};" . $this->_config_format($posted_value);
1970         elseif ($posted_value == '')
1971             return "${n};" . $this->_config_format('0');
1972         else
1973             return "${n}" . $this->_config_format($posted_value);
1974     }
1975 }
1976
1977 class _define_selection
1978 extends _variable_selection {
1979     function _config_format($value) {
1980         return sprintf("%s = %s", $this->get_config_item_name(), $value);
1981     }
1982     function _get_config_line($posted_value) {
1983         return _define::_get_config_line($posted_value);
1984     }
1985     function get_html() {
1986         return _variable_selection::get_html();
1987     }
1988 }
1989
1990 class _define_selection_optional
1991 extends _define_selection { }
1992
1993 class _variable_selection_optional
1994 extends _variable_selection { }
1995
1996 class _define_selection_optional_commented
1997 extends _define_selection_optional { 
1998     function _get_config_line($posted_value) {
1999         if ($this->description)
2000             $n = "\n";
2001         if ($posted_value == $this->default_value)
2002             return "${n};" . $this->_config_format($posted_value);
2003         elseif ($posted_value == '')
2004             return "${n};" . $this->_config_format("");
2005         else
2006             return "${n}" . $this->_config_format($posted_value);
2007     }
2008 }
2009
2010 class _define_password
2011 extends _define {
2012
2013     function _define_password($config_item_name, $default_value='', $description = '', $jscheck = '') {
2014         if ($config_item_name == $default_value) $default_value = '';
2015         $this->_define($config_item_name, $default_value, $description, $jscheck);
2016         if (!$jscheck)
2017             $this->jscheck = "onchange=\"validate_ereg('Sorry, \'%s\' cannot be empty.', '^.+$', '" 
2018                 . $this->get_config_item_name() . "', this);\"";
2019     }
2020     function _get_config_line($posted_value) {
2021         if ($this->description)
2022             $n = "\n";
2023         if ($posted_value == '') {
2024             $p = "${n};" . $this->_config_format("");
2025             $p .= "\n; If you used the passencrypt.php utility to encode the password";
2026             $p .= "\n; then uncomment this line:";
2027             $p .= "\n;ENCRYPTED_PASSWD = true";
2028             return $p;
2029         } else {
2030             if (function_exists('crypt')) {
2031                 $salt_length = max(CRYPT_SALT_LENGTH,
2032                                     2 * CRYPT_STD_DES,
2033                                     9 * CRYPT_EXT_DES,
2034                                    12 * CRYPT_MD5,
2035                                    16 * CRYPT_BLOWFISH);
2036                 // generate an encrypted password
2037                 $crypt_pass = crypt($posted_value, rand_ascii($salt_length));
2038                 $p = "${n}" . $this->_config_format($crypt_pass);
2039                 return $p . "\nENCRYPTED_PASSWD = true";
2040             } else {
2041                 $p = "${n}" . $this->_config_format($posted_value);
2042                 $p .= "\n; Encrypted passwords cannot be used:";
2043                 $p .= "\n; 'function crypt()' not available in this version of php";
2044                 $p .= "\nENCRYPTED_PASSWD = false";
2045                 return $p;
2046             }
2047         }
2048     }
2049     function get_html() {
2050         return _variable_password::get_html();
2051     }
2052 }
2053
2054 class _define_password_optional
2055 extends _define_password { 
2056
2057     function _define_password_optional($config_item_name, $default_value='', $description = '', $jscheck = '') {
2058         if ($config_item_name == $default_value) $default_value = '';
2059         if (!$jscheck) $this->jscheck = " ";
2060         $this->_define($config_item_name, $default_value, $description, $jscheck);
2061     }
2062
2063     function _get_config_line($posted_value) {
2064         if ($this->description)
2065             $n = "\n";
2066         if ($posted_value == '') {
2067             return "${n};" . $this->_config_format("");
2068         } else {
2069             return "${n}" . $this->_config_format($posted_value);
2070         }
2071     }
2072     function get_html() {
2073         $s = $this->get_config_item_header();
2074         // dont re-encrypt already encrypted passwords
2075         $value = $this->value();
2076         $encrypted = !empty($GLOBALS['properties']["Encrypted Passwords"]) and 
2077                      $GLOBALS['properties']["Encrypted Passwords"]->value();
2078         if (empty($value))
2079             $encrypted = false;
2080         $s .= "<input type=\"". ($encrypted ? "text" : "password") . "\" name=\"" . $this->get_config_item_name()
2081            . "\" value=\"" . $value . "\" {$this->jscheck} />";
2082         return $s;
2083     }
2084 }
2085
2086 class _define_password_commented_optional
2087 extends _define_password_optional { }
2088
2089 class _variable_password
2090 extends _variable {
2091     function _variable_password($config_item_name, $default_value='', $description = '', $jscheck = '') {
2092         if ($config_item_name == $default_value) $default_value = '';
2093         $this->_define($config_item_name, $default_value, $description, $jscheck);
2094         if (!$jscheck)
2095             $this->jscheck = "onchange=\"validate_ereg('Sorry, \'%s\' cannot be empty.', '^.+$', '" . $this->get_config_item_name() . "', this);\"";
2096     }
2097     function get_html() {
2098         global $HTTP_POST_VARS, $HTTP_GET_VARS;
2099         $s = $this->get_config_item_header();
2100         if (isset($HTTP_POST_VARS['create']) or isset($HTTP_GET_VARS['create'])) {
2101             $new_password = random_good_password();
2102             $this->default_value = $new_password;
2103             $s .= "Created password: <strong>$new_password</strong><br />&nbsp;<br />";
2104         }
2105         // dont re-encrypt already encrypted passwords
2106         $value = $this->value();
2107         $encrypted = !empty($GLOBALS['properties']["Encrypted Passwords"]) and 
2108                      $GLOBALS['properties']["Encrypted Passwords"]->value();
2109         if (empty($value))
2110             $encrypted = false;
2111         $s .= "<input type=\"". ($encrypted ? "text" : "password") . "\" name=\"" . $this->get_config_item_name()
2112            . "\" value=\"" . $value . "\" {$this->jscheck} />" 
2113            . "&nbsp;&nbsp;<input type=\"submit\" name=\"create\" value=\"Create Random Password\" />";
2114         if (empty($value))
2115             $s .= "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: red\">Cannot be empty.</p>";
2116         elseif (strlen($this->default_value) < 4)
2117             $s .= "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: red\">Must be longer than 4 chars.</p>";
2118         else
2119             $s .= "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: green\">Input accepted.</p>";
2120         return $s;
2121     }
2122 }
2123
2124 class list_variable
2125 extends _variable {
2126     function _get_config_line($posted_value) {
2127         // split the phrase by any number of commas or space characters,
2128         // which include " ", \r, \t, \n and \f
2129         $list_values = preg_split("/[\s,]+/", $posted_value, -1, PREG_SPLIT_NO_EMPTY);
2130         if ($list_values)
2131             $list_values = join("|", $list_values);
2132         return _variable::_get_config_line($list_values);
2133     }
2134     function get_html() {
2135         $list_values = explode("|", $this->default_value);
2136         $rows = max(3, count($list_values) +1);
2137         $list_values = join("\n", $list_values);
2138         $ta = $this->get_config_item_header();
2139         $ta .= "<textarea cols=\"18\" rows=\"". $rows ."\" name=\"".$this->get_config_item_name()."\" {$this->jscheck}>";
2140         $ta .= $list_values . "</textarea>";
2141         $ta .= "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: green\">Input accepted.</p>";
2142         return $ta;
2143     }
2144 }
2145
2146 class list_define
2147 extends _define {
2148     function _get_config_line($posted_value) {
2149         $list_values = preg_split("/[\s,]+/", $posted_value, -1, PREG_SPLIT_NO_EMPTY);
2150         if ($list_values)
2151             $list_values = join("|", $list_values);
2152         return _variable::_get_config_line($list_values);
2153     }
2154     function get_html() {
2155         $list_values = explode("|", $this->default_value);
2156         $rows = max(3, count($list_values) +1);
2157         if ($list_values)
2158             $list_values = join("\n", $list_values);
2159         $ta = $this->get_config_item_header();
2160         $ta .= "<textarea cols=\"18\" rows=\"". $rows ."\" name=\"".$this->get_config_item_name()."\" {$this->jscheck}>";
2161         $ta .= $list_values . "</textarea>";
2162         $ta .= "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: green\">Input accepted.</p>";
2163         return $ta;
2164     }
2165 }
2166
2167 class array_variable
2168 extends _variable {
2169     function _config_format($value) {
2170         return sprintf("%s = \"%s\"", $this->get_config_item_name(), 
2171                        is_array($value) ? join(':', $value) : $value);
2172     }
2173     function _get_config_line($posted_value) {
2174         // split the phrase by any number of commas or space characters,
2175         // which include " ", \r, \t, \n and \f
2176         $list_values = preg_split("/[\s,]+/", $posted_value, -1, PREG_SPLIT_NO_EMPTY);
2177         if (!empty($list_values)) {
2178             $list_values = "'".join("', '", $list_values)."'";
2179             return "\n" . $this->_config_format($list_values);
2180         } else
2181             return "\n;" . $this->_config_format('');
2182     }
2183     function get_html() {
2184         if (is_array($this->default_value))
2185             $list_values = join("\n", $this->default_value);
2186         else    
2187             $list_values = $this->default_value;
2188         $rows = max(3, count($this->default_value) +1);
2189         $ta = $this->get_config_item_header();
2190         $ta .= "<textarea cols=\"18\" rows=\"". $rows ."\" name=\"".$this->get_config_item_name()."\" {$this->jscheck}>";
2191         $ta .= $list_values . "</textarea>";
2192         $ta .= "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: green\">Input accepted.</p>";
2193         return $ta;
2194     }
2195 }
2196
2197 class array_define
2198 extends _define {
2199     function _config_format($value) {
2200         return sprintf("%s = \"%s\"", $this->get_config_item_name(), 
2201                        is_array($value) ? join(' : ', $value) : $value);
2202     }
2203     function _get_config_line($posted_value) {
2204         // split the phrase by any number of commas or space characters,
2205         // which include " ", \r, \t, \n and \f
2206         $list_values = preg_split("/[\s,:]+/", $posted_value, -1, PREG_SPLIT_NO_EMPTY);
2207         if (!empty($list_values)) {
2208             $list_values = join(" : ", $list_values);
2209             return "\n" . $this->_config_format($list_values);
2210         } else
2211             return "\n;" . $this->_config_format('');
2212     }
2213     function get_html () {
2214         if (!$this->default_value)
2215             $this->default_value = array();
2216         elseif (is_string($this->default_value))
2217             $this->default_value = preg_split("/[\s,:]+/", $this->default_value, -1, PREG_SPLIT_NO_EMPTY);
2218         $list_values = join(" : \n", $this->default_value);
2219         $rows = max(3, count($this->default_value) + 1);
2220         $ta = $this->get_config_item_header();
2221         $ta .= "<textarea cols=\"18\" rows=\"". $rows ."\" name=\"".$this->get_config_item_name()."\" {$this->jscheck}>";
2222         $ta .= $list_values . "</textarea>";
2223         $ta .= "<p id=\"" . $this->get_config_item_id() . "\" style=\"color: green\">Input accepted.</p>";
2224         return $ta;
2225     }
2226 }
2227
2228 /*
2229 class _ini_set
2230 extends _variable {
2231     function value() {
2232         global $HTTP_POST_VARS;
2233         if ($v = $HTTP_POST_VARS[$this->config_item_name])
2234             return $v;
2235         else {
2236             return ini_get($this->get_config_item_name);
2237         }
2238     }
2239     function _config_format($value) {
2240         return sprintf("ini_set('%s', '%s');", $this->get_config_item_name(), $value);
2241     }
2242     function _get_config_line($posted_value) {
2243         if ($posted_value && ! $posted_value == $this->default_value)
2244             return "\n" . $this->_config_format($posted_value);
2245         else
2246             return "\n;" . $this->_config_format($this->default_value);
2247     }
2248 }
2249 */
2250
2251 class boolean_define
2252 extends _define {
2253
2254     // adds ->values property, instead of ->default_value
2255     function boolean_define($config_item_name, $values = false, $description = '', $jscheck = '') {
2256         $this->config_item_name = $config_item_name;
2257         if (!$description)
2258             $description = text_from_dist($config_item_name);
2259         $this->description = $description;
2260         // TESTME: get boolean default value from config-default.ini
2261         if (defined($config_item_name))
2262             $this->default_value = constant($config_item_name); // ignore given default value
2263         elseif (is_array($values))
2264             list($this->default_value,$dummy) = $values[0];
2265         if (!$values) 
2266             $values = array('false' => "Disabled",
2267                             'true'  => "Enabled");
2268         $this->values  = $values;
2269         $this->jscheck = $jscheck;
2270         $this->prefix = "";
2271     }
2272     function _get_config_line($posted_value) {
2273         if ($this->description)
2274             $n = "\n";
2275         return "${n}" . $this->_config_format($posted_value);
2276     }
2277     function _config_format($value) {
2278         if (strtolower(trim($value)) == 'false')
2279             $value = false;
2280         return sprintf("%s = %s", $this->get_config_item_name(),
2281                        (bool)$value ? 'true' : 'false');
2282     }
2283     //TODO: radiobuttons, no list
2284     function get_html() {
2285         $output = $this->get_config_item_header();
2286         $name = $this->get_config_item_name();
2287         $output .= '<select name="' . $name . "\" {$this->jscheck}>\n";
2288         $values = $this->values;
2289         $default_value = $this->default_value ? 'true' : 'false';
2290         /* There can usually only be two options, there can be
2291          * three options in the case of a boolean_define_commented_optional */
2292         while (list($option, $label) = each($values)) {
2293             if (!is_null($this->default_value) and $option === $default_value)
2294                 $output .= "  <option value=\"$option\" selected=\"selected\">$label</option>\n";
2295             else
2296                 $output .= "  <option value=\"$option\">$label</option>\n";
2297         }
2298         $output .= "</select>\n";
2299         return $output;
2300     }
2301 }
2302
2303 class boolean_define_optional
2304 extends boolean_define {}
2305
2306 class boolean_define_commented
2307 extends boolean_define {
2308     function _get_config_line($posted_value) {
2309         if ($this->description)
2310             $n = "\n";
2311         list($default_value, $label) = each($this->default_value);
2312         if ($posted_value == $default_value)
2313             return "${n};" . $this->_config_format($posted_value);
2314         elseif ($posted_value == '')
2315             return "${n};" . $this->_config_format('false');
2316         else
2317             return "${n}" . $this->_config_format($posted_value);
2318     }
2319 }
2320
2321 class boolean_define_commented_optional
2322 extends boolean_define_commented {}
2323
2324 class part
2325 extends _variable {
2326     function value () { return; }
2327     function get_config($posted_value) {
2328         $d = stripHtml($this->_get_description());
2329         global $SEPARATOR;
2330         return "\n".$SEPARATOR . str_replace("\n", "\n; ", $d) ."\n".$this->default_value;
2331     }
2332     function get_instructions($title) {
2333         $id = preg_replace("/\W/","",$this->config_item_name);
2334         $group_name = preg_replace("/\W/","",$title);
2335         $i = "<tr class=\"header\" id=\"$id\">\n<td class=\"part\" width=\"100%\" colspan=\"2\" bgcolor=\"#eeeeee\">\n";
2336         $i .= "<h2>" . $title . "</h2>\n    " . nl2p($this->_get_description()) ."\n";
2337         $i .= "<p><a href=\"javascript:toggle_group('$id')\" id=\"{$id}_text\">Hide options.</a></p>";
2338         return  $i ."</td>\n";
2339     }
2340     function get_html() {
2341         return "";
2342     }
2343 }
2344
2345 // html utility functions
2346 function nl2p($text) {
2347   preg_match_all("@\s*(<pre>.*?</pre>|<dl>.*?</dl>|.*?(?=\n\n|<pre>|<dl>|$))@s",
2348                  $text, $m, PREG_PATTERN_ORDER);
2349
2350   $text = '';
2351   foreach ($m[1] as $par) {
2352     if (!($par = trim($par)))
2353       continue;
2354     if (!preg_match('/^<(pre|dl)>/', $par))
2355       $par = "<p>$par</p>";
2356     $text .= $par;
2357   }
2358   return $text;
2359 }
2360
2361 function text_from_dist($var) {
2362     static $distfile = 0;
2363     static $f;
2364     
2365     if (!$distfile) {
2366         $sep = (substr(PHP_OS,0,3) == 'WIN' ? '\\' : '/');
2367         $distfile = dirname(__FILE__) . $sep . "config" . $sep . "config-dist.ini";
2368         $f = fopen($distfile, "r");
2369     }
2370     if ($var == '_MAGIC_CLOSE_FILE') {
2371         fclose($f);
2372         return;
2373     }
2374     // if all vars would be in natural order as in the config-dist this would not be needed.
2375     fseek($f, 0); 
2376     $par = "\n";
2377     while (!feof($f)) {
2378         $s = fgets($f);
2379         if (preg_match("/^; \w/", $s)) {
2380             $par .= (substr($s,2) . " ");
2381         } elseif (preg_match("/^;\s*$/", $s)) {
2382             $par .= "\n\n";
2383         }
2384         if (preg_match("/^;?".preg_quote($var)."\s*=/", $s))
2385             return $par;
2386         if (preg_match("/^\s*$/", $s)) // new paragraph
2387             $par = "\n";
2388     }
2389     return '';
2390 }
2391
2392 function stripHtml($text) {
2393         $d = str_replace("<pre>", "", $text);
2394         $d = str_replace("</pre>", "", $d);
2395         $d = str_replace("<dl>", "", $d);
2396         $d = str_replace("</dl>", "", $d);
2397         $d = str_replace("<dt>", "", $d);
2398         $d = str_replace("</dt>", "", $d);
2399         $d = str_replace("<dd>", "", $d);
2400         $d = str_replace("</dd>", "", $d);
2401         $d = str_replace("<p>", "", $d);
2402         $d = str_replace("</p>", "", $d);
2403         //restore html entities into characters
2404         // http://www.php.net/manual/en/function.htmlentities.php
2405         $trans = get_html_translation_table (HTML_ENTITIES);
2406         $trans = array_flip ($trans);
2407         $d = strtr($d, $trans);
2408         return $d;
2409 }
2410
2411 include_once(dirname(__FILE__)."/lib/stdlib.php");
2412
2413 ////
2414 // Function to create better user passwords (much larger keyspace),
2415 // suitable for user passwords.
2416 // Sequence of random ASCII numbers, letters and some special chars.
2417 // Note: There exist other algorithms for easy-to-remember passwords.
2418 function random_good_password ($minlength = 5, $maxlength = 8) {
2419   $newpass = '';
2420   // assume ASCII ordering (not valid on EBCDIC systems!)
2421   $valid_chars = "!#%&+-.0123456789=@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
2422   $start = ord($valid_chars);
2423   $end   = ord(substr($valid_chars,-1));
2424   better_srand();
2425   if (function_exists('mt_rand')) // mersenne twister
2426       $length = mt_rand($minlength, $maxlength);
2427   else  // the usually bad glibc rand()
2428       $length = rand($minlength, $maxlength);
2429   while ($length > 0) {
2430       if (function_exists('mt_rand'))
2431           $newchar = mt_rand($start, $end);
2432       else
2433           $newchar = rand($start, $end);
2434       if (! strrpos($valid_chars,$newchar) ) continue; // skip holes
2435       $newpass .= sprintf("%c", $newchar);
2436       $length--;
2437   }
2438   return($newpass);
2439 }
2440
2441 // debugging
2442 function printArray($a) {
2443     echo "<hr />\n<pre>\n";
2444     print_r($a);
2445     echo "\n</pre>\n<hr />\n";
2446 }
2447
2448 // end of class definitions
2449 /////////////////////////////
2450 // begin auto generation code
2451
2452 if (!function_exists('is_a')) {
2453   function is_a($object, $class) {
2454     $class = strtolower($class);
2455     return (get_class($object) == $class) or is_subclass_of($object, $class);
2456   }
2457 }
2458
2459
2460 if (!empty($HTTP_POST_VARS['action']) 
2461     and $HTTP_POST_VARS['action'] == 'make_config'
2462     and !empty($HTTP_POST_VARS['ADMIN_USER'])
2463     and !empty($HTTP_POST_VARS['ADMIN_PASSWD'])
2464     )
2465 {
2466
2467     $timestamp = date ('dS of F, Y H:i:s');
2468
2469     $config = "
2470 ; This is a local configuration file for PhpWiki.
2471 ; It was automatically generated by the configurator script
2472 ; on the $timestamp.
2473 ;
2474 ; $preamble
2475 ";
2476
2477     $posted = $GLOBALS['HTTP_POST_VARS'];
2478     /*if (defined('DEBUG'))
2479      printArray($GLOBALS['HTTP_POST_VARS']);*/
2480
2481     foreach ($properties as $option_name => $a) {
2482         $posted_value = stripslashes($posted[$a->config_item_name]);
2483         $config .= $properties[$option_name]->get_config($posted_value);
2484     }
2485
2486     $config .= $end;
2487
2488     if (is_writable($fs_config_file)) {
2489       // We first check if the config-file exists.
2490       if (file_exists($fs_config_file)) {
2491         // We make a backup copy of the file
2492         $new_filename = preg_replace('/\.ini$/', '-' . time() . '.ini', $fs_config_file);
2493         if (@copy($fs_config_file, $new_filename)) {
2494             $fp = @fopen($fs_config_file, 'w');
2495         }
2496       } else {
2497         $fp = @fopen($fs_config_file, 'w');
2498       }
2499     }
2500     else {
2501       $fp = false;
2502     }
2503     
2504     if ($fp) {
2505         fputs($fp, $config);
2506         fclose($fp);
2507         echo "<p>The configuration was written to <code><b>$config_file</b></code>.</p>\n";
2508         if ($new_filename) {
2509             echo "<p>A backup was made to <code><b>$new_filename</b></code>.</p>\n";
2510         } else {
2511             ; //echo "<p><strong>You must rename or copy this</strong> <code><b>$config_file</b></code> <strong>file to</strong> <code><b>config/config.ini</b></code>.</p>\n";
2512         }
2513     } else {
2514         echo "<p>The configuration file could <b>not</b> be written.<br />\n",
2515             " You should copy the above configuration to a file, ",
2516             "and manually save it as <code><b>config/config.ini</b></code>.</p>\n";
2517     }
2518
2519     echo "<hr />\n<p>Here's the configuration file based on your answers:</p>\n";
2520     echo "<form method=\"get\" action=\"", $configurator, "\">\n";
2521     echo "<textarea id='config-output' readonly='readonly' style='width:100%;' rows='30' cols='100'>\n";
2522     echo htmlentities($config);
2523     echo "</textarea></form>\n";
2524     echo "<hr />\n";
2525
2526     echo "<p>To make any corrections, <a href=\"configurator.php\">edit the settings again</a>.</p>\n";
2527
2528 } else { // first time or create password
2529     $posted = $GLOBALS['HTTP_POST_VARS'];
2530     // No action has been specified - we make a form.
2531
2532     if (!empty($GLOBALS['HTTP_GET_VARS']['start_debug'])) 
2533         $configurator .= ("?start_debug=" . $GLOBALS['HTTP_GET_VARS']['start_debug']);
2534     echo '
2535 <form action="',$configurator,'" method="post">
2536 <input type="hidden" name="action" value="make_config" />
2537 <table cellpadding="4" cellspacing="0">
2538 ';
2539
2540     while (list($property, $obj) = each($properties)) {
2541         echo $obj->get_instructions($property);
2542         if ($h = $obj->get_html()) {
2543             if (defined('DEBUG') and DEBUG)  $h = get_class($obj) . "<br />\n" . $h;
2544             echo "<td>".$h."</td>\n";
2545         }
2546         echo '</tr>';
2547     }
2548
2549     echo '
2550 </table>
2551 <p><input type="submit" id="submit" value="Save ',$config_file,'" /> <input type="reset" value="Clear" /></p>
2552 </form>
2553 ';
2554 }
2555 ?>
2556 </body>
2557 </html>