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