2 rcs_id('$Id: config.php,v 1.96 2004-04-12 10:08:34 rurban Exp $');
4 * NOTE: the settings here should probably not need to be changed.
7 * (The user-configurable settings have been moved to index.php.)
10 if (!defined("LC_ALL")) {
11 // Backward compatibility (for PHP < 4.0.5)
13 define("LC_CTYPE", 2);
17 return @preg_match('/CGI/',$GLOBALS['HTTP_ENV_VARS']['GATEWAY_INTERFACE']);
21 // copy some $_ENV vars to $_SERVER for CGI compatibility. php does it automatically since when?
23 foreach (explode(':','SERVER_SOFTWARE:SERVER_NAME:GATEWAY_INTERFACE:SERVER_PROTOCOL:SERVER_PORT:REQUEST_METHOD:HTTP_ACCEPT:PATH_INFO:PATH_TRANSLATED:SCRIPT_NAME:QUERY_STRING:REMOTE_HOST:REMOTE_ADDR:REMOTE_USER:AUTH_TYPE:CONTENT_TYPE:CONTENT_LENGTH') as $key) {
24 $GLOBALS['HTTP_SERVER_VARS'][$key] = &$GLOBALS['HTTP_ENV_VARS'][$key];
29 // essential internal stuff
30 set_magic_quotes_runtime(0);
34 // "\x80"-"\x9f" (and "\x00" - "\x1f") are non-printing control
35 // chars in iso-8859-*
36 // $FieldSeparator = "\263"; //this is a superscript 3 in ISO-8859-1.
37 // $FieldSeparator = "\xFF"; // this byte should never appear in utf-8
38 if (strtolower(CHARSET) == 'utf-8')
39 $FieldSeparator = "\xFF";
41 $FieldSeparator = "\x81";
44 * Browser Detection Functions
47 * NS/IE < 4.0 doesn't accept < ? xml version="1.0" ? >
48 * NS/IE < 4.0 cannot display PNG
49 * NS/IE < 4.0 cannot display all XHTML tags
50 * NS < 5.0 needs textarea wrap=virtual
51 * IE55 has problems with transparent PNG's
54 function browserAgent() {
55 static $HTTP_USER_AGENT = false;
56 if (!$HTTP_USER_AGENT)
57 $HTTP_USER_AGENT = @$GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'];
58 if (!$HTTP_USER_AGENT) // CGI
59 $HTTP_USER_AGENT = $GLOBALS['HTTP_ENV_VARS']['HTTP_USER_AGENT'];
60 return $HTTP_USER_AGENT;
62 function browserDetect($match) {
63 return strstr(browserAgent(), $match);
65 // returns a similar number for Netscape/Mozilla (gecko=5.0)/IE/Opera features.
66 function browserVersion() {
67 if (strstr(browserAgent(),"Mozilla/4.0 (compatible; MSIE"))
68 return (float) substr(browserAgent(),30);
70 return (float) substr(browserAgent(),8);
72 function isBrowserIE() {
73 return (browserDetect('Mozilla/') and
74 browserDetect('MSIE'));
76 // problem with transparent PNG's
77 function isBrowserIE55() {
78 return (isBrowserIE() and
79 browserVersion() > 5.1 and browserVersion() < 6.0);
81 function isBrowserNetscape() {
82 return (browserDetect('Mozilla/') and
83 ! browserDetect('Gecko/') and
84 ! browserDetect('MSIE'));
87 function isBrowserNS3() {
88 return (isBrowserNetscape() and browserVersion() < 4.0);
91 require_once('lib/FileFinder.php');
92 // Search PHP's include_path to find file or directory.
93 function FindFile ($file, $missing_okay = false, $slashify = false)
97 $finder = new FileFinder;
98 $s = $finder->findFile($file, $missing_okay);
100 $s = $finder->slashifyPath($s);
104 // Search PHP's include_path to find file or directory.
105 // Searches for "locale/$LANG/$file", then for "$file".
106 function FindLocalizedFile ($file, $missing_okay = false, $re_init = false)
109 if ($re_init or !isset($finder))
110 $finder = new LocalizedFileFinder;
111 return $finder->findFile($file, $missing_okay);
114 function FindLocalizedButtonFile ($file, $missing_okay = false, $re_init = false)
116 static $buttonfinder;
117 if ($re_init or !isset($buttonfinder))
118 $buttonfinder = new LocalizedButtonFinder;
119 return $buttonfinder->findFile($file, $missing_okay);
124 * Smart? setlocale().
126 * This is a version of the builtin setlocale() which is
127 * smart enough to try some alternatives...
129 * @param mixed $category
130 * @param string $locale
131 * @return string The new locale, or <code>false</code> if unable
132 * to set the requested locale.
135 function guessing_setlocale ($category, $locale) {
136 if ($res = setlocale($category, $locale))
138 $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'),
139 'de' => array('de_DE', 'de_DE', 'de_DE@euro',
140 'de_AT@euro', 'de_AT', 'German_Austria.1252', 'deutsch',
142 'es' => array('es_ES', 'es_MX', 'es_AR', 'spanish'),
143 'nl' => array('nl_NL', 'dutch'),
144 'fr' => array('fr_FR', 'français', 'french'),
145 'it' => array('it_IT'),
146 'sv' => array('sv_SE'),
147 'ja' => array('ja_JP','ja_JP.eucJP','japanese.euc')
149 if (strlen($locale) == 2)
152 list ($lang) = split('_', $locale);
153 if (!isset($alt[$lang]))
156 foreach ($alt[$lang] as $try) {
157 if ($res = setlocale($category, $try))
159 // Try with charset appended...
160 $try = $try . '.' . CHARSET;
161 if ($res = setlocale($category, $try))
163 foreach (array('@', ".", '_') as $sep) {
164 list ($try) = split($sep, $try);
165 if ($res = setlocale($category, $try))
171 // A standard locale name is typically of the form
172 // language[_territory][.codeset][@modifier], where language is
173 // an ISO 639 language code, territory is an ISO 3166 country code,
174 // and codeset is a character set or encoding identifier like
175 // ISO-8859-1 or UTF-8.
178 function update_locale($loc) {
179 $newlocale = guessing_setlocale(LC_ALL, $loc);
181 //trigger_error(sprintf(_("Can't setlocale(LC_ALL,'%s')"), $loc), E_USER_NOTICE);
182 // => LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C
183 //$loc = setlocale(LC_CTYPE, ''); // pull locale from environment.
184 $newlocale = FileFinder::_get_lang();
185 list ($newlocale,) = split('_', $newlocale, 2);
186 //$GLOBALS['LANG'] = $loc;
190 //if (substr($newlocale,0,2) == $loc) // don't update with C or failing setlocale
191 $GLOBALS['LANG'] = $loc;
192 // Try to put new locale into environment (so any
193 // programs we run will get the right locale.)
195 // If PHP is in safe mode, this is not allowed,
197 @putenv("LC_ALL=$newlocale");
198 @putenv("LANG=$newlocale");
199 @putenv("LANGUAGE=$newlocale");
201 if (!function_exists ('bindtextdomain')) {
202 // Reinitialize translation array.
205 // do reinit to purge PHP's static cache
206 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok','reinit')) ) {
211 // To get the POSIX character classes in the PCRE's (e.g.
212 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
213 // to set the locale, using setlocale().
215 // The problem is which locale to set? We would like to recognize all
216 // upper-case characters in the iso-8859-1 character set as upper-case
217 // characters --- not just the ones which are in the current $LANG.
219 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
220 // you setlocale() to anything but "C" it works fine. (I'm not sure
221 // whether this is how it's supposed to be, or whether this is a bug
224 // We don't currently use the locale setting for anything else, so for
225 // now, just set the locale to US English.
227 // FIXME: Not all environments may support en_US? We should probably
228 // have a list of locales to try.
229 if (setlocale(LC_CTYPE, 0) == 'C') {
230 $x = setlocale(LC_CTYPE, 'en_US.' . CHARSET );
232 $x = setlocale(LC_CTYPE, $newlocale);
238 if (!defined('DEFAULT_LANGUAGE'))
239 define('DEFAULT_LANGUAGE', 'en');
242 // Set up (possibly fake) gettext()
244 if (!function_exists ('bindtextdomain')) {
247 function gettext ($text) {
249 if (!empty ($locale[$text]))
250 return $locale[$text];
255 return gettext($text);
259 // Working around really weird gettext problems: (4.3.2, 4.3.6 win)
260 // bindtextdomain() returns the current domain path.
261 // 1. If the script is not index.php but something like "de", on a different path
262 // then bindtextdomain() fails, but after chdir to the correct path it will work okay.
263 // 2. But the weird error "Undefined variable: bindtextdomain" is generated then.
264 $bindtextdomain_path = FindFile("locale", false, true);
266 $bindtextdomain_path = str_replace("/","\\",$bindtextdomain_path);
267 $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain);
268 if ($bindtextdomain_real != $bindtextdomain_path) {
269 // this will happen with virtual_paths. chdir and try again.
270 chdir($bindtextdomain_path);
271 $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain);
273 textdomain("phpwiki");
274 if ($bindtextdomain_real != $bindtextdomain_path) { // change back
275 chdir($bindtextdomain_real . (isWindows() ? "\\.." : "/.."));
279 /** string pcre_fix_posix_classes (string $regexp)
281 * Older version (pre 3.x?) of the PCRE library do not support
282 * POSIX named character classes (e.g. [[:alnum:]]).
284 * This is a helper function which can be used to convert a regexp
285 * which contains POSIX named character classes to one that doesn't.
287 * All instances of strings like '[:<class>:]' are replaced by the equivalent
288 * enumerated character class.
290 * Implementation Notes:
292 * Currently we use hard-coded values which are valid only for
293 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
294 * [:upper:] and [:lower:] are implemented. (The missing classes:
295 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
296 * [:space:], and [:xdigit:] could easily be added if needed.)
298 * This is a hack. I tried to generate these classes automatically
299 * using ereg(), but discovered that in my PHP, at least, ereg() is
300 * slightly broken w.r.t. POSIX character classes. (It includes
301 * "\xaa" and "\xba" in [:alpha:].)
303 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
305 function pcre_fix_posix_classes ($regexp) {
306 // First check to see if our PCRE lib supports POSIX character
307 // classes. If it does, there's nothing to do.
308 if (preg_match('/[[:upper:]]/', 'Ä'))
311 static $classes = array(
312 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
313 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
314 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
315 'lower' => "a-z\xdf-\xf6\xf8-\xff"
318 $keys = join('|', array_keys($classes));
320 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
323 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
324 $KeywordLinkRegexp = pcre_fix_posix_classes($KeywordLinkRegexp);
326 //////////////////////////////////////////////////////////////////
327 // Autodetect URL settings:
329 if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
330 if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
331 if (!defined('SERVER_PROTOCOL')) {
332 if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
333 define('SERVER_PROTOCOL', 'http');
335 define('SERVER_PROTOCOL', 'https');
338 function deduce_script_name() {
339 $s = &$GLOBALS['HTTP_SERVER_VARS'];
340 $script = @$s['SCRIPT_NAME'];
341 if (empty($script) or $script[0] != '/') {
342 // Some places (e.g. Lycos) only supply a relative name in
343 // SCRIPT_NAME, but give what we really want in SCRIPT_URL.
344 if (!empty($s['SCRIPT_URL']))
345 $script = $s['SCRIPT_URL'];
350 if (!defined('SCRIPT_NAME'))
351 define('SCRIPT_NAME', deduce_script_name());
353 if (!defined('USE_PATH_INFO'))
356 * If SCRIPT_NAME does not look like php source file,
357 * or user cgi we assume that php is getting run by an
358 * action handler in /cgi-bin. In this case,
359 * I think there is no way to get Apache to pass
360 * useful PATH_INFO to the php script (PATH_INFO
361 * is used to the the php interpreter where the
364 switch (php_sapi_name()) {
366 case 'apache2handler':
367 define('USE_PATH_INFO', true);
370 case 'apache2filter':
371 define('USE_PATH_INFO', false);
374 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', SCRIPT_NAME));
379 // If user has not defined DATA_PATH, we want to use relative URLs.
380 if (!defined('DATA_PATH') && USE_PATH_INFO)
381 define('DATA_PATH', '..');
383 function IsProbablyRedirectToIndex () {
384 // This might be a redirect to the DirectoryIndex,
385 // e.g. REQUEST_URI = /dir/ got redirected
386 // to SCRIPT_NAME = /dir/index.php
388 // In this case, the proper virtual path is still
389 // $SCRIPT_NAME, since pages appear at
390 // e.g. /dir/index.php/HomePage.
392 $requri = preg_quote($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'], '%');
393 return preg_match("%^${requri}[^/]*$%", $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
397 if (!defined('VIRTUAL_PATH')) {
398 // We'd like to auto-detect when the cases where apaches
399 // 'Action' directive (or similar means) is used to
400 // redirect page requests to a cgi-handler.
402 // In cases like this, requests for e.g. /wiki/HomePage
403 // get redirected to a cgi-script called, say,
404 // /path/to/wiki/index.php. The script gets all
405 // of /wiki/HomePage as it's PATH_INFO.
408 // How to detect when this has happened reliably?
409 // How to pick out the "virtual path" (in this case '/wiki')?
411 // (Another time an redirect might occur is to a DirectoryIndex
412 // -- the requested URI is '/wikidir/', the request gets
413 // passed to '/wikidir/index.php'. In this case, the
414 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
415 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
418 $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
419 if (USE_PATH_INFO and isset($REDIRECT_URL)
420 and ! IsProbablyRedirectToIndex()) {
421 // FIXME: This is a hack, and won't work if the requested
422 // pagename has a slash in it.
423 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
425 define('VIRTUAL_PATH', SCRIPT_NAME);
430 && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
432 SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
436 SERVER_PROTOCOL . '://' . SERVER_NAME);
439 if (VIRTUAL_PATH != SCRIPT_NAME) {
440 // Apache action handlers are used.
441 define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
444 define('PATH_INFO_PREFIX', '/');
447 define('PHPWIKI_BASE_URL',
448 SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
450 //////////////////////////////////////////////////////////////////
453 if (empty($DBParams['dbtype']))
454 $DBParams['dbtype'] = 'dba';
456 if (!defined('THEME'))
457 define('THEME', 'default');
459 update_locale(isset($LANG) ? $LANG : DEFAULT_LANGUAGE);
461 if (!defined('WIKI_NAME'))
462 define('WIKI_NAME', _("An unnamed PhpWiki"));
464 if (!defined('HOME_PAGE'))
465 define('HOME_PAGE', _("HomePage"));
469 if (!defined('ACCESS_LOG'))
470 define('ACCESS_LOG', '');
473 // Get remote host name, if apache hasn't done it for us
474 if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
475 $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
477 // check whether the crypt() function is needed and present
478 if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
479 $error = sprintf(_("Encrypted passwords cannot be used: %s."),
480 "'function crypt()' not available in this version of php");
481 trigger_error($error);
484 if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
485 trigger_error(_("The admin password cannot be empty. Please update your /index.php"));
487 if (defined('USE_DB_SESSION') and USE_DB_SESSION) {
488 if (! $DBParams['db_session_table'] ) {
489 trigger_error(_("Empty db_session_table. Turn USE_DB_SESSION off or define the table name."),
491 // this is flawed. constants cannot be changed.
492 define('USE_DB_SESSION',false);
495 // default: true (since v1.3.8)
496 if (!defined('USE_DB_SESSION'))
497 define('USE_DB_SESSION',true);
500 if (!defined('ENABLE_USER_NEW')) define('ENABLE_USER_NEW',true);
501 if (!defined('ALLOW_USER_LOGIN'))
502 define('ALLOW_USER_LOGIN', defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
503 if (!defined('ALLOW_ANON_USER')) define('ALLOW_ANON_USER', true);
504 if (!defined('ALLOW_ANON_EDIT')) define('ALLOW_ANON_EDIT', false);
505 if (!defined('REQUIRE_SIGNIN_BEFORE_EDIT')) define('REQUIRE_SIGNIN_BEFORE_EDIT', ! ALLOW_ANON_EDIT);
506 if (!defined('ALLOW_BOGO_LOGIN')) define('ALLOW_BOGO_LOGIN', true);
508 if (ALLOW_USER_LOGIN and !empty($DBAuthParams) and empty($DBAuthParams['auth_dsn'])) {
509 if (isset($DBParams['dsn']))
510 $DBAuthParams['auth_dsn'] = $DBParams['dsn'];
518 // c-hanging-comment-ender-p: nil
519 // indent-tabs-mode: nil