2 rcs_id('$Id: config.php,v 1.66 2002-09-18 18:34:13 dairiki 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 define("LC_ALL", "LC_ALL");
13 define("LC_CTYPE", "LC_CTYPE");
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 = "\x81";
39 require_once('lib/FileFinder.php');
40 // Search PHP's include_path to find file or directory.
41 function FindFile ($file, $missing_okay = false, $slashify = false)
45 $finder = new FileFinder;
46 $s = $finder->findFile($file, $missing_okay);
48 $s = $finder->slashifyPath($s);
52 // Search PHP's include_path to find file or directory.
53 // Searches for "locale/$LANG/$file", then for "$file".
54 function FindLocalizedFile ($file, $missing_okay = false)
58 $finder = new LocalizedFileFinder;
59 return $finder->findFile($file, $missing_okay);
62 function FindLocalizedButtonFile ($file, $missing_okay = false)
65 if (!isset($buttonfinder))
66 $buttonfinder = new LocalizedButtonFinder;
67 return $buttonfinder->findFile($file, $missing_okay);
71 // Set up (possibly fake) gettext()
73 if (!function_exists ('bindtextdomain')) {
76 function gettext ($text) {
78 if (!empty ($locale[$text]))
79 return $locale[$text];
84 return gettext($text);
88 bindtextdomain("phpwiki", FindFile("locale", false, true));
89 textdomain("phpwiki");
96 * This is a version of the builtin setlocale() which is
97 * smart enough to try some alternatives...
99 * @param mixed $category
100 * @param string $locale
101 * @return string The new locale, or <code>false</code> if unable
102 * to set the requested locale.
105 function guessing_setlocale ($category, $locale) {
106 if ($res = setlocale($category, $locale))
109 $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'),
110 'de' => array('de_DE', 'deutsch', 'german'),
111 'es' => array('es_ES', 'es_MX', 'es_AR', 'spanish'),
112 'nl' => array('nl_NL', 'dutch'),
113 'fr' => array('fr_FR', 'français', 'french'),
114 'it' => array('it_IT'),
115 'sv' => array('sv_SE')
118 list ($lang) = split('_', $locale);
119 if (!isset($alt[$lang]))
122 foreach ($alt[$lang] as $try) {
123 // Try first with charset appended...
124 $try = $try . '.' . CHARSET;
125 if ($res = setlocale($category, $try))
127 foreach (array('@', ".", '_') as $sep) {
128 list ($try) = split($sep, $try);
129 if ($res = setlocale($category, $try))
135 // A standard locale name is typically of the form
136 // language[_territory][.codeset][@modifier], where language is
137 // an ISO 639 language code, territory is an ISO 3166 country code,
138 // and codeset is a character set or encoding identifier like
139 // ISO-8859-1 or UTF-8.
142 function update_locale ($loc) {
143 $newlocale = guessing_setlocale(LC_ALL, $loc);
145 trigger_error(fmt("Can't set locale: '%s'", $loc), E_USER_NOTICE);
146 $loc = setlocale(LC_ALL, ''); // pull locale from environment.
147 list ($loc,) = split('_', $loc, 2);
148 $GLOBALS['LANG'] = $loc;
152 $GLOBALS['LANG'] = $loc;
153 // Try to put new locale into environment (so any
154 // programs we run will get the right locale.)
156 // If PHP is in safe mode, this is not allowed,
158 @putenv("LC_ALL=$newlocale");
159 @putenv("LANG=$newlocale");
161 if (!function_exists ('bindtextdomain')) {
162 // Reinitialize translation array.
165 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
170 // To get the POSIX character classes in the PCRE's (e.g.
171 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
172 // to set the locale, using setlocale().
174 // The problem is which locale to set? We would like to recognize all
175 // upper-case characters in the iso-8859-1 character set as upper-case
176 // characters --- not just the ones which are in the current $LANG.
178 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
179 // you setlocale() to anything but "C" it works fine. (I'm not sure
180 // whether this is how it's supposed to be, or whether this is a bug
183 // We don't currently use the locale setting for anything else, so for
184 // now, just set the locale to US English.
186 // FIXME: Not all environments may support en_US? We should probably
187 // have a list of locales to try.
188 if (setlocale(LC_CTYPE, 0) == 'C')
189 setlocale(LC_CTYPE, 'en_US.' . CHARSET );
191 setlocale(LC_CTYPE, $newlocale);
196 if (!defined('DEFAULT_LANGUAGE'))
197 define('DEFAULT_LANGUAGE', 'en');
198 update_locale(DEFAULT_LANGUAGE);
201 /** string pcre_fix_posix_classes (string $regexp)
203 * Older version (pre 3.x?) of the PCRE library do not support
204 * POSIX named character classes (e.g. [[:alnum:]]).
206 * This is a helper function which can be used to convert a regexp
207 * which contains POSIX named character classes to one that doesn't.
209 * All instances of strings like '[:<class>:]' are replaced by the equivalent
210 * enumerated character class.
212 * Implementation Notes:
214 * Currently we use hard-coded values which are valid only for
215 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
216 * [:upper:] and [:lower:] are implemented. (The missing classes:
217 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
218 * [:space:], and [:xdigit:] could easily be added if needed.)
220 * This is a hack. I tried to generate these classes automatically
221 * using ereg(), but discovered that in my PHP, at least, ereg() is
222 * slightly broken w.r.t. POSIX character classes. (It includes
223 * "\xaa" and "\xba" in [:alpha:].)
225 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
227 function pcre_fix_posix_classes ($regexp) {
228 // First check to see if our PCRE lib supports POSIX character
229 // classes. If it does, there's nothing to do.
230 if (preg_match('/[[:upper:]]/', 'Ä'))
233 static $classes = array(
234 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
235 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
236 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
237 'lower' => "a-z\xdf-\xf6\xf8-\xff"
240 $keys = join('|', array_keys($classes));
242 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
245 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
247 //////////////////////////////////////////////////////////////////
248 // Autodetect URL settings:
250 if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
251 if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
252 if (!defined('SERVER_PROTOCOL')) {
253 if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
254 define('SERVER_PROTOCOL', 'http');
256 define('SERVER_PROTOCOL', 'https');
259 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $HTTP_SERVER_VARS['SCRIPT_NAME']);
261 if (!defined('DATA_PATH')) define('DATA_PATH', dirname(SCRIPT_NAME));
263 if (!defined('USE_PATH_INFO'))
266 * If SCRIPT_NAME does not look like php source file,
267 * or user cgi we assume that php is getting run by an
268 * action handler in /cgi-bin. In this case,
269 * I think there is no way to get Apache to pass
270 * useful PATH_INFO to the php script (PATH_INFO
271 * is used to the the php interpreter where the
274 if (php_sapi_name() == 'apache')
275 define('USE_PATH_INFO', true);
277 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
281 function IsProbablyRedirectToIndex () {
282 // This might be a redirect to the DirectoryIndex,
283 // e.g. REQUEST_URI = /dir/ got redirected
284 // to SCRIPT_NAME = /dir/index.php
286 // In this case, the proper virtual path is still
287 // $SCRIPT_NAME, since pages appear at
288 // e.g. /dir/index.php/HomePage.
290 $requri = preg_quote($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'], '%');
291 return preg_match("%^${requri}[^/]*$%", $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
295 if (!defined('VIRTUAL_PATH')) {
296 // We'd like to auto-detect when the cases where apaches
297 // 'Action' directive (or similar means) is used to
298 // redirect page requests to a cgi-handler.
300 // In cases like this, requests for e.g. /wiki/HomePage
301 // get redirected to a cgi-script called, say,
302 // /path/to/wiki/index.php. The script gets all
303 // of /wiki/HomePage as it's PATH_INFO.
306 // How to detect when this has happened reliably?
307 // How to pick out the "virtual path" (in this case '/wiki')?
309 // (Another time an redirect might occur is to a DirectoryIndex
310 // -- the requested URI is '/wikidir/', the request gets
311 // passed to '/wikidir/index.php'. In this case, the
312 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
313 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
316 $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
317 if (USE_PATH_INFO and isset($REDIRECT_URL)
318 and ! IsProbablyRedirectToIndex()) {
319 // FIXME: This is a hack, and won't work if the requested
320 // pagename has a slash in it.
321 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
323 define('VIRTUAL_PATH', SCRIPT_NAME);
328 && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
330 SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
334 SERVER_PROTOCOL . '://' . SERVER_NAME);
337 if (VIRTUAL_PATH != SCRIPT_NAME) {
338 // Apache action handlers are used.
339 define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
342 define('PATH_INFO_PREFIX', '/');
346 SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
348 //////////////////////////////////////////////////////////////////
351 if (empty($DBParams['dbtype']))
352 $DBParams['dbtype'] = 'dba';
354 if (!defined('WIKI_NAME'))
355 define('WIKI_NAME', _("An unnamed PhpWiki"));
357 if (!defined('THEME'))
358 define('THEME', 'default');
360 if (!defined('HOME_PAGE'))
361 define('HOME_PAGE', _("HomePage"));
366 if (!defined('ACCESS_LOG'))
367 define('ACCESS_LOG', '');
370 // Get remote host name, if apache hasn't done it for us
371 if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
372 $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
374 // check whether the crypt() function is needed and present
375 if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
376 $error = sprintf(_("Encrypted passwords cannot be used: %s."),
377 "'function crypt()' not available in this version of php");
378 trigger_error($error);
381 if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
382 trigger_error(_("The admin password cannot be empty. Please update your /index.php"));
384 if (defined('USE_DB_SESSION') and USE_DB_SESSION) {
385 if ($DBParams['dbtype'] != 'SQL') {
386 trigger_error(sprintf(_("You can use %s only with %s"),
387 'DB_Session', '$DBParams[\'dbtype\']: SQL'),
389 define('USE_DB_SESSION',false);
391 elseif (! $DBParams['db_session_table'] ) {
392 trigger_error(_("Empty db_session_table. Turn USE_DB_SESSION off or define the table name."),
394 define('USE_DB_SESSION',false);
397 if (!defined('USE_DB_SESSION'))
398 define('USE_DB_SESSION',false);
406 // c-hanging-comment-ender-p: nil
407 // indent-tabs-mode: nil