]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/IniConfig.php
Remove unused function
[SourceForge/phpwiki.git] / lib / IniConfig.php
1 <?php
2
3 /**
4  * A configurator intended to read its config from a PHP-style INI file,
5  * instead of a PHP file.
6  *
7  * Pass a filename to the IniConfig() function and it will read all its
8  * definitions from there, all by itself, and proceed to do a mass-define
9  * of all valid PHPWiki config items.  In this way, we can hopefully be
10  * totally backwards-compatible with the old index.php method, while still
11  * providing a much tastier on-going experience.
12  *
13  * @author: Joby Walker, Reini Urban, Matthew Palmer
14  */
15 /*
16  * Copyright 2004,2005,2006,2007 $ThePhpWikiProgrammingTeam
17  * Copyright 2008-2010 Marc-Etienne Vargenau, Alcatel-Lucent
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 along
32  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
33  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34  */
35
36 /**
37  * DONE:
38  * - Convert the value lists to provide defaults, so that every "if
39  *      (defined())" and "if (!defined())" can fuck off to the dismal hole
40  *      it belongs in.
41  * - config.ini => config.php dumper for faster startup. (really faster? to time)
42  *
43  * TODO:
44  * - Old-style index.php => config/config.ini converter.
45  *
46  * - Don't use too much globals for easier integration into other projects
47  *   (namespace pollution). (FusionForge, phpnuke, postnuke, phpBB2, carolina, ...)
48  *   Use one global $phpwiki object instead which holds the cfg vars, constants
49  *   and all other globals.
50  *     (global $FieldSeparator, $WikiNameRegexp, $KeywordLinkRegexp;
51  *      global $DisabledActions, $DBParams, $LANG, $AllActionPages)
52  *
53  * - Resurrect the larger "config object" code (in config/) so it'll aid the
54  *   GUI config writers, and allow us to do proper validation and default
55  *   value handling.
56  *
57  * - Get rid of WikiNameRegexp and KeywordLinkRegexp as globals by finding
58  *   everywhere that uses them as variables and modify the code to use
59  *   them as constants.
60  */
61
62 include_once (dirname(__FILE__) . "/config.php");
63 include_once (dirname(__FILE__) . "/FileFinder.php");
64
65 /**
66  * Speed-up iniconfig loading.
67  *
68  * Dump the static parts of the parsed config/config.ini settings to a fast-loadable config.php file.
69  * The dynamic parts are then evaluated as before.
70  * Requires write-permissions to config/config.php
71  *
72  * @param string $file
73  */
74 function save_dump($file)
75 {
76     $vars =& $GLOBALS; // copy + unset not possible
77     $ignore = array();
78     foreach (array("SERVER", "ENV", "GET", "POST", "REQUEST", "COOKIE", "FILES") as $key) {
79         $ignore["HTTP_" . $key . "_VARS"]++;
80         $ignore["_" . $key]++;
81     }
82     foreach (array("HTTP_POST_FILES", "GLOBALS", "RUNTIMER", "ErrorManager", 'LANG',
83                  'HOME_PAGE', 'request', 'SCRIPT_NAME', 'VIRTUAL_PATH', 'SCRIPT_FILENAME') as $key)
84         $ignore[$key]++;
85     $fp = fopen($file, "wb");
86     fwrite($fp, "<?php\n");
87     fwrite($fp, "function wiki_configrestore(){\n");
88     //TODO: optimize this by removing ignore, big serialized array and merge into existing GLOBALS
89     foreach ($vars as $var => $val) {
90         if (!$ignore[$var])
91             fwrite($fp, "\$GLOBALS['" . $var . "']=unserialize(\""
92                 . addslashes(serialize($val)) . "\");\n");
93     }
94     // cannot be optimized, maybe leave away predefined consts somehow
95     foreach (get_defined_constants() as $var => $val) {
96         if (substr($var, 0, 4) != "PHP_" and substr($var, 0, 2) != "E_"
97             and substr($var, 0, 2) != "T_"  and substr($var, 0, 2) != "M_"
98         )
99             fwrite($fp, "if(!defined('" . $var . "')) define('" . $var . "',unserialize(\""
100                 . addslashes(serialize($val)) . "\"));\n");
101     }
102     fwrite($fp, "return 'noerr';}");
103     fwrite($fp, "?>");
104     fclose($fp);
105 }
106
107 function _check_int_constant(&$c)
108 {
109     // if int value == string value, force int type
110     if (sprintf("%d", (int)$c) === $c) { // DEBUG & _DEBUG_bla
111         $c = (int)$c;
112     }
113 }
114
115 function IniConfig($file)
116 {
117
118     // Optionally check config/config.php dump for faster startup
119     $dump = substr($file, 0, -3) . "php";
120     if (isWindows($dump)) $dump = str_replace("/", "\\", $dump);
121     if (file_exists($dump) and is_readable($dump) and filesize($dump) > 0 and sort_file_mtime($dump, $file) < 0) {
122         @include($dump) or die("Error including " . $dump);
123         if (function_exists('wiki_configrestore') and (wiki_configrestore() === 'noerr')) {
124             fixup_dynamic_configs();
125             return;
126         }
127     }
128
129     // First-time installer detection here...
130     // Similar to SetupWiki()
131     if (!file_exists($file)) {
132         // We need to DATA_PATH for configurator, or pass the posted values
133         // somewhow to the script
134         include_once(dirname(__FILE__) . "/install.php");
135         run_install("_part1");
136         if (!defined("_PHPWIKI_INSTALL_RUNNING"))
137             trigger_error("Datasource file '$file' does not exist", E_USER_ERROR);
138         exit();
139     }
140
141     // List of all valid config options to be define()d which take "values" (not
142     // booleans). Needs to be categorised, and generally made a lot tidier.
143     $_IC_VALID_VALUE = array
144     ('WIKI_NAME', 'ADMIN_USER', 'ADMIN_PASSWD',
145         'DEFAULT_DUMP_DIR', 'HTML_DUMP_DIR',
146         'HTML_DUMP_SUFFIX', 'MAX_UPLOAD_SIZE', 'MINOR_EDIT_TIMEOUT',
147         'ACCESS_LOG', 'CACHE_CONTROL', 'CACHE_CONTROL_MAX_AGE',
148         'COOKIE_EXPIRATION_DAYS', 'COOKIE_DOMAIN',
149         'PASSWORD_LENGTH_MINIMUM', 'USER_AUTH_POLICY',
150         'GROUP_METHOD',
151         'EDITING_POLICY', 'THEME',
152         'WIKI_PGSRC', 'DEFAULT_WIKI_PGSRC',
153         'ALLOWED_PROTOCOLS', 'INLINE_IMAGES', /*'KEYWORDS',*/
154         // extra logic:
155         //'DATABASE_PREFIX', 'DATABASE_DSN', 'DATABASE_TYPE', 'DATABASE_DBHANDLER',
156         'DATABASE_OPTIMISE_FREQUENCY',
157         'INTERWIKI_MAP_FILE', 'COPYRIGHTPAGE_TITLE', 'COPYRIGHTPAGE_URL',
158         'AUTHORPAGE_TITLE', 'AUTHORPAGE_URL',
159         'WIKI_NAME_REGEXP',
160         'PLUGIN_CACHED_DATABASE', 'PLUGIN_CACHED_FILENAME_PREFIX',
161         'PLUGIN_CACHED_HIGHWATER', 'PLUGIN_CACHED_LOWWATER', 'PLUGIN_CACHED_MAXLIFETIME',
162         'PLUGIN_CACHED_MAXARGLEN', 'PLUGIN_CACHED_IMGTYPES',
163         'WYSIWYG_BACKEND',
164         // extra logic:
165         'SERVER_NAME', 'SERVER_PORT', 'SCRIPT_NAME', 'DATA_PATH', 'PHPWIKI_DIR', 'VIRTUAL_PATH',
166         'EXTERNAL_HTML2PDF_PAGELIST', 'PLUGIN_CACHED_CACHE_DIR'
167     );
168
169     // Optional values which need to be defined.
170     // These are not defined in config-default.ini and empty if not defined.
171     $_IC_OPTIONAL_VALUE = array
172     (
173         'DEBUG', 'TEMP_DIR', 'DEFAULT_LANGUAGE',
174         'LDAP_AUTH_HOST', 'LDAP_SET_OPTION', 'LDAP_BASE_DN', 'LDAP_AUTH_USER',
175         'LDAP_AUTH_PASSWORD', 'LDAP_SEARCH_FIELD', 'LDAP_OU_GROUP', 'LDAP_OU_USERS',
176         'AUTH_USER_FILE', 'DBAUTH_AUTH_DSN',
177         'IMAP_AUTH_HOST', 'POP3_AUTH_HOST',
178         'AUTH_USER_FILE', 'AUTH_GROUP_FILE', 'AUTH_SESS_USER', 'AUTH_SESS_LEVEL',
179         'GOOGLE_LICENSE_KEY', 'FORTUNE_DIR',
180         'DISABLE_GETIMAGESIZE', 'DBADMIN_USER', 'DBADMIN_PASSWD',
181         'SESSION_SAVE_PATH',
182         'TOOLBAR_PAGELINK_PULLDOWN', 'TOOLBAR_TEMPLATE_PULLDOWN', 'TOOLBAR_IMAGE_PULLDOWN',
183         'EXTERNAL_LINK_TARGET', 'ACCESS_LOG_SQL', 'USE_EXTERNAL_HTML2PDF',
184         'LOGIN_LOG', 'LDAP_SEARCH_FILTER'
185     );
186
187     // List of all valid config options to be define()d which take booleans.
188     $_IC_VALID_BOOL = array
189     ('ENABLE_PAGEPERM', 'ENABLE_EDIT_TOOLBAR', 'JS_SEARCHREPLACE',
190         'ENABLE_XHTML_XML', 'ENABLE_DOUBLECLICKEDIT',
191         'USECACHE', 'WIKIDB_NOCACHE_MARKUP',
192         'ENABLE_REVERSE_DNS', 'ENCRYPTED_PASSWD', 'ZIPDUMP_AUTH',
193         'ENABLE_RAW_HTML', 'ENABLE_RAW_HTML_LOCKEDONLY', 'ENABLE_RAW_HTML_SAFE',
194         'STRICT_MAILABLE_PAGEDUMPS', 'COMPRESS_OUTPUT',
195         'ALLOW_ANON_USER', 'ALLOW_ANON_EDIT',
196         'ALLOW_BOGO_LOGIN', 'ALLOW_USER_PASSWORDS',
197         'AUTH_USER_FILE_STORABLE', 'ALLOW_HTTP_AUTH_LOGIN',
198         'ALLOW_USER_LOGIN', 'ALLOW_LDAP_LOGIN', 'ALLOW_IMAP_LOGIN',
199         'WARN_NONPUBLIC_INTERWIKIMAP', 'USE_PATH_INFO',
200         'DISABLE_HTTP_REDIRECT',
201         'PLUGIN_CACHED_USECACHE', 'PLUGIN_CACHED_FORCE_SYNCMAP',
202         'BLOG_DEFAULT_EMPTY_PREFIX', 'DATABASE_PERSISTENT',
203         'FUSIONFORGE',
204         'ENABLE_DISCUSSION_LINK', 'ENABLE_CAPTCHA',
205         'ENABLE_WYSIWYG', 'WYSIWYG_DEFAULT_PAGETYPE_HTML',
206         'DISABLE_MARKUP_WIKIWORD', 'ENABLE_MARKUP_COLOR', 'ENABLE_MARKUP_TEMPLATE',
207         'ENABLE_MARKUP_MEDIAWIKI_TABLE',
208         'ENABLE_MARKUP_DIVSPAN', 'USE_BYTEA', 'UPLOAD_USERDIR', 'DISABLE_UNITS',
209         'ENABLE_SEARCHHIGHLIGHT', 'DISABLE_UPLOAD_ONLY_ALLOWED_EXTENSIONS',
210         'ENABLE_AUTH_OPENID', 'INSECURE_ACTIONS_LOCALHOST_ONLY',
211         'ENABLE_MAILNOTIFY', 'ENABLE_RECENTCHANGESBOX', 'ENABLE_PAGE_PUBLIC',
212         'ENABLE_AJAX', 'ENABLE_EXTERNAL_PAGES',
213         'READONLY'
214     );
215
216     $rs = @parse_ini_file($file);
217     $rsdef = @parse_ini_file(dirname(__FILE__) . "/../config/config-default.ini");
218     foreach ($rsdef as $k => $v) {
219         if (defined($k)) {
220             $rs[$k] = constant($k);
221         } elseif (!isset($rs[$k])) {
222             $rs[$k] = $v;
223         }
224     }
225     unset($k);
226     unset($v);
227
228     foreach ($_IC_VALID_VALUE as $item) {
229         if (defined($item)) {
230             unset($rs[$item]);
231             continue;
232         }
233         if (array_key_exists($item, $rs)) {
234             _check_int_constant($rs[$item]);
235             define($item, $rs[$item]);
236             unset($rs[$item]);
237             //} elseif (array_key_exists($item, $rsdef)) {
238             //    define($item, $rsdef[$item]);
239             // calculate them later or not at all:
240         } elseif (in_array($item,
241             array('DATABASE_PREFIX', 'SERVER_NAME', 'SERVER_PORT',
242                 'SCRIPT_NAME', 'DATA_PATH', 'PHPWIKI_DIR', 'VIRTUAL_PATH',
243                 'LDAP_AUTH_HOST', 'IMAP_AUTH_HOST', 'POP3_AUTH_HOST',
244                 'PLUGIN_CACHED_CACHE_DIR', 'EXTERNAL_HTML2PDF_PAGELIST'))
245         ) {
246             ;
247         } elseif (!defined("_PHPWIKI_INSTALL_RUNNING")) {
248             trigger_error(sprintf("missing config setting for %s", $item));
249         }
250     }
251     unset($item);
252
253     // Boolean options are slightly special - if they're set to any of
254     // '', 'false', '0', or 'no' (all case-insensitive) then the value will
255     // be a boolean false, otherwise if there is anything set it'll
256     // be true.
257     foreach ($_IC_VALID_BOOL as $item) {
258         if (defined($item)) {
259             unset($rs[$item]);
260             continue;
261         }
262         if (array_key_exists($item, $rs)) {
263             $val = $rs[$item];
264             //} elseif (array_key_exists($item, $rsdef)) {
265             //    $val = $rsdef[$item];
266         } else {
267             $val = false;
268             //trigger_error(sprintf("missing boolean config setting for %s",$item));
269         }
270
271         // calculate them later: old or dynamic constants
272         if (!array_key_exists($item, $rs) and
273             in_array($item, array('USE_PATH_INFO', 'USE_DB_SESSION',
274                 'ALLOW_HTTP_AUTH_LOGIN', 'ALLOW_LDAP_LOGIN',
275                 'ALLOW_IMAP_LOGIN', 'ALLOW_USER_LOGIN',
276                 'REQUIRE_SIGNIN_BEFORE_EDIT',
277                 'WIKIDB_NOCACHE_MARKUP',
278                 'COMPRESS_OUTPUT', 'USE_BYTEA', 'READONLY',
279             ))
280         ) {
281             ;
282         } elseif (!$val) {
283             define($item, false);
284         } elseif (strtolower($val) == 'false' ||
285             strtolower($val) == 'no' ||
286             $val == '' ||
287             $val == false ||
288             $val == '0'
289         ) {
290             define($item, false);
291         } else {
292             define($item, true);
293         }
294         unset($rs[$item]);
295     }
296     unset($item);
297
298     // Database
299     global $DBParams;
300     foreach (array('DATABASE_TYPE' => 'dbtype',
301                  'DATABASE_DSN' => 'dsn',
302                  'DATABASE_SESSION_TABLE' => 'db_session_table',
303                  'DATABASE_DBA_HANDLER' => 'dba_handler',
304                  'DATABASE_DIRECTORY' => 'directory',
305                  'DATABASE_TIMEOUT' => 'timeout',
306                  'DATABASE_PREFIX' => 'prefix')
307              as $item => $k) {
308         if (defined($item)) {
309             $DBParams[$k] = constant($item);
310             unset($rs[$item]);
311         } elseif (array_key_exists($item, $rs)) {
312             $DBParams[$k] = $rs[$item];
313             define($item, $rs[$item]);
314             unset($rs[$item]);
315         } elseif (array_key_exists($item, $rsdef)) {
316             $DBParams[$k] = $rsdef[$item];
317             define($item, $rsdef[$item]);
318             unset($rsdef[$item]);
319         }
320     }
321     $valid_database_types = array('SQL', 'ADODB', 'PDO', 'dba', 'file', 'flatfile');
322     if (!in_array(DATABASE_TYPE, $valid_database_types))
323         trigger_error(sprintf("Invalid DATABASE_TYPE=%s. Choose one of %s",
324                 DATABASE_TYPE, join(",", $valid_database_types)),
325             E_USER_ERROR);
326     unset($valid_database_types);
327
328     // Detect readonly database, e.g. system mounted read-only for maintenance
329     // via dbh->readonly later. Unfortunately not possible as constant.
330
331     // USE_DB_SESSION default logic:
332     if (!defined('USE_DB_SESSION')) {
333         if ($DBParams['db_session_table']
334             and in_array($DBParams['dbtype'], array('SQL', 'ADODB', 'PDO', 'dba'))
335         ) {
336             define('USE_DB_SESSION', true);
337         } else {
338             define('USE_DB_SESSION', false);
339         }
340     }
341     unset($item);
342     unset($k);
343
344     // Expiry stuff
345     global $ExpireParams;
346     foreach (array('major', 'minor', 'author') as $major) {
347         foreach (array('max_age', 'min_age', 'min_keep', 'keep', 'max_keep') as $max) {
348             $item = strtoupper($major) . '_' . strtoupper($max);
349             if (defined($item))
350                 $val = constant($item);
351             elseif (array_key_exists($item, $rs))
352                 $val = $rs[$item];
353             elseif (array_key_exists($item, $rsdef))
354                 $val = $rsdef[$item];
355             if (!isset($ExpireParams[$major]))
356                 $ExpireParams[$major] = array();
357             $ExpireParams[$major][$max] = $val;
358             unset($rs[$item]);
359         }
360     }
361     unset($item);
362     unset($major);
363     unset($max);
364
365     // User authentication
366     if (!isset($GLOBALS['USER_AUTH_ORDER'])) {
367         if (isset($rs['USER_AUTH_ORDER']))
368             $GLOBALS['USER_AUTH_ORDER'] = preg_split('/\s*:\s*/',
369                 $rs['USER_AUTH_ORDER']);
370         else
371             $GLOBALS['USER_AUTH_ORDER'] = array("PersonalPage");
372     }
373
374     // Now it's the external DB authentication stuff's turn
375     if (in_array('Db', $GLOBALS['USER_AUTH_ORDER']) && empty($rs['DBAUTH_AUTH_DSN'])) {
376         $rs['DBAUTH_AUTH_DSN'] = $DBParams['dsn'];
377     }
378
379     global $DBAuthParams;
380     $DBAP_MAP = array('DBAUTH_AUTH_DSN' => 'auth_dsn',
381         'DBAUTH_AUTH_CHECK' => 'auth_check',
382         'DBAUTH_AUTH_USER_EXISTS' => 'auth_user_exists',
383         'DBAUTH_AUTH_CRYPT_METHOD' => 'auth_crypt_method',
384         'DBAUTH_AUTH_UPDATE' => 'auth_update',
385         'DBAUTH_AUTH_CREATE' => 'auth_create',
386         'DBAUTH_PREF_SELECT' => 'pref_select',
387         'DBAUTH_PREF_INSERT' => 'pref_insert',
388         'DBAUTH_PREF_UPDATE' => 'pref_update',
389         'DBAUTH_IS_MEMBER' => 'is_member',
390         'DBAUTH_GROUP_MEMBERS' => 'group_members',
391         'DBAUTH_USER_GROUPS' => 'user_groups'
392     );
393     foreach ($DBAP_MAP as $rskey => $apkey) {
394         if (defined($rskey)) {
395             $DBAuthParams[$apkey] = constant($rskey);
396         } elseif (isset($rs[$rskey])) {
397             $DBAuthParams[$apkey] = $rs[$rskey];
398             define($rskey, $rs[$rskey]);
399         } elseif (isset($rsdef[$rskey])) {
400             $DBAuthParams[$apkey] = $rsdef[$rskey];
401             define($rskey, $rsdef[$rskey]);
402         }
403         unset($rs[$rskey]);
404     }
405     unset($rskey);
406     unset($apkey);
407
408     // TODO: Currently unsupported on non-SQL. Nice to have for RhNavPlugin
409     // CHECKME: PDO
410     if (!defined('ACCESS_LOG_SQL')) {
411         if (array_key_exists('ACCESS_LOG_SQL', $rs)) {
412             // WikiDB_backend::isSql() not yet loaded
413             if (!in_array(DATABASE_TYPE, array('SQL', 'ADODB', 'PDO'))) {
414                 // override false config setting on no SQL WikiDB database.
415                 define('ACCESS_LOG_SQL', 0);
416             }
417             // SQL defaults to ACCESS_LOG_SQL = 2
418         } else {
419             define('ACCESS_LOG_SQL',
420             in_array(DATABASE_TYPE, array('SQL', 'ADODB', 'PDO')) ? 2 : 0);
421         }
422     }
423
424     if (empty($rs['TEMP_DIR'])) {
425         $rs['TEMP_DIR'] = "/tmp";
426         if (getenv("TEMP"))
427             $rs['TEMP_DIR'] = getenv("TEMP");
428     }
429     // optional values will be set to '' to simplify the logic.
430     foreach ($_IC_OPTIONAL_VALUE as $item) {
431         if (defined($item)) {
432             unset($rs[$item]);
433             continue;
434         }
435         if (array_key_exists($item, $rs)) {
436             _check_int_constant($rs[$item]);
437             define($item, $rs[$item]);
438             unset($rs[$item]);
439         } else
440             define($item, '');
441     }
442
443     if (USE_EXTERNAL_HTML2PDF) {
444         $item = 'EXTERNAL_HTML2PDF_PAGELIST';
445         if (defined($item)) {
446             unset($rs[$item]);
447         } elseif (array_key_exists($item, $rs)) {
448             define($item, $rs[$item]);
449             unset($rs[$item]);
450         } elseif (array_key_exists($item, $rsdef)) {
451             define($item, $rsdef[$item]);
452         }
453     }
454     unset($item);
455
456     // LDAP bind options
457     global $LDAP_SET_OPTION;
458     if (defined('LDAP_SET_OPTION') and LDAP_SET_OPTION) {
459         $optlist = preg_split('/\s*:\s*/', LDAP_SET_OPTION);
460         foreach ($optlist as $opt) {
461             $bits = preg_split('/\s*=\s*/', $opt, 2);
462             if (count($bits) == 2) {
463                 if (is_string($bits[0]) and defined($bits[0]))
464                     $bits[0] = constant($bits[0]);
465                 $LDAP_SET_OPTION[$bits[0]] = $bits[1];
466             } else {
467                 // Possibly throw some sort of error?
468             }
469         }
470         unset($opt);
471         unset($bits);
472     }
473
474     // Default Wiki pages to force loading from pgsrc
475     global $GenericPages;
476     $GenericPages = preg_split('/\s*:\s*/', @$rs['DEFAULT_WIKI_PAGES']);
477
478     // Wiki name regexp:  Should be a define(), but might needed to be changed at runtime
479     // (different LC_CHAR need different posix classes)
480     global $WikiNameRegexp;
481     $WikiNameRegexp = constant('WIKI_NAME_REGEXP');
482     if (!trim($WikiNameRegexp))
483         $WikiNameRegexp = '(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])';
484
485     // Got rid of global $KeywordLinkRegexp by using a TextSearchQuery instead
486     // of "Category:Topic"
487     if (!isset($rs['KEYWORDS'])) $rs['KEYWORDS'] = @$rsdef['KEYWORDS'];
488     if (!isset($rs['KEYWORDS'])) $rs['KEYWORDS'] = "Category* OR Topic*";
489     if ($rs['KEYWORDS'] == 'Category:Topic') $rs['KEYWORDS'] = "Category* OR Topic*";
490     if (!defined('KEYWORDS')) define('KEYWORDS', $rs['KEYWORDS']);
491     //if (empty($keywords)) $keywords = array("Category","Topic");
492     //$KeywordLinkRegexp = '(?<=' . implode('|^', $keywords) . ')[[:upper:]].*$';
493
494     // TODO: can this be a constant?
495     global $DisabledActions;
496     if (!array_key_exists('DISABLED_ACTIONS', $rs)
497         and array_key_exists('DISABLED_ACTIONS', $rsdef)
498     )
499         $rs['DISABLED_ACTIONS'] = @$rsdef['DISABLED_ACTIONS'];
500     if (array_key_exists('DISABLED_ACTIONS', $rs))
501         $DisabledActions = preg_split('/\s*:\s*/', $rs['DISABLED_ACTIONS']);
502
503     global $PLUGIN_CACHED_IMGTYPES;
504     $PLUGIN_CACHED_IMGTYPES = preg_split('/\s*[|:]\s*/', PLUGIN_CACHED_IMGTYPES);
505
506     if (!defined('PLUGIN_CACHED_CACHE_DIR')) {
507         if (empty($rs['PLUGIN_CACHED_CACHE_DIR']) and !empty($rsdef['PLUGIN_CACHED_CACHE_DIR']))
508             $rs['PLUGIN_CACHED_CACHE_DIR'] = $rsdef['PLUGIN_CACHED_CACHE_DIR'];
509         if (empty($rs['PLUGIN_CACHED_CACHE_DIR'])) {
510             if (!empty($rs['INCLUDE_PATH'])) {
511                 @ini_set('include_path', $rs['INCLUDE_PATH']);
512                 $GLOBALS['INCLUDE_PATH'] = $rs['INCLUDE_PATH'];
513             }
514             $rs['PLUGIN_CACHED_CACHE_DIR'] = TEMP_DIR . '/cache';
515             if (!FindFile($rs['PLUGIN_CACHED_CACHE_DIR'], 1)) { // [29ms]
516                 FindFile(TEMP_DIR, false, 1); // TEMP must exist!
517                 mkdir($rs['PLUGIN_CACHED_CACHE_DIR'], 0777);
518             }
519             // will throw an error if not exists.
520             define('PLUGIN_CACHED_CACHE_DIR', FindFile($rs['PLUGIN_CACHED_CACHE_DIR'], false, 1));
521         } else {
522             define('PLUGIN_CACHED_CACHE_DIR', $rs['PLUGIN_CACHED_CACHE_DIR']);
523             // will throw an error if not exists.
524             FindFile(PLUGIN_CACHED_CACHE_DIR);
525         }
526     }
527
528     // process the rest of the config.ini settings:
529     foreach ($rs as $item => $v) {
530         if (defined($item)) {
531             continue;
532         } else {
533             _check_int_constant($v);
534             define($item, $v);
535         }
536     }
537     unset($item);
538     unset($v);
539
540     unset($rs);
541     unset($rsdef);
542
543     fixup_static_configs($file); //[1ms]
544     // Dump all globals and constants
545     // The question is if reading this is faster then doing IniConfig() + fixup_static_configs()
546     if (is_writable($dump)) {
547         save_dump($dump);
548     }
549     // store locale[] in config.php? This is too problematic.
550     fixup_dynamic_configs(); // [100ms]
551 }
552
553 // moved from lib/config.php [1ms]
554 function fixup_static_configs($file)
555 {
556     global $FieldSeparator, $AllActionPages;
557     global $DBParams;
558     // init FileFinder to add proper include paths
559     FindFile("lib/interwiki.map", true);
560
561     // $FieldSeparator = "\xFF"; // this byte should never appear in utf-8
562     $FieldSeparator = "\xFF";
563
564     // All pages containing plugins of the same name as the filename
565     $ActionPages = explode(':',
566         'AllPages:AllUsers:AppendText:AuthorHistory:'
567             . 'BackLinks:BlogArchives:BlogJournal:'
568             . 'CreatePage:'
569             . 'FullTextSearch:FuzzyPages:'
570             . 'LikePages:LinkDatabase:LinkSearch:ListRelations:'
571             . 'ModeratedPage:MostPopular:'
572             . 'NewPagesPerUser:'
573             . 'OrphanedPages:'
574             . 'PageDump:PageHistory:PageInfo:PluginManager:'
575             . 'RateIt:' // RateIt works only in wikilens derived themes
576             . 'RandomPage:RecentChanges:RelatedChanges:RecentEdits:'
577             . 'SearchHighlight:SemanticRelations:SemanticSearch:SystemInfo:'
578             . 'TitleSearch:'
579             . 'UpLoad:UserPreferences:'
580             . 'UserRatings:' // UserRatings works only in wikilens derived themes
581             . 'WantedPages:WatchPage:WikiBlog:WhoIsOnline:WikiAdminSelect');
582
583     // The FUSIONFORGE theme omits them
584     if (!(defined('FUSIONFORGE') && FUSIONFORGE)) {
585         // Add some some action pages
586         $ActionPages[] = 'DebugInfo';
587         $ActionPages[] = 'SpellCheck'; // SpellCheck does not work
588         $ActionPages[] = 'EditMetaData';
589         $ActionPages[] = 'InterWikiSearch';
590         $ActionPages[] = 'LdapSearch';
591         $ActionPages[] = 'PasswordReset';
592         $ActionPages[] = 'RecentComments';
593         $ActionPages[] = 'TranslateText';
594         $ActionPages[] = 'UriResolver';
595     }
596
597     global $AllAllowedPlugins;
598     $AllAllowedPlugins = $ActionPages;
599     // Add plugins that have no corresponding action page
600     $AllAllowedPlugins[] = 'AddComment';
601     $AllAllowedPlugins[] = 'AsciiMath';
602     $AllAllowedPlugins[] = 'AsciiSVG';
603     $AllAllowedPlugins[] = 'AtomFeed';
604     $AllAllowedPlugins[] = 'BoxRight';
605     $AllAllowedPlugins[] = 'CalendarList';
606     $AllAllowedPlugins[] = 'Calendar';
607     $AllAllowedPlugins[] = 'CategoryPage';
608     $AllAllowedPlugins[] = 'Chart';
609     $AllAllowedPlugins[] = 'Comment';
610     $AllAllowedPlugins[] = 'CreateBib';
611     $AllAllowedPlugins[] = 'CreateToc';
612     $AllAllowedPlugins[] = 'CurrentTime';
613     $AllAllowedPlugins[] = 'DeadEndPages';
614     $AllAllowedPlugins[] = 'Diff';
615     $AllAllowedPlugins[] = 'DynamicIncludePage';
616     $AllAllowedPlugins[] = 'ExternalSearch';
617     $AllAllowedPlugins[] = 'FacebookLike';
618     $AllAllowedPlugins[] = 'FileInfo';
619     $AllAllowedPlugins[] = 'GoogleMaps';
620     $AllAllowedPlugins[] = 'GooglePlugin';
621     $AllAllowedPlugins[] = 'GoTo';
622     $AllAllowedPlugins[] = 'HelloWorld';
623     $AllAllowedPlugins[] = 'IncludePage';
624     $AllAllowedPlugins[] = 'IncludePages';
625     $AllAllowedPlugins[] = 'IncludeSiteMap';
626     $AllAllowedPlugins[] = 'IncludeTree';
627     $AllAllowedPlugins[] = 'ListPages';
628     $AllAllowedPlugins[] = 'ListSubpages';
629     $AllAllowedPlugins[] = 'MediawikiTable';
630     $AllAllowedPlugins[] = 'NoCache';
631     $AllAllowedPlugins[] = 'OldStyleTable';
632     $AllAllowedPlugins[] = 'PageGroup';
633     $AllAllowedPlugins[] = 'PageTrail';
634     $AllAllowedPlugins[] = 'PhotoAlbum';
635     $AllAllowedPlugins[] = 'PhpHighlight';
636     $AllAllowedPlugins[] = 'PopularTags';
637     $AllAllowedPlugins[] = 'PopUp';
638     $AllAllowedPlugins[] = 'PrevNext';
639     $AllAllowedPlugins[] = 'Processing';
640     $AllAllowedPlugins[] = 'RawHtml';
641     $AllAllowedPlugins[] = 'RecentChangesCached';
642     $AllAllowedPlugins[] = 'RecentReferrers';
643     $AllAllowedPlugins[] = 'RedirectTo';
644     $AllAllowedPlugins[] = 'RichTable';
645     $AllAllowedPlugins[] = 'RssFeed';
646     $AllAllowedPlugins[] = 'SemanticSearchAdvanced';
647     $AllAllowedPlugins[] = 'SiteMap';
648     $AllAllowedPlugins[] = 'SyncWiki';
649     $AllAllowedPlugins[] = 'SyntaxHighlighter';
650     $AllAllowedPlugins[] = 'Template';
651     $AllAllowedPlugins[] = 'Transclude';
652     $AllAllowedPlugins[] = 'UnfoldSubpages';
653     $AllAllowedPlugins[] = 'Video';
654     $AllAllowedPlugins[] = 'WikiAdminChown';
655     $AllAllowedPlugins[] = 'WikiAdminPurge';
656     $AllAllowedPlugins[] = 'WikiAdminRemove';
657     $AllAllowedPlugins[] = 'WikiAdminRename';
658     $AllAllowedPlugins[] = 'WikiAdminSearchReplace';
659     $AllAllowedPlugins[] = 'WikiAdminDeleteAcl';
660     $AllAllowedPlugins[] = 'WikiAdminSetAcl';
661     $AllAllowedPlugins[] = 'WikiAdminSetAclSimple';
662     $AllAllowedPlugins[] = 'WikiAdminUtils';
663     $AllAllowedPlugins[] = 'WikicreoleTable';
664     $AllAllowedPlugins[] = 'WikiForm';
665     $AllAllowedPlugins[] = 'WikiFormRich';
666     $AllAllowedPlugins[] = 'WikiPoll';
667     $AllAllowedPlugins[] = 'YouTube';
668     $AllAllowedPlugins[] = 'DebugGroupInfo';
669     $AllAllowedPlugins[] = 'DebugAuthInfo';
670     $AllAllowedPlugins[] = 'DebugBackendInfo';
671     $AllAllowedPlugins[] = 'DebugRetransform';
672
673     // The FUSIONFORGE theme omits them
674     if (!(defined('FUSIONFORGE') && FUSIONFORGE)) {
675         $AllAllowedPlugins[] = 'AnalyseAccessLogSql';
676         $AllAllowedPlugins[] = 'CacheTest';
677         $AllAllowedPlugins[] = 'CategoryPage';
678         $AllAllowedPlugins[] = 'FoafViewer';
679         $AllAllowedPlugins[] = 'GraphViz';
680         $AllAllowedPlugins[] = 'HtmlConverter';
681         $AllAllowedPlugins[] = 'JabberPresence';
682         $AllAllowedPlugins[] = 'ListPages';
683         $AllAllowedPlugins[] = 'PhpWeather';
684         $AllAllowedPlugins[] = 'Ploticus';
685         $AllAllowedPlugins[] = 'PopularNearby';
686         $AllAllowedPlugins[] = 'PreferenceApp';
687         $AllAllowedPlugins[] = 'PreferencesInfo';
688         $AllAllowedPlugins[] = 'SqlResult';
689         $AllAllowedPlugins[] = 'TeX2png';
690         $AllAllowedPlugins[] = 'text2png';
691         $AllAllowedPlugins[] = 'TexToPng';
692         $AllAllowedPlugins[] = 'VisualWiki';
693         $AllAllowedPlugins[] = 'WantedPagesOld';
694         $AllAllowedPlugins[] = 'WikiForum';
695         $AllAllowedPlugins[] = 'WikiTranslation';
696     }
697
698     // Used by SetupWiki to pull in required pages, if not translated, then in English.
699     // Also used by WikiTranslation. Really important are only those which return pagelists
700     // or contain basic functionality.
701     $AllActionPages = $ActionPages;
702     $AllActionPages[] = 'AllPagesCreatedByMe';
703     $AllActionPages[] = 'AllPagesLastEditedByMe';
704     $AllActionPages[] = 'AllPagesOwnedByMe';
705     $AllActionPages[] = 'AllPagesByAcl';
706     $AllActionPages[] = 'AllUserPages';
707     $AllActionPages[] = 'FullRecentChanges';
708     $AllActionPages[] = 'LeastPopular';
709     $AllActionPages[] = 'LockedPages';
710     $AllActionPages[] = 'MyRatings'; // MyRatings works only in wikilens-derived themes
711     $AllActionPages[] = 'MyRecentEdits';
712     $AllActionPages[] = 'MyRecentChanges';
713     $AllActionPages[] = 'PhpWikiAdministration';
714     $AllActionPages[] = 'PhpWikiAdministration/Chown';
715     $AllActionPages[] = 'PhpWikiAdministration/Purge';
716     $AllActionPages[] = 'PhpWikiAdministration/Remove';
717     $AllActionPages[] = 'PhpWikiAdministration/Rename';
718     $AllActionPages[] = 'PhpWikiAdministration/SearchReplace';
719     $AllActionPages[] = 'PhpWikiAdministration/DeleteAcl';
720     $AllActionPages[] = 'PhpWikiAdministration/SetAcl';
721     $AllActionPages[] = 'PhpWikiAdministration/SetAclSimple';
722     $AllActionPages[] = 'RecentChangesMyPages';
723     $AllActionPages[] = 'RecentEdits';
724     $AllActionPages[] = 'RecentNewPages';
725     $AllActionPages[] = 'SetGlobalAccessRights';
726     $AllActionPages[] = 'SetGlobalAccessRightsSimple';
727     $AllActionPages[] = 'UserContribs';
728
729     if ((defined('FUSIONFORGE') && FUSIONFORGE)) {
730         if (ENABLE_EXTERNAL_PAGES) {
731             $AllAllowedPlugins[] = 'WikiAdminSetExternal';
732             $AllActionPages[] = 'PhpWikiAdministration/SetExternal';
733             $AllActionPages[] = 'ExternalPages';
734         }
735     }
736
737     // If user has not defined PHPWIKI_DIR, and we need it
738     if (!defined('PHPWIKI_DIR') and !file_exists("themes/default")) {
739         $themes_dir = FindFile("themes");
740         define('PHPWIKI_DIR', dirname($themes_dir));
741     }
742
743     // If user has not defined DATA_PATH, we want to use relative URLs.
744     if (!defined('DATA_PATH')) {
745         // fix similar to the one suggested by jkalmbach for
746         // installations in the webrootdir, like "http://phpwiki.fr/HomePage"
747         if (!defined('SCRIPT_NAME'))
748             define('SCRIPT_NAME', deduce_script_name());
749         $temp = dirname(SCRIPT_NAME);
750         if (($temp == '/') || ($temp == '\\'))
751             $temp = '';
752         define('DATA_PATH', $temp);
753         /*
754         if (USE_PATH_INFO)
755             define('DATA_PATH', '..');
756         */
757     }
758
759     //////////////////////////////////////////////////////////////////
760     // Select database
761     //
762     if (empty($DBParams['dbtype']))
763         $DBParams['dbtype'] = 'dba';
764
765     if (!defined('THEME'))
766         define('THEME', 'default');
767
768     // Basic configurator validation
769     if (!defined('ADMIN_USER') or ADMIN_USER == '') {
770         $error = sprintf("%s may not be empty. Please update your configuration.",
771             "ADMIN_USER");
772         // protect against recursion
773         if (!preg_match("/config\-(dist|default)\.ini$/", $file)
774             and !defined("_PHPWIKI_INSTALL_RUNNING")
775         ) {
776             include_once(dirname(__FILE__) . "/install.php");
777             run_install("_part1");
778             trigger_error($error, E_USER_ERROR);
779             exit();
780         } elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
781             $GLOBALS['HTTP_GET_VARS']['show'] = '_part1';
782             trigger_error($error, E_USER_WARNING);
783         }
784     }
785     if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '') {
786         $error = sprintf("%s may not be empty. Please update your configuration.",
787             "ADMIN_PASSWD");
788         // protect against recursion
789         if (!preg_match("/config\-(dist|default)\.ini$/", $file)
790             and !defined("_PHPWIKI_INSTALL_RUNNING")
791         ) {
792             include_once(dirname(__FILE__) . "/install.php");
793             run_install("_part1");
794             trigger_error($error, E_USER_ERROR);
795             exit();
796         } elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
797             $GLOBALS['HTTP_GET_VARS']['show'] = '_part1';
798             trigger_error($error, E_USER_WARNING);
799         }
800     }
801
802     if (defined('USE_DB_SESSION') and USE_DB_SESSION) {
803         if (!$DBParams['db_session_table']) {
804             $DBParams['db_session_table'] = @$DBParams['prefix'] . 'session';
805             trigger_error(sprintf("DATABASE_SESSION_TABLE configuration set to %s.",
806                     $DBParams['db_session_table']),
807                 E_USER_ERROR);
808         }
809     }
810     // legacy:
811     if (!defined('ALLOW_USER_LOGIN'))
812         define('ALLOW_USER_LOGIN', defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
813     if (!defined('ALLOW_ANON_USER')) define('ALLOW_ANON_USER', true);
814     if (!defined('ALLOW_ANON_EDIT')) define('ALLOW_ANON_EDIT', false);
815     if (!defined('REQUIRE_SIGNIN_BEFORE_EDIT')) define('REQUIRE_SIGNIN_BEFORE_EDIT', !ALLOW_ANON_EDIT);
816     if (!defined('ALLOW_BOGO_LOGIN')) define('ALLOW_BOGO_LOGIN', true);
817     if (ALLOW_USER_LOGIN and !empty($DBAuthParams) and empty($DBAuthParams['auth_dsn'])) {
818         if (isset($DBParams['dsn']))
819             $DBAuthParams['auth_dsn'] = $DBParams['dsn'];
820     }
821 }
822
823 /**
824  * Define constants which are client or request specific and should not be dumped statically.
825  * Such as the language, and the virtual and server paths, which might be overridden
826  * by startup scripts for wiki farms.
827  */
828 function fixup_dynamic_configs()
829 {
830     global $LANG;
831
832     if (defined('INCLUDE_PATH') and INCLUDE_PATH) {
833         @ini_set('include_path', INCLUDE_PATH);
834         $GLOBALS['INCLUDE_PATH'] = INCLUDE_PATH;
835     }
836     if (defined('SESSION_SAVE_PATH') and SESSION_SAVE_PATH)
837         @ini_set('session.save_path', SESSION_SAVE_PATH);
838     if (!defined('DEFAULT_LANGUAGE')) // not needed anymore
839         define('DEFAULT_LANGUAGE', ''); // detect from client
840
841     // FusionForge hack
842     if (!(defined('FUSIONFORGE') && FUSIONFORGE)) {
843         // Disable update_locale because Zend Debugger crash
844         if (!extension_loaded('Zend Debugger')) {
845             update_locale(isset($LANG) ? $LANG : DEFAULT_LANGUAGE);
846         }
847     }
848
849     if (empty($LANG)) {
850         if (!defined("DEFAULT_LANGUAGE") or !DEFAULT_LANGUAGE) {
851             // TODO: defer this to WikiRequest::initializeLang()
852             $LANG = guessing_lang();
853             guessing_setlocale(LC_ALL, $LANG);
854         } else
855             $LANG = DEFAULT_LANGUAGE;
856     }
857
858     // Set up (possibly fake) gettext()
859     // Todo: this could be moved to fixup_static_configs()
860     // Bug #1381464 with php-5.1.1
861     if (!function_exists('bindtextdomain')
862         and !function_exists('gettext')
863             and !function_exists('_')
864     ) {
865         $locale = array();
866
867         function gettext($text)
868         {
869             global $locale;
870             if (!empty ($locale[$text]))
871                 return $locale[$text];
872             return $text;
873         }
874
875         function _($text)
876         {
877             return gettext($text);
878         }
879     } else {
880         $chback = 0;
881         if ($LANG != 'en') {
882
883             // Working around really weird gettext problems: (4.3.2, 4.3.6 win)
884             // bindtextdomain() in returns the current domain path.
885             // 1. If the script is not index.php but something like "de", on a different path
886             //    then bindtextdomain() fails, but after chdir to the correct path it will work okay.
887             // 2. But the weird error "Undefined variable: bindtextdomain" is generated then.
888             $bindtextdomain_path = FindFile("locale", false, true);
889             if (isWindows())
890                 $bindtextdomain_path = str_replace("/", "\\", $bindtextdomain_path);
891             $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain_path);
892             if (realpath($bindtextdomain_real) != realpath($bindtextdomain_path)) {
893                 // this will happen with virtual_paths. chdir and try again.
894                 chdir($bindtextdomain_path);
895                 $chback = 1;
896                 $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain_path);
897             }
898         }
899         // tell gettext not to use unicode. PHP >= 4.2.0. Thanks to Kai Krakow.
900         if ($LANG != 'en')
901             textdomain("phpwiki");
902         if ($chback) { // change back
903             chdir($bindtextdomain_real . (isWindows() ? "\\.." : "/.."));
904         }
905     }
906
907     // language dependent updates:
908     if (!defined('CATEGORY_GROUP_PAGE'))
909         define('CATEGORY_GROUP_PAGE', _("CategoryGroup"));
910     if (!defined('WIKI_NAME'))
911         define('WIKI_NAME', _("An unnamed PhpWiki"));
912     if (!defined('HOME_PAGE'))
913         define('HOME_PAGE', __("HomePage"));
914
915     //////////////////////////////////////////////////////////////////
916     // Autodetect URL settings:
917     //
918     foreach (array('SERVER_NAME', 'SERVER_PORT') as $var) {
919         //FIXME: for CGI without _SERVER
920         if (!defined($var) and !empty($_SERVER[$var]))
921             // IPV6 fix by matt brown, #1546571
922             // An IPv6 address must be surrounded by square brackets to form a valid server name.
923             if ($var == 'SERVER_NAME' &&
924                 strstr($_SERVER[$var], ':')
925             ) {
926                 define($var, '[' . $_SERVER[$var] . ']');
927             } else {
928                 define($var, $_SERVER[$var]);
929             }
930     }
931     if (!defined('SERVER_NAME')) define('SERVER_NAME', '127.0.0.1');
932     if (!defined('SERVER_PORT')) define('SERVER_PORT', 80);
933     if (!defined('SERVER_PROTOCOL')) {
934         if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')
935             define('SERVER_PROTOCOL', 'http');
936         else
937             define('SERVER_PROTOCOL', 'https');
938     }
939
940     if (!defined('SCRIPT_NAME'))
941         define('SCRIPT_NAME', deduce_script_name());
942
943     if (!defined('USE_PATH_INFO')) {
944         if (isCGI())
945             define('USE_PATH_INFO', false);
946         else {
947             /*
948              * If SCRIPT_NAME does not look like php source file,
949              * or user cgi we assume that php is getting run by an
950              * action handler in /cgi-bin.  In this case,
951              * I think there is no way to get Apache to pass
952              * useful PATH_INFO to the php script (PATH_INFO
953              * is used to the the php interpreter where the
954              * php script is...)
955              */
956             switch (php_sapi_name()) {
957                 case 'apache':
958                 case 'apache2handler':
959                     define('USE_PATH_INFO', true);
960                     break;
961                 case 'cgi':
962                 case 'apache2filter':
963                     define('USE_PATH_INFO', false);
964                     break;
965                 default:
966                     define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', SCRIPT_NAME));
967                     break;
968             }
969         }
970     }
971
972     if (SERVER_PORT
973         && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)
974     ) {
975         define('SERVER_URL',
976             SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
977     } else {
978         define('SERVER_URL',
979             SERVER_PROTOCOL . '://' . SERVER_NAME);
980     }
981
982     if (!defined('VIRTUAL_PATH')) {
983         // We'd like to auto-detect when the cases where apaches
984         // 'Action' directive (or similar means) is used to
985         // redirect page requests to a cgi-handler.
986         //
987         // In cases like this, requests for e.g. /wiki/HomePage
988         // get redirected to a cgi-script called, say,
989         // /path/to/wiki/index.php.  The script gets all
990         // of /wiki/HomePage as it's PATH_INFO.
991         //
992         // The problem is:
993         //   How to detect when this has happened reliably?
994         //   How to pick out the "virtual path" (in this case '/wiki')?
995         //
996         // (Another time an redirect might occur is to a DirectoryIndex
997         // -- the requested URI is '/wikidir/', the request gets
998         // passed to '/wikidir/index.php'.  In this case, the
999         // proper VIRTUAL_PATH is '/wikidir/index.php', since the
1000         // pages will appear at e.g. '/wikidir/index.php/HomePage'.
1001         //
1002
1003         $REDIRECT_URL = &$_SERVER['REDIRECT_URL'];
1004         if (USE_PATH_INFO and isset($REDIRECT_URL)
1005             and !IsProbablyRedirectToIndex()
1006         ) {
1007             // FIXME: This is a hack, and won't work if the requested
1008             // pagename has a slash in it.
1009             $temp = strtr(dirname($REDIRECT_URL . 'x'), "\\", '/');
1010             if (($temp == '/') || ($temp == '\\'))
1011                 $temp = '';
1012             define('VIRTUAL_PATH', $temp);
1013         } else {
1014             define('VIRTUAL_PATH', SCRIPT_NAME);
1015         }
1016     }
1017
1018     if (!defined('PATH_INFO_PREFIX')) {
1019         if (VIRTUAL_PATH != SCRIPT_NAME) {
1020             // Apache action handlers are used.
1021             define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
1022         } else {
1023             define('PATH_INFO_PREFIX', '/');
1024         }
1025     }
1026
1027     define('PHPWIKI_BASE_URL',
1028         SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
1029
1030     // Detect PrettyWiki setup (not loading index.php directly)
1031     // $SCRIPT_FILENAME should be the same as __FILE__ in index.php
1032     if (!isset($SCRIPT_FILENAME))
1033         $SCRIPT_FILENAME = @$_SERVER['SCRIPT_FILENAME'];
1034     if (!isset($SCRIPT_FILENAME))
1035         $SCRIPT_FILENAME = @$_ENV['SCRIPT_FILENAME'];
1036     if (!isset($SCRIPT_FILENAME))
1037         $SCRIPT_FILENAME = dirname(__FILE__ . '/../') . '/index.php';
1038     if (isWindows())
1039         $SCRIPT_FILENAME = str_replace('\\\\', '\\', strtr($SCRIPT_FILENAME, '/', '\\'));
1040     define('SCRIPT_FILENAME', $SCRIPT_FILENAME);
1041
1042     // Get remote host name, if Apache hasn't done it for us
1043     if (empty($_SERVER['REMOTE_HOST'])
1044         and !empty($_SERVER['REMOTE_ADDR'])
1045             and ENABLE_REVERSE_DNS
1046     )
1047         $_SERVER['REMOTE_HOST'] = gethostbyaddr($_SERVER['REMOTE_ADDR']);
1048
1049 }
1050
1051 /*
1052  * We have to handle three languages:
1053  * 1) English, the language of the source code
1054  * 2) The language in which the wiki was created (DEFAULT_LANGUAGE)
1055  * 3) The language selected by the user, in which the wiki is displayed (LANG)
1056  *
1057  * The function "_" translates from English to LANG.
1058  * The function "__" translates from English to DEFAULT_LANGUAGE.
1059  */
1060
1061 function __($text)
1062 {
1063     return $text;
1064 }
1065
1066 // Local Variables:
1067 // mode: php
1068 // tab-width: 8
1069 // c-basic-offset: 4
1070 // c-hanging-comment-ender-p: nil
1071 // indent-tabs-mode: nil
1072 // End: