2 rcs_id('$Id: config.php,v 1.61 2002-08-27 21:51:31 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)
32 $finder = new FileFinder;
33 $s = $finder->findFile($file, $missing_okay);
37 // Search PHP's include_path to find file or directory.
38 // Searches for "locale/$LANG/$file", then for "$file".
39 function FindLocalizedFile ($file, $missing_okay = false)
43 $finder = new LocalizedFileFinder;
44 return $finder->findFile($file, $missing_okay);
47 function FindLocalizedButtonFile ($file, $missing_okay = false)
50 if (!isset($buttonfinder))
51 $buttonfinder = new LocalizedButtonFinder;
52 return $buttonfinder->findFile($file, $missing_okay);
55 // I think this putenv is unnecessary, and it causes trouble
56 // if PHP's safe_mode is enabled:
57 //putenv("LC_ALL=$LANG");
59 if (!function_exists ('bindtextdomain')) {
62 function gettext ($text) {
64 if (!empty ($locale[$text]))
65 return $locale[$text];
70 return gettext($text);
73 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
79 // This is currently broken, after trying to enable dynamic UserPreferences
81 function update_locale ($LANG) {
83 global $locale, $LC_ALL, $language_locales;
84 if (empty($language_locales[$LANG]))
87 $LC_ALL = $language_locales[$LANG];
91 // Fixme: Currently we just check the dirs under locale for all
92 // available languages, but with setlocale we must use the long form,
93 // like 'de_DE','nl_NL', 'es_MX', 'es_AR', 'fr_FR'. For Windows maybe even 'german'.
94 setlocale(LC_ALL, $LC_ALL);
96 if (!function_exists ('bindtextdomain')) {
97 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
101 if (empty($language_locales[$LANG])) {
102 trigger_error(_("Dynamically changing the language not (yet) available on this locale"), E_USER_NOTICE);
104 // Setup localisation
105 bindtextdomain ("phpwiki", FindFile("locale"));
106 textdomain ("phpwiki");
110 //update_locale ($LANG);
112 if (empty($language_locales[$LANG]))
115 $LC_ALL = $language_locales[$LANG];
119 // Fixme: Currently we just check the dirs under locale for all
120 // available languages, but with setlocale we must use the long form,
121 // like 'de_DE','nl_NL', 'es_MX', 'es_AR', 'fr_FR'. For Windows maybe even 'german'.
122 setlocale(LC_ALL, $LC_ALL);
124 if (!function_exists ('bindtextdomain')) {
125 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
129 if (empty($language_locales[$LANG])) {
130 trigger_error(_("Dynamically changing the language not (yet) available on this locale"), E_USER_NOTICE);
132 // Setup localisation
133 bindtextdomain ("phpwiki", FindFile("locale"));
134 textdomain ("phpwiki");
138 // To get the POSIX character classes in the PCRE's (e.g.
139 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
140 // to set the locale, using setlocale().
142 // The problem is which locale to set? We would like to recognize all
143 // upper-case characters in the iso-8859-1 character set as upper-case
144 // characters --- not just the ones which are in the current $LANG.
146 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
147 // you setlocale() to anything but "C" it works fine. (I'm not sure
148 // whether this is how it's supposed to be, or whether this is a bug
151 // We don't currently use the locale setting for anything else, so for
152 // now, just set the locale to US English.
154 // FIXME: Not all environments may support en_US? We should probably
155 // have a list of locales to try.
156 if (setlocale(LC_CTYPE, 0) == 'C')
157 setlocale(LC_CTYPE, 'en_US.' . CHARSET );
159 /** string pcre_fix_posix_classes (string $regexp)
161 * Older version (pre 3.x?) of the PCRE library do not support
162 * POSIX named character classes (e.g. [[:alnum:]]).
164 * This is a helper function which can be used to convert a regexp
165 * which contains POSIX named character classes to one that doesn't.
167 * All instances of strings like '[:<class>:]' are replaced by the equivalent
168 * enumerated character class.
170 * Implementation Notes:
172 * Currently we use hard-coded values which are valid only for
173 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
174 * [:upper:] and [:lower:] are implemented. (The missing classes:
175 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
176 * [:space:], and [:xdigit:] could easily be added if needed.)
178 * This is a hack. I tried to generate these classes automatically
179 * using ereg(), but discovered that in my PHP, at least, ereg() is
180 * slightly broken w.r.t. POSIX character classes. (It includes
181 * "\xaa" and "\xba" in [:alpha:].)
183 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
185 function pcre_fix_posix_classes ($regexp) {
186 // First check to see if our PCRE lib supports POSIX character
187 // classes. If it does, there's nothing to do.
188 if (preg_match('/[[:upper:]]/', 'Ä'))
191 static $classes = array(
192 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
193 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
194 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
195 'lower' => "a-z\xdf-\xf6\xf8-\xff"
198 $keys = join('|', array_keys($classes));
200 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
203 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
205 //////////////////////////////////////////////////////////////////
206 // Autodetect URL settings:
208 if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
209 if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
210 if (!defined('SERVER_PROTOCOL')) {
211 if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
212 define('SERVER_PROTOCOL', 'http');
214 define('SERVER_PROTOCOL', 'https');
217 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $HTTP_SERVER_VARS['SCRIPT_NAME']);
219 if (!defined('DATA_PATH')) define('DATA_PATH', dirname(SCRIPT_NAME));
221 if (!defined('USE_PATH_INFO'))
224 * If SCRIPT_NAME does not look like php source file,
225 * or user cgi we assume that php is getting run by an
226 * action handler in /cgi-bin. In this case,
227 * I think there is no way to get Apache to pass
228 * useful PATH_INFO to the php script (PATH_INFO
229 * is used to the the php interpreter where the
232 if (php_sapi_name() == 'apache')
233 define('USE_PATH_INFO', true);
235 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
239 function IsProbablyRedirectToIndex ()
241 // This might be a redirect to the DirectoryIndex,
242 // e.g. REQUEST_URI = /dir/ got redirected
243 // to SCRIPT_NAME = /dir/index.php
245 // In this case, the proper virtual path is still
246 // $SCRIPT_NAME, since pages appear at
247 // e.g. /dir/index.php/HomePage.
249 //global $REQUEST_URI, $SCRIPT_NAME;
250 extract($GLOBALS['HTTP_SERVER_VARS']);
252 $requri = preg_quote($REQUEST_URI, '%');
253 return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
257 if (!defined('VIRTUAL_PATH'))
259 // We'd like to auto-detect when the cases where apaches
260 // 'Action' directive (or similar means) is used to
261 // redirect page requests to a cgi-handler.
263 // In cases like this, requests for e.g. /wiki/HomePage
264 // get redirected to a cgi-script called, say,
265 // /path/to/wiki/index.php. The script gets all
266 // of /wiki/HomePage as it's PATH_INFO.
269 // How to detect when this has happened reliably?
270 // How to pick out the "virtual path" (in this case '/wiki')?
272 // (Another time an redirect might occur is to a DirectoryIndex
273 // -- the requested URI is '/wikidir/', the request gets
274 // passed to '/wikidir/index.php'. In this case, the
275 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
276 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
279 $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
280 if (USE_PATH_INFO and isset($REDIRECT_URL)
281 and ! IsProbablyRedirectToIndex())
283 // FIXME: This is a hack, and won't work if the requested
284 // pagename has a slash in it.
285 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
288 define('VIRTUAL_PATH', SCRIPT_NAME);
292 && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
294 SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
298 SERVER_PROTOCOL . '://' . SERVER_NAME);
301 if (VIRTUAL_PATH != SCRIPT_NAME)
303 // Apache action handlers are used.
304 define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
307 define('PATH_INFO_PREFIX', '/');
311 SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
313 //////////////////////////////////////////////////////////////////
316 if (empty($DBParams['dbtype']))
317 $DBParams['dbtype'] = 'dba';
319 if (!defined('WIKI_NAME'))
320 define('WIKI_NAME', _("An unnamed PhpWiki"));
322 if (!defined('THEME'))
323 define('THEME', 'default');
325 if (!defined('HOME_PAGE'))
326 define('HOME_PAGE', _("HomePage"));
331 if (!defined('ACCESS_LOG'))
332 define('ACCESS_LOG', '');
335 // Get remote host name, if apache hasn't done it for us
336 if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
337 $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
339 // check whether the crypt() function is needed and present
340 if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
341 $error = sprintf(_("Encrypted passwords cannot be used: %s."),
342 "'function crypt()' not available in this version of php");
343 trigger_error($error);
346 if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
347 trigger_error(_("The admin password cannot be empty. Please update your /index.php"));
354 // c-hanging-comment-ender-p: nil
355 // indent-tabs-mode: nil