]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/IniConfig.php
new TEMP_DIR for ziplib
[SourceForge/phpwiki.git] / lib / IniConfig.php
1 <?php
2 rcs_id('$Id: IniConfig.php,v 1.37 2004-06-19 12:32: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', 'TEMP_DIR',
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             if (!FindFile('/tmp', 1)) {
311                 mkdir('/tmp', 777);
312             }
313             mkdir('/tmp/cache', 777);
314         }
315         define('PLUGIN_CACHED_CACHE_DIR', FindFile('/tmp/cache',false,1)); // will throw an error
316     } else {
317         FindFile(PLUGIN_CACHED_CACHE_DIR);
318     }
319
320     fix_configs();
321 }
322
323 // moved from lib/config.php
324 function fix_configs() {
325     global $FieldSeparator, $charset, $WikiNameRegexp, $KeywordLinkRegexp, $AllActionPages;
326     global $DisabledActions, $HTTP_SERVER_VARS, $DBParams, $LANG;
327
328     // init FileFinder to add proper include paths
329     require_once(dirname(__FILE__)."/FileFinder.php");
330     FindFile("lib/interwiki.map",true);
331     
332     // "\x80"-"\x9f" (and "\x00" - "\x1f") are non-printing control
333     // chars in iso-8859-*
334     // $FieldSeparator = "\263"; // this is a superscript 3 in ISO-8859-1.
335     // $FieldSeparator = "\xFF"; // this byte should never appear in utf-8
336     // FIXME: get rid of constant. pref is dynamic and language specific
337     $charset = CHARSET;
338     if (isset($LANG) and in_array($LANG,array('ja','zh')))
339         $charset = 'utf-8';
340     if (strtolower($charset) == 'utf-8')
341         $FieldSeparator = "\xFF";
342     else
343         $FieldSeparator = "\x81";
344
345     if (!defined('DEFAULT_LANGUAGE'))
346         define('DEFAULT_LANGUAGE', 'en');
347     update_locale(isset($LANG) ? $LANG : DEFAULT_LANGUAGE);
348
349     // Set up (possibly fake) gettext()
350     //
351     if (!function_exists ('bindtextdomain')) {
352         $locale = array();
353
354         function gettext ($text) { 
355             global $locale;
356             if (!empty ($locale[$text]))
357                 return $locale[$text];
358             return $text;
359         }
360
361         function _ ($text) {
362             return gettext($text);
363         }
364     }
365     else {
366         // Working around really weird gettext problems: (4.3.2, 4.3.6 win)
367         // bindtextdomain() returns the current domain path.
368         // 1. If the script is not index.php but something like "de", on a different path
369         //    then bindtextdomain() fails, but after chdir to the correct path it will work okay.
370         // 2. But the weird error "Undefined variable: bindtextdomain" is generated then.
371         $bindtextdomain_path = FindFile("locale", false, true);
372         if (isWindows())
373             $bindtextdomain_path = str_replace("/","\\",$bindtextdomain_path);
374         $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain);
375         if ($bindtextdomain_real != $bindtextdomain_path) {
376             // this will happen with virtual_paths. chdir and try again.
377             chdir($bindtextdomain_path);
378             $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain);
379         }
380         textdomain("phpwiki");
381         if ($bindtextdomain_real != $bindtextdomain_path) { // change back
382             chdir($bindtextdomain_real . (isWindows() ? "\\.." : "/.."));
383         }
384     }
385
386     $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
387     $KeywordLinkRegexp = pcre_fix_posix_classes($KeywordLinkRegexp);
388
389     $AllActionPages = explode(':','AllPages:BackLinks:DebugInfo:EditMetaData:FindPage:FullRecentChanges:'
390                               .'FullTextSearch:FuzzyPages:InterWikiSearch:LikePages:MostPopular:'
391                               .'OrphanedPages:PageDump:PageHistory:PageInfo:RandomPage:RateIt:'
392                               .'RecentChanges:RecentEdits:RelatedChanges:TitleSearch:TranslateText:'
393                               .'UpLoad:UserPreferences:WantedPages:WhoIsOnline:'
394                               .'PhpWikiAdministration/Remove:'
395                               .'PhpWikiAdministration/Rename:PhpWikiAdministration/Replace:'
396                               .'PhpWikiAdministration/SetAcl:PhpWikiAdministration/Chown'
397                               );
398
399     //////////////////////////////////////////////////////////////////
400     // Autodetect URL settings:
401     //
402     if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
403     if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
404     if (!defined('SERVER_PROTOCOL')) {
405         if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
406             define('SERVER_PROTOCOL', 'http');
407         else
408             define('SERVER_PROTOCOL', 'https');
409     }
410
411     if (!defined('SCRIPT_NAME'))
412         define('SCRIPT_NAME', deduce_script_name());
413
414     if (!defined('USE_PATH_INFO')) {
415         if (isCGI())
416             define('USE_PATH_INFO', false);
417         else {
418             /*
419              * If SCRIPT_NAME does not look like php source file,
420              * or user cgi we assume that php is getting run by an
421              * action handler in /cgi-bin.  In this case,
422              * I think there is no way to get Apache to pass
423              * useful PATH_INFO to the php script (PATH_INFO
424              * is used to the the php interpreter where the
425              * php script is...)
426              */
427             switch (php_sapi_name()) {
428             case 'apache':
429             case 'apache2handler':
430                 define('USE_PATH_INFO', true);
431                 break;
432             case 'cgi':
433             case 'apache2filter':
434                 define('USE_PATH_INFO', false);
435                 break;
436             default:
437                 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', SCRIPT_NAME));
438                 break;
439             }
440         }
441     }
442      
443     // If user has not defined PHPWIKI_DIR, and we need it
444     if (!defined('PHPWIKI_DIR') and !file_exists("themes/default")) {
445         $themes_dir = FindFile("themes");
446         define('PHPWIKI_DIR', dirname($themes_dir));
447     }
448         
449     if (!defined('VIRTUAL_PATH')) {
450         // We'd like to auto-detect when the cases where apaches
451         // 'Action' directive (or similar means) is used to
452         // redirect page requests to a cgi-handler.
453         //
454         // In cases like this, requests for e.g. /wiki/HomePage
455         // get redirected to a cgi-script called, say,
456         // /path/to/wiki/index.php.  The script gets all
457         // of /wiki/HomePage as it's PATH_INFO.
458         //
459         // The problem is:
460         //   How to detect when this has happened reliably?
461         //   How to pick out the "virtual path" (in this case '/wiki')?
462         //
463         // (Another time an redirect might occur is to a DirectoryIndex
464         // -- the requested URI is '/wikidir/', the request gets
465         // passed to '/wikidir/index.php'.  In this case, the
466         // proper VIRTUAL_PATH is '/wikidir/index.php', since the
467         // pages will appear at e.g. '/wikidir/index.php/HomePage'.
468         //
469
470         $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
471         if (USE_PATH_INFO and isset($REDIRECT_URL)
472             and ! IsProbablyRedirectToIndex()) {
473             // FIXME: This is a hack, and won't work if the requested
474             // pagename has a slash in it.
475             $temp = strtr(dirname($REDIRECT_URL . 'x'),"\\",'/');
476             if ( ($temp == '/') || ($temp == '\\') )
477                 $temp = '';
478             define('VIRTUAL_PATH', $temp);
479         } else {
480             define('VIRTUAL_PATH', SCRIPT_NAME);
481         }
482     }
483
484     // If user has not defined DATA_PATH, we want to use relative URLs.
485     if (!defined('DATA_PATH')) {
486         // fix similar to the one suggested by jkalmbach for 
487         // installations in the webrootdir, like "http://phpwiki.org/HomePage"
488         $temp = dirname(SCRIPT_NAME);
489         if ( ($temp == '/') || ($temp == '\\') )
490             $temp = '';
491         define('DATA_PATH', $temp);
492         /*
493         if (USE_PATH_INFO)
494             define('DATA_PATH', '..');
495         */
496     }
497
498     if (SERVER_PORT
499         && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
500         define('SERVER_URL',
501                SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
502     }
503     else {
504         define('SERVER_URL',
505                SERVER_PROTOCOL . '://' . SERVER_NAME);
506     }
507
508     if (VIRTUAL_PATH != SCRIPT_NAME) {
509         // Apache action handlers are used.
510         define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
511     }
512     else
513         define('PATH_INFO_PREFIX', '/');
514
515     define('PHPWIKI_BASE_URL',
516            SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
517
518     // Detect PrettyWiki setup (not loading index.php directly)
519     // $SCRIPT_FILENAME should be the same as __FILE__ in index.php
520     if (!isset($SCRIPT_FILENAME))
521         $SCRIPT_FILENAME = @$HTTP_SERVER_VARS['SCRIPT_FILENAME'];
522     if (!isset($SCRIPT_FILENAME))
523         $SCRIPT_FILENAME = @$HTTP_ENV_VARS['SCRIPT_FILENAME'];
524     if (!isset($SCRIPT_FILENAME))
525         $SCRIPT_FILENAME = dirname(__FILE__.'/../') . '/index.php';
526     if (isWindows())
527         $SCRIPT_FILENAME = strtr($SCRIPT_FILENAME,'/','\\');
528     define('SCRIPT_FILENAME',$SCRIPT_FILENAME);
529
530     //////////////////////////////////////////////////////////////////
531     // Select database
532     //
533     if (empty($DBParams['dbtype']))
534         $DBParams['dbtype'] = 'dba';
535
536     if (!defined('THEME'))
537         define('THEME', 'default');
538
539     if (!defined('WIKI_NAME'))
540         define('WIKI_NAME', _("An unnamed PhpWiki"));
541
542     if (!defined('HOME_PAGE'))
543         define('HOME_PAGE', _("HomePage"));
544
545     // FIXME: delete
546     // Access log
547     if (!defined('ACCESS_LOG'))
548         define('ACCESS_LOG', '');
549
550     // FIXME: delete
551     // Get remote host name, if apache hasn't done it for us
552     if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
553         $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
554
555     // check whether the crypt() function is needed and present
556     if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
557         $error = sprintf(_("Encrypted passwords cannot be used: %s."),
558                          "'function crypt()' not available in this version of php");
559         trigger_error($error);
560     }
561
562     if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
563         trigger_error(_("The admin password cannot be empty. Please update your config/config.ini"));
564
565     if (defined('USE_DB_SESSION') and USE_DB_SESSION) {
566         if (! $DBParams['db_session_table'] ) {
567             trigger_error(_("Empty db_session_table. Turn USE_DB_SESSION off or define the table name."), 
568                           E_USER_ERROR);
569             // this is flawed. constants cannot be changed.
570             define('USE_DB_SESSION',false);
571             $DBParams['db_session_table'] = @$DBParams['prefix'] . 'session';
572         }
573     } else {
574         // default: true (since v1.3.8)
575         if (!defined('USE_DB_SESSION'))
576             define('USE_DB_SESSION',true);
577     }
578     // legacy:
579     if (!defined('ENABLE_USER_NEW')) define('ENABLE_USER_NEW',true);
580     if (!defined('ALLOW_USER_LOGIN'))
581         define('ALLOW_USER_LOGIN', defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
582     if (!defined('ALLOW_ANON_USER')) define('ALLOW_ANON_USER', true); 
583     if (!defined('ALLOW_ANON_EDIT')) define('ALLOW_ANON_EDIT', false); 
584     if (!defined('REQUIRE_SIGNIN_BEFORE_EDIT')) define('REQUIRE_SIGNIN_BEFORE_EDIT', ! ALLOW_ANON_EDIT);
585     if (!defined('ALLOW_BOGO_LOGIN')) define('ALLOW_BOGO_LOGIN', true);
586     if (!defined('ALLOW_LDAP_LOGIN')) define('ALLOW_LDAP_LOGIN', defined('LDAP_AUTH_HOST'));
587     if (!defined('ALLOW_IMAP_LOGIN')) define('ALLOW_IMAP_LOGIN', defined('IMAP_AUTH_HOST'));
588
589     if (ALLOW_USER_LOGIN and !empty($DBAuthParams) and empty($DBAuthParams['auth_dsn'])) {
590         if (isset($DBParams['dsn']))
591             $DBAuthParams['auth_dsn'] = $DBParams['dsn'];
592     }
593 }
594
595 // $Log: not supported by cvs2svn $
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 ?>