2 rcs_id('$Id: config.php,v 1.62 2002-09-09 08:38:19 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");
16 // essential internal stuff
17 set_magic_quotes_runtime(0);
21 // "\x80"-"\x9f" (and "\x00" - "\x1f") are non-printing control
22 // chars in iso-8859-*
23 // $FieldSeparator = "\263"; //this is a superscript 3 in ISO-8859-1.
24 $FieldSeparator = "\x81";
26 require_once('lib/FileFinder.php');
27 // Search PHP's include_path to find file or directory.
28 function FindFile ($file, $missing_okay = false, $slashify = false)
32 $finder = new FileFinder;
33 $s = $finder->findFile($file, $missing_okay);
35 $s = $finder->slashifyPath($s);
39 // Search PHP's include_path to find file or directory.
40 // Searches for "locale/$LANG/$file", then for "$file".
41 function FindLocalizedFile ($file, $missing_okay = false)
45 $finder = new LocalizedFileFinder;
46 return $finder->findFile($file, $missing_okay);
49 function FindLocalizedButtonFile ($file, $missing_okay = false)
52 if (!isset($buttonfinder))
53 $buttonfinder = new LocalizedButtonFinder;
54 return $buttonfinder->findFile($file, $missing_okay);
57 // I think this putenv is unnecessary, and it causes trouble
58 // if PHP's safe_mode is enabled:
59 //putenv("LC_ALL=$LANG");
61 if (!function_exists ('bindtextdomain')) {
64 function gettext ($text) {
66 if (!empty ($locale[$text]))
67 return $locale[$text];
72 return gettext($text);
75 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
81 // This is currently broken, after trying to enable dynamic UserPreferences
83 function update_locale ($language) {
84 global $locale, $LC_ALL, $language_locales;
86 // shortterm LANG fix. We really should define LC_ALL as "C" and LANG as "en"
87 if ($language == 'C') {
88 $language = 'en'; $LC_ALL = 'C';
91 if (empty($language_locales[$language]))
94 $LC_ALL = $language_locales[$language];
99 // Fixme: Currently we just check the dirs under locale for all
100 // available languages, but with setlocale we must use the long form,
101 // like 'de_DE','nl_NL', 'es_MX', 'es_AR', 'fr_FR'. For Windows maybe even 'german'.
102 $result = setlocale(LC_ALL, $LC_ALL);
103 if (!$result and !($result = setlocale(LC_ALL, substr($LC_ALL,0,2)))) {
104 putenv("LANG=$LC_ALL");
105 // The system supported locale. E.g. my Windows returns "German_Austria.1252"
106 $result = setlocale(LC_ALL,'');
110 putenv("LC_ALL=$LC_ALL");
111 putenv("LANG=$LC_ALL");
114 if (!function_exists ('bindtextdomain')) {
115 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
119 if (empty($language_locales[$language])) {
120 trigger_error(sprintf(_("No default locale for this language '%s'"), $language), E_USER_NOTICE);
122 // Setup localisation
123 $f = FindFile("locale", false, true);
125 bindtextdomain ("phpwiki", $f);
126 textdomain ("phpwiki");
128 $GLOBALS['LANG'] = $language;
130 update_locale ($LANG);
131 $default_language = $LANG;
133 // To get the POSIX character classes in the PCRE's (e.g.
134 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
135 // to set the locale, using setlocale().
137 // The problem is which locale to set? We would like to recognize all
138 // upper-case characters in the iso-8859-1 character set as upper-case
139 // characters --- not just the ones which are in the current $LANG.
141 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
142 // you setlocale() to anything but "C" it works fine. (I'm not sure
143 // whether this is how it's supposed to be, or whether this is a bug
146 // We don't currently use the locale setting for anything else, so for
147 // now, just set the locale to US English.
149 // FIXME: Not all environments may support en_US? We should probably
150 // have a list of locales to try.
151 if (setlocale(LC_CTYPE, 0) == 'C')
152 setlocale(LC_CTYPE, 'en_US.' . CHARSET );
154 /** string pcre_fix_posix_classes (string $regexp)
156 * Older version (pre 3.x?) of the PCRE library do not support
157 * POSIX named character classes (e.g. [[:alnum:]]).
159 * This is a helper function which can be used to convert a regexp
160 * which contains POSIX named character classes to one that doesn't.
162 * All instances of strings like '[:<class>:]' are replaced by the equivalent
163 * enumerated character class.
165 * Implementation Notes:
167 * Currently we use hard-coded values which are valid only for
168 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
169 * [:upper:] and [:lower:] are implemented. (The missing classes:
170 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
171 * [:space:], and [:xdigit:] could easily be added if needed.)
173 * This is a hack. I tried to generate these classes automatically
174 * using ereg(), but discovered that in my PHP, at least, ereg() is
175 * slightly broken w.r.t. POSIX character classes. (It includes
176 * "\xaa" and "\xba" in [:alpha:].)
178 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
180 function pcre_fix_posix_classes ($regexp) {
181 // First check to see if our PCRE lib supports POSIX character
182 // classes. If it does, there's nothing to do.
183 if (preg_match('/[[:upper:]]/', 'Ä'))
186 static $classes = array(
187 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
188 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
189 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
190 'lower' => "a-z\xdf-\xf6\xf8-\xff"
193 $keys = join('|', array_keys($classes));
195 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
198 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
200 //////////////////////////////////////////////////////////////////
201 // Autodetect URL settings:
203 if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
204 if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
205 if (!defined('SERVER_PROTOCOL')) {
206 if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
207 define('SERVER_PROTOCOL', 'http');
209 define('SERVER_PROTOCOL', 'https');
212 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $HTTP_SERVER_VARS['SCRIPT_NAME']);
214 if (!defined('DATA_PATH')) define('DATA_PATH', dirname(SCRIPT_NAME));
216 if (!defined('USE_PATH_INFO'))
219 * If SCRIPT_NAME does not look like php source file,
220 * or user cgi we assume that php is getting run by an
221 * action handler in /cgi-bin. In this case,
222 * I think there is no way to get Apache to pass
223 * useful PATH_INFO to the php script (PATH_INFO
224 * is used to the the php interpreter where the
227 if (php_sapi_name() == 'apache')
228 define('USE_PATH_INFO', true);
230 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
234 function IsProbablyRedirectToIndex ()
236 // This might be a redirect to the DirectoryIndex,
237 // e.g. REQUEST_URI = /dir/ got redirected
238 // to SCRIPT_NAME = /dir/index.php
240 // In this case, the proper virtual path is still
241 // $SCRIPT_NAME, since pages appear at
242 // e.g. /dir/index.php/HomePage.
244 //global $REQUEST_URI, $SCRIPT_NAME;
245 extract($GLOBALS['HTTP_SERVER_VARS']);
247 $requri = preg_quote($REQUEST_URI, '%');
248 return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
252 if (!defined('VIRTUAL_PATH'))
254 // We'd like to auto-detect when the cases where apaches
255 // 'Action' directive (or similar means) is used to
256 // redirect page requests to a cgi-handler.
258 // In cases like this, requests for e.g. /wiki/HomePage
259 // get redirected to a cgi-script called, say,
260 // /path/to/wiki/index.php. The script gets all
261 // of /wiki/HomePage as it's PATH_INFO.
264 // How to detect when this has happened reliably?
265 // How to pick out the "virtual path" (in this case '/wiki')?
267 // (Another time an redirect might occur is to a DirectoryIndex
268 // -- the requested URI is '/wikidir/', the request gets
269 // passed to '/wikidir/index.php'. In this case, the
270 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
271 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
274 $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
275 if (USE_PATH_INFO and isset($REDIRECT_URL)
276 and ! IsProbablyRedirectToIndex())
278 // FIXME: This is a hack, and won't work if the requested
279 // pagename has a slash in it.
280 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
283 define('VIRTUAL_PATH', SCRIPT_NAME);
287 && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
289 SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
293 SERVER_PROTOCOL . '://' . SERVER_NAME);
296 if (VIRTUAL_PATH != SCRIPT_NAME)
298 // Apache action handlers are used.
299 define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
302 define('PATH_INFO_PREFIX', '/');
306 SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
308 //////////////////////////////////////////////////////////////////
311 if (empty($DBParams['dbtype']))
312 $DBParams['dbtype'] = 'dba';
314 if (!defined('WIKI_NAME'))
315 define('WIKI_NAME', _("An unnamed PhpWiki"));
317 if (!defined('THEME'))
318 define('THEME', 'default');
320 if (!defined('HOME_PAGE'))
321 define('HOME_PAGE', _("HomePage"));
326 if (!defined('ACCESS_LOG'))
327 define('ACCESS_LOG', '');
330 // Get remote host name, if apache hasn't done it for us
331 if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
332 $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
334 // check whether the crypt() function is needed and present
335 if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
336 $error = sprintf(_("Encrypted passwords cannot be used: %s."),
337 "'function crypt()' not available in this version of php");
338 trigger_error($error);
341 if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
342 trigger_error(_("The admin password cannot be empty. Please update your /index.php"));
349 // c-hanging-comment-ender-p: nil
350 // indent-tabs-mode: nil