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