2 rcs_id('$Id: config.php,v 1.41 2001-09-18 19:16:23 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");
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 // Search PHP's include_path to find file or directory.
27 function FindFile ($file, $missing_okay = false)
29 // FIXME: This wont work for DOS filenames.
30 if (ereg('^/', $file))
33 if (file_exists($file))
38 $include_path = ini_get('include_path');
39 if (empty($include_path))
41 // FIXME: This wont work for DOS filenames.
42 $path = explode(':', $include_path);
43 while (list($i, $dir) = each ($path))
44 if (file_exists("$dir/$file"))
49 ExitWiki("$file: file not found");
53 // Search PHP's include_path to find file or directory.
54 // Searches for "locale/$LANG/$file", then for "$file".
55 function FindLocalizedFile ($file, $missing_okay = false)
57 $language = $GLOBALS['LANG'];
60 $language = getenv("LC_ALL");
62 $language = getenv("LC_MESSAGES");
64 $language = getenv("LC_RESPONSES"); // deprecated
66 $language = getenv("LANG");
70 // FIXME: This wont work for DOS filenames.
71 if (!ereg('^/', $file))
73 if ( ($path = FindFile("locale/$language/$file", 'missing_is_okay')) )
75 // A locale can be, e.g. de_DE.iso8859-1@euro.
76 // Try less specific versions of the locale:
77 $seps = array('@', '.', '_');
78 for ($i = 0; $i < count($seps); $i++)
79 if ( ($tail = strchr($language, $seps[$i])) ) {
80 $head = substr($language, 0, -strlen($tail));
81 if ( ($path = FindFile("locale/$head/$file", 'missing_is_okay')) )
85 return FindFile($file, $missing_okay);
89 setlocale(LC_ALL, "$LANG");
90 putenv("LC_ALL=$LANG");
92 if (!function_exists ('gettext'))
96 function gettext ($text) {
98 if (!empty ($locale[$text]))
99 return $locale[$text];
103 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) )
110 // Setup localisation
111 bindtextdomain ("phpwiki", FindFile("locale"));
112 textdomain ("phpwiki");
117 // To get the POSIX character classes in the PCRE's (e.g.
118 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
119 // to set the locale, using setlocale().
121 // The problem is which locale to set? We would like to recognize all
122 // upper-case characters in the iso-8859-1 character set as upper-case
123 // characters --- not just the ones which are in the current $LANG.
125 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
126 // you setlocale() to anything but "C" it works fine. (I'm not sure
127 // whether this is how it's supposed to be, or whether this is a bug
130 // We don't currently use the locale setting for anything else, so for
131 // now, just set the locale to US English.
133 // FIXME: Not all environments may support en_US? We should probably
134 // have a list of locales to try.
135 if (setlocale(LC_CTYPE, 0) == 'C')
136 setlocale(LC_CTYPE, 'en_US.iso-8859-1');
138 /** string pcre_fix_posix_classes (string $regexp)
140 * Older version (pre 3.x?) of the PCRE library do not support
141 * POSIX named character classes (e.g. [[:alnum:]]).
143 * This is a helper function which can be used to convert a regexp
144 * which contains POSIX named character classes to one that doesn't.
146 * All instances of strings like '[:<class>:]' are replaced by the equivalent
147 * enumerated character class.
149 * Implementation Notes:
151 * Currently we use hard-coded values which are valid only for
152 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
153 * [:upper:] and [:lower:] are implemented. (The missing classes:
154 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
155 * [:space:], and [:xdigit:] could easily be added if needed.)
157 * This is a hack. I tried to generate these classes automatically
158 * using ereg(), but discovered that in my PHP, at least, ereg() is
159 * slightly broken w.r.t. POSIX character classes. (It includes
160 * "\xaa" and "\xba" in [:alpha:].)
162 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
164 function pcre_fix_posix_classes ($regexp) {
165 // First check to see if our PCRE lib supports POSIX character
166 // classes. If it does, there's nothing to do.
167 if (preg_match('/[[:upper:]]/', 'A'))
170 static $classes = array(
171 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
172 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
173 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
174 'lower' => "a-z\xdf-\xf6\xf8-\xff"
177 $keys = join('|', array_keys($classes));
179 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
182 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
184 //////////////////////////////////////////////////////////////////
185 // Autodetect URL settings:
187 if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
188 if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
189 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $HTTP_SERVER_VARS['SCRIPT_NAME']);
190 if (!defined('DATA_PATH'))
191 define('DATA_PATH', dirname(SCRIPT_NAME));
192 if (!defined('USE_PATH_INFO'))
195 * If SCRIPT_NAME does not look like php source file,
196 * or user cgi we assume that php is getting run by an
197 * action handler in /cgi-bin. In this case,
198 * I think there is no way to get Apache to pass
199 * useful PATH_INFO to the php script (PATH_INFO
200 * is used to the the php interpreter where the
203 if (php_sapi_name() == 'apache')
204 define('USE_PATH_INFO', true);
206 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
210 function IsProbablyRedirectToIndex ()
212 // This might be a redirect to the DirectoryIndex,
213 // e.g. REQUEST_URI = /dir/ got redirected
214 // to SCRIPT_NAME = /dir/index.php
216 // In this case, the proper virtual path is still
217 // $SCRIPT_NAME, since pages appear at
218 // e.g. /dir/index.php/HomePage.
220 //global $REQUEST_URI, $SCRIPT_NAME;
221 extract($GLOBALS['HTTP_SERVER_VARS']);
223 $requri = preg_quote($REQUEST_URI, '%');
224 return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
228 if (!defined('VIRTUAL_PATH'))
230 // We'd like to auto-detect when the cases where apaches
231 // 'Action' directive (or similar means) is used to
232 // redirect page requests to a cgi-handler.
234 // In cases like this, requests for e.g. /wiki/HomePage
235 // get redirected to a cgi-script called, say,
236 // /path/to/wiki/index.php. The script gets all
237 // of /wiki/HomePage as it's PATH_INFO.
240 // How to detect when this has happened reliably?
241 // How to pick out the "virtual path" (in this case '/wiki')?
243 // (Another time an redirect might occur is to a DirectoryIndex
244 // -- the requested URI is '/wikidir/', the request gets
245 // passed to '/wikidir/index.php'. In this case, the
246 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
247 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
250 $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
251 if (USE_PATH_INFO and isset($REDIRECT_URL)
252 and ! IsProbablyRedirectToIndex())
254 // FIXME: This is a hack, and won't work if the requested
255 // pagename has a slash in it.
256 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
259 define('VIRTUAL_PATH', SCRIPT_NAME);
262 if (SERVER_PORT && SERVER_PORT != 80)
264 "http://" . SERVER_NAME . ':' . SERVER_PORT);
267 "http://" . SERVER_NAME);
269 if (VIRTUAL_PATH != SCRIPT_NAME)
271 // Apache action handlers are used.
272 define('PATH_INFO_PREFIX', VIRTUAL_PATH . "/");
275 define("PATH_INFO_PREFIX", '/');
278 //////////////////////////////////////////////////////////////////
281 if (empty($DBParams['dbtype']))
283 $DBParams['dbtype'] = 'dba';
286 // InterWiki linking -- wiki-style links to other wikis on the web
288 if (defined('INTERWIKI_MAP_FILE'))
290 include ('lib/interwiki.php');
295 if (!defined('ACCESS_LOG'))
296 define('ACCESS_LOG', '');
299 // Get remote host name, if apache hasn't done it for us
300 if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
301 $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
307 // c-file-style: "ellemtel"