2 rcs_id('$Id: config.php,v 1.38 2001-04-06 18:21:37 wainstead 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 // essential internal stuff
12 set_magic_quotes_runtime(0);
16 // "\x80"-"\x9f" (and "\x00" - "\x1f") are non-printing control
17 // chars in iso-8859-*
18 // $FieldSeparator = "\263"; //this is a superscript 3 in ISO-8859-1.
19 $FieldSeparator = "\x81";
22 // constants for flags in $pagehash
23 define("FLAG_PAGE_LOCKED", 1);
25 //////////////////////////////////////////////////////////////////
27 // Set up localization
33 // Search PHP's include_path to find file or directory.
34 function FindFile ($file, $missing_okay = false)
36 // FIXME: This wont work for DOS filenames.
37 if (ereg('^/', $file))
40 if (file_exists($file))
45 $include_path = ini_get('include_path');
46 if (empty($include_path))
48 // FIXME: This wont work for DOS filenames.
49 $path = explode(':', $include_path);
50 while (list($i, $dir) = each ($path))
51 if (file_exists("$dir/$file"))
56 ExitWiki("$file: file not found");
60 // Search PHP's include_path to find file or directory.
61 // Searches for "locale/$LANG/$file", then for "$file".
62 function FindLocalizedFile ($file, $missing_okay = false)
66 // FIXME: This wont work for DOS filenames.
67 if (!ereg('^/', $file))
69 if ( ($path = FindFile("locale/$LANG/$file", 'missing_is_okay')) )
72 return FindFile($file, $missing_okay);
75 if (!function_exists ('gettext'))
79 function gettext ($text) {
81 if (!empty ($locale[$text]))
82 return $locale[$text];
86 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) )
93 putenv ("LANG=$LANG");
94 bindtextdomain ("phpwiki", "./locale");
95 textdomain ("phpwiki");
98 // To get the POSIX character classes in the PCRE's (e.g.
99 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
100 // to set the locale, using setlocale().
102 // The problem is which locale to set? We would like to recognize all
103 // upper-case characters in the iso-8859-1 character set as upper-case
104 // characters --- not just the ones which are in the current $LANG.
106 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
107 // you setlocale() to anything but "C" it works fine. (I'm not sure
108 // whether this is how it's supposed to be, or whether this is a bug
111 // We don't currently use the locale setting for anything else, so for
112 // now, just set the locale to US English.
114 // FIXME: Not all environments may support en_US? We should probably
115 // have a list of locales to try.
117 if (setlocale('LC_CTYPE', 0) == 'C')
118 setlocale('LC_CTYPE', 'en_US.iso-8859-1');
120 /** string pcre_fix_posix_classes (string $regexp)
122 * Older version (pre 3.x?) of the PCRE library do not support
123 * POSIX named character classes (e.g. [[:alnum:]]).
125 * This is a helper function which can be used to convert a regexp
126 * which contains POSIX named character classes to one that doesn't.
128 * All instances of strings like '[:<class>:]' are replaced by the equivalent
129 * enumerated character class.
131 * Implementation Notes:
133 * Currently we use hard-coded values which are valid only for
134 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
135 * [:upper:] and [:lower:] are implemented. (The missing classes:
136 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
137 * [:space:], and [:xdigit:] could easily be added if needed.)
139 * This is a hack. I tried to generate these classes automatically
140 * using ereg(), but discovered that in my PHP, at least, ereg() is
141 * slightly broken w.r.t. POSIX character classes. (It includes
142 * "\xaa" and "\xba" in [:alpha:].)
144 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
146 function pcre_fix_posix_classes ($regexp) {
147 // First check to see if our PCRE lib supports POSIX character
148 // classes. If it does, there's nothing to do.
149 if (preg_match('/[[:upper:]]/', 'A'))
152 static $classes = array(
153 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
154 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
155 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
156 'lower' => "a-z\xdf-\xf6\xf8-\xff"
159 $keys = join('|', array_keys($classes));
161 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
164 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
166 //////////////////////////////////////////////////////////////////
167 // Autodetect URL settings:
169 if (!defined('SERVER_NAME')) define('SERVER_NAME', $SERVER_NAME);
170 if (!defined('SERVER_PORT')) define('SERVER_PORT', $SERVER_PORT);
171 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $SCRIPT_NAME);
172 if (!defined('DATA_PATH'))
173 define('DATA_PATH', dirname(SCRIPT_NAME));
174 if (!defined('USE_PATH_INFO'))
177 * If SCRIPT_NAME does not look like php source file,
178 * or user cgi we assume that php is getting run by an
179 * action handler in /cgi-bin. In this case,
180 * I think there is no way to get Apache to pass
181 * useful PATH_INFO to the php script (PATH_INFO
182 * is used to the the php interpreter where the
185 if (php_sapi_name() == 'apache')
186 define('USE_PATH_INFO', true);
188 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
192 function IsProbablyRedirectToIndex ()
194 // This might be a redirect to the DirectoryIndex,
195 // e.g. REQUEST_URI = /dir/ got redirected
196 // to SCRIPT_NAME = /dir/index.php
198 // In this case, the proper virtual path is still
199 // $SCRIPT_NAME, since pages appear at
200 // e.g. /dir/index.php/HomePage.
202 global $REQUEST_URI, $SCRIPT_NAME;
204 $requri = preg_quote($REQUEST_URI, '%');
205 return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
209 if (!defined('VIRTUAL_PATH'))
211 // We'd like to auto-detect when the cases where apaches
212 // 'Action' directive (or similar means) is used to
213 // redirect page requests to a cgi-handler.
215 // In cases like this, requests for e.g. /wiki/HomePage
216 // get redirected to a cgi-script called, say,
217 // /path/to/wiki/index.php. The script gets all
218 // of /wiki/HomePage as it's PATH_INFO.
221 // How to detect when this has happened reliably?
222 // How to pick out the "virtual path" (in this case '/wiki')?
224 // (Another time an redirect might occur is to a DirectoryIndex
225 // -- the requested URI is '/wikidir/', the request gets
226 // passed to '/wikidir/index.php'. In this case, the
227 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
228 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
231 if (USE_PATH_INFO and isset($REDIRECT_URL)
232 and ! IsProbablyRedirectToIndex())
234 // FIXME: This is a hack, and won't work if the requested
235 // pagename has a slash in it.
236 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
239 define('VIRTUAL_PATH', SCRIPT_NAME);
242 if (SERVER_PORT && SERVER_PORT != 80)
244 "http://" . SERVER_NAME . ':' . SERVER_PORT);
247 "http://" . SERVER_NAME);
249 if (VIRTUAL_PATH != SCRIPT_NAME)
251 // Apache action handlers are used.
252 define('PATH_INFO_PREFIX', VIRTUAL_PATH . "/");
255 define("PATH_INFO_PREFIX", '/');
258 //////////////////////////////////////////////////////////////////
261 if (empty($DBParams['dbtype']))
263 if ( floor(phpversion()) == 3) {
264 $DBParams['dbtype'] = 'dbm';
266 $DBParams['dbtype'] = 'dba';
270 switch ($DBParams['dbtype'])
273 include 'lib/dbmlib.php';
276 include 'lib/dbalib.php';
279 include 'lib/mysql.php';
282 include 'lib/pgsql.php';
285 include 'lib/msql.php';
288 include "lib/db_filesystem.php";
291 ExitWiki($DBParams['dbtype'] . ": unknown DBTYPE");
294 // InterWiki linking -- wiki-style links to other wikis on the web
296 if (defined('INTERWIKI_MAP_FILE'))
298 include ('lib/interwiki.php');
302 if (!defined('ACCESS_LOG'))
303 define('ACCESS_LOG', '');
305 // Get remote host name, if apache hasn't done it for us
306 if (empty($REMOTE_HOST) && ENABLE_REVERSE_DNS)
307 $REMOTE_HOST = gethostbyaddr($REMOTE_ADDR);
313 // c-file-style: "ellemtel"