]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/config.php
Fixed (I think) SF bug #132469. The problem was that the value
[SourceForge/phpwiki.git] / lib / config.php
1 <?php
2 rcs_id('$Id: config.php,v 1.33 2001-02-15 05:57:18 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
30 if (empty($LANG))
31    $LANG = "C";
32
33    
34 // Search PHP's include_path to find file or directory.
35 function FindFile ($file, $missing_okay = false)
36 {
37    // FIXME: This wont work for DOS filenames.
38    if (ereg('^/', $file))
39    {
40       // absolute path.
41       if (file_exists($file))
42          return $file;
43    }
44    else
45    {
46       $include_path = ini_get('include_path');
47       if (empty($include_path))
48          $include_path = '.';
49       // FIXME: This wont work for DOS filenames.
50       $path = explode(':', $include_path);
51       while (list($i, $dir) = each ($path))
52          if (file_exists("$dir/$file"))
53             return "$dir/$file";
54    }
55    
56    if (!$missing_okay)
57       ExitWiki("$file: file not found");
58    return false;
59 }
60
61 // Search PHP's include_path to find file or directory.
62 // Searches for "locale/$LANG/$file", then for "$file".
63 function FindLocalizedFile ($file, $missing_okay = false)
64 {
65    global $LANG;
66    
67    // FIXME: This wont work for DOS filenames.
68    if (!ereg('^/', $file))
69    {
70       if ( ($path = FindFile("locale/$LANG/$file", 'missing_is_okay')) )
71          return $path;
72    }
73    return FindFile($file, $missing_okay);
74 }
75
76 if (!function_exists ('gettext'))
77 {
78    $locale = array();
79
80    function gettext ($text) { 
81       global $locale;
82       if (!empty ($locale[$text]))
83          return $locale[$text];
84       return $text;
85    }
86
87    if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) )
88    {
89       include($lcfile);
90    }
91 }
92 else
93 {
94    putenv ("LANG=$LANG");
95    bindtextdomain ("phpwiki", "./locale");
96    textdomain ("phpwiki");
97 }
98
99 //////////////////////////////////////////////////////////////////
100 // Autodetect URL settings:
101 //
102 if (!defined('SERVER_NAME')) define('SERVER_NAME', $SERVER_NAME);
103 if (!defined('SERVER_PORT')) define('SERVER_PORT', $SERVER_PORT);
104 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $SCRIPT_NAME);
105 if (!defined('DATA_PATH'))
106    define('DATA_PATH', dirname(SCRIPT_NAME));
107 if (!defined('USE_PATH_INFO'))
108 {
109    /*
110     * If SCRIPT_NAME does not look like php source file,
111     * or user cgi we assume that php is getting run by an
112     * action handler in /cgi-bin.  In this case,
113     * I think there is no way to get Apache to pass
114     * useful PATH_INFO to the php script (PATH_INFO
115     * is used to the the php interpreter where the
116     * php script is...)
117     */
118    if (php_sapi_name() == 'apache')
119       define('USE_PATH_INFO', true);
120    else
121       define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
122 }
123
124
125 function IsProbablyRedirectToIndex () 
126 {
127    // This might be a redirect to the DirectoryIndex,
128    // e.g. REQUEST_URI = /dir/  got redirected
129    // to SCRIPT_NAME = /dir/index.php
130    
131    // In this case, the proper virtual path is still
132    // $SCRIPT_NAME, since pages appear at
133    // e.g. /dir/index.php/FrontPage.
134    
135    global $REQUEST_URI, $SCRIPT_NAME;
136    
137    $requri = preg_quote($REQUEST_URI, '%');
138    return preg_match("%^${requri}[^/]*$%", $SCRIPT_NAME);
139 }
140
141    
142 if (!defined('VIRTUAL_PATH'))
143 {
144    // We'd like to auto-detect when the cases where apaches
145    // 'Action' directive (or similar means) is used to
146    // redirect page requests to a cgi-handler.
147    //
148    // In cases like this, requests for e.g. /wiki/FrontPage
149    // get redirected to a cgi-script called, say,
150    // /path/to/wiki/index.php.  The script gets all
151    // of /wiki/FrontPage as it's PATH_INFO.
152    //
153    // The problem is:
154    //   How to detect when this has happened reliably?
155    //   How to pick out the "virtual path" (in this case '/wiki')?
156    //
157    // (Another time an redirect might occur is to a DirectoryIndex
158    // -- the requested URI is '/wikidir/', the request gets
159    // passed to '/wikidir/index.php'.  In this case, the
160    // proper VIRTUAL_PATH is '/wikidir/index.php', since the
161    // pages will appear at e.g. '/wikidir/index.php/FrontPage'.
162    //
163
164    if (USE_PATH_INFO and isset($REDIRECT_URL)
165        and ! IsProbablyRedirectToIndex())
166    {
167       // FIXME: This is a hack, and won't work if the requested
168       // pagename has a slash in it.
169       define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
170    }
171    else
172       define('VIRTUAL_PATH', SCRIPT_NAME);
173 }
174
175 if (SERVER_PORT && SERVER_PORT != 80)
176    define('SERVER_URL',
177           "http://" . SERVER_NAME . ':' . SERVER_PORT);
178 else
179    define('SERVER_URL',
180           "http://" . SERVER_NAME);
181
182 if (VIRTUAL_PATH != SCRIPT_NAME)
183 {
184    // Apache action handlers are used.
185    define('PATH_INFO_PREFIX', VIRTUAL_PATH . "/");
186 }
187 else
188    define("PATH_INFO_PREFIX", '/');
189
190
191 //////////////////////////////////////////////////////////////////
192 // Select database
193 //
194 if (empty($DBParams['dbtype']))
195 {
196    if ( floor(phpversion()) == 3) {
197       $DBParams['dbtype'] = 'dbm';
198    } else {
199       $DBParams['dbtype'] = 'dba';
200    }
201 }
202
203 switch ($DBParams['dbtype']) 
204 {
205    case 'dbm':
206       include 'lib/dbmlib.php';
207       break;
208    case 'dba':
209       include 'lib/dbalib.php';
210       break;
211    case 'mysql':
212       include 'lib/mysql.php';
213       break;
214    case 'pgsql':
215       include 'lib/pgsql.php';
216       break;
217    case 'msql':
218       include 'lib/msql.php';
219       break;
220    case 'file':
221       include "lib/db_filesystem.php";
222       break;
223    default:
224       ExitWiki($DBParams['dbtype'] . ": unknown DBTYPE");
225 }
226
227 // InterWiki linking -- wiki-style links to other wikis on the web
228 //
229 if (defined('INTERWIKI_MAP_FILE'))
230 {
231    include ('lib/interwiki.php');
232 }
233
234 // For emacs users
235 // Local Variables:
236 // mode: php
237 // c-file-style: "ellemtel"
238 // End:   
239 ?>