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