2 rcs_id('$Id: config.php,v 1.60 2002-08-23 18:29:29 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 return $finder->findFile($file, $missing_okay);
36 // Search PHP's include_path to find file or directory.
37 // Searches for "locale/$LANG/$file", then for "$file".
38 function FindLocalizedFile ($file, $missing_okay = false)
42 $finder = new LocalizedFileFinder;
43 return $finder->findFile($file, $missing_okay);
46 function FindLocalizedButtonFile ($file, $missing_okay = false)
49 if (!isset($buttonfinder))
50 $buttonfinder = new LocalizedButtonFinder;
51 return $buttonfinder->findFile($file, $missing_okay);
54 // I think this putenv is unnecessary, and it causes trouble
55 // if PHP's safe_mode is enabled:
56 //putenv("LC_ALL=$LANG");
58 if (!function_exists ('bindtextdomain')) {
61 function gettext ($text) {
63 if (!empty ($locale[$text]))
64 return $locale[$text];
69 return gettext($text);
74 function update_locale ($LANG) {
77 setlocale(LC_ALL, "$LANG");
79 if (!function_exists ('bindtextdomain')) {
80 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
85 bindtextdomain ("phpwiki", FindFile("locale"));
86 textdomain ("phpwiki");
90 update_locale ($LANG);
93 // To get the POSIX character classes in the PCRE's (e.g.
94 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
95 // to set the locale, using setlocale().
97 // The problem is which locale to set? We would like to recognize all
98 // upper-case characters in the iso-8859-1 character set as upper-case
99 // characters --- not just the ones which are in the current $LANG.
101 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
102 // you setlocale() to anything but "C" it works fine. (I'm not sure
103 // whether this is how it's supposed to be, or whether this is a bug
106 // We don't currently use the locale setting for anything else, so for
107 // now, just set the locale to US English.
109 // FIXME: Not all environments may support en_US? We should probably
110 // have a list of locales to try.
111 if (setlocale(LC_CTYPE, 0) == 'C')
112 setlocale(LC_CTYPE, 'en_US.' . CHARSET );
114 /** string pcre_fix_posix_classes (string $regexp)
116 * Older version (pre 3.x?) of the PCRE library do not support
117 * POSIX named character classes (e.g. [[:alnum:]]).
119 * This is a helper function which can be used to convert a regexp
120 * which contains POSIX named character classes to one that doesn't.
122 * All instances of strings like '[:<class>:]' are replaced by the equivalent
123 * enumerated character class.
125 * Implementation Notes:
127 * Currently we use hard-coded values which are valid only for
128 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
129 * [:upper:] and [:lower:] are implemented. (The missing classes:
130 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
131 * [:space:], and [:xdigit:] could easily be added if needed.)
133 * This is a hack. I tried to generate these classes automatically
134 * using ereg(), but discovered that in my PHP, at least, ereg() is
135 * slightly broken w.r.t. POSIX character classes. (It includes
136 * "\xaa" and "\xba" in [:alpha:].)
138 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
140 function pcre_fix_posix_classes ($regexp) {
141 // First check to see if our PCRE lib supports POSIX character
142 // classes. If it does, there's nothing to do.
143 if (preg_match('/[[:upper:]]/', 'Ä'))
146 static $classes = array(
147 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
148 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
149 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
150 'lower' => "a-z\xdf-\xf6\xf8-\xff"
153 $keys = join('|', array_keys($classes));
155 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
158 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
160 //////////////////////////////////////////////////////////////////
161 // Autodetect URL settings:
163 if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
164 if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
165 if (!defined('SERVER_PROTOCOL')) {
166 if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
167 define('SERVER_PROTOCOL', 'http');
169 define('SERVER_PROTOCOL', 'https');
172 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $HTTP_SERVER_VARS['SCRIPT_NAME']);
174 if (!defined('DATA_PATH')) define('DATA_PATH', dirname(SCRIPT_NAME));
176 if (!defined('USE_PATH_INFO'))
179 * If SCRIPT_NAME does not look like php source file,
180 * or user cgi we assume that php is getting run by an
181 * action handler in /cgi-bin. In this case,
182 * I think there is no way to get Apache to pass
183 * useful PATH_INFO to the php script (PATH_INFO
184 * is used to the the php interpreter where the
187 if (php_sapi_name() == 'apache')
188 define('USE_PATH_INFO', true);
190 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
194 function IsProbablyRedirectToIndex ()
196 // This might be a redirect to the DirectoryIndex,
197 // e.g. REQUEST_URI = /dir/ got redirected
198 // to SCRIPT_NAME = /dir/index.php
200 // In this case, the proper virtual path is still
201 // $SCRIPT_NAME, since pages appear at
202 // e.g. /dir/index.php/HomePage.
204 //global $REQUEST_URI, $SCRIPT_NAME;
205 extract($GLOBALS['HTTP_SERVER_VARS']);
207 $requri = preg_quote($REQUEST_URI, '%');
208 return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
212 if (!defined('VIRTUAL_PATH'))
214 // We'd like to auto-detect when the cases where apaches
215 // 'Action' directive (or similar means) is used to
216 // redirect page requests to a cgi-handler.
218 // In cases like this, requests for e.g. /wiki/HomePage
219 // get redirected to a cgi-script called, say,
220 // /path/to/wiki/index.php. The script gets all
221 // of /wiki/HomePage as it's PATH_INFO.
224 // How to detect when this has happened reliably?
225 // How to pick out the "virtual path" (in this case '/wiki')?
227 // (Another time an redirect might occur is to a DirectoryIndex
228 // -- the requested URI is '/wikidir/', the request gets
229 // passed to '/wikidir/index.php'. In this case, the
230 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
231 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
234 $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
235 if (USE_PATH_INFO and isset($REDIRECT_URL)
236 and ! IsProbablyRedirectToIndex())
238 // FIXME: This is a hack, and won't work if the requested
239 // pagename has a slash in it.
240 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
243 define('VIRTUAL_PATH', SCRIPT_NAME);
247 && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
249 SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
253 SERVER_PROTOCOL . '://' . SERVER_NAME);
256 if (VIRTUAL_PATH != SCRIPT_NAME)
258 // Apache action handlers are used.
259 define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
262 define('PATH_INFO_PREFIX', '/');
266 SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
268 //////////////////////////////////////////////////////////////////
271 if (empty($DBParams['dbtype']))
272 $DBParams['dbtype'] = 'dba';
274 if (!defined('WIKI_NAME'))
275 define('WIKI_NAME', _("An unnamed PhpWiki"));
277 if (!defined('THEME'))
278 define('THEME', 'default');
280 if (!defined('HOME_PAGE'))
281 define('HOME_PAGE', _("HomePage"));
286 if (!defined('ACCESS_LOG'))
287 define('ACCESS_LOG', '');
290 // Get remote host name, if apache hasn't done it for us
291 if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
292 $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
294 // check whether the crypt() function is needed and present
295 if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
296 $error = sprintf(_("Encrypted passwords cannot be used: %s."),
297 "'function crypt()' not available in this version of php");
298 trigger_error($error);
301 if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
302 trigger_error(_("The admin password cannot be empty. Please update your /index.php"));
309 // c-hanging-comment-ender-p: nil
310 // indent-tabs-mode: nil