]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/config.php
Recognize international characters in WikiWords.
[SourceForge/phpwiki.git] / lib / config.php
1 <?php
2 rcs_id('$Id: config.php,v 1.35 2001-03-07 16:45:20 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 // 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 one's 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 //////////////////////////////////////////////////////////////////
121 // Autodetect URL settings:
122 //
123 if (!defined('SERVER_NAME')) define('SERVER_NAME', $SERVER_NAME);
124 if (!defined('SERVER_PORT')) define('SERVER_PORT', $SERVER_PORT);
125 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $SCRIPT_NAME);
126 if (!defined('DATA_PATH'))
127    define('DATA_PATH', dirname(SCRIPT_NAME));
128 if (!defined('USE_PATH_INFO'))
129 {
130    /*
131     * If SCRIPT_NAME does not look like php source file,
132     * or user cgi we assume that php is getting run by an
133     * action handler in /cgi-bin.  In this case,
134     * I think there is no way to get Apache to pass
135     * useful PATH_INFO to the php script (PATH_INFO
136     * is used to the the php interpreter where the
137     * php script is...)
138     */
139    if (php_sapi_name() == 'apache')
140       define('USE_PATH_INFO', true);
141    else
142       define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
143 }
144
145
146 function IsProbablyRedirectToIndex () 
147 {
148    // This might be a redirect to the DirectoryIndex,
149    // e.g. REQUEST_URI = /dir/  got redirected
150    // to SCRIPT_NAME = /dir/index.php
151    
152    // In this case, the proper virtual path is still
153    // $SCRIPT_NAME, since pages appear at
154    // e.g. /dir/index.php/FrontPage.
155    
156    global $REQUEST_URI, $SCRIPT_NAME;
157    
158    $requri = preg_quote($REQUEST_URI, '%');
159    return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
160 }
161
162    
163 if (!defined('VIRTUAL_PATH'))
164 {
165    // We'd like to auto-detect when the cases where apaches
166    // 'Action' directive (or similar means) is used to
167    // redirect page requests to a cgi-handler.
168    //
169    // In cases like this, requests for e.g. /wiki/FrontPage
170    // get redirected to a cgi-script called, say,
171    // /path/to/wiki/index.php.  The script gets all
172    // of /wiki/FrontPage as it's PATH_INFO.
173    //
174    // The problem is:
175    //   How to detect when this has happened reliably?
176    //   How to pick out the "virtual path" (in this case '/wiki')?
177    //
178    // (Another time an redirect might occur is to a DirectoryIndex
179    // -- the requested URI is '/wikidir/', the request gets
180    // passed to '/wikidir/index.php'.  In this case, the
181    // proper VIRTUAL_PATH is '/wikidir/index.php', since the
182    // pages will appear at e.g. '/wikidir/index.php/FrontPage'.
183    //
184
185    if (USE_PATH_INFO and isset($REDIRECT_URL)
186        and ! IsProbablyRedirectToIndex())
187    {
188       // FIXME: This is a hack, and won't work if the requested
189       // pagename has a slash in it.
190       define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
191    }
192    else
193       define('VIRTUAL_PATH', SCRIPT_NAME);
194 }
195
196 if (SERVER_PORT && SERVER_PORT != 80)
197    define('SERVER_URL',
198           "http://" . SERVER_NAME . ':' . SERVER_PORT);
199 else
200    define('SERVER_URL',
201           "http://" . SERVER_NAME);
202
203 if (VIRTUAL_PATH != SCRIPT_NAME)
204 {
205    // Apache action handlers are used.
206    define('PATH_INFO_PREFIX', VIRTUAL_PATH . "/");
207 }
208 else
209    define("PATH_INFO_PREFIX", '/');
210
211
212 //////////////////////////////////////////////////////////////////
213 // Select database
214 //
215 if (empty($DBParams['dbtype']))
216 {
217    if ( floor(phpversion()) == 3) {
218       $DBParams['dbtype'] = 'dbm';
219    } else {
220       $DBParams['dbtype'] = 'dba';
221    }
222 }
223
224 switch ($DBParams['dbtype']) 
225 {
226    case 'dbm':
227       include 'lib/dbmlib.php';
228       break;
229    case 'dba':
230       include 'lib/dbalib.php';
231       break;
232    case 'mysql':
233       include 'lib/mysql.php';
234       break;
235    case 'pgsql':
236       include 'lib/pgsql.php';
237       break;
238    case 'msql':
239       include 'lib/msql.php';
240       break;
241    case 'file':
242       include "lib/db_filesystem.php";
243       break;
244    default:
245       ExitWiki($DBParams['dbtype'] . ": unknown DBTYPE");
246 }
247
248 // InterWiki linking -- wiki-style links to other wikis on the web
249 //
250 if (defined('INTERWIKI_MAP_FILE'))
251 {
252    include ('lib/interwiki.php');
253 }
254
255 // Access log
256 if (!defined('ACCESS_LOG'))
257    define('ACCESS_LOG', '');
258    
259 // Get remote host name, if apache hasn't done it for us
260 if (empty($REMOTE_HOST) && ENABLE_REVERSE_DNS)
261    $REMOTE_HOST = gethostbyaddr($REMOTE_ADDR);
262
263    
264 // For emacs users
265 // Local Variables:
266 // mode: php
267 // c-file-style: "ellemtel"
268 // End:   
269 ?>