]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/IniConfig.php
Moved lib/plugincache-config.php to config/*.ini
[SourceForge/phpwiki.git] / lib / IniConfig.php
1 <?php
2 rcs_id('$Id: IniConfig.php,v 1.36 2004-06-19 10:06:37 rurban Exp $');
3
4 /**
5  * A configurator intended to read it's config from a PHP-style INI file,
6  * instead of a PHP file.
7  *
8  * Pass a filename to the IniConfig() function and it will read all it's
9  * definitions from there, all by itself, and proceed to do a mass-define
10  * of all valid PHPWiki config items.  In this way, we can hopefully be
11  * totally backwards-compatible with the old index.php method, while still
12  * providing a much tastier on-going experience.
13  *
14  * @author: Joby Walker, Reini Urban, Matthew Palmer
15  */
16 /*
17  * Copyright 2004 $ThePhpWikiProgrammingTeam
18  *
19  * This file is part of PhpWiki.
20  *
21  * PhpWiki is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation; either version 2 of the License, or
24  * (at your option) any later version.
25  * 
26  * PhpWiki is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  * 
31  * You should have received a copy of the GNU General Public License
32  * along with PhpWiki; if not, write to the Free Software
33  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34  */
35
36 /** TODO
37  * - Convert the value lists to provide defaults, so that every "if
38  *      (defined())" and "if (!defined())" can fuck off to the dismal hole
39  *      it belongs in.
40  *
41  * - Resurrect the larger "config object" code (in config/) so it'll aid the
42  *      GUI config writers, and allow us to do proper validation and default
43  *      value handling.
44  *
45  * - Get rid of WikiNameRegexp and KeywordLinkRegexp as globals by finding
46  *      everywhere that uses them as variables and modify the code to use
47  *      them as constants.  Will involve hacking around
48  *      pcre_fix_posix_classes (probably with redefines()).
49  */
50
51 include_once (dirname(__FILE__)."/config.php");
52 include_once (dirname(__FILE__)."/FileFinder.php");
53
54 function IniConfig($file) {
55     
56     //FindFile("pear/Config.php");
57     //require_once("Config.php");
58  
59     // List of all valid config options to be define()d which take "values" (not
60     // booleans). Needs to be categorised, and generally made a lot tidier. 
61     $_IC_VALID_VALUE = array
62         ('WIKI_NAME', 'ADMIN_USER', 'ADMIN_PASSWD',
63          'HTML_DUMP_SUFFIX', 'MAX_UPLOAD_SIZE', 'MINOR_EDIT_TIMEOUT',
64          'ACCESS_LOG', 'CACHE_CONTROL', 'CACHE_CONTROL_MAX_AGE',
65          'PASSWORD_LENGTH_MINIMUM', 'USER_AUTH_POLICY', 
66          'GROUP_METHOD',
67          'EDITING_POLICY', 'THEME', 'CHARSET',
68          'DEFAULT_LANGUAGE', 'WIKI_PGSRC', 'DEFAULT_WIKI_PGSRC',
69          'ALLOWED_PROTOCOLS', 'INLINE_IMAGES', 'SUBPAGE_SEPARATOR',
70          'INTERWIKI_MAP_FILE', 'COPYRIGHTPAGE_TITLE', 'COPYRIGHTPAGE_URL',
71          'AUTHORPAGE_TITLE', 'AUTHORPAGE_URL', 'SERVER_NAME', 'SERVER_PORT',
72          'SCRIPT_NAME', 'DATA_PATH', 'PHPWIKI_DIR', 'VIRTUAL_PATH',
73          'WIKI_NAME_REGEXP',
74          'PLUGIN_CACHED_DATABASE', 'PLUGIN_CACHED_FILENAME_PREFIX',
75          'PLUGIN_CACHED_HIGHWATER', 'PLUGIN_CACHED_LOWWATER', 'PLUGIN_CACHED_MAXLIFETIME',
76          'PLUGIN_CACHED_MAXARGLEN', 'PLUGIN_CACHED_IMGTYPES'
77          );
78
79     // Optional values which need to be defined.
80     // These are not defined in config-default.ini and empty if not defined.
81     $_IC_OPTIONAL_VALUE = array
82         ( 
83          'DEBUG', 
84          'LDAP_AUTH_HOST','LDAP_SET_OPTION','LDAP_BASE_DN', 'LDAP_AUTH_USER',
85          'LDAP_AUTH_PASSWORD','LDAP_SEARCH_FIELD','AUTH_USER_FILE','DBAUTH_AUTH_DSN',
86          'IMAP_AUTH_HOST', 'POP3_AUTH_HOST',
87          'AUTH_USER_FILE', 'AUTH_GROUP_FILE', 'AUTH_SESS_USER', 'AUTH_SESS_LEVEL',
88          'GOOGLE_LICENSE_KEY','FORTUNE_DIR',
89          );
90
91     // List of all valid config options to be define()d which take booleans.
92     $_IC_VALID_BOOL = array
93         ('ENABLE_USER_NEW', 'ENABLE_PAGEPERM', 'ENABLE_EDIT_TOOLBAR', 'JS_SEARCHREPLACE',
94          'USE_TAGLINES',
95          'ENABLE_REVERSE_DNS', 'ENCRYPTED_PASSWD', 'ZIPDUMP_AUTH', 
96          'ENABLE_RAW_HTML', 'STRICT_MAILABLE_PAGEDUMPS', 'COMPRESS_OUTPUT',
97          'WIKIDB_NOCACHE_MARKUP', 'ALLOW_ANON_USER', 'ALLOW_ANON_EDIT',
98          'ALLOW_BOGO_LOGIN', 'ALLOW_USER_PASSWORDS',
99          'AUTH_USER_FILE_STORABLE', 'ALLOW_HTTP_AUTH_LOGIN',
100          'ALLOW_USER_LOGIN', 'ALLOW_LDAP_LOGIN', 'ALLOW_IMAP_LOGIN',
101          'WARN_NONPUBLIC_INTERWIKIMAP', 'USE_PATH_INFO',
102          'DISABLE_HTTP_REDIRECT',
103          'PLUGIN_CACHED_USECACHE', 'PLUGIN_CACHED_FORCE_SYNCMAP'
104          );
105
106     if(!file_exists($file)){
107         trigger_error("Datasource file '$file' does not exist", E_USER_ERROR);
108         exit();
109     }
110          
111     $rs = @parse_ini_file($file);
112     $rsdef = @parse_ini_file(dirname(__FILE__)."/../config/config-default.ini");
113     foreach ($rsdef as $k => $v) {
114         if (defined($k))
115             $rs[$k] = constant($k);
116         elseif (!isset($rs[$k]))
117             $rs[$k] = $v;
118     }
119
120     foreach ($_IC_VALID_VALUE as $item) {
121         if (defined($item)) continue;
122         if (array_key_exists($item, $rs)) {
123             define($item, $rs[$item]);
124         //} elseif (array_key_exists($item, $rsdef)) {
125         //    define($item, $rsdef[$item]);
126         // calculate them later or not at all:
127         } elseif (in_array($item,array('DATABASE_PREFIX', 'SERVER_NAME', 'SERVER_PORT',
128                                        'SCRIPT_NAME', 'DATA_PATH', 'PHPWIKI_DIR', 'VIRTUAL_PATH',
129                                        'LDAP_AUTH_HOST','IMAP_AUTH_HOST','POP3_AUTH_HOST'))) 
130         {
131             ;
132         } else {
133             trigger_error(sprintf("missing config setting for %s",$item));
134         }
135     }
136
137     // Boolean options are slightly special - if they're set to any of
138     // '', 'false', '0', or 'no' (all case-insensitive) then the value will
139     // be a boolean false, otherwise if there is anything set it'll
140     // be true.
141     foreach ($_IC_VALID_BOOL as $item) {
142         if (defined($item)) continue;
143         if (array_key_exists($item, $rs)) {
144             $val = $rs[$item];
145         //} elseif (array_key_exists($item, $rsdef)) {
146         //    $val = $rsdef[$item];
147         } else {
148             $val = false; //trigger_error(sprintf("missing boolean config setting for %s",$item));
149         }
150         
151         // calculate them later: old or dynamic constants
152         if (!array_key_exists($item, $rs) and
153             in_array($item,array('USE_PATH_INFO', 'USE_DB_SESSION',
154                                  'ALLOW_HTTP_AUTH_LOGIN', 'ALLOW_LDAP_LOGIN',
155                                  'ALLOW_IMAP_LOGIN', 'ALLOW_USER_LOGIN',
156                                  'REQUIRE_SIGNIN_BEFORE_EDIT',
157                                  'WIKIDB_NOCACHE_MARKUP')))
158         {
159             ;
160         }
161         elseif (!$val) {
162             define($item, false);
163         }
164         elseif (strtolower($val) == 'false' ||
165                 strtolower($val) == 'no' ||
166                 $val == '' ||
167                 $val == false ||
168                 $val == '0') {
169             define($item, false);
170         }
171         else {
172             define($item, true);
173         }
174     }
175
176     // Special handling for some config options
177     if (!empty($rs['INCLUDE_PATH'])) {
178         ini_set('include_path', $rs['INCLUDE_PATH']);
179     }
180     if (!empty($rs['SESSION_SAVE_PATH'])) {
181         ini_set('session.save_path', $rs['SESSION_SAVE_PATH']);
182     }
183
184     // Database
185     global $DBParams;
186     $DBParams['dbtype'] = @$rs['DATABASE_TYPE'];
187     if (isset($rs['DATABASE_DSN']))
188         $DBParams['dsn'] = $rs['DATABASE_DSN'];
189     if (isset($rs['DATABASE_PREFIX']))
190         $DBParams['prefix'] = $rs['DATABASE_PREFIX'];
191     $DBParams['db_session_table'] = @$rs['DATABASE_SESSION_TABLE'];
192     $DBParams['dba_handler'] = @$rs['DATABASE_DBA_HANDLER'];
193     $DBParams['directory'] = @$rs['DATABASE_DIRECTORY'];
194     $DBParams['timeout'] = @$rs['DATABASE_TIMEOUT'];
195     if (!defined('USE_DB_SESSION') and $DBParams['db_session_table'] and 
196         in_array($DBParams['dbtype'],array('SQL','ADODB'/*,'dba'*/))) {
197         define('USE_DB_SESSION', true);
198     }
199
200     // Expiry stuff
201     global $ExpireParams;
202     $ExpireParams['major'] = array(
203                                    'max_age'  => @$rs['MAJOR_MAX_AGE'],
204                                    'min_age'  => @$rs['MAJOR_MIN_AGE'],
205                                    'min_keep' => @$rs['MAJOR_MIN_KEEP'],
206                                    'keep'     => @$rs['MAJOR_KEEP'],
207                                    'max_keep' => @$rs['MAJOR_MAX_KEEP']
208                                    );
209     $ExpireParams['minor'] = array(
210                                    'max_age'  => @$rs['MINOR_MAX_AGE'],
211                                    'min_age'  => @$rs['MINOR_MIN_AGE'],
212                                    'min_keep' => @$rs['MINOR_MIN_KEEP'],
213                                    'keep'     => @$rs['MINOR_KEEP'],
214                                    'max_keep' => @$rs['MINOR_MAX_KEEP']
215                                    );
216     $ExpireParams['author'] = array(
217                                     'max_age'  => @$rs['AUTHOR_MAX_AGE'],
218                                     'min_age'  => @$rs['AUTHOR_MIN_AGE'],
219                                     'min_keep' => @$rs['AUTHOR_MIN_KEEP'],
220                                     'keep'     => @$rs['AUTHOR_KEEP'],
221                                     'max_keep' => @$rs['AUTHOR_MAX_KEEP']
222                                     );
223
224     // User authentication
225     if (!isset($GLOBALS['USER_AUTH_ORDER']))
226         if (isset($rs['USER_AUTH_ORDER']))
227             $GLOBALS['USER_AUTH_ORDER'] = preg_split('/\s*:\s*/', $rs['USER_AUTH_ORDER']);
228         else 
229             $GLOBALS['USER_AUTH_ORDER'] = array("PersonalPage");
230
231     // LDAP bind options
232     global $LDAP_SET_OPTION;
233     if (isset($rs['LDAP_SET_OPTION'])) {
234         $optlist = preg_split('/\s*:\s*/', @$rs['LDAP_SET_OPTION']);
235         foreach ($optlist as $opt) {
236             $bits = preg_split('/\s*=\s*/', $opt, 2);
237             if (count($bits) == 2) {
238                 $LDAP_SET_OPTION[$bits[0]] = $bits[1];
239             }
240             else {
241                 // Possibly throw some sort of error?
242             }
243         }
244     }
245
246     // Now it's the external DB authentication stuff's turn
247     if (in_array('Db', $GLOBALS['USER_AUTH_ORDER']) && empty($rs['DBAUTH_AUTH_DSN'])) {
248         $rs['DBAUTH_AUTH_DSN'] = $DBParams['dsn'];
249     }
250     
251     global $DBAuthParams;
252     $DBAP_MAP = array('DBAUTH_AUTH_DSN' => 'auth_dsn',
253                       'DBAUTH_AUTH_CHECK' => 'auth_check',
254                       'DBAUTH_AUTH_USER_EXISTS' => 'auth_user_exists',
255                       'DBAUTH_AUTH_CRYPT_METHOD' => 'auth_crypt_method',
256                       'DBAUTH_AUTH_UPDATE' => 'auth_update',
257                       'DBAUTH_AUTH_CREATE' => 'auth_create',
258                       'DBAUTH_PREF_SELECT' => 'pref_select',
259                       'DBAUTH_PREF_UPDATE' => 'pref_update',
260                       'DBAUTH_IS_MEMBER' => 'is_member',
261                       'DBAUTH_GROUP_MEMBERS' => 'group_members',
262                       'DBAUTH_USER_GROUPS' => 'user_groups'
263                       );
264     foreach ($DBAP_MAP as $rskey => $apkey) {
265         if (isset($rs[$rskey])) {
266             $DBAuthParams[$apkey] = $rs[$rskey];
267         } elseif (isset($rsdef[$rskey])) {
268             $DBAuthParams[$apkey] = $rsdef[$rskey];
269         }
270     }
271
272     // optional values will be set to '' to simplify the logic.
273     foreach ($_IC_OPTIONAL_VALUE as $item) {
274         if (defined($item)) continue;
275         if (array_key_exists($item, $rs)) {
276             define($item, $rs[$item]);
277         } else 
278             define($item, '');
279     }
280
281     // Default Wiki pages to force loading from pgsrc
282     global $GenericPages;
283     $GenericPages = preg_split('/\s*:\s*/', @$rs['DEFAULT_WIKI_PAGES']);
284
285     // Wiki name regexp:  Should be a define(), but might needed to be changed at runtime
286     // (different LC_CHAR need different posix classes)
287     global $WikiNameRegexp;
288     $WikiNameRegexp = constant('WIKI_NAME_REGEXP');
289     if (!trim($WikiNameRegexp))
290        $WikiNameRegexp = '(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])';
291
292     // Another "too-tricky" redefine
293     global $KeywordLinkRegexp;
294     if (!isset($rs['KEYWORDS'])) $rs['KEYWORDS'] = "Category:Topic";
295     $keywords = preg_split('/\s*:\s*/', $rs['KEYWORDS']);
296     if (empty($keywords)) $keywords = array("Category","Topic");
297     $KeywordLinkRegexp = '(?<=' . implode('|^', $keywords) . ')[[:upper:]].*$';
298         
299     global $DisabledActions;
300     $DisabledActions = preg_split('/\s*:\s*/', @$rs['DISABLED_ACTIONS']);
301     
302     /*global $AllowedProtocols, $InlineImages;
303     $AllowedProtocols = constant("ALLOWED_PROTOCOLS");
304     $InlineImages = constant("INLINE_IMAGES");*/
305
306     global $PLUGIN_CACHED_IMGTYPES;
307     $PLUGIN_CACHED_IMGTYPES = preg_split('/\s*:\s*/', PLUGIN_CACHED_IMGTYPES);
308     if (!defined('PLUGIN_CACHED_CACHE_DIR')) {
309         if (!FindFile('/tmp/cache', 1))
310             mkdir('/tmp/cache', 777);
311         define('PLUGIN_CACHED_CACHE_DIR', FindFile('/tmp/cache',false,1)); // will throw an error
312     } else {
313         FindFile(PLUGIN_CACHED_CACHE_DIR);
314     }
315
316     fix_configs();
317 }
318
319 // moved from lib/config.php
320 function fix_configs() {
321     global $FieldSeparator, $charset, $WikiNameRegexp, $KeywordLinkRegexp, $AllActionPages;
322     global $DisabledActions, $HTTP_SERVER_VARS, $DBParams, $LANG;
323
324     // init FileFinder to add proper include paths
325     require_once(dirname(__FILE__)."/FileFinder.php");
326     FindFile("lib/interwiki.map",true);
327     
328     // "\x80"-"\x9f" (and "\x00" - "\x1f") are non-printing control
329     // chars in iso-8859-*
330     // $FieldSeparator = "\263"; // this is a superscript 3 in ISO-8859-1.
331     // $FieldSeparator = "\xFF"; // this byte should never appear in utf-8
332     // FIXME: get rid of constant. pref is dynamic and language specific
333     $charset = CHARSET;
334     if (isset($LANG) and in_array($LANG,array('ja','zh')))
335         $charset = 'utf-8';
336     if (strtolower($charset) == 'utf-8')
337         $FieldSeparator = "\xFF";
338     else
339         $FieldSeparator = "\x81";
340
341     if (!defined('DEFAULT_LANGUAGE'))
342         define('DEFAULT_LANGUAGE', 'en');
343     update_locale(isset($LANG) ? $LANG : DEFAULT_LANGUAGE);
344
345     // Set up (possibly fake) gettext()
346     //
347     if (!function_exists ('bindtextdomain')) {
348         $locale = array();
349
350         function gettext ($text) { 
351             global $locale;
352             if (!empty ($locale[$text]))
353                 return $locale[$text];
354             return $text;
355         }
356
357         function _ ($text) {
358             return gettext($text);
359         }
360     }
361     else {
362         // Working around really weird gettext problems: (4.3.2, 4.3.6 win)
363         // bindtextdomain() returns the current domain path.
364         // 1. If the script is not index.php but something like "de", on a different path
365         //    then bindtextdomain() fails, but after chdir to the correct path it will work okay.
366         // 2. But the weird error "Undefined variable: bindtextdomain" is generated then.
367         $bindtextdomain_path = FindFile("locale", false, true);
368         if (isWindows())
369             $bindtextdomain_path = str_replace("/","\\",$bindtextdomain_path);
370         $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain);
371         if ($bindtextdomain_real != $bindtextdomain_path) {
372             // this will happen with virtual_paths. chdir and try again.
373             chdir($bindtextdomain_path);
374             $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain);
375         }
376         textdomain("phpwiki");
377         if ($bindtextdomain_real != $bindtextdomain_path) { // change back
378             chdir($bindtextdomain_real . (isWindows() ? "\\.." : "/.."));
379         }
380     }
381
382     $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
383     $KeywordLinkRegexp = pcre_fix_posix_classes($KeywordLinkRegexp);
384
385     $AllActionPages = explode(':','AllPages:BackLinks:DebugInfo:EditMetaData:FindPage:FullRecentChanges:'
386                               .'FullTextSearch:FuzzyPages:InterWikiSearch:LikePages:MostPopular:'
387                               .'OrphanedPages:PageDump:PageHistory:PageInfo:RandomPage:RateIt:'
388                               .'RecentChanges:RecentEdits:RelatedChanges:TitleSearch:TranslateText:'
389                               .'UpLoad:UserPreferences:WantedPages:WhoIsOnline:'
390                               .'PhpWikiAdministration/Remove:'
391                               .'PhpWikiAdministration/Rename:PhpWikiAdministration/Replace:'
392                               .'PhpWikiAdministration/SetAcl:PhpWikiAdministration/Chown'
393                               );
394
395     //////////////////////////////////////////////////////////////////
396     // Autodetect URL settings:
397     //
398     if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
399     if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
400     if (!defined('SERVER_PROTOCOL')) {
401         if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
402             define('SERVER_PROTOCOL', 'http');
403         else
404             define('SERVER_PROTOCOL', 'https');
405     }
406
407     if (!defined('SCRIPT_NAME'))
408         define('SCRIPT_NAME', deduce_script_name());
409
410     if (!defined('USE_PATH_INFO')) {
411         if (isCGI())
412             define('USE_PATH_INFO', false);
413         else {
414             /*
415              * If SCRIPT_NAME does not look like php source file,
416              * or user cgi we assume that php is getting run by an
417              * action handler in /cgi-bin.  In this case,
418              * I think there is no way to get Apache to pass
419              * useful PATH_INFO to the php script (PATH_INFO
420              * is used to the the php interpreter where the
421              * php script is...)
422              */
423             switch (php_sapi_name()) {
424             case 'apache':
425             case 'apache2handler':
426                 define('USE_PATH_INFO', true);
427                 break;
428             case 'cgi':
429             case 'apache2filter':
430                 define('USE_PATH_INFO', false);
431                 break;
432             default:
433                 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', SCRIPT_NAME));
434                 break;
435             }
436         }
437     }
438      
439     // If user has not defined PHPWIKI_DIR, and we need it
440     if (!defined('PHPWIKI_DIR') and !file_exists("themes/default")) {
441         $themes_dir = FindFile("themes");
442         define('PHPWIKI_DIR', dirname($themes_dir));
443     }
444         
445     if (!defined('VIRTUAL_PATH')) {
446         // We'd like to auto-detect when the cases where apaches
447         // 'Action' directive (or similar means) is used to
448         // redirect page requests to a cgi-handler.
449         //
450         // In cases like this, requests for e.g. /wiki/HomePage
451         // get redirected to a cgi-script called, say,
452         // /path/to/wiki/index.php.  The script gets all
453         // of /wiki/HomePage as it's PATH_INFO.
454         //
455         // The problem is:
456         //   How to detect when this has happened reliably?
457         //   How to pick out the "virtual path" (in this case '/wiki')?
458         //
459         // (Another time an redirect might occur is to a DirectoryIndex
460         // -- the requested URI is '/wikidir/', the request gets
461         // passed to '/wikidir/index.php'.  In this case, the
462         // proper VIRTUAL_PATH is '/wikidir/index.php', since the
463         // pages will appear at e.g. '/wikidir/index.php/HomePage'.
464         //
465
466         $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
467         if (USE_PATH_INFO and isset($REDIRECT_URL)
468             and ! IsProbablyRedirectToIndex()) {
469             // FIXME: This is a hack, and won't work if the requested
470             // pagename has a slash in it.
471             $temp = strtr(dirname($REDIRECT_URL . 'x'),"\\",'/');
472             if ( ($temp == '/') || ($temp == '\\') )
473                 $temp = '';
474             define('VIRTUAL_PATH', $temp);
475         } else {
476             define('VIRTUAL_PATH', SCRIPT_NAME);
477         }
478     }
479
480     // If user has not defined DATA_PATH, we want to use relative URLs.
481     if (!defined('DATA_PATH')) {
482         // fix similar to the one suggested by jkalmbach for 
483         // installations in the webrootdir, like "http://phpwiki.org/HomePage"
484         $temp = dirname(SCRIPT_NAME);
485         if ( ($temp == '/') || ($temp == '\\') )
486             $temp = '';
487         define('DATA_PATH', $temp);
488         /*
489         if (USE_PATH_INFO)
490             define('DATA_PATH', '..');
491         */
492     }
493
494     if (SERVER_PORT
495         && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
496         define('SERVER_URL',
497                SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
498     }
499     else {
500         define('SERVER_URL',
501                SERVER_PROTOCOL . '://' . SERVER_NAME);
502     }
503
504     if (VIRTUAL_PATH != SCRIPT_NAME) {
505         // Apache action handlers are used.
506         define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
507     }
508     else
509         define('PATH_INFO_PREFIX', '/');
510
511     define('PHPWIKI_BASE_URL',
512            SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
513
514     // Detect PrettyWiki setup (not loading index.php directly)
515     // $SCRIPT_FILENAME should be the same as __FILE__ in index.php
516     if (!isset($SCRIPT_FILENAME))
517         $SCRIPT_FILENAME = @$HTTP_SERVER_VARS['SCRIPT_FILENAME'];
518     if (!isset($SCRIPT_FILENAME))
519         $SCRIPT_FILENAME = @$HTTP_ENV_VARS['SCRIPT_FILENAME'];
520     if (!isset($SCRIPT_FILENAME))
521         $SCRIPT_FILENAME = dirname(__FILE__.'/../') . '/index.php';
522     if (isWindows())
523         $SCRIPT_FILENAME = strtr($SCRIPT_FILENAME,'/','\\');
524     define('SCRIPT_FILENAME',$SCRIPT_FILENAME);
525
526     //////////////////////////////////////////////////////////////////
527     // Select database
528     //
529     if (empty($DBParams['dbtype']))
530         $DBParams['dbtype'] = 'dba';
531
532     if (!defined('THEME'))
533         define('THEME', 'default');
534
535     if (!defined('WIKI_NAME'))
536         define('WIKI_NAME', _("An unnamed PhpWiki"));
537
538     if (!defined('HOME_PAGE'))
539         define('HOME_PAGE', _("HomePage"));
540
541     // FIXME: delete
542     // Access log
543     if (!defined('ACCESS_LOG'))
544         define('ACCESS_LOG', '');
545
546     // FIXME: delete
547     // Get remote host name, if apache hasn't done it for us
548     if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
549         $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
550
551     // check whether the crypt() function is needed and present
552     if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
553         $error = sprintf(_("Encrypted passwords cannot be used: %s."),
554                          "'function crypt()' not available in this version of php");
555         trigger_error($error);
556     }
557
558     if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
559         trigger_error(_("The admin password cannot be empty. Please update your config/config.ini"));
560
561     if (defined('USE_DB_SESSION') and USE_DB_SESSION) {
562         if (! $DBParams['db_session_table'] ) {
563             trigger_error(_("Empty db_session_table. Turn USE_DB_SESSION off or define the table name."), 
564                           E_USER_ERROR);
565             // this is flawed. constants cannot be changed.
566             define('USE_DB_SESSION',false);
567             $DBParams['db_session_table'] = @$DBParams['prefix'] . 'session';
568         }
569     } else {
570         // default: true (since v1.3.8)
571         if (!defined('USE_DB_SESSION'))
572             define('USE_DB_SESSION',true);
573     }
574     // legacy:
575     if (!defined('ENABLE_USER_NEW')) define('ENABLE_USER_NEW',true);
576     if (!defined('ALLOW_USER_LOGIN'))
577         define('ALLOW_USER_LOGIN', defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
578     if (!defined('ALLOW_ANON_USER')) define('ALLOW_ANON_USER', true); 
579     if (!defined('ALLOW_ANON_EDIT')) define('ALLOW_ANON_EDIT', false); 
580     if (!defined('REQUIRE_SIGNIN_BEFORE_EDIT')) define('REQUIRE_SIGNIN_BEFORE_EDIT', ! ALLOW_ANON_EDIT);
581     if (!defined('ALLOW_BOGO_LOGIN')) define('ALLOW_BOGO_LOGIN', true);
582     if (!defined('ALLOW_LDAP_LOGIN')) define('ALLOW_LDAP_LOGIN', defined('LDAP_AUTH_HOST'));
583     if (!defined('ALLOW_IMAP_LOGIN')) define('ALLOW_IMAP_LOGIN', defined('IMAP_AUTH_HOST'));
584
585     if (ALLOW_USER_LOGIN and !empty($DBAuthParams) and empty($DBAuthParams['auth_dsn'])) {
586         if (isset($DBParams['dsn']))
587             $DBAuthParams['auth_dsn'] = $DBParams['dsn'];
588     }
589 }
590
591 // $Log: not supported by cvs2svn $
592 // Revision 1.35  2004/06/15 09:15:52  rurban
593 // IMPORTANT: fixed passwd handling for passwords stored in prefs:
594 //   fix encrypted usage, actually store and retrieve them from db
595 //   fix bogologin with passwd set.
596 // fix php crashes with call-time pass-by-reference (references wrongly used
597 //   in declaration AND call). This affected mainly Apache2 and IIS.
598 //   (Thanks to John Cole to detect this!)
599 //
600 // Revision 1.34  2004/06/13 13:54:25  rurban
601 // Catch fatals on the four dump calls (as file and zip, as html and mimified)
602 // FoafViewer: Check against external requirements, instead of fatal.
603 // Change output for xhtmldumps: using file:// urls to the local fs.
604 // Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
605 // Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
606 //
607 // Revision 1.33  2004/06/08 19:48:16  rurban
608 // fixed foreign setup: no ugly skipped msg for the GenericPages, load english actionpages if translated not found
609 //
610 // Revision 1.32  2004/06/08 10:54:46  rurban
611 // better acl dump representation, read back acl and owner
612 //
613 // Revision 1.31  2004/06/06 16:58:51  rurban
614 // added more required ActionPages for foreign languages
615 // install now english ActionPages if no localized are found. (again)
616 // fixed default anon user level to be 0, instead of -1
617 //   (wrong "required administrator to view this page"...)
618 //
619 // Revision 1.30  2004/06/04 12:40:21  rurban
620 // Restrict valid usernames to prevent from attacks against external auth or compromise
621 // possible holes.
622 // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
623 // Fxied more warnings
624 //
625 // Revision 1.29  2004/06/04 11:58:38  rurban
626 // added USE_TAGLINES
627 //
628 // Revision 1.28  2004/06/03 20:42:49  rurban
629 // fixed bad warning #964850
630 //
631 // Revision 1.27  2004/06/03 10:18:19  rurban
632 // fix FileUser locking issues, new config ENABLE_PAGEPERM
633 //
634 // Revision 1.26  2004/06/02 18:01:45  rurban
635 // init global FileFinder to add proper include paths at startup
636 //   adds PHPWIKI_DIR if started from another dir, lib/pear also
637 // fix slashify for Windows
638 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
639 //
640 // Revision 1.25  2004/05/27 17:49:05  rurban
641 // renamed DB_Session to DbSession (in CVS also)
642 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
643 // remove leading slash in error message
644 // added force_unlock parameter to File_Passwd (no return on stale locks)
645 // fixed adodb session AffectedRows
646 // added FileFinder helpers to unify local filenames and DATA_PATH names
647 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
648 //
649 // Revision 1.24  2004/05/18 13:33:13  rurban
650 // we already have a CGI function
651 //
652 // Revision 1.23  2004/05/17 17:43:29  rurban
653 // CGI: no PATH_INFO fix
654 //
655 // Revision 1.22  2004/05/16 22:07:35  rurban
656 // check more config-default and predefined constants
657 // various PagePerm fixes:
658 //   fix default PagePerms, esp. edit and view for Bogo and Password users
659 //   implemented Creator and Owner
660 //   BOGOUSERS renamed to BOGOUSER
661 // fixed syntax errors in signin.tmpl
662 //
663 // Revision 1.21  2004/05/08 22:55:12  rurban
664 // Fixed longstanding sf.net:demo problem. endless loop, caused by an empty definition of
665 // WIKI_NAME_REGEXP. Exactly this constant wasn't checked for its default setting.
666 //
667 // Revision 1.20  2004/05/08 20:21:00  rurban
668 // remove php tags in Log
669 //
670 // Revision 1.19  2004/05/08 19:55:29  rurban
671 // support <span>inlined plugin-result</span>:
672 //   if the plugin is parsed inside a line, use <span> instead of
673 //   <div tightenable top bottom>
674 //   e.g. for "This is the current Phpwiki <plugin SystemInfo version> version.
675 //
676 // Revision 1.18  2004/05/08 16:58:19  rurban
677 // don't ignore some false config values (e.g. USE_PATH_INFO false was ignored)
678 //
679 // Revision 1.17  2004/05/06 19:26:15  rurban
680 // improve stability, trying to find the InlineParser endless loop on sf.net
681 //
682 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
683 //
684 // Revision 1.16  2004/05/02 15:10:05  rurban
685 // new finally reliable way to detect if /index.php is called directly
686 //   and if to include lib/main.php
687 // new global AllActionPages
688 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
689 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
690 // PageGroupTestOne => subpages
691 // renamed PhpWikiRss to PhpWikiRecentChanges
692 // more docs, default configs, ...
693 //
694 // Revision 1.15  2004/05/01 15:59:29  rurban
695 // more php-4.0.6 compatibility: superglobals
696 //
697 // Revision 1.14  2004/04/29 23:25:12  rurban
698 // re-ordered locale init (as in 1.3.9)
699 // fixed loadfile with subpages, and merge/restore anyway
700 //   (sf.net bug #844188)
701 //
702 // Revision 1.13  2004/04/29 21:54:05  rurban
703 // typo
704 //
705 // Revision 1.12  2004/04/27 16:16:27  rurban
706 // more subtle config problems with defaults
707 //
708 // Revision 1.11  2004/04/26 20:44:34  rurban
709 // locking table specific for better databases
710 //
711 // Revision 1.10  2004/04/26 13:22:32  rurban
712 // calculate bool old or dynamic constants later
713 //
714 // Revision 1.9  2004/04/26 12:15:01  rurban
715 // check default config values
716 //
717 // Revision 1.8  2004/04/23 16:55:59  zorloc
718 // If using Db auth and DBAUTH_AUTH_DSN is empty set DBAUTH_AUTH_DSN to $DBParams['dsn']
719 //
720 // Revision 1.7  2004/04/20 22:26:27  zorloc
721 // Removed Pear_Config for parse_ini_file().
722 //
723 // Revision 1.6  2004/04/20 18:10:27  rurban
724 // config refactoring:
725 //   FileFinder is needed for WikiFarm scripts calling index.php
726 //   config run-time calls moved to lib/IniConfig.php:fix_configs()
727 //   added PHPWIKI_DIR smart-detection code (Theme finder)
728 //   moved FileFind to lib/FileFinder.php
729 //   cleaned lib/config.php
730 //
731 // Revision 1.5  2004/04/20 17:21:57  rurban
732 // WikiFarm code: honor predefined constants
733 //
734 // Revision 1.4  2004/04/20 17:08:19  rurban
735 // Some IniConfig fixes: prepend our private lib/pear dir
736 //   switch from " to ' in the auth statements
737 //   use error handling.
738 // WikiUserNew changes for the new "'$variable'" syntax
739 //   in the statements
740 // TODO: optimization to put config vars into the session.
741 //
742
743 // (c-file-style: "gnu")
744 // Local Variables:
745 // mode: php
746 // tab-width: 8
747 // c-basic-offset: 4
748 // c-hanging-comment-ender-p: nil
749 // indent-tabs-mode: nil
750 // End:   
751 ?>