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