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