2 rcs_id('$Id: config.php,v 1.39 2001-04-07 00:34:30 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 // 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
29 setlocale('LC_ALL', "");
31 // Search PHP's include_path to find file or directory.
32 function FindFile ($file, $missing_okay = false)
34 // FIXME: This wont work for DOS filenames.
35 if (ereg('^/', $file))
38 if (file_exists($file))
43 $include_path = ini_get('include_path');
44 if (empty($include_path))
46 // FIXME: This wont work for DOS filenames.
47 $path = explode(':', $include_path);
48 while (list($i, $dir) = each ($path))
49 if (file_exists("$dir/$file"))
54 ExitWiki("$file: file not found");
58 // Search PHP's include_path to find file or directory.
59 // Searches for "locale/$LANG/$file", then for "$file".
60 function FindLocalizedFile ($file, $missing_okay = false)
62 $language = getenv("LC_ALL");
64 $language = getenv("LC_MESSAGES");
66 $language = getenv("LC_RESPONSES"); // deprecated
68 $language = getenv("LANG");
73 // FIXME: This wont work for DOS filenames.
74 if (!ereg('^/', $file))
76 if ( ($path = FindFile("locale/$language/$file", 'missing_is_okay')) )
78 // A locale can be, e.g. de_DE.iso8859-1@euro.
79 // Try less specific versions of the locale:
80 $seps = array('@', '.', '_');
81 for ($i = 0; $i < count($seps); $i++)
82 if ( ($tail = strchr($language, $seps[$i])) ) {
83 $head = substr($language, 0, -strlen($tail));
84 if ( ($path = FindFile("locale/$head/$file", 'missing_is_okay')) )
88 return FindFile($file, $missing_okay);
91 if (!function_exists ('gettext'))
95 function gettext ($text) {
97 if (!empty ($locale[$text]))
98 return $locale[$text];
102 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) )
109 bindtextdomain ("phpwiki", FindFile("locale"));
110 textdomain ("phpwiki");
115 // To get the POSIX character classes in the PCRE's (e.g.
116 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
117 // to set the locale, using setlocale().
119 // The problem is which locale to set? We would like to recognize all
120 // upper-case characters in the iso-8859-1 character set as upper-case
121 // characters --- not just the ones which are in the current $LANG.
123 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
124 // you setlocale() to anything but "C" it works fine. (I'm not sure
125 // whether this is how it's supposed to be, or whether this is a bug
128 // We don't currently use the locale setting for anything else, so for
129 // now, just set the locale to US English.
131 // FIXME: Not all environments may support en_US? We should probably
132 // have a list of locales to try.
133 if (setlocale('LC_CTYPE', 0) == 'C')
134 setlocale('LC_CTYPE', 'en_US.iso-8859-1');
136 /** string pcre_fix_posix_classes (string $regexp)
138 * Older version (pre 3.x?) of the PCRE library do not support
139 * POSIX named character classes (e.g. [[:alnum:]]).
141 * This is a helper function which can be used to convert a regexp
142 * which contains POSIX named character classes to one that doesn't.
144 * All instances of strings like '[:<class>:]' are replaced by the equivalent
145 * enumerated character class.
147 * Implementation Notes:
149 * Currently we use hard-coded values which are valid only for
150 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
151 * [:upper:] and [:lower:] are implemented. (The missing classes:
152 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
153 * [:space:], and [:xdigit:] could easily be added if needed.)
155 * This is a hack. I tried to generate these classes automatically
156 * using ereg(), but discovered that in my PHP, at least, ereg() is
157 * slightly broken w.r.t. POSIX character classes. (It includes
158 * "\xaa" and "\xba" in [:alpha:].)
160 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
162 function pcre_fix_posix_classes ($regexp) {
163 // First check to see if our PCRE lib supports POSIX character
164 // classes. If it does, there's nothing to do.
165 if (preg_match('/[[:upper:]]/', 'A'))
168 static $classes = array(
169 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
170 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
171 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
172 'lower' => "a-z\xdf-\xf6\xf8-\xff"
175 $keys = join('|', array_keys($classes));
177 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
180 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
182 //////////////////////////////////////////////////////////////////
183 // Autodetect URL settings:
185 if (!defined('SERVER_NAME')) define('SERVER_NAME', $SERVER_NAME);
186 if (!defined('SERVER_PORT')) define('SERVER_PORT', $SERVER_PORT);
187 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $SCRIPT_NAME);
188 if (!defined('DATA_PATH'))
189 define('DATA_PATH', dirname(SCRIPT_NAME));
190 if (!defined('USE_PATH_INFO'))
193 * If SCRIPT_NAME does not look like php source file,
194 * or user cgi we assume that php is getting run by an
195 * action handler in /cgi-bin. In this case,
196 * I think there is no way to get Apache to pass
197 * useful PATH_INFO to the php script (PATH_INFO
198 * is used to the the php interpreter where the
201 if (php_sapi_name() == 'apache')
202 define('USE_PATH_INFO', true);
204 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
208 function IsProbablyRedirectToIndex ()
210 // This might be a redirect to the DirectoryIndex,
211 // e.g. REQUEST_URI = /dir/ got redirected
212 // to SCRIPT_NAME = /dir/index.php
214 // In this case, the proper virtual path is still
215 // $SCRIPT_NAME, since pages appear at
216 // e.g. /dir/index.php/HomePage.
218 global $REQUEST_URI, $SCRIPT_NAME;
220 $requri = preg_quote($REQUEST_URI, '%');
221 return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
225 if (!defined('VIRTUAL_PATH'))
227 // We'd like to auto-detect when the cases where apaches
228 // 'Action' directive (or similar means) is used to
229 // redirect page requests to a cgi-handler.
231 // In cases like this, requests for e.g. /wiki/HomePage
232 // get redirected to a cgi-script called, say,
233 // /path/to/wiki/index.php. The script gets all
234 // of /wiki/HomePage as it's PATH_INFO.
237 // How to detect when this has happened reliably?
238 // How to pick out the "virtual path" (in this case '/wiki')?
240 // (Another time an redirect might occur is to a DirectoryIndex
241 // -- the requested URI is '/wikidir/', the request gets
242 // passed to '/wikidir/index.php'. In this case, the
243 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
244 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
247 if (USE_PATH_INFO and isset($REDIRECT_URL)
248 and ! IsProbablyRedirectToIndex())
250 // FIXME: This is a hack, and won't work if the requested
251 // pagename has a slash in it.
252 define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
255 define('VIRTUAL_PATH', SCRIPT_NAME);
258 if (SERVER_PORT && SERVER_PORT != 80)
260 "http://" . SERVER_NAME . ':' . SERVER_PORT);
263 "http://" . SERVER_NAME);
265 if (VIRTUAL_PATH != SCRIPT_NAME)
267 // Apache action handlers are used.
268 define('PATH_INFO_PREFIX', VIRTUAL_PATH . "/");
271 define("PATH_INFO_PREFIX", '/');
274 //////////////////////////////////////////////////////////////////
277 if (empty($DBParams['dbtype']))
279 if ( floor(phpversion()) == 3) {
280 $DBParams['dbtype'] = 'dbm';
282 $DBParams['dbtype'] = 'dba';
286 switch ($DBParams['dbtype'])
289 include 'lib/dbmlib.php';
292 include 'lib/dbalib.php';
295 include 'lib/mysql.php';
298 include 'lib/pgsql.php';
301 include 'lib/msql.php';
304 include "lib/db_filesystem.php";
307 ExitWiki($DBParams['dbtype'] . ": unknown DBTYPE");
310 // InterWiki linking -- wiki-style links to other wikis on the web
312 if (defined('INTERWIKI_MAP_FILE'))
314 include ('lib/interwiki.php');
318 if (!defined('ACCESS_LOG'))
319 define('ACCESS_LOG', '');
321 // Get remote host name, if apache hasn't done it for us
322 if (empty($REMOTE_HOST) && ENABLE_REVERSE_DNS)
323 $REMOTE_HOST = gethostbyaddr($REMOTE_ADDR);
329 // c-file-style: "ellemtel"