2 rcs_id('$Id: config.php,v 1.65 2002-09-12 17:36:01 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 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);
70 // I think this putenv is unnecessary, and it causes trouble
71 // if PHP's safe_mode is enabled:
72 //putenv("LC_ALL=$LANG");
74 if (!function_exists ('bindtextdomain')) {
77 function gettext ($text) {
79 if (!empty ($locale[$text]))
80 return $locale[$text];
85 return gettext($text);
88 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
94 // This is currently broken, after trying to enable dynamic UserPreferences
96 function update_locale ($language) {
97 global $locale, $LC_ALL, $language_locales;
98 if (!$language and $GLOBALS['default_language']) {
99 return $GLOBALS['default_language'];
102 // shortterm LANG fix. We really should define LC_ALL as "C" and LANG as "en"
103 if ($language == 'C') {
104 $language = 'en'; $LC_ALL = 'C';
106 if (empty($LC_ALL)) {
107 if (empty($language_locales[$language]))
110 $LC_ALL = $language_locales[$language];
115 // Fixme: Currently we just check the dirs under locale for all
116 // available languages, but with setlocale we must use the long form,
117 // like 'de_DE','nl_NL', 'es_MX', 'es_AR', 'fr_FR'. For Windows maybe even 'german'.
118 $result = setlocale(LC_ALL, $LC_ALL);
119 if (!$result and !($result = setlocale(LC_ALL, substr($LC_ALL,0,2)))) {
120 putenv("LANG=$LC_ALL");
121 // The system supported locale. E.g. my Windows returns "German_Austria.1252"
122 $result = setlocale(LC_ALL,'');
126 putenv("LC_ALL=$LC_ALL");
128 putenv("LANG=$LC_ALL");
130 if (!function_exists ('bindtextdomain')) {
131 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
135 if (empty($language_locales[$language])) {
136 trigger_error(sprintf(_("No default locale for this language '%s'"), $language), E_USER_NOTICE);
138 // Setup localisation
139 $f = FindFile("locale", false, true);
141 bindtextdomain ("phpwiki", $f);
142 textdomain ("phpwiki");
144 $GLOBALS['LANG'] = $language;
146 $default_language = $LANG;
147 update_locale ($LANG);
149 // To get the POSIX character classes in the PCRE's (e.g.
150 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
151 // to set the locale, using setlocale().
153 // The problem is which locale to set? We would like to recognize all
154 // upper-case characters in the iso-8859-1 character set as upper-case
155 // characters --- not just the ones which are in the current $LANG.
157 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
158 // you setlocale() to anything but "C" it works fine. (I'm not sure
159 // whether this is how it's supposed to be, or whether this is a bug
162 // We don't currently use the locale setting for anything else, so for
163 // now, just set the locale to US English.
165 // FIXME: Not all environments may support en_US? We should probably
166 // have a list of locales to try.
167 if (setlocale(LC_CTYPE, 0) == 'C')
168 setlocale(LC_CTYPE, 'en_US.' . CHARSET );
170 /** string pcre_fix_posix_classes (string $regexp)
172 * Older version (pre 3.x?) of the PCRE library do not support
173 * POSIX named character classes (e.g. [[:alnum:]]).
175 * This is a helper function which can be used to convert a regexp
176 * which contains POSIX named character classes to one that doesn't.
178 * All instances of strings like '[:<class>:]' are replaced by the equivalent
179 * enumerated character class.
181 * Implementation Notes:
183 * Currently we use hard-coded values which are valid only for
184 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
185 * [:upper:] and [:lower:] are implemented. (The missing classes:
186 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
187 * [:space:], and [:xdigit:] could easily be added if needed.)
189 * This is a hack. I tried to generate these classes automatically
190 * using ereg(), but discovered that in my PHP, at least, ereg() is
191 * slightly broken w.r.t. POSIX character classes. (It includes
192 * "\xaa" and "\xba" in [:alpha:].)
194 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
196 function pcre_fix_posix_classes ($regexp) {
197 // First check to see if our PCRE lib supports POSIX character
198 // classes. If it does, there's nothing to do.
199 if (preg_match('/[[:upper:]]/', 'Ä'))
202 static $classes = array(
203 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
204 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
205 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
206 'lower' => "a-z\xdf-\xf6\xf8-\xff"
209 $keys = join('|', array_keys($classes));
211 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
214 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
216 //////////////////////////////////////////////////////////////////
217 // Autodetect URL settings:
219 if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
220 if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
221 if (!defined('SERVER_PROTOCOL')) {
222 if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
223 define('SERVER_PROTOCOL', 'http');
225 define('SERVER_PROTOCOL', 'https');
228 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $HTTP_SERVER_VARS['SCRIPT_NAME']);
230 if (!defined('DATA_PATH')) define('DATA_PATH', dirname(SCRIPT_NAME));
232 if (!defined('USE_PATH_INFO'))
235 * If SCRIPT_NAME does not look like php source file,
236 * or user cgi we assume that php is getting run by an
237 * action handler in /cgi-bin. In this case,
238 * I think there is no way to get Apache to pass
239 * useful PATH_INFO to the php script (PATH_INFO
240 * is used to the the php interpreter where the
243 if (php_sapi_name() == 'apache')
244 define('USE_PATH_INFO', true);
246 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
250 function IsProbablyRedirectToIndex () {
251 // This might be a redirect to the DirectoryIndex,
252 // e.g. REQUEST_URI = /dir/ got redirected
253 // to SCRIPT_NAME = /dir/index.php
255 // In this case, the proper virtual path is still
256 // $SCRIPT_NAME, since pages appear at
257 // e.g. /dir/index.php/HomePage.
259 $requri = preg_quote($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'], '%');
260 return preg_match("%^${requri}[^/]*$%", $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
264 if (!defined('VIRTUAL_PATH')) {
265 // We'd like to auto-detect when the cases where apaches
266 // 'Action' directive (or similar means) is used to
267 // redirect page requests to a cgi-handler.
269 // In cases like this, requests for e.g. /wiki/HomePage
270 // get redirected to a cgi-script called, say,
271 // /path/to/wiki/index.php. The script gets all
272 // of /wiki/HomePage as it's PATH_INFO.
275 // How to detect when this has happened reliably?
276 // How to pick out the "virtual path" (in this case '/wiki')?
278 // (Another time an redirect might occur is to a DirectoryIndex
279 // -- the requested URI is '/wikidir/', the request gets
280 // passed to '/wikidir/index.php'. In this case, the
281 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
282 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
285 $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
286 if (USE_PATH_INFO and isset($REDIRECT_URL)
287 and ! IsProbablyRedirectToIndex()) {
288 // FIXME: This is a hack, and won't work if the requested
289 // pagename has a slash in it.
290 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
292 define('VIRTUAL_PATH', SCRIPT_NAME);
297 && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
299 SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
303 SERVER_PROTOCOL . '://' . SERVER_NAME);
306 if (VIRTUAL_PATH != SCRIPT_NAME) {
307 // Apache action handlers are used.
308 define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
311 define('PATH_INFO_PREFIX', '/');
315 SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
317 //////////////////////////////////////////////////////////////////
320 if (empty($DBParams['dbtype']))
321 $DBParams['dbtype'] = 'dba';
323 if (!defined('WIKI_NAME'))
324 define('WIKI_NAME', _("An unnamed PhpWiki"));
326 if (!defined('THEME'))
327 define('THEME', 'default');
329 if (!defined('HOME_PAGE'))
330 define('HOME_PAGE', _("HomePage"));
335 if (!defined('ACCESS_LOG'))
336 define('ACCESS_LOG', '');
339 // Get remote host name, if apache hasn't done it for us
340 if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
341 $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
343 // check whether the crypt() function is needed and present
344 if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
345 $error = sprintf(_("Encrypted passwords cannot be used: %s."),
346 "'function crypt()' not available in this version of php");
347 trigger_error($error);
350 if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
351 trigger_error(_("The admin password cannot be empty. Please update your /index.php"));
353 if (defined('USE_DB_SESSION') and USE_DB_SESSION) {
354 if ($DBParams['dbtype'] != 'SQL') {
355 trigger_error(sprintf(_("You can use %s only with %s"),
356 'DB_Session', '$DBParams[\'dbtype\']: SQL'),
358 define('USE_DB_SESSION',false);
360 elseif (! $DBParams['db_session_table'] ) {
361 trigger_error(_("Empty db_session_table. Turn USE_DB_SESSION off or define the table name."),
363 define('USE_DB_SESSION',false);
366 if (!defined('USE_DB_SESSION'))
367 define('USE_DB_SESSION',false);
375 // c-hanging-comment-ender-p: nil
376 // indent-tabs-mode: nil