]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/config.php
Did find-grep to replace all occurances of FrontPage to HomePage.
[SourceForge/phpwiki.git] / lib / config.php
1 <?php
2 rcs_id('$Id: config.php,v 1.38 2001-04-06 18:21:37 wainstead 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 // essential internal stuff
11
12 set_magic_quotes_runtime(0);
13
14 // Some constants.
15
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";
20
21
22 // constants for flags in $pagehash
23 define("FLAG_PAGE_LOCKED", 1);
24
25 //////////////////////////////////////////////////////////////////
26 //
27 // Set up localization
28 //
29 if (empty($LANG))
30    $LANG = "C";
31
32    
33 // Search PHP's include_path to find file or directory.
34 function FindFile ($file, $missing_okay = false)
35 {
36    // FIXME: This wont work for DOS filenames.
37    if (ereg('^/', $file))
38    {
39       // absolute path.
40       if (file_exists($file))
41          return $file;
42    }
43    else
44    {
45       $include_path = ini_get('include_path');
46       if (empty($include_path))
47          $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"))
52             return "$dir/$file";
53    }
54    
55    if (!$missing_okay)
56       ExitWiki("$file: file not found");
57    return false;
58 }
59
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)
63 {
64    global $LANG;
65    
66    // FIXME: This wont work for DOS filenames.
67    if (!ereg('^/', $file))
68    {
69       if ( ($path = FindFile("locale/$LANG/$file", 'missing_is_okay')) )
70          return $path;
71    }
72    return FindFile($file, $missing_okay);
73 }
74
75 if (!function_exists ('gettext'))
76 {
77    $locale = array();
78
79    function gettext ($text) { 
80       global $locale;
81       if (!empty ($locale[$text]))
82          return $locale[$text];
83       return $text;
84    }
85
86    if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) )
87    {
88       include($lcfile);
89    }
90 }
91 else
92 {
93    putenv ("LANG=$LANG");
94    bindtextdomain ("phpwiki", "./locale");
95    textdomain ("phpwiki");
96 }
97
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().
101 //
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.
105 //
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
109 // in the libc...)
110 //
111 // We don't currently use the locale setting for anything else, so for
112 // now, just set the locale to US English.
113 //
114 // FIXME: Not all environments may support en_US?  We should probably
115 // have a list of locales to try.
116
117 if (setlocale('LC_CTYPE', 0) == 'C')
118    setlocale('LC_CTYPE', 'en_US.iso-8859-1');
119
120 /** string pcre_fix_posix_classes (string $regexp)
121  *
122  * Older version (pre 3.x?) of the PCRE library do not support
123  * POSIX named character classes (e.g. [[:alnum:]]).
124  *
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.
127  *
128  * All instances of strings like '[:<class>:]' are replaced by the equivalent
129  * enumerated character class.
130  *
131  * Implementation Notes:
132  *
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.)
138  *
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:].)
143  *
144  * So for now, this will do.  --Jeff <dairiki@dairiki.org> 14 Mar, 2001
145  */
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'))
150       return $regexp;
151
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"
157       );
158
159    $keys = join('|', array_keys($classes));
160
161    return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
162 }
163          
164 $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
165
166 //////////////////////////////////////////////////////////////////
167 // Autodetect URL settings:
168 //
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'))
175 {
176    /*
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
183     * php script is...)
184     */
185    if (php_sapi_name() == 'apache')
186       define('USE_PATH_INFO', true);
187    else
188       define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
189 }
190
191
192 function IsProbablyRedirectToIndex () 
193 {
194    // This might be a redirect to the DirectoryIndex,
195    // e.g. REQUEST_URI = /dir/  got redirected
196    // to SCRIPT_NAME = /dir/index.php
197    
198    // In this case, the proper virtual path is still
199    // $SCRIPT_NAME, since pages appear at
200    // e.g. /dir/index.php/HomePage.
201    
202    global $REQUEST_URI, $SCRIPT_NAME;
203    
204    $requri = preg_quote($REQUEST_URI, '%');
205    return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
206 }
207
208    
209 if (!defined('VIRTUAL_PATH'))
210 {
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.
214    //
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.
219    //
220    // The problem is:
221    //   How to detect when this has happened reliably?
222    //   How to pick out the "virtual path" (in this case '/wiki')?
223    //
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'.
229    //
230
231    if (USE_PATH_INFO and isset($REDIRECT_URL)
232        and ! IsProbablyRedirectToIndex())
233    {
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'));
237    }
238    else
239       define('VIRTUAL_PATH', SCRIPT_NAME);
240 }
241
242 if (SERVER_PORT && SERVER_PORT != 80)
243    define('SERVER_URL',
244           "http://" . SERVER_NAME . ':' . SERVER_PORT);
245 else
246    define('SERVER_URL',
247           "http://" . SERVER_NAME);
248
249 if (VIRTUAL_PATH != SCRIPT_NAME)
250 {
251    // Apache action handlers are used.
252    define('PATH_INFO_PREFIX', VIRTUAL_PATH . "/");
253 }
254 else
255    define("PATH_INFO_PREFIX", '/');
256
257
258 //////////////////////////////////////////////////////////////////
259 // Select database
260 //
261 if (empty($DBParams['dbtype']))
262 {
263    if ( floor(phpversion()) == 3) {
264       $DBParams['dbtype'] = 'dbm';
265    } else {
266       $DBParams['dbtype'] = 'dba';
267    }
268 }
269
270 switch ($DBParams['dbtype']) 
271 {
272    case 'dbm':
273       include 'lib/dbmlib.php';
274       break;
275    case 'dba':
276       include 'lib/dbalib.php';
277       break;
278    case 'mysql':
279       include 'lib/mysql.php';
280       break;
281    case 'pgsql':
282       include 'lib/pgsql.php';
283       break;
284    case 'msql':
285       include 'lib/msql.php';
286       break;
287    case 'file':
288       include "lib/db_filesystem.php";
289       break;
290    default:
291       ExitWiki($DBParams['dbtype'] . ": unknown DBTYPE");
292 }
293
294 // InterWiki linking -- wiki-style links to other wikis on the web
295 //
296 if (defined('INTERWIKI_MAP_FILE'))
297 {
298    include ('lib/interwiki.php');
299 }
300
301 // Access log
302 if (!defined('ACCESS_LOG'))
303    define('ACCESS_LOG', '');
304    
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);
308
309    
310 // For emacs users
311 // Local Variables:
312 // mode: php
313 // c-file-style: "ellemtel"
314 // End:   
315 ?>