2 rcs_id('$Id: config.php,v 1.86 2004-02-28 21:14:08 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)
12 // huh? I have LC_ALL = 0. Does old PHP really have this odd definition?
13 define("LC_ALL", "LC_ALL");
14 define("LC_CTYPE", "LC_CTYPE");
18 return @preg_match('/CGI/',$GLOBALS['HTTP_ENV_VARS']['GATEWAY_INTERFACE']);
22 // copy some $_ENV vars to $_SERVER for CGI compatibility. php does it automatically since when?
24 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) {
25 $GLOBALS['HTTP_SERVER_VARS'][$key] = &$GLOBALS['HTTP_ENV_VARS'][$key];
30 // essential internal stuff
31 set_magic_quotes_runtime(0);
35 // "\x80"-"\x9f" (and "\x00" - "\x1f") are non-printing control
36 // chars in iso-8859-*
37 // $FieldSeparator = "\263"; //this is a superscript 3 in ISO-8859-1.
38 $FieldSeparator = "\x81";
40 require_once('lib/FileFinder.php');
41 // Search PHP's include_path to find file or directory.
42 function FindFile ($file, $missing_okay = false, $slashify = false)
46 $finder = new FileFinder;
47 $s = $finder->findFile($file, $missing_okay);
49 $s = $finder->slashifyPath($s);
53 // Search PHP's include_path to find file or directory.
54 // Searches for "locale/$LANG/$file", then for "$file".
55 function FindLocalizedFile ($file, $missing_okay = false)
59 $finder = new LocalizedFileFinder;
60 return $finder->findFile($file, $missing_okay);
63 function FindLocalizedButtonFile ($file, $missing_okay = false)
66 if (!isset($buttonfinder))
67 $buttonfinder = new LocalizedButtonFinder;
68 return $buttonfinder->findFile($file, $missing_okay);
75 * This is a version of the builtin setlocale() which is
76 * smart enough to try some alternatives...
78 * @param mixed $category
79 * @param string $locale
80 * @return string The new locale, or <code>false</code> if unable
81 * to set the requested locale.
84 function guessing_setlocale ($category, $locale) {
85 if ($res = setlocale($category, $locale))
87 // gettext problem on windows
88 $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'),
89 'de' => array('de_DE', 'German_Austria.1252', 'de_DE@euro', 'de_AT@euro', 'deutsch',
90 'german', 'German', 'de_AT', 'ge'),
91 'es' => array('es_ES', 'es_MX', 'es_AR', 'spanish'),
92 'nl' => array('nl_NL', 'dutch'),
93 'fr' => array('fr_FR', 'français', 'french'),
94 'it' => array('it_IT'),
95 'sv' => array('sv_SE'),
96 'ja' => array('ja_JP','ja_JP.eucJP')
99 list ($lang) = split('_', $locale);
100 if (!isset($alt[$lang]))
103 foreach ($alt[$lang] as $try) {
104 // Try first with charset appended...
105 $try = $try . '.' . CHARSET;
106 if ($res = setlocale($category, $try))
108 foreach (array('@', ".", '_') as $sep) {
109 list ($try) = split($sep, $try);
110 if ($res = setlocale($category, $try))
116 // A standard locale name is typically of the form
117 // language[_territory][.codeset][@modifier], where language is
118 // an ISO 639 language code, territory is an ISO 3166 country code,
119 // and codeset is a character set or encoding identifier like
120 // ISO-8859-1 or UTF-8.
123 function update_locale ($loc) {
124 $newlocale = guessing_setlocale(LC_ALL, $loc);
126 trigger_error(sprintf(_("Can't set locale: '%s'"), $loc), E_USER_NOTICE);
127 // => LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C
128 $loc = setlocale(LC_CTYPE, ''); // pull locale from environment.
129 list ($loc,) = split('_', $loc, 2);
130 $GLOBALS['LANG'] = $loc;
134 $GLOBALS['LANG'] = $loc;
135 // Try to put new locale into environment (so any
136 // programs we run will get the right locale.)
138 // If PHP is in safe mode, this is not allowed,
140 @putenv("LC_ALL=$newlocale");
141 @putenv("LANG=$newlocale");
143 if (!function_exists ('bindtextdomain')) {
144 // Reinitialize translation array.
147 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
152 // To get the POSIX character classes in the PCRE's (e.g.
153 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
154 // to set the locale, using setlocale().
156 // The problem is which locale to set? We would like to recognize all
157 // upper-case characters in the iso-8859-1 character set as upper-case
158 // characters --- not just the ones which are in the current $LANG.
160 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
161 // you setlocale() to anything but "C" it works fine. (I'm not sure
162 // whether this is how it's supposed to be, or whether this is a bug
165 // We don't currently use the locale setting for anything else, so for
166 // now, just set the locale to US English.
168 // FIXME: Not all environments may support en_US? We should probably
169 // have a list of locales to try.
170 if (setlocale(LC_CTYPE, 0) == 'C')
171 setlocale(LC_CTYPE, 'en_US.' . CHARSET );
173 setlocale(LC_CTYPE, $newlocale);
178 if (!defined('DEFAULT_LANGUAGE'))
179 define('DEFAULT_LANGUAGE', 'en');
182 // Set up (possibly fake) gettext()
184 if (!function_exists ('bindtextdomain')) {
187 function gettext ($text) {
189 if (!empty ($locale[$text]))
190 return $locale[$text];
195 return gettext($text);
199 //update_locale (DEFAULT_LANGUAGE); // will fail with a failing gettext
200 bindtextdomain("phpwiki", FindFile("locale", false, true));
201 textdomain("phpwiki");
204 /** string pcre_fix_posix_classes (string $regexp)
206 * Older version (pre 3.x?) of the PCRE library do not support
207 * POSIX named character classes (e.g. [[:alnum:]]).
209 * This is a helper function which can be used to convert a regexp
210 * which contains POSIX named character classes to one that doesn't.
212 * All instances of strings like '[:<class>:]' are replaced by the equivalent
213 * enumerated character class.
215 * Implementation Notes:
217 * Currently we use hard-coded values which are valid only for
218 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
219 * [:upper:] and [:lower:] are implemented. (The missing classes:
220 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
221 * [:space:], and [:xdigit:] could easily be added if needed.)
223 * This is a hack. I tried to generate these classes automatically
224 * using ereg(), but discovered that in my PHP, at least, ereg() is
225 * slightly broken w.r.t. POSIX character classes. (It includes
226 * "\xaa" and "\xba" in [:alpha:].)
228 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
230 function pcre_fix_posix_classes ($regexp) {
231 // First check to see if our PCRE lib supports POSIX character
232 // classes. If it does, there's nothing to do.
233 if (preg_match('/[[:upper:]]/', 'Ä'))
236 static $classes = array(
237 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
238 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
239 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
240 'lower' => "a-z\xdf-\xf6\xf8-\xff"
243 $keys = join('|', array_keys($classes));
245 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
248 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
249 $KeywordLinkRegexp = pcre_fix_posix_classes($KeywordLinkRegexp);
251 //////////////////////////////////////////////////////////////////
252 // Autodetect URL settings:
254 if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
255 if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
256 if (!defined('SERVER_PROTOCOL')) {
257 if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
258 define('SERVER_PROTOCOL', 'http');
260 define('SERVER_PROTOCOL', 'https');
263 function deduce_script_name() {
264 $s = &$GLOBALS['HTTP_SERVER_VARS'];
265 $script = @$s['SCRIPT_NAME'];
266 if (empty($script) or $script[0] != '/') {
267 // Some places (e.g. Lycos) only supply a relative name in
268 // SCRIPT_NAME, but give what we really want in SCRIPT_URL.
269 if (!empty($s['SCRIPT_URL']))
270 $script = $s['SCRIPT_URL'];
275 if (!defined('SCRIPT_NAME'))
276 define('SCRIPT_NAME', deduce_script_name());
278 if (!defined('USE_PATH_INFO'))
281 * If SCRIPT_NAME does not look like php source file,
282 * or user cgi we assume that php is getting run by an
283 * action handler in /cgi-bin. In this case,
284 * I think there is no way to get Apache to pass
285 * useful PATH_INFO to the php script (PATH_INFO
286 * is used to the the php interpreter where the
289 switch (php_sapi_name()) {
291 case 'apache2handler':
292 define('USE_PATH_INFO', true);
295 case 'apache2filter':
296 define('USE_PATH_INFO', false);
299 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', SCRIPT_NAME));
304 // If user has not defined DATA_PATH, we want to use relative URLs.
305 if (!defined('DATA_PATH') && USE_PATH_INFO)
306 define('DATA_PATH', '..');
308 function IsProbablyRedirectToIndex () {
309 // This might be a redirect to the DirectoryIndex,
310 // e.g. REQUEST_URI = /dir/ got redirected
311 // to SCRIPT_NAME = /dir/index.php
313 // In this case, the proper virtual path is still
314 // $SCRIPT_NAME, since pages appear at
315 // e.g. /dir/index.php/HomePage.
317 $requri = preg_quote($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'], '%');
318 return preg_match("%^${requri}[^/]*$%", $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
322 if (!defined('VIRTUAL_PATH')) {
323 // We'd like to auto-detect when the cases where apaches
324 // 'Action' directive (or similar means) is used to
325 // redirect page requests to a cgi-handler.
327 // In cases like this, requests for e.g. /wiki/HomePage
328 // get redirected to a cgi-script called, say,
329 // /path/to/wiki/index.php. The script gets all
330 // of /wiki/HomePage as it's PATH_INFO.
333 // How to detect when this has happened reliably?
334 // How to pick out the "virtual path" (in this case '/wiki')?
336 // (Another time an redirect might occur is to a DirectoryIndex
337 // -- the requested URI is '/wikidir/', the request gets
338 // passed to '/wikidir/index.php'. In this case, the
339 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
340 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
343 $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
344 if (USE_PATH_INFO and isset($REDIRECT_URL)
345 and ! IsProbablyRedirectToIndex()) {
346 // FIXME: This is a hack, and won't work if the requested
347 // pagename has a slash in it.
348 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
350 define('VIRTUAL_PATH', SCRIPT_NAME);
355 && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
357 SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
361 SERVER_PROTOCOL . '://' . SERVER_NAME);
364 if (VIRTUAL_PATH != SCRIPT_NAME) {
365 // Apache action handlers are used.
366 define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
369 define('PATH_INFO_PREFIX', '/');
372 define('PHPWIKI_BASE_URL',
373 SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
375 //////////////////////////////////////////////////////////////////
378 if (empty($DBParams['dbtype']))
379 $DBParams['dbtype'] = 'dba';
381 if (!defined('WIKI_NAME'))
382 define('WIKI_NAME', _("An unnamed PhpWiki"));
384 if (!defined('THEME'))
385 define('THEME', 'default');
387 if (!defined('HOME_PAGE'))
388 define('HOME_PAGE', _("HomePage"));
393 if (!defined('ACCESS_LOG'))
394 define('ACCESS_LOG', '');
397 // Get remote host name, if apache hasn't done it for us
398 if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
399 $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
401 // check whether the crypt() function is needed and present
402 if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
403 $error = sprintf(_("Encrypted passwords cannot be used: %s."),
404 "'function crypt()' not available in this version of php");
405 trigger_error($error);
408 if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
409 trigger_error(_("The admin password cannot be empty. Please update your /index.php"));
411 if (defined('USE_DB_SESSION') and USE_DB_SESSION) {
412 if (! $DBParams['db_session_table'] ) {
413 trigger_error(_("Empty db_session_table. Turn USE_DB_SESSION off or define the table name."),
415 // this is flawed. constants cannot be changed.
416 define('USE_DB_SESSION',false);
419 // default: true (since v1.3.8)
420 if (!defined('USE_DB_SESSION'))
421 define('USE_DB_SESSION',true);
424 if (!defined('ENABLE_USER_NEW')) define('ENABLE_USER_NEW',true);
425 if (!defined('ALLOW_USER_LOGIN'))
426 define('ALLOW_USER_LOGIN', defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
427 if (!defined('ALLOW_ANON_USER')) define('ALLOW_ANON_USER', true);
428 if (!defined('ALLOW_ANON_EDIT')) define('ALLOW_ANON_EDIT', false);
429 if (!defined('REQUIRE_SIGNIN_BEFORE_EDIT')) define('REQUIRE_SIGNIN_BEFORE_EDIT', ! ALLOW_ANON_EDIT);
430 if (!defined('ALLOW_BOGO_LOGIN')) define('ALLOW_BOGO_LOGIN', true);
432 if (ALLOW_USER_LOGIN and empty($DBAuthParams['auth_dsn'])) {
433 if (isset($DBParams['dsn']))
434 $DBAuthParams['auth_dsn'] = $DBParams['dsn'];
442 // c-hanging-comment-ender-p: nil
443 // indent-tabs-mode: nil