]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/config.php
FileFinder: added OS specific code. Just for testing. Will be changed to seperate...
[SourceForge/phpwiki.git] / lib / config.php
1 <?php
2 rcs_id('$Id: config.php,v 1.62 2002-09-09 08:38:19 rurban Exp $');
3 /*
4  * NOTE: the settings here should probably not need to be changed.
5 *
6 *
7 * (The user-configurable settings have been moved to index.php.)
8 */
9
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");
14 }
15
16 // essential internal stuff
17 set_magic_quotes_runtime(0);
18
19 // Some constants.
20
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";
25
26 require_once('lib/FileFinder.php');
27 // Search PHP's include_path to find file or directory.
28 function FindFile ($file, $missing_okay = false, $slashify = false)
29 {
30     static $finder;
31     if (!isset($finder))
32         $finder = new FileFinder;
33     $s = $finder->findFile($file, $missing_okay);
34     if ($slashify)
35       $s = $finder->slashifyPath($s);
36     return $s;
37 }
38
39 // Search PHP's include_path to find file or directory.
40 // Searches for "locale/$LANG/$file", then for "$file".
41 function FindLocalizedFile ($file, $missing_okay = false)
42 {
43     static $finder;
44     if (!isset($finder))
45         $finder = new LocalizedFileFinder;
46     return $finder->findFile($file, $missing_okay);
47 }
48
49 function FindLocalizedButtonFile ($file, $missing_okay = false)
50 {
51     static $buttonfinder;
52     if (!isset($buttonfinder))
53         $buttonfinder = new LocalizedButtonFinder;
54     return $buttonfinder->findFile($file, $missing_okay);
55 }
56
57 // I think this putenv is unnecessary, and it causes trouble
58 // if PHP's safe_mode is enabled:
59 //putenv("LC_ALL=$LANG");
60
61 if (!function_exists ('bindtextdomain')) {
62     $locale = array();
63
64     function gettext ($text) { 
65         global $locale;
66         if (!empty ($locale[$text]))
67             return $locale[$text];
68         return $text;
69     }
70
71     function _ ($text) {
72         return gettext($text);
73     }
74
75     if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
76         include($lcfile);
77     }
78 }
79
80 // Setup localisation
81 // This is currently broken, after trying to enable dynamic UserPreferences 
82 // on the language.
83 function update_locale ($language) {
84     global $locale, $LC_ALL, $language_locales;
85     
86     // shortterm LANG fix. We really should define LC_ALL as "C" and LANG as "en"
87     if ($language == 'C') {
88         $language = 'en'; $LC_ALL = 'C';
89     }
90     if (empty($LC_ALL)) {
91         if (empty($language_locales[$language]))
92             $LC_ALL = $language;
93         else
94             $LC_ALL = $language_locales[$language];
95     }
96     if (empty($LC_ALL))
97        $LC_ALL = $language;
98
99     // Fixme: Currently we just check the dirs under locale for all 
100     // available languages, but with setlocale we must use the long form, 
101     // like 'de_DE','nl_NL', 'es_MX', 'es_AR', 'fr_FR'. For Windows maybe even 'german'.
102     $result = setlocale(LC_ALL, $LC_ALL);
103     if (!$result and !($result = setlocale(LC_ALL, substr($LC_ALL,0,2)))) {
104         putenv("LANG=$LC_ALL");
105         // The system supported locale. E.g. my Windows returns "German_Austria.1252"
106         $result = setlocale(LC_ALL,'');
107     }
108     if ($result) {
109         $LC_ALL = $result;
110         putenv("LC_ALL=$LC_ALL");
111         putenv("LANG=$LC_ALL");
112     }
113
114     if (!function_exists ('bindtextdomain')) {
115         if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) ) {
116             include($lcfile);
117         }
118     } else {
119         if (empty($language_locales[$language])) {
120             trigger_error(sprintf(_("No default locale for this language '%s'"), $language), E_USER_NOTICE);
121         }
122         // Setup localisation
123         $f = FindFile("locale", false, true);
124         
125         bindtextdomain ("phpwiki", $f);
126         textdomain ("phpwiki");
127     }
128     $GLOBALS['LANG'] = $language;
129 }
130 update_locale ($LANG);
131 $default_language = $LANG;
132
133 // To get the POSIX character classes in the PCRE's (e.g.
134 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
135 // to set the locale, using setlocale().
136 //
137 // The problem is which locale to set?  We would like to recognize all
138 // upper-case characters in the iso-8859-1 character set as upper-case
139 // characters --- not just the ones which are in the current $LANG.
140 //
141 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
142 // you setlocale() to anything but "C" it works fine.  (I'm not sure
143 // whether this is how it's supposed to be, or whether this is a bug
144 // in the libc...)
145 //
146 // We don't currently use the locale setting for anything else, so for
147 // now, just set the locale to US English.
148 //
149 // FIXME: Not all environments may support en_US?  We should probably
150 // have a list of locales to try.
151 if (setlocale(LC_CTYPE, 0) == 'C')
152      setlocale(LC_CTYPE, 'en_US.' . CHARSET );
153
154 /** string pcre_fix_posix_classes (string $regexp)
155 *
156 * Older version (pre 3.x?) of the PCRE library do not support
157 * POSIX named character classes (e.g. [[:alnum:]]).
158 *
159 * This is a helper function which can be used to convert a regexp
160 * which contains POSIX named character classes to one that doesn't.
161 *
162 * All instances of strings like '[:<class>:]' are replaced by the equivalent
163 * enumerated character class.
164 *
165 * Implementation Notes:
166 *
167 * Currently we use hard-coded values which are valid only for
168 * ISO-8859-1.  Also, currently on the classes [:alpha:], [:alnum:],
169 * [:upper:] and [:lower:] are implemented.  (The missing classes:
170 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
171 * [:space:], and [:xdigit:] could easily be added if needed.)
172 *
173 * This is a hack.  I tried to generate these classes automatically
174 * using ereg(), but discovered that in my PHP, at least, ereg() is
175 * slightly broken w.r.t. POSIX character classes.  (It includes
176 * "\xaa" and "\xba" in [:alpha:].)
177 *
178 * So for now, this will do.  --Jeff <dairiki@dairiki.org> 14 Mar, 2001
179 */
180 function pcre_fix_posix_classes ($regexp) {
181     // First check to see if our PCRE lib supports POSIX character
182     // classes.  If it does, there's nothing to do.
183     if (preg_match('/[[:upper:]]/', 'Ä'))
184         return $regexp;
185
186     static $classes = array(
187                             'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
188                             'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
189                             'upper' => "A-Z\xc0-\xd6\xd8-\xde",
190                             'lower' => "a-z\xdf-\xf6\xf8-\xff"
191                             );
192
193     $keys = join('|', array_keys($classes));
194
195     return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
196 }
197
198 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
199
200 //////////////////////////////////////////////////////////////////
201 // Autodetect URL settings:
202 //
203 if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
204 if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
205 if (!defined('SERVER_PROTOCOL')) {
206     if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off')
207         define('SERVER_PROTOCOL', 'http');
208     else
209         define('SERVER_PROTOCOL', 'https');
210 }
211
212 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $HTTP_SERVER_VARS['SCRIPT_NAME']);
213
214 if (!defined('DATA_PATH'))   define('DATA_PATH', dirname(SCRIPT_NAME));
215
216 if (!defined('USE_PATH_INFO'))
217 {
218     /*
219      * If SCRIPT_NAME does not look like php source file,
220      * or user cgi we assume that php is getting run by an
221      * action handler in /cgi-bin.  In this case,
222      * I think there is no way to get Apache to pass
223      * useful PATH_INFO to the php script (PATH_INFO
224      * is used to the the php interpreter where the
225      * php script is...)
226      */
227     if (php_sapi_name() == 'apache')
228         define('USE_PATH_INFO', true);
229     else
230         define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
231 }
232
233
234 function IsProbablyRedirectToIndex () 
235 {
236     // This might be a redirect to the DirectoryIndex,
237     // e.g. REQUEST_URI = /dir/  got redirected
238     // to SCRIPT_NAME = /dir/index.php
239
240     // In this case, the proper virtual path is still
241     // $SCRIPT_NAME, since pages appear at
242     // e.g. /dir/index.php/HomePage.
243
244 //global $REQUEST_URI, $SCRIPT_NAME;
245     extract($GLOBALS['HTTP_SERVER_VARS']);
246
247     $requri = preg_quote($REQUEST_URI, '%');
248     return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
249 }
250
251
252 if (!defined('VIRTUAL_PATH'))
253 {
254     // We'd like to auto-detect when the cases where apaches
255     // 'Action' directive (or similar means) is used to
256     // redirect page requests to a cgi-handler.
257     //
258     // In cases like this, requests for e.g. /wiki/HomePage
259     // get redirected to a cgi-script called, say,
260     // /path/to/wiki/index.php.  The script gets all
261     // of /wiki/HomePage as it's PATH_INFO.
262     //
263     // The problem is:
264     //   How to detect when this has happened reliably?
265     //   How to pick out the "virtual path" (in this case '/wiki')?
266     //
267     // (Another time an redirect might occur is to a DirectoryIndex
268     // -- the requested URI is '/wikidir/', the request gets
269     // passed to '/wikidir/index.php'.  In this case, the
270     // proper VIRTUAL_PATH is '/wikidir/index.php', since the
271     // pages will appear at e.g. '/wikidir/index.php/HomePage'.
272     //
273
274     $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
275     if (USE_PATH_INFO and isset($REDIRECT_URL)
276         and ! IsProbablyRedirectToIndex())
277         {
278             // FIXME: This is a hack, and won't work if the requested
279             // pagename has a slash in it.
280             define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
281         }
282     else
283         define('VIRTUAL_PATH', SCRIPT_NAME);
284 }
285
286 if (SERVER_PORT
287     && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
288     define('SERVER_URL',
289            SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
290 }
291 else {
292     define('SERVER_URL',
293            SERVER_PROTOCOL . '://' . SERVER_NAME);
294 }
295
296 if (VIRTUAL_PATH != SCRIPT_NAME)
297 {
298     // Apache action handlers are used.
299     define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
300 }
301 else
302 define('PATH_INFO_PREFIX', '/');
303
304
305 define('BASE_URL',
306        SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
307
308 //////////////////////////////////////////////////////////////////
309 // Select database
310 //
311 if (empty($DBParams['dbtype']))
312     $DBParams['dbtype'] = 'dba';
313
314 if (!defined('WIKI_NAME'))
315     define('WIKI_NAME', _("An unnamed PhpWiki"));
316
317 if (!defined('THEME'))
318     define('THEME', 'default');
319
320 if (!defined('HOME_PAGE'))
321     define('HOME_PAGE', _("HomePage"));
322
323
324 // FIXME: delete
325 // Access log
326 if (!defined('ACCESS_LOG'))
327      define('ACCESS_LOG', '');
328
329 // FIXME: delete
330 // Get remote host name, if apache hasn't done it for us
331 if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
332      $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
333
334 // check whether the crypt() function is needed and present
335 if (defined('ENCRYPTED_PASSWD') && !function_exists('crypt')) {
336     $error = sprintf(_("Encrypted passwords cannot be used: %s."),
337                      "'function crypt()' not available in this version of php");
338     trigger_error($error);
339 }
340
341 if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '')
342     trigger_error(_("The admin password cannot be empty. Please update your /index.php"));
343
344 // For emacs users
345 // Local Variables:
346 // mode: php
347 // tab-width: 8
348 // c-basic-offset: 4
349 // c-hanging-comment-ender-p: nil
350 // indent-tabs-mode: nil
351 // End:
352 ?>