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