]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/IniConfig.php
removed USE_TAGLINES constant
[SourceForge/phpwiki.git] / lib / IniConfig.php
1 <?php
2 rcs_id('$Id: IniConfig.php,v 1.40 2004-06-22 07:12:48 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          '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         // will throw an error if not exists.
313         define('PLUGIN_CACHED_CACHE_DIR', FindFile('/tmp/cache',false,1)); 
314     } else {
315         // will throw an error if not exists.
316         FindFile(PLUGIN_CACHED_CACHE_DIR);
317     }
318
319     fix_configs();
320 }
321
322 // moved from lib/config.php
323 function fix_configs() {
324     global $FieldSeparator, $charset, $WikiNameRegexp, $KeywordLinkRegexp, $AllActionPages;
325     global $DisabledActions, $HTTP_SERVER_VARS, $DBParams, $LANG;
326
327     // init FileFinder to add proper include paths
328     require_once(dirname(__FILE__)."/FileFinder.php");
329     FindFile("lib/interwiki.map",true);
330     
331     // "\x80"-"\x9f" (and "\x00" - "\x1f") are non-printing control
332     // chars in iso-8859-*
333     // $FieldSeparator = "\263"; // this is a superscript 3 in ISO-8859-1.
334     // $FieldSeparator = "\xFF"; // this byte should never appear in utf-8
335     // FIXME: get rid of constant. pref is dynamic and language specific
336     $charset = CHARSET;
337     if (isset($LANG) and in_array($LANG,array('ja','zh')))
338         $charset = 'utf-8';
339     if (strtolower($charset) == 'utf-8')
340         $FieldSeparator = "\xFF";
341     else
342         $FieldSeparator = "\x81";
343
344     if (!defined('DEFAULT_LANGUAGE'))
345         define('DEFAULT_LANGUAGE', 'en');
346     update_locale(isset($LANG) ? $LANG : DEFAULT_LANGUAGE);
347
348     // Set up (possibly fake) gettext()
349     //
350     if (!function_exists ('bindtextdomain')) {
351         $locale = array();
352
353         function gettext ($text) { 
354             global $locale;
355             if (!empty ($locale[$text]))
356                 return $locale[$text];
357             return $text;
358         }
359
360         function _ ($text) {
361             return gettext($text);
362         }
363     }
364     else {
365         // Working around really weird gettext problems: (4.3.2, 4.3.6 win)
366         // bindtextdomain() returns the current domain path.
367         // 1. If the script is not index.php but something like "de", on a different path
368         //    then bindtextdomain() fails, but after chdir to the correct path it will work okay.
369         // 2. But the weird error "Undefined variable: bindtextdomain" is generated then.
370         $bindtextdomain_path = FindFile("locale", false, true);
371         if (isWindows())
372             $bindtextdomain_path = str_replace("/","\\",$bindtextdomain_path);
373         $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain);
374         if ($bindtextdomain_real != $bindtextdomain_path) {
375             // this will happen with virtual_paths. chdir and try again.
376             chdir($bindtextdomain_path);
377             $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain);
378         }
379         textdomain("phpwiki");
380         if ($bindtextdomain_real != $bindtextdomain_path) { // change back
381             chdir($bindtextdomain_real . (isWindows() ? "\\.." : "/.."));
382         }
383     }
384
385     $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
386     $KeywordLinkRegexp = pcre_fix_posix_classes($KeywordLinkRegexp);
387
388     $AllActionPages = explode(':','AllPages:BackLinks:DebugInfo:EditMetaData:FindPage:FullRecentChanges:'
389                               .'FullTextSearch:FuzzyPages:InterWikiSearch:LikePages:MostPopular:'
390                               .'OrphanedPages:PageDump:PageHistory:PageInfo:RandomPage:RateIt:'
391                               .'RecentChanges:RecentEdits:RelatedChanges:TitleSearch:TranslateText:'
392                               .'UpLoad:UserPreferences:WantedPages:WhoIsOnline:'
393                               .'PhpWikiAdministration/Remove:'
394                               .'PhpWikiAdministration/Rename:PhpWikiAdministration/Replace:'
395                               .'PhpWikiAdministration/SetAcl:PhpWikiAdministration/Chown'
396                               );
397
398     //////////////////////////////////////////////////////////////////
399     // Autodetect URL settings:
400     //
401     if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
402     if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
403     if (!defined('SERVER_PROTOCOL')) {
404         if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
405             define('SERVER_PROTOCOL', 'http');
406         else
407             define('SERVER_PROTOCOL', 'https');
408     }
409
410     if (!defined('SCRIPT_NAME'))
411         define('SCRIPT_NAME', deduce_script_name());
412
413     if (!defined('USE_PATH_INFO')) {
414         if (isCGI())
415             define('USE_PATH_INFO', false);
416         else {
417             /*
418              * If SCRIPT_NAME does not look like php source file,
419              * or user cgi we assume that php is getting run by an
420              * action handler in /cgi-bin.  In this case,
421              * I think there is no way to get Apache to pass
422              * useful PATH_INFO to the php script (PATH_INFO
423              * is used to the the php interpreter where the
424              * php script is...)
425              */
426             switch (php_sapi_name()) {
427             case 'apache':
428             case 'apache2handler':
429                 define('USE_PATH_INFO', true);
430                 break;
431             case 'cgi':
432             case 'apache2filter':
433                 define('USE_PATH_INFO', false);
434                 break;
435             default:
436                 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', SCRIPT_NAME));
437                 break;
438             }
439         }
440     }
441      
442     // If user has not defined PHPWIKI_DIR, and we need it
443     if (!defined('PHPWIKI_DIR') and !file_exists("themes/default")) {
444         $themes_dir = FindFile("themes");
445         define('PHPWIKI_DIR', dirname($themes_dir));
446     }
447         
448     if (!defined('VIRTUAL_PATH')) {
449         // We'd like to auto-detect when the cases where apaches
450         // 'Action' directive (or similar means) is used to
451         // redirect page requests to a cgi-handler.
452         //
453         // In cases like this, requests for e.g. /wiki/HomePage
454         // get redirected to a cgi-script called, say,
455         // /path/to/wiki/index.php.  The script gets all
456         // of /wiki/HomePage as it's PATH_INFO.
457         //
458         // The problem is:
459         //   How to detect when this has happened reliably?
460         //   How to pick out the "virtual path" (in this case '/wiki')?
461         //
462         // (Another time an redirect might occur is to a DirectoryIndex
463         // -- the requested URI is '/wikidir/', the request gets
464         // passed to '/wikidir/index.php'.  In this case, the
465         // proper VIRTUAL_PATH is '/wikidir/index.php', since the
466         // pages will appear at e.g. '/wikidir/index.php/HomePage'.
467         //
468
469         $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
470         if (USE_PATH_INFO and isset($REDIRECT_URL)
471             and ! IsProbablyRedirectToIndex()) {
472             // FIXME: This is a hack, and won't work if the requested
473             // pagename has a slash in it.
474             $temp = strtr(dirname($REDIRECT_URL . 'x'),"\\",'/');
475             if ( ($temp == '/') || ($temp == '\\') )
476                 $temp = '';
477             define('VIRTUAL_PATH', $temp);
478         } else {
479             define('VIRTUAL_PATH', SCRIPT_NAME);
480         }
481     }
482
483     // If user has not defined DATA_PATH, we want to use relative URLs.
484     if (!defined('DATA_PATH')) {
485         // fix similar to the one suggested by jkalmbach for 
486         // installations in the webrootdir, like "http://phpwiki.org/HomePage"
487         $temp = dirname(SCRIPT_NAME);
488         if ( ($temp == '/') || ($temp == '\\') )
489             $temp = '';
490         define('DATA_PATH', $temp);
491         /*
492         if (USE_PATH_INFO)
493             define('DATA_PATH', '..');
494         */
495     }
496
497     if (SERVER_PORT
498         && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
499         define('SERVER_URL',
500                SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
501     }
502     else {
503         define('SERVER_URL',
504                SERVER_PROTOCOL . '://' . SERVER_NAME);
505     }
506
507     if (VIRTUAL_PATH != SCRIPT_NAME) {
508         // Apache action handlers are used.
509         define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
510     }
511     else
512         define('PATH_INFO_PREFIX', '/');
513
514     define('PHPWIKI_BASE_URL',
515            SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
516
517     // Detect PrettyWiki setup (not loading index.php directly)
518     // $SCRIPT_FILENAME should be the same as __FILE__ in index.php
519     if (!isset($SCRIPT_FILENAME))
520         $SCRIPT_FILENAME = @$HTTP_SERVER_VARS['SCRIPT_FILENAME'];
521     if (!isset($SCRIPT_FILENAME))
522         $SCRIPT_FILENAME = @$HTTP_ENV_VARS['SCRIPT_FILENAME'];
523     if (!isset($SCRIPT_FILENAME))
524         $SCRIPT_FILENAME = dirname(__FILE__.'/../') . '/index.php';
525     if (isWindows())
526         $SCRIPT_FILENAME = strtr($SCRIPT_FILENAME,'/','\\');
527     define('SCRIPT_FILENAME',$SCRIPT_FILENAME);
528
529     //////////////////////////////////////////////////////////////////
530     // Select database
531     //
532     if (empty($DBParams['dbtype']))
533         $DBParams['dbtype'] = 'dba';
534
535     if (!defined('THEME'))
536         define('THEME', 'default');
537
538     if (!defined('WIKI_NAME'))
539         define('WIKI_NAME', _("An unnamed PhpWiki"));
540
541     if (!defined('HOME_PAGE'))
542         define('HOME_PAGE', _("HomePage"));
543
544     // FIXME: delete
545     // Access log
546     if (!defined('ACCESS_LOG'))
547         define('ACCESS_LOG', '');
548
549     // FIXME: delete
550     // Get remote host name, if apache hasn't done it for us
551     if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
552         $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
553
554     // check whether the crypt() function is needed and present
555     if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
556         $error = sprintf(_("Encrypted passwords cannot be used: %s."),
557                          "'function crypt()' not available in this version of php");
558         trigger_error($error);
559     }
560
561     if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
562         trigger_error(_("The admin password cannot be empty. Please update your config/config.ini"));
563
564     if (defined('USE_DB_SESSION') and USE_DB_SESSION) {
565         if (! $DBParams['db_session_table'] ) {
566             trigger_error(_("Empty db_session_table. Turn USE_DB_SESSION off or define the table name."), 
567                           E_USER_ERROR);
568             // this is flawed. constants cannot be changed.
569             define('USE_DB_SESSION',false);
570             $DBParams['db_session_table'] = @$DBParams['prefix'] . 'session';
571         }
572     } else {
573         // default: true (since v1.3.8)
574         if (!defined('USE_DB_SESSION'))
575             define('USE_DB_SESSION',true);
576     }
577     // legacy:
578     if (!defined('ENABLE_USER_NEW')) define('ENABLE_USER_NEW',true);
579     if (!defined('ALLOW_USER_LOGIN'))
580         define('ALLOW_USER_LOGIN', defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
581     if (!defined('ALLOW_ANON_USER')) define('ALLOW_ANON_USER', true); 
582     if (!defined('ALLOW_ANON_EDIT')) define('ALLOW_ANON_EDIT', false); 
583     if (!defined('REQUIRE_SIGNIN_BEFORE_EDIT')) define('REQUIRE_SIGNIN_BEFORE_EDIT', ! ALLOW_ANON_EDIT);
584     if (!defined('ALLOW_BOGO_LOGIN')) define('ALLOW_BOGO_LOGIN', true);
585     if (!defined('ALLOW_LDAP_LOGIN')) define('ALLOW_LDAP_LOGIN', defined('LDAP_AUTH_HOST'));
586     if (!defined('ALLOW_IMAP_LOGIN')) define('ALLOW_IMAP_LOGIN', defined('IMAP_AUTH_HOST'));
587
588     if (ALLOW_USER_LOGIN and !empty($DBAuthParams) and empty($DBAuthParams['auth_dsn'])) {
589         if (isset($DBParams['dsn']))
590             $DBAuthParams['auth_dsn'] = $DBParams['dsn'];
591     }
592 }
593
594 // $Log: not supported by cvs2svn $
595 // Revision 1.39  2004/06/21 16:22:28  rurban
596 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
597 // fixed dumping buttons locally (images/buttons/),
598 // support pages arg for dumphtml,
599 // optional directory arg for dumpserial + dumphtml,
600 // fix a AllPages warning,
601 // show dump warnings/errors on DEBUG,
602 // don't warn just ignore on wikilens pagelist columns, if not loaded.
603 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
604 //
605 // Revision 1.38  2004/06/21 08:39:36  rurban
606 // pear/Cache update from Cache-1.5.4 (added db and trifile container)
607 // pear/DB update from DB-1.6.1 (mysql bugfixes, php5 compat, DB_PORTABILITY features)
608 //
609 // Revision 1.37  2004/06/19 12:32:37  rurban
610 // new TEMP_DIR for ziplib
611 //
612 // Revision 1.36  2004/06/19 10:06:37  rurban
613 // Moved lib/plugincache-config.php to config/*.ini
614 // use PLUGIN_CACHED_* constants instead of global $CacheParams
615 //
616 // Revision 1.35  2004/06/15 09:15:52  rurban
617 // IMPORTANT: fixed passwd handling for passwords stored in prefs:
618 //   fix encrypted usage, actually store and retrieve them from db
619 //   fix bogologin with passwd set.
620 // fix php crashes with call-time pass-by-reference (references wrongly used
621 //   in declaration AND call). This affected mainly Apache2 and IIS.
622 //   (Thanks to John Cole to detect this!)
623 //
624 // Revision 1.34  2004/06/13 13:54:25  rurban
625 // Catch fatals on the four dump calls (as file and zip, as html and mimified)
626 // FoafViewer: Check against external requirements, instead of fatal.
627 // Change output for xhtmldumps: using file:// urls to the local fs.
628 // Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
629 // Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
630 //
631 // Revision 1.33  2004/06/08 19:48:16  rurban
632 // fixed foreign setup: no ugly skipped msg for the GenericPages, load english actionpages if translated not found
633 //
634 // Revision 1.32  2004/06/08 10:54:46  rurban
635 // better acl dump representation, read back acl and owner
636 //
637 // Revision 1.31  2004/06/06 16:58:51  rurban
638 // added more required ActionPages for foreign languages
639 // install now english ActionPages if no localized are found. (again)
640 // fixed default anon user level to be 0, instead of -1
641 //   (wrong "required administrator to view this page"...)
642 //
643 // Revision 1.30  2004/06/04 12:40:21  rurban
644 // Restrict valid usernames to prevent from attacks against external auth or compromise
645 // possible holes.
646 // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
647 // Fxied more warnings
648 //
649 // Revision 1.29  2004/06/04 11:58:38  rurban
650 // added USE_TAGLINES
651 //
652 // Revision 1.28  2004/06/03 20:42:49  rurban
653 // fixed bad warning #964850
654 //
655 // Revision 1.27  2004/06/03 10:18:19  rurban
656 // fix FileUser locking issues, new config ENABLE_PAGEPERM
657 //
658 // Revision 1.26  2004/06/02 18:01:45  rurban
659 // init global FileFinder to add proper include paths at startup
660 //   adds PHPWIKI_DIR if started from another dir, lib/pear also
661 // fix slashify for Windows
662 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
663 //
664 // Revision 1.25  2004/05/27 17:49:05  rurban
665 // renamed DB_Session to DbSession (in CVS also)
666 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
667 // remove leading slash in error message
668 // added force_unlock parameter to File_Passwd (no return on stale locks)
669 // fixed adodb session AffectedRows
670 // added FileFinder helpers to unify local filenames and DATA_PATH names
671 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
672 //
673 // Revision 1.24  2004/05/18 13:33:13  rurban
674 // we already have a CGI function
675 //
676 // Revision 1.23  2004/05/17 17:43:29  rurban
677 // CGI: no PATH_INFO fix
678 //
679 // Revision 1.22  2004/05/16 22:07:35  rurban
680 // check more config-default and predefined constants
681 // various PagePerm fixes:
682 //   fix default PagePerms, esp. edit and view for Bogo and Password users
683 //   implemented Creator and Owner
684 //   BOGOUSERS renamed to BOGOUSER
685 // fixed syntax errors in signin.tmpl
686 //
687 // Revision 1.21  2004/05/08 22:55:12  rurban
688 // Fixed longstanding sf.net:demo problem. endless loop, caused by an empty definition of
689 // WIKI_NAME_REGEXP. Exactly this constant wasn't checked for its default setting.
690 //
691 // Revision 1.20  2004/05/08 20:21:00  rurban
692 // remove php tags in Log
693 //
694 // Revision 1.19  2004/05/08 19:55:29  rurban
695 // support <span>inlined plugin-result</span>:
696 //   if the plugin is parsed inside a line, use <span> instead of
697 //   <div tightenable top bottom>
698 //   e.g. for "This is the current Phpwiki <plugin SystemInfo version> version.
699 //
700 // Revision 1.18  2004/05/08 16:58:19  rurban
701 // don't ignore some false config values (e.g. USE_PATH_INFO false was ignored)
702 //
703 // Revision 1.17  2004/05/06 19:26:15  rurban
704 // improve stability, trying to find the InlineParser endless loop on sf.net
705 //
706 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
707 //
708 // Revision 1.16  2004/05/02 15:10:05  rurban
709 // new finally reliable way to detect if /index.php is called directly
710 //   and if to include lib/main.php
711 // new global AllActionPages
712 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
713 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
714 // PageGroupTestOne => subpages
715 // renamed PhpWikiRss to PhpWikiRecentChanges
716 // more docs, default configs, ...
717 //
718 // Revision 1.15  2004/05/01 15:59:29  rurban
719 // more php-4.0.6 compatibility: superglobals
720 //
721 // Revision 1.14  2004/04/29 23:25:12  rurban
722 // re-ordered locale init (as in 1.3.9)
723 // fixed loadfile with subpages, and merge/restore anyway
724 //   (sf.net bug #844188)
725 //
726 // Revision 1.13  2004/04/29 21:54:05  rurban
727 // typo
728 //
729 // Revision 1.12  2004/04/27 16:16:27  rurban
730 // more subtle config problems with defaults
731 //
732 // Revision 1.11  2004/04/26 20:44:34  rurban
733 // locking table specific for better databases
734 //
735 // Revision 1.10  2004/04/26 13:22:32  rurban
736 // calculate bool old or dynamic constants later
737 //
738 // Revision 1.9  2004/04/26 12:15:01  rurban
739 // check default config values
740 //
741 // Revision 1.8  2004/04/23 16:55:59  zorloc
742 // If using Db auth and DBAUTH_AUTH_DSN is empty set DBAUTH_AUTH_DSN to $DBParams['dsn']
743 //
744 // Revision 1.7  2004/04/20 22:26:27  zorloc
745 // Removed Pear_Config for parse_ini_file().
746 //
747 // Revision 1.6  2004/04/20 18:10:27  rurban
748 // config refactoring:
749 //   FileFinder is needed for WikiFarm scripts calling index.php
750 //   config run-time calls moved to lib/IniConfig.php:fix_configs()
751 //   added PHPWIKI_DIR smart-detection code (Theme finder)
752 //   moved FileFind to lib/FileFinder.php
753 //   cleaned lib/config.php
754 //
755 // Revision 1.5  2004/04/20 17:21:57  rurban
756 // WikiFarm code: honor predefined constants
757 //
758 // Revision 1.4  2004/04/20 17:08:19  rurban
759 // Some IniConfig fixes: prepend our private lib/pear dir
760 //   switch from " to ' in the auth statements
761 //   use error handling.
762 // WikiUserNew changes for the new "'$variable'" syntax
763 //   in the statements
764 // TODO: optimization to put config vars into the session.
765 //
766
767 // (c-file-style: "gnu")
768 // Local Variables:
769 // mode: php
770 // tab-width: 8
771 // c-basic-offset: 4
772 // c-hanging-comment-ender-p: nil
773 // indent-tabs-mode: nil
774 // End:   
775 ?>