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