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