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