4 * A configurator intended to read its config from a PHP-style INI file,
5 * instead of a PHP file.
7 * Pass a filename to the IniConfig() function and it will read all its
8 * definitions from there, all by itself, and proceed to do a mass-define
9 * of all valid PHPWiki config items. In this way, we can hopefully be
10 * totally backwards-compatible with the old index.php method, while still
11 * providing a much tastier on-going experience.
13 * @author: Joby Walker, Reini Urban, Matthew Palmer
16 * Copyright 2004,2005,2006,2007 $ThePhpWikiProgrammingTeam
17 * Copyright 2008-2010 Marc-Etienne Vargenau, Alcatel-Lucent
19 * This file is part of PhpWiki.
21 * PhpWiki is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
26 * PhpWiki is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License along
32 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
33 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38 * - Convert the value lists to provide defaults, so that every "if
39 * (defined())" and "if (!defined())" can fuck off to the dismal hole
41 * - config.ini => config.php dumper for faster startup. (really faster? to time)
44 * - Old-style index.php => config/config.ini converter.
46 * - Don't use too much globals for easier integration into other projects
47 * (namespace pollution). (FusionForge, phpnuke, postnuke, phpBB2, carolina, ...)
48 * Use one global $phpwiki object instead which holds the cfg vars, constants
49 * and all other globals.
50 * (global $FieldSeparator, $WikiNameRegexp, $KeywordLinkRegexp;
51 * global $DisabledActions, $DBParams, $LANG, $AllActionPages)
53 * - Resurrect the larger "config object" code (in config/) so it'll aid the
54 * GUI config writers, and allow us to do proper validation and default
57 * - Get rid of WikiNameRegexp and KeywordLinkRegexp as globals by finding
58 * everywhere that uses them as variables and modify the code to use
62 include_once (dirname(__FILE__) . "/config.php");
63 include_once (dirname(__FILE__) . "/FileFinder.php");
66 * Speed-up iniconfig loading.
68 * Dump the static parts of the parsed config/config.ini settings to a fast-loadable config.php file.
69 * The dynamic parts are then evaluated as before.
70 * Requires write-permissions to config/config.php
74 function save_dump($file)
76 $vars =& $GLOBALS; // copy + unset not possible
78 foreach (array("SERVER", "ENV", "GET", "POST", "REQUEST", "COOKIE", "FILES") as $key) {
79 $ignore["HTTP_" . $key . "_VARS"]++;
80 $ignore["_" . $key]++;
82 foreach (array("HTTP_POST_FILES", "GLOBALS", "RUNTIMER", "ErrorManager", 'LANG',
83 'HOME_PAGE', 'request', 'SCRIPT_NAME', 'VIRTUAL_PATH', 'SCRIPT_FILENAME') as $key)
85 $fp = fopen($file, "wb");
86 fwrite($fp, "<?php\n");
87 fwrite($fp, "function wiki_configrestore(){\n");
88 //TODO: optimize this by removing ignore, big serialized array and merge into existing GLOBALS
89 foreach ($vars as $var => $val) {
91 fwrite($fp, "\$GLOBALS['" . $var . "']=unserialize(\""
92 . addslashes(serialize($val)) . "\");\n");
94 // cannot be optimized, maybe leave away predefined consts somehow
95 foreach (get_defined_constants() as $var => $val) {
96 if (substr($var, 0, 4) != "PHP_" and substr($var, 0, 2) != "E_"
97 and substr($var, 0, 2) != "T_" and substr($var, 0, 2) != "M_"
99 fwrite($fp, "if(!defined('" . $var . "')) define('" . $var . "',unserialize(\""
100 . addslashes(serialize($val)) . "\"));\n");
102 fwrite($fp, "return 'noerr';}");
107 function _check_int_constant(&$c)
109 // if int value == string value, force int type
110 if (sprintf("%d", (int)$c) === $c) { // DEBUG & _DEBUG_bla
115 function IniConfig($file)
118 // Optionally check config/config.php dump for faster startup
119 $dump = substr($file, 0, -3) . "php";
120 if (isWindows($dump)) $dump = str_replace("/", "\\", $dump);
121 if (file_exists($dump) and is_readable($dump) and filesize($dump) > 0 and sort_file_mtime($dump, $file) < 0) {
122 @include($dump) or die("Error including " . $dump);
123 if (function_exists('wiki_configrestore') and (wiki_configrestore() === 'noerr')) {
124 fixup_dynamic_configs();
129 // First-time installer detection here...
130 // Similar to SetupWiki()
131 if (!file_exists($file)) {
132 // We need to DATA_PATH for configurator, or pass the posted values
133 // somewhow to the script
134 include_once(dirname(__FILE__) . "/install.php");
135 run_install("_part1");
136 if (!defined("_PHPWIKI_INSTALL_RUNNING"))
137 trigger_error("Datasource file '$file' does not exist", E_USER_ERROR);
141 // List of all valid config options to be define()d which take "values" (not
142 // booleans). Needs to be categorised, and generally made a lot tidier.
143 $_IC_VALID_VALUE = array
144 ('WIKI_NAME', 'ADMIN_USER', 'ADMIN_PASSWD',
145 'DEFAULT_DUMP_DIR', 'HTML_DUMP_DIR',
146 'HTML_DUMP_SUFFIX', 'MAX_UPLOAD_SIZE', 'MINOR_EDIT_TIMEOUT',
147 'ACCESS_LOG', 'CACHE_CONTROL', 'CACHE_CONTROL_MAX_AGE',
148 'COOKIE_EXPIRATION_DAYS', 'COOKIE_DOMAIN',
149 'PASSWORD_LENGTH_MINIMUM', 'USER_AUTH_POLICY',
151 'EDITING_POLICY', 'THEME',
152 'WIKI_PGSRC', 'DEFAULT_WIKI_PGSRC',
153 'ALLOWED_PROTOCOLS', 'INLINE_IMAGES', 'SUBPAGE_SEPARATOR', /*'KEYWORDS',*/
155 //'DATABASE_PREFIX', 'DATABASE_DSN', 'DATABASE_TYPE', 'DATABASE_DBHANDLER',
156 'DATABASE_OPTIMISE_FREQUENCY',
157 'INTERWIKI_MAP_FILE', 'COPYRIGHTPAGE_TITLE', 'COPYRIGHTPAGE_URL',
158 'AUTHORPAGE_TITLE', 'AUTHORPAGE_URL',
160 'PLUGIN_CACHED_DATABASE', 'PLUGIN_CACHED_FILENAME_PREFIX',
161 'PLUGIN_CACHED_HIGHWATER', 'PLUGIN_CACHED_LOWWATER', 'PLUGIN_CACHED_MAXLIFETIME',
162 'PLUGIN_CACHED_MAXARGLEN', 'PLUGIN_CACHED_IMGTYPES',
163 'WYSIWYG_BACKEND', 'PLUGIN_MARKUP_MAP',
165 'SERVER_NAME', 'SERVER_PORT', 'SCRIPT_NAME', 'DATA_PATH', 'PHPWIKI_DIR', 'VIRTUAL_PATH',
166 'EXTERNAL_HTML2PDF_PAGELIST', 'PLUGIN_CACHED_CACHE_DIR'
169 // Optional values which need to be defined.
170 // These are not defined in config-default.ini and empty if not defined.
171 $_IC_OPTIONAL_VALUE = array
173 'DEBUG', 'TEMP_DIR', 'DEFAULT_LANGUAGE',
174 'LDAP_AUTH_HOST', 'LDAP_SET_OPTION', 'LDAP_BASE_DN', 'LDAP_AUTH_USER',
175 'LDAP_AUTH_PASSWORD', 'LDAP_SEARCH_FIELD', 'LDAP_OU_GROUP', 'LDAP_OU_USERS',
176 'AUTH_USER_FILE', 'DBAUTH_AUTH_DSN',
177 'IMAP_AUTH_HOST', 'POP3_AUTH_HOST',
178 'AUTH_USER_FILE', 'AUTH_GROUP_FILE', 'AUTH_SESS_USER', 'AUTH_SESS_LEVEL',
179 'GOOGLE_LICENSE_KEY', 'FORTUNE_DIR',
180 'DISABLE_GETIMAGESIZE', 'DBADMIN_USER', 'DBADMIN_PASSWD',
182 'TOOLBAR_PAGELINK_PULLDOWN', 'TOOLBAR_TEMPLATE_PULLDOWN', 'TOOLBAR_IMAGE_PULLDOWN',
183 'EXTERNAL_LINK_TARGET', 'ACCESS_LOG_SQL', 'USE_EXTERNAL_HTML2PDF',
184 'LOGIN_LOG', 'LDAP_SEARCH_FILTER'
187 // List of all valid config options to be define()d which take booleans.
188 $_IC_VALID_BOOL = array
189 ('ENABLE_PAGEPERM', 'ENABLE_EDIT_TOOLBAR', 'JS_SEARCHREPLACE',
190 'ENABLE_XHTML_XML', 'ENABLE_DOUBLECLICKEDIT', 'ENABLE_LIVESEARCH', 'ENABLE_ACDROPDOWN',
191 'USECACHE', 'WIKIDB_NOCACHE_MARKUP',
192 'ENABLE_REVERSE_DNS', 'ENCRYPTED_PASSWD', 'ZIPDUMP_AUTH',
193 'ENABLE_RAW_HTML', 'ENABLE_RAW_HTML_LOCKEDONLY', 'ENABLE_RAW_HTML_SAFE',
194 'STRICT_MAILABLE_PAGEDUMPS', 'COMPRESS_OUTPUT',
195 'ALLOW_ANON_USER', 'ALLOW_ANON_EDIT',
196 'ALLOW_BOGO_LOGIN', 'ALLOW_USER_PASSWORDS',
197 'AUTH_USER_FILE_STORABLE', 'ALLOW_HTTP_AUTH_LOGIN',
198 'ALLOW_USER_LOGIN', 'ALLOW_LDAP_LOGIN', 'ALLOW_IMAP_LOGIN',
199 'WARN_NONPUBLIC_INTERWIKIMAP', 'USE_PATH_INFO',
200 'DISABLE_HTTP_REDIRECT',
201 'PLUGIN_CACHED_USECACHE', 'PLUGIN_CACHED_FORCE_SYNCMAP',
202 'BLOG_DEFAULT_EMPTY_PREFIX', 'DATABASE_PERSISTENT',
204 'ENABLE_DISCUSSION_LINK', 'ENABLE_CAPTCHA',
205 'ENABLE_WYSIWYG', 'WYSIWYG_DEFAULT_PAGETYPE_HTML',
206 'DISABLE_MARKUP_WIKIWORD', 'ENABLE_MARKUP_COLOR', 'ENABLE_MARKUP_TEMPLATE',
207 'ENABLE_MARKUP_MEDIAWIKI_TABLE',
208 'ENABLE_MARKUP_DIVSPAN', 'USE_BYTEA', 'UPLOAD_USERDIR', 'DISABLE_UNITS',
209 'ENABLE_SEARCHHIGHLIGHT', 'DISABLE_UPLOAD_ONLY_ALLOWED_EXTENSIONS',
210 'ENABLE_AUTH_OPENID', 'INSECURE_ACTIONS_LOCALHOST_ONLY',
211 'ENABLE_MAILNOTIFY', 'ENABLE_RECENTCHANGESBOX', 'ENABLE_PAGE_PUBLIC',
212 'ENABLE_AJAX', 'ENABLE_EXTERNAL_PAGES',
216 $rs = @parse_ini_file($file);
217 $rsdef = @parse_ini_file(dirname(__FILE__) . "/../config/config-default.ini");
218 foreach ($rsdef as $k => $v) {
220 $rs[$k] = constant($k);
221 } elseif (!isset($rs[$k])) {
228 foreach ($_IC_VALID_VALUE as $item) {
229 if (defined($item)) {
233 if (array_key_exists($item, $rs)) {
234 _check_int_constant($rs[$item]);
235 define($item, $rs[$item]);
237 //} elseif (array_key_exists($item, $rsdef)) {
238 // define($item, $rsdef[$item]);
239 // calculate them later or not at all:
240 } elseif (in_array($item,
241 array('DATABASE_PREFIX', 'SERVER_NAME', 'SERVER_PORT',
242 'SCRIPT_NAME', 'DATA_PATH', 'PHPWIKI_DIR', 'VIRTUAL_PATH',
243 'LDAP_AUTH_HOST', 'IMAP_AUTH_HOST', 'POP3_AUTH_HOST',
244 'PLUGIN_CACHED_CACHE_DIR', 'EXTERNAL_HTML2PDF_PAGELIST'))
247 } elseif (!defined("_PHPWIKI_INSTALL_RUNNING")) {
248 trigger_error(sprintf("missing config setting for %s", $item));
253 // Boolean options are slightly special - if they're set to any of
254 // '', 'false', '0', or 'no' (all case-insensitive) then the value will
255 // be a boolean false, otherwise if there is anything set it'll
257 foreach ($_IC_VALID_BOOL as $item) {
258 if (defined($item)) {
262 if (array_key_exists($item, $rs)) {
264 //} elseif (array_key_exists($item, $rsdef)) {
265 // $val = $rsdef[$item];
268 //trigger_error(sprintf("missing boolean config setting for %s",$item));
271 // calculate them later: old or dynamic constants
272 if (!array_key_exists($item, $rs) and
273 in_array($item, array('USE_PATH_INFO', 'USE_DB_SESSION',
274 'ALLOW_HTTP_AUTH_LOGIN', 'ALLOW_LDAP_LOGIN',
275 'ALLOW_IMAP_LOGIN', 'ALLOW_USER_LOGIN',
276 'REQUIRE_SIGNIN_BEFORE_EDIT',
277 'WIKIDB_NOCACHE_MARKUP',
278 'COMPRESS_OUTPUT', 'USE_BYTEA', 'READONLY',
283 define($item, false);
284 } elseif (strtolower($val) == 'false' ||
285 strtolower($val) == 'no' ||
290 define($item, false);
300 foreach (array('DATABASE_TYPE' => 'dbtype',
301 'DATABASE_DSN' => 'dsn',
302 'DATABASE_SESSION_TABLE' => 'db_session_table',
303 'DATABASE_DBA_HANDLER' => 'dba_handler',
304 'DATABASE_DIRECTORY' => 'directory',
305 'DATABASE_TIMEOUT' => 'timeout',
306 'DATABASE_PREFIX' => 'prefix')
308 if (defined($item)) {
309 $DBParams[$k] = constant($item);
311 } elseif (array_key_exists($item, $rs)) {
312 $DBParams[$k] = $rs[$item];
313 define($item, $rs[$item]);
315 } elseif (array_key_exists($item, $rsdef)) {
316 $DBParams[$k] = $rsdef[$item];
317 define($item, $rsdef[$item]);
318 unset($rsdef[$item]);
321 $valid_database_types = array('SQL', 'ADODB', 'PDO', 'dba', 'file', 'flatfile', 'cvs', 'cvsclient');
322 if (!in_array(DATABASE_TYPE, $valid_database_types))
323 trigger_error(sprintf("Invalid DATABASE_TYPE=%s. Choose one of %s",
324 DATABASE_TYPE, join(",", $valid_database_types)),
326 unset($valid_database_types);
327 if (DATABASE_TYPE == 'PDO') {
328 // try to load it dynamically (unix only)
329 if (!loadPhpExtension("pdo")) {
330 echo $GLOBALS['php_errormsg'], "<br>\n";
331 trigger_error(sprintf("dl() problem: Required extension “%s” could not be loaded!",
336 // Detect readonly database, e.g. system mounted read-only for maintenance
337 // via dbh->readonly later. Unfortunately not possible as constant.
339 // USE_DB_SESSION default logic:
340 if (!defined('USE_DB_SESSION')) {
341 if ($DBParams['db_session_table']
342 and in_array($DBParams['dbtype'], array('SQL', 'ADODB', 'PDO', 'dba'))
344 define('USE_DB_SESSION', true);
346 define('USE_DB_SESSION', false);
353 global $ExpireParams;
354 foreach (array('major', 'minor', 'author') as $major) {
355 foreach (array('max_age', 'min_age', 'min_keep', 'keep', 'max_keep') as $max) {
356 $item = strtoupper($major) . '_' . strtoupper($max);
357 if (defined($item)) $val = constant($item);
358 elseif (array_key_exists($item, $rs))
359 $val = $rs[$item]; elseif (array_key_exists($item, $rsdef))
360 $val = $rsdef[$item];
361 if (!isset($ExpireParams[$major]))
362 $ExpireParams[$major] = array();
363 $ExpireParams[$major][$max] = $val;
371 // User authentication
372 if (!isset($GLOBALS['USER_AUTH_ORDER'])) {
373 if (isset($rs['USER_AUTH_ORDER']))
374 $GLOBALS['USER_AUTH_ORDER'] = preg_split('/\s*:\s*/',
375 $rs['USER_AUTH_ORDER']);
377 $GLOBALS['USER_AUTH_ORDER'] = array("PersonalPage");
380 // Now it's the external DB authentication stuff's turn
381 if (in_array('Db', $GLOBALS['USER_AUTH_ORDER']) && empty($rs['DBAUTH_AUTH_DSN'])) {
382 $rs['DBAUTH_AUTH_DSN'] = $DBParams['dsn'];
385 global $DBAuthParams;
386 $DBAP_MAP = array('DBAUTH_AUTH_DSN' => 'auth_dsn',
387 'DBAUTH_AUTH_CHECK' => 'auth_check',
388 'DBAUTH_AUTH_USER_EXISTS' => 'auth_user_exists',
389 'DBAUTH_AUTH_CRYPT_METHOD' => 'auth_crypt_method',
390 'DBAUTH_AUTH_UPDATE' => 'auth_update',
391 'DBAUTH_AUTH_CREATE' => 'auth_create',
392 'DBAUTH_PREF_SELECT' => 'pref_select',
393 'DBAUTH_PREF_INSERT' => 'pref_insert',
394 'DBAUTH_PREF_UPDATE' => 'pref_update',
395 'DBAUTH_IS_MEMBER' => 'is_member',
396 'DBAUTH_GROUP_MEMBERS' => 'group_members',
397 'DBAUTH_USER_GROUPS' => 'user_groups'
399 foreach ($DBAP_MAP as $rskey => $apkey) {
400 if (defined($rskey)) {
401 $DBAuthParams[$apkey] = constant($rskey);
402 } elseif (isset($rs[$rskey])) {
403 $DBAuthParams[$apkey] = $rs[$rskey];
404 define($rskey, $rs[$rskey]);
405 } elseif (isset($rsdef[$rskey])) {
406 $DBAuthParams[$apkey] = $rsdef[$rskey];
407 define($rskey, $rsdef[$rskey]);
414 // TODO: Currently unsupported on non-SQL. Nice to have for RhNavPlugin
416 if (!defined('ACCESS_LOG_SQL')) {
417 if (array_key_exists('ACCESS_LOG_SQL', $rs)) {
418 // WikiDB_backend::isSql() not yet loaded
419 if (!in_array(DATABASE_TYPE, array('SQL', 'ADODB', 'PDO'))) {
420 // override false config setting on no SQL WikiDB database.
421 define('ACCESS_LOG_SQL', 0);
423 // SQL defaults to ACCESS_LOG_SQL = 2
425 define('ACCESS_LOG_SQL',
426 in_array(DATABASE_TYPE, array('SQL', 'ADODB', 'PDO')) ? 2 : 0);
430 global $PLUGIN_MARKUP_MAP;
431 $PLUGIN_MARKUP_MAP = array();
432 if (defined('PLUGIN_MARKUP_MAP') and trim(PLUGIN_MARKUP_MAP) != "") {
433 $_map = preg_split('/\s+/', PLUGIN_MARKUP_MAP);
434 foreach ($_map as $v) {
435 list($xml, $plugin) = explode(':', $v);
436 if (!empty($xml) and !empty($plugin))
437 $PLUGIN_MARKUP_MAP[$xml] = $plugin;
445 if (empty($rs['TEMP_DIR'])) {
446 $rs['TEMP_DIR'] = "/tmp";
448 $rs['TEMP_DIR'] = getenv("TEMP");
450 // optional values will be set to '' to simplify the logic.
451 foreach ($_IC_OPTIONAL_VALUE as $item) {
452 if (defined($item)) {
456 if (array_key_exists($item, $rs)) {
457 _check_int_constant($rs[$item]);
458 define($item, $rs[$item]);
464 if (USE_EXTERNAL_HTML2PDF) {
465 $item = 'EXTERNAL_HTML2PDF_PAGELIST';
466 if (defined($item)) {
468 } elseif (array_key_exists($item, $rs)) {
469 define($item, $rs[$item]);
471 } elseif (array_key_exists($item, $rsdef)) {
472 define($item, $rsdef[$item]);
478 global $LDAP_SET_OPTION;
479 if (defined('LDAP_SET_OPTION') and LDAP_SET_OPTION) {
480 $optlist = preg_split('/\s*:\s*/', LDAP_SET_OPTION);
481 foreach ($optlist as $opt) {
482 $bits = preg_split('/\s*=\s*/', $opt, 2);
483 if (count($bits) == 2) {
484 if (is_string($bits[0]) and defined($bits[0]))
485 $bits[0] = constant($bits[0]);
486 $LDAP_SET_OPTION[$bits[0]] = $bits[1];
488 // Possibly throw some sort of error?
495 // Default Wiki pages to force loading from pgsrc
496 global $GenericPages;
497 $GenericPages = preg_split('/\s*:\s*/', @$rs['DEFAULT_WIKI_PAGES']);
499 // Wiki name regexp: Should be a define(), but might needed to be changed at runtime
500 // (different LC_CHAR need different posix classes)
501 global $WikiNameRegexp;
502 $WikiNameRegexp = constant('WIKI_NAME_REGEXP');
503 if (!trim($WikiNameRegexp))
504 $WikiNameRegexp = '(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])';
506 // Got rid of global $KeywordLinkRegexp by using a TextSearchQuery instead
507 // of "Category:Topic"
508 if (!isset($rs['KEYWORDS'])) $rs['KEYWORDS'] = @$rsdef['KEYWORDS'];
509 if (!isset($rs['KEYWORDS'])) $rs['KEYWORDS'] = "Category* OR Topic*";
510 if ($rs['KEYWORDS'] == 'Category:Topic') $rs['KEYWORDS'] = "Category* OR Topic*";
511 if (!defined('KEYWORDS')) define('KEYWORDS', $rs['KEYWORDS']);
512 //if (empty($keywords)) $keywords = array("Category","Topic");
513 //$KeywordLinkRegexp = '(?<=' . implode('|^', $keywords) . ')[[:upper:]].*$';
515 // TODO: can this be a constant?
516 global $DisabledActions;
517 if (!array_key_exists('DISABLED_ACTIONS', $rs)
518 and array_key_exists('DISABLED_ACTIONS', $rsdef)
520 $rs['DISABLED_ACTIONS'] = @$rsdef['DISABLED_ACTIONS'];
521 if (array_key_exists('DISABLED_ACTIONS', $rs))
522 $DisabledActions = preg_split('/\s*:\s*/', $rs['DISABLED_ACTIONS']);
524 global $PLUGIN_CACHED_IMGTYPES;
525 $PLUGIN_CACHED_IMGTYPES = preg_split('/\s*[|:]\s*/', PLUGIN_CACHED_IMGTYPES);
527 if (!defined('PLUGIN_CACHED_CACHE_DIR')) {
528 if (empty($rs['PLUGIN_CACHED_CACHE_DIR']) and !empty($rsdef['PLUGIN_CACHED_CACHE_DIR']))
529 $rs['PLUGIN_CACHED_CACHE_DIR'] = $rsdef['PLUGIN_CACHED_CACHE_DIR'];
530 if (empty($rs['PLUGIN_CACHED_CACHE_DIR'])) {
531 if (!empty($rs['INCLUDE_PATH'])) {
532 @ini_set('include_path', $rs['INCLUDE_PATH']);
533 $GLOBALS['INCLUDE_PATH'] = $rs['INCLUDE_PATH'];
535 $rs['PLUGIN_CACHED_CACHE_DIR'] = TEMP_DIR . '/cache';
536 if (!FindFile($rs['PLUGIN_CACHED_CACHE_DIR'], 1)) { // [29ms]
537 FindFile(TEMP_DIR, false, 1); // TEMP must exist!
538 mkdir($rs['PLUGIN_CACHED_CACHE_DIR'], 0777);
540 // will throw an error if not exists.
541 define('PLUGIN_CACHED_CACHE_DIR', FindFile($rs['PLUGIN_CACHED_CACHE_DIR'], false, 1));
543 define('PLUGIN_CACHED_CACHE_DIR', $rs['PLUGIN_CACHED_CACHE_DIR']);
544 // will throw an error if not exists.
545 FindFile(PLUGIN_CACHED_CACHE_DIR);
549 // process the rest of the config.ini settings:
550 foreach ($rs as $item => $v) {
551 if (defined($item)) {
554 _check_int_constant($v);
564 fixup_static_configs($file); //[1ms]
565 // Dump all globals and constants
566 // The question is if reading this is faster then doing IniConfig() + fixup_static_configs()
567 if (is_writable($dump)) {
570 // store locale[] in config.php? This is too problematic.
571 fixup_dynamic_configs(); // [100ms]
574 function _ignore_unknown_charset_warning(&$error)
576 if (preg_match('/^htmlspecialchars\(\): charset \`.+\' not supported, assuming iso-8859-1/',
580 return true; // Ignore error
585 // moved from lib/config.php [1ms]
586 function fixup_static_configs($file)
588 global $FieldSeparator, $WikiNameRegexp, $AllActionPages;
589 global $DBParams, $LANG, $ErrorManager;
590 // init FileFinder to add proper include paths
591 FindFile("lib/interwiki.map", true);
593 // $FieldSeparator = "\xFF"; // this byte should never appear in utf-8
594 $FieldSeparator = "\xFF";
596 // All pages containing plugins of the same name as the filename
597 $ActionPages = explode(':',
598 'AllPages:AllUsers:AppendText:AuthorHistory:'
601 . 'FullTextSearch:FuzzyPages:'
602 . 'LikePages:LinkDatabase:LinkSearch:ListRelations:'
603 . 'ModeratedPage:MostPopular:'
606 . 'PageDump:PageHistory:PageInfo:PluginManager:'
607 . 'RateIt:' // RateIt works only in wikilens derived themes
608 . 'RandomPage:RecentChanges:RelatedChanges:RecentEdits:'
609 . 'SearchHighlight:SemanticRelations:SemanticSearch:SystemInfo:'
611 . 'UpLoad:UserPreferences:'
612 . 'UserRatings:' // UserRatings works only in wikilens derived themes
613 . 'WantedPages:WatchPage:WhoIsOnline:WikiAdminSelect');
615 // The FUSIONFORGE theme omits them
616 if (!(defined('FUSIONFORGE') and FUSIONFORGE)) {
617 // Add some some action pages
618 $ActionPages[] = 'DebugInfo';
619 $ActionPages[] = 'SpellCheck'; // SpellCheck does not work
620 $ActionPages[] = 'BlogArchives';
621 $ActionPages[] = 'BlogJournal';
622 $ActionPages[] = 'EditMetaData';
623 $ActionPages[] = 'InterWikiSearch';
624 $ActionPages[] = 'LdapSearch';
625 $ActionPages[] = 'PasswordReset';
626 $ActionPages[] = 'RecentComments';
627 $ActionPages[] = 'TranslateText';
628 $ActionPages[] = 'UriResolver';
629 $ActionPages[] = 'WikiBlog';
632 global $AllAllowedPlugins;
633 $AllAllowedPlugins = $ActionPages;
634 // Add plugins that have no corresponding action page
635 $AllAllowedPlugins[] = 'AddComment';
636 $AllAllowedPlugins[] = 'AsciiMath';
637 $AllAllowedPlugins[] = 'AsciiSVG';
638 $AllAllowedPlugins[] = 'AtomFeed';
639 $AllAllowedPlugins[] = 'BoxRight';
640 $AllAllowedPlugins[] = 'CalendarList';
641 $AllAllowedPlugins[] = 'Calendar';
642 $AllAllowedPlugins[] = 'CategoryPage';
643 $AllAllowedPlugins[] = 'Chart';
644 $AllAllowedPlugins[] = 'Comment';
645 $AllAllowedPlugins[] = 'CreateBib';
646 $AllAllowedPlugins[] = 'CreateToc';
647 $AllAllowedPlugins[] = 'CurrentTime';
648 $AllAllowedPlugins[] = 'DeadEndPages';
649 $AllAllowedPlugins[] = 'Diff';
650 $AllAllowedPlugins[] = 'DynamicIncludePage';
651 $AllAllowedPlugins[] = 'ExternalSearch';
652 $AllAllowedPlugins[] = 'FacebookLike';
653 $AllAllowedPlugins[] = 'FileInfo';
654 $AllAllowedPlugins[] = 'GoogleMaps';
655 $AllAllowedPlugins[] = 'GooglePlugin';
656 $AllAllowedPlugins[] = 'GoTo';
657 $AllAllowedPlugins[] = 'HelloWorld';
658 $AllAllowedPlugins[] = 'IncludePage';
659 $AllAllowedPlugins[] = 'IncludePages';
660 $AllAllowedPlugins[] = 'IncludeSiteMap';
661 $AllAllowedPlugins[] = 'IncludeTree';
662 $AllAllowedPlugins[] = 'ListPages';
663 $AllAllowedPlugins[] = 'ListSubpages';
664 $AllAllowedPlugins[] = 'MediawikiTable';
665 $AllAllowedPlugins[] = 'NoCache';
666 $AllAllowedPlugins[] = 'OldStyleTable';
667 $AllAllowedPlugins[] = 'PageGroup';
668 $AllAllowedPlugins[] = 'PageTrail';
669 $AllAllowedPlugins[] = 'PhotoAlbum';
670 $AllAllowedPlugins[] = 'PhpHighlight';
671 $AllAllowedPlugins[] = 'PopularTags';
672 $AllAllowedPlugins[] = 'PopUp';
673 $AllAllowedPlugins[] = 'PrevNext';
674 $AllAllowedPlugins[] = 'Processing';
675 $AllAllowedPlugins[] = 'RawHtml';
676 $AllAllowedPlugins[] = 'RecentChangesCached';
677 $AllAllowedPlugins[] = 'RecentReferrers';
678 $AllAllowedPlugins[] = 'RedirectTo';
679 $AllAllowedPlugins[] = 'RichTable';
680 $AllAllowedPlugins[] = 'RssFeed';
681 $AllAllowedPlugins[] = 'SemanticSearchAdvanced';
682 $AllAllowedPlugins[] = 'SiteMap';
683 $AllAllowedPlugins[] = 'SyncWiki';
684 $AllAllowedPlugins[] = 'SyntaxHighlighter';
685 $AllAllowedPlugins[] = 'Template';
686 $AllAllowedPlugins[] = 'Transclude';
687 $AllAllowedPlugins[] = 'UnfoldSubpages';
688 $AllAllowedPlugins[] = 'Video';
689 $AllAllowedPlugins[] = 'WikiAdminChown';
690 $AllAllowedPlugins[] = 'WikiAdminPurge';
691 $AllAllowedPlugins[] = 'WikiAdminRemove';
692 $AllAllowedPlugins[] = 'WikiAdminRename';
693 $AllAllowedPlugins[] = 'WikiAdminSearchReplace';
694 $AllAllowedPlugins[] = 'WikiAdminDeleteAcl';
695 $AllAllowedPlugins[] = 'WikiAdminSetAcl';
696 $AllAllowedPlugins[] = 'WikiAdminSetAclSimple';
697 $AllAllowedPlugins[] = 'WikiAdminUtils';
698 $AllAllowedPlugins[] = 'WikicreoleTable';
699 $AllAllowedPlugins[] = 'WikiForm';
700 $AllAllowedPlugins[] = 'WikiFormRich';
701 $AllAllowedPlugins[] = 'WikiPoll';
702 $AllAllowedPlugins[] = 'YouTube';
703 $AllAllowedPlugins[] = 'DebugGroupInfo';
704 $AllAllowedPlugins[] = 'DebugAuthInfo';
705 $AllAllowedPlugins[] = 'DebugBackendInfo';
707 // The FUSIONFORGE theme omits them
708 if (!(defined('FUSIONFORGE') and FUSIONFORGE)) {
709 $AllAllowedPlugins[] = 'AnalyseAccessLogSql';
710 $AllAllowedPlugins[] = 'CacheTest';
711 $AllAllowedPlugins[] = 'CategoryPage';
712 $AllAllowedPlugins[] = 'FoafViewer';
713 $AllAllowedPlugins[] = 'GraphViz';
714 $AllAllowedPlugins[] = 'HtmlConverter';
715 $AllAllowedPlugins[] = 'JabberPresence';
716 $AllAllowedPlugins[] = 'ListPages';
717 $AllAllowedPlugins[] = 'PhpWeather';
718 $AllAllowedPlugins[] = 'Ploticus';
719 $AllAllowedPlugins[] = 'PopularNearby';
720 $AllAllowedPlugins[] = 'PreferenceApp';
721 $AllAllowedPlugins[] = 'PreferencesInfo';
722 $AllAllowedPlugins[] = '_Retransform';
723 $AllAllowedPlugins[] = 'SqlResult';
724 $AllAllowedPlugins[] = 'TeX2png';
725 $AllAllowedPlugins[] = 'text2png';
726 $AllAllowedPlugins[] = 'TexToPng';
727 $AllAllowedPlugins[] = 'VisualWiki';
728 $AllAllowedPlugins[] = 'WantedPagesOld';
729 $AllAllowedPlugins[] = 'WikiForum';
730 $AllAllowedPlugins[] = 'WikiTranslation';
733 // Used by SetupWiki to pull in required pages, if not translated, then in English.
734 // Also used by WikiTranslation. Really important are only those which return pagelists
735 // or contain basic functionality.
736 $AllActionPages = $ActionPages;
737 $AllActionPages[] = 'AllPagesCreatedByMe';
738 $AllActionPages[] = 'AllPagesLastEditedByMe';
739 $AllActionPages[] = 'AllPagesOwnedByMe';
740 $AllActionPages[] = 'AllPagesByAcl';
741 $AllActionPages[] = 'AllUserPages';
742 $AllActionPages[] = 'FullRecentChanges';
743 $AllActionPages[] = 'LeastPopular';
744 $AllActionPages[] = 'LockedPages';
745 $AllActionPages[] = 'MyRatings'; // MyRatings works only in wikilens-derived themes
746 $AllActionPages[] = 'MyRecentEdits';
747 $AllActionPages[] = 'MyRecentChanges';
748 $AllActionPages[] = 'PhpWikiAdministration';
749 $AllActionPages[] = 'PhpWikiAdministration/Chown';
750 $AllActionPages[] = 'PhpWikiAdministration/Purge';
751 $AllActionPages[] = 'PhpWikiAdministration/Remove';
752 $AllActionPages[] = 'PhpWikiAdministration/Rename';
753 $AllActionPages[] = 'PhpWikiAdministration/SearchReplace';
754 $AllActionPages[] = 'PhpWikiAdministration/DeleteAcl';
755 $AllActionPages[] = 'PhpWikiAdministration/SetAcl';
756 $AllActionPages[] = 'PhpWikiAdministration/SetAclSimple';
757 $AllActionPages[] = 'RecentChangesMyPages';
758 $AllActionPages[] = 'RecentEdits';
759 $AllActionPages[] = 'RecentNewPages';
760 $AllActionPages[] = 'SetGlobalAccessRights';
761 $AllActionPages[] = 'SetGlobalAccessRightsSimple';
762 $AllActionPages[] = 'UserContribs';
764 if ((defined('FUSIONFORGE') and FUSIONFORGE)) {
765 if (ENABLE_EXTERNAL_PAGES) {
766 $AllAllowedPlugins[] = 'WikiAdminSetExternal';
767 $AllActionPages[] = 'PhpWikiAdministration/SetExternal';
768 $AllActionPages[] = 'ExternalPages';
772 // If user has not defined PHPWIKI_DIR, and we need it
773 if (!defined('PHPWIKI_DIR') and !file_exists("themes/default")) {
774 $themes_dir = FindFile("themes");
775 define('PHPWIKI_DIR', dirname($themes_dir));
778 // If user has not defined DATA_PATH, we want to use relative URLs.
779 if (!defined('DATA_PATH')) {
780 // fix similar to the one suggested by jkalmbach for
781 // installations in the webrootdir, like "http://phpwiki.fr/HomePage"
782 if (!defined('SCRIPT_NAME'))
783 define('SCRIPT_NAME', deduce_script_name());
784 $temp = dirname(SCRIPT_NAME);
785 if (($temp == '/') || ($temp == '\\'))
787 define('DATA_PATH', $temp);
790 define('DATA_PATH', '..');
794 //////////////////////////////////////////////////////////////////
797 if (empty($DBParams['dbtype']))
798 $DBParams['dbtype'] = 'dba';
800 if (!defined('THEME'))
801 define('THEME', 'default');
803 // Basic configurator validation
804 if (!defined('ADMIN_USER') or ADMIN_USER == '') {
805 $error = sprintf("%s may not be empty. Please update your configuration.",
807 // protect against recursion
808 if (!preg_match("/config\-(dist|default)\.ini$/", $file)
809 and !defined("_PHPWIKI_INSTALL_RUNNING")
811 include_once(dirname(__FILE__) . "/install.php");
812 run_install("_part1");
813 trigger_error($error, E_USER_ERROR);
815 } elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
816 $GLOBALS['HTTP_GET_VARS']['show'] = '_part1';
817 trigger_error($error, E_USER_WARNING);
820 if (!defined('ADMIN_PASSWD') or ADMIN_PASSWD == '') {
821 $error = sprintf("%s may not be empty. Please update your configuration.",
823 // protect against recursion
824 if (!preg_match("/config\-(dist|default)\.ini$/", $file)
825 and !defined("_PHPWIKI_INSTALL_RUNNING")
827 include_once(dirname(__FILE__) . "/install.php");
828 run_install("_part1");
829 trigger_error($error, E_USER_ERROR);
831 } elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
832 $GLOBALS['HTTP_GET_VARS']['show'] = '_part1';
833 trigger_error($error, E_USER_WARNING);
837 if (defined('USE_DB_SESSION') and USE_DB_SESSION) {
838 if (!$DBParams['db_session_table']) {
839 $DBParams['db_session_table'] = @$DBParams['prefix'] . 'session';
840 trigger_error(sprintf("DATABASE_SESSION_TABLE configuration set to %s.",
841 $DBParams['db_session_table']),
846 if (!defined('ALLOW_USER_LOGIN'))
847 define('ALLOW_USER_LOGIN', defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
848 if (!defined('ALLOW_ANON_USER')) define('ALLOW_ANON_USER', true);
849 if (!defined('ALLOW_ANON_EDIT')) define('ALLOW_ANON_EDIT', false);
850 if (!defined('REQUIRE_SIGNIN_BEFORE_EDIT')) define('REQUIRE_SIGNIN_BEFORE_EDIT', !ALLOW_ANON_EDIT);
851 if (!defined('ALLOW_BOGO_LOGIN')) define('ALLOW_BOGO_LOGIN', true);
852 if (ALLOW_USER_LOGIN and !empty($DBAuthParams) and empty($DBAuthParams['auth_dsn'])) {
853 if (isset($DBParams['dsn']))
854 $DBAuthParams['auth_dsn'] = $DBParams['dsn'];
859 * Define constants which are client or request specific and should not be dumped statically.
860 * Such as the language, and the virtual and server paths, which might be overridden
861 * by startup scripts for wiki farms.
863 function fixup_dynamic_configs()
865 global $WikiNameRegexp;
866 global $DBParams, $LANG;
868 if (defined('INCLUDE_PATH') and INCLUDE_PATH) {
869 @ini_set('include_path', INCLUDE_PATH);
870 $GLOBALS['INCLUDE_PATH'] = INCLUDE_PATH;
872 if (defined('SESSION_SAVE_PATH') and SESSION_SAVE_PATH)
873 @ini_set('session.save_path', SESSION_SAVE_PATH);
874 if (!defined('DEFAULT_LANGUAGE')) // not needed anymore
875 define('DEFAULT_LANGUAGE', ''); // detect from client
878 if (!(defined('FUSIONFORGE') and FUSIONFORGE)) {
879 // Disable update_locale because Zend Debugger crash
880 if (!extension_loaded('Zend Debugger')) {
881 update_locale(isset($LANG) ? $LANG : DEFAULT_LANGUAGE);
886 if (!defined("DEFAULT_LANGUAGE") or !DEFAULT_LANGUAGE) {
887 // TODO: defer this to WikiRequest::initializeLang()
888 $LANG = guessing_lang();
889 guessing_setlocale(LC_ALL, $LANG);
891 $LANG = DEFAULT_LANGUAGE;
894 // Set up (possibly fake) gettext()
895 // Todo: this could be moved to fixup_static_configs()
896 // Bug #1381464 with php-5.1.1
897 if (!function_exists('bindtextdomain')
898 and !function_exists('gettext')
899 and !function_exists('_')
903 function gettext($text)
906 if (!empty ($locale[$text]))
907 return $locale[$text];
913 return gettext($text);
919 // Working around really weird gettext problems: (4.3.2, 4.3.6 win)
920 // bindtextdomain() in returns the current domain path.
921 // 1. If the script is not index.php but something like "de", on a different path
922 // then bindtextdomain() fails, but after chdir to the correct path it will work okay.
923 // 2. But the weird error "Undefined variable: bindtextdomain" is generated then.
924 $bindtextdomain_path = FindFile("locale", false, true);
926 $bindtextdomain_path = str_replace("/", "\\", $bindtextdomain_path);
927 $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain_path);
928 if (realpath($bindtextdomain_real) != realpath($bindtextdomain_path)) {
929 // this will happen with virtual_paths. chdir and try again.
930 chdir($bindtextdomain_path);
932 $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain_path);
935 // tell gettext not to use unicode. PHP >= 4.2.0. Thanks to Kai Krakow.
937 textdomain("phpwiki");
938 if ($chback) { // change back
939 chdir($bindtextdomain_real . (isWindows() ? "\\.." : "/.."));
943 // language dependent updates:
944 if (!defined('CATEGORY_GROUP_PAGE'))
945 define('CATEGORY_GROUP_PAGE', _("CategoryGroup"));
946 if (!defined('WIKI_NAME'))
947 define('WIKI_NAME', _("An unnamed PhpWiki"));
948 if (!defined('HOME_PAGE'))
949 define('HOME_PAGE', __("HomePage"));
951 //////////////////////////////////////////////////////////////////
952 // Autodetect URL settings:
954 foreach (array('SERVER_NAME', 'SERVER_PORT') as $var) {
955 //FIXME: for CGI without _SERVER
956 if (!defined($var) and !empty($_SERVER[$var]))
957 // IPV6 fix by matt brown, #1546571
958 // An IPv6 address must be surrounded by square brackets to form a valid server name.
959 if ($var == 'SERVER_NAME' &&
960 strstr($_SERVER[$var], ':')
962 define($var, '[' . $_SERVER[$var] . ']');
964 define($var, $_SERVER[$var]);
967 if (!defined('SERVER_NAME')) define('SERVER_NAME', '127.0.0.1');
968 if (!defined('SERVER_PORT')) define('SERVER_PORT', 80);
969 if (!defined('SERVER_PROTOCOL')) {
970 if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')
971 define('SERVER_PROTOCOL', 'http');
973 define('SERVER_PROTOCOL', 'https');
976 if (!defined('SCRIPT_NAME'))
977 define('SCRIPT_NAME', deduce_script_name());
979 if (!defined('USE_PATH_INFO')) {
981 define('USE_PATH_INFO', false);
984 * If SCRIPT_NAME does not look like php source file,
985 * or user cgi we assume that php is getting run by an
986 * action handler in /cgi-bin. In this case,
987 * I think there is no way to get Apache to pass
988 * useful PATH_INFO to the php script (PATH_INFO
989 * is used to the the php interpreter where the
992 switch (php_sapi_name()) {
994 case 'apache2handler':
995 define('USE_PATH_INFO', true);
998 case 'apache2filter':
999 define('USE_PATH_INFO', false);
1002 define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', SCRIPT_NAME));
1009 && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)
1011 define('SERVER_URL',
1012 SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
1014 define('SERVER_URL',
1015 SERVER_PROTOCOL . '://' . SERVER_NAME);
1018 if (!defined('VIRTUAL_PATH')) {
1019 // We'd like to auto-detect when the cases where apaches
1020 // 'Action' directive (or similar means) is used to
1021 // redirect page requests to a cgi-handler.
1023 // In cases like this, requests for e.g. /wiki/HomePage
1024 // get redirected to a cgi-script called, say,
1025 // /path/to/wiki/index.php. The script gets all
1026 // of /wiki/HomePage as it's PATH_INFO.
1029 // How to detect when this has happened reliably?
1030 // How to pick out the "virtual path" (in this case '/wiki')?
1032 // (Another time an redirect might occur is to a DirectoryIndex
1033 // -- the requested URI is '/wikidir/', the request gets
1034 // passed to '/wikidir/index.php'. In this case, the
1035 // proper VIRTUAL_PATH is '/wikidir/index.php', since the
1036 // pages will appear at e.g. '/wikidir/index.php/HomePage'.
1039 $REDIRECT_URL = &$_SERVER['REDIRECT_URL'];
1040 if (USE_PATH_INFO and isset($REDIRECT_URL)
1041 and !IsProbablyRedirectToIndex()
1043 // FIXME: This is a hack, and won't work if the requested
1044 // pagename has a slash in it.
1045 $temp = strtr(dirname($REDIRECT_URL . 'x'), "\\", '/');
1046 if (($temp == '/') || ($temp == '\\'))
1048 define('VIRTUAL_PATH', $temp);
1050 define('VIRTUAL_PATH', SCRIPT_NAME);
1054 if (!defined('PATH_INFO_PREFIX')) {
1055 if (VIRTUAL_PATH != SCRIPT_NAME) {
1056 // Apache action handlers are used.
1057 define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
1059 define('PATH_INFO_PREFIX', '/');
1063 define('PHPWIKI_BASE_URL',
1064 SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
1066 // Detect PrettyWiki setup (not loading index.php directly)
1067 // $SCRIPT_FILENAME should be the same as __FILE__ in index.php
1068 if (!isset($SCRIPT_FILENAME))
1069 $SCRIPT_FILENAME = @$_SERVER['SCRIPT_FILENAME'];
1070 if (!isset($SCRIPT_FILENAME))
1071 $SCRIPT_FILENAME = @$_ENV['SCRIPT_FILENAME'];
1072 if (!isset($SCRIPT_FILENAME))
1073 $SCRIPT_FILENAME = dirname(__FILE__ . '/../') . '/index.php';
1075 $SCRIPT_FILENAME = str_replace('\\\\', '\\', strtr($SCRIPT_FILENAME, '/', '\\'));
1076 define('SCRIPT_FILENAME', $SCRIPT_FILENAME);
1078 // Get remote host name, if Apache hasn't done it for us
1079 if (empty($_SERVER['REMOTE_HOST'])
1080 and !empty($_SERVER['REMOTE_ADDR'])
1081 and ENABLE_REVERSE_DNS
1083 $_SERVER['REMOTE_HOST'] = gethostbyaddr($_SERVER['REMOTE_ADDR']);
1088 * We have to handle three languages:
1089 * 1) English, the language of the source code
1090 * 2) The language in which the wiki was created (DEFAULT_LANGUAGE)
1091 * 3) The language selected by the user, in which the wiki is displayed (LANG)
1093 * The function "_" translates from English to LANG.
1094 * The function "__" translates from English to DEFAULT_LANGUAGE.
1105 // c-basic-offset: 4
1106 // c-hanging-comment-ender-p: nil
1107 // indent-tabs-mode: nil