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