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