/** * Constructor requires the DB parameters. */ function WikiDB_cvs($dbparams) { if (loadPhpExtension('cvsclient')) { $this->_backend = new WikiDB_backend_cvsclient($dbparams); } else { $this->_backend = new WikiDB_backend_cvs($dbparams); } }
function userExists() { if (!loadPhpExtension('openssl')) { trigger_error(sprintf(_("The PECL %s extension cannot be loaded."), "openssl") . sprintf(_(" %s AUTH ignored."), 'Facebook'), E_USER_WARNING); return $this->_tryNextUser(); } if (DEBUG & _DEBUG_LOGIN) { trigger_error(get_class($this) . "::userExists => true (dummy)", E_USER_WARNING); } return true; }
function WikiDB_backend_PDO($dbparams) { $this->_dbparams = $dbparams; if (strstr($dbparams['dsn'], "://")) { // pear DB syntax $parsed = parseDSN($dbparams['dsn']); $this->_parsedDSN = $parsed; /* Need to convert the DSN * dbtype(dbsyntax)://username:password@protocol+hostspec/database?option=value&option2=value2 * to dbtype:option1=value1;option2=value2 * PDO passes the DSN verbatim to the driver. But we need to extract the username + password * and cannot rely that the parseDSN keys have the same name as needed by the driver. * e.g: odbc:DSN=SAMPLE;UID=db2inst1;PWD=ibmdb2, mysql:host=127.0.0.1;dbname=testdb */ $driver = $parsed['phptype']; unset($parsed['phptype']); unset($parsed['dbsyntax']); $dbparams['dsn'] = $driver . ":"; $this->_dbh->database = $parsed['database']; // mysql needs to map database=>dbname, hostspec=>host. TODO for the others. $dsnmap = array('mysql' => array('database' => 'dbname', 'hostspec' => 'host')); foreach (array('protocol', 'hostspec', 'port', 'socket', 'database') as $option) { if (!empty($parsed[$option])) { $optionname = (isset($dsnmap[$driver][$option]) and !isset($parsed[$optionname])) ? $dsnmap[$driver][$option] : $option; $dbparams['dsn'] .= $optionname . "=" . $parsed[$option] . ";"; unset($parsed[$optionname]); } unset($parsed[$option]); } unset($parsed['username']); unset($parsed['password']); // pass the rest verbatim to the driver. foreach ($parsed as $option => $value) { $dbparams['dsn'] .= $option . "=" . $value . ";"; } } else { list($driver, $dsn) = explode(":", $dbparams['dsn'], 2); foreach (explode(";", trim($dsn)) as $pair) { if ($pair) { list($option, $value) = explode("=", $pair, 2); $this->_parsedDSN[$option] = $value; } } $this->_dbh->database = isset($this->_parsedDSN['database']) ? $this->_parsedDSN['database'] : $this->_parsedDSN['dbname']; } if (empty($this->_parsedDSN['password'])) { $this->_parsedDSN['password'] = ''; } try { // try to load it dynamically (unix only) if (!loadPhpExtension("pdo_{$driver}")) { echo $GLOBALS['php_errormsg'], "<br>\n"; trigger_error(sprintf("dl() problem: Required extension '%s' could not be loaded!", "pdo_{$driver}"), E_USER_WARNING); } // persistent is defined as DSN option, or with a config value. // phptype://username:password@hostspec/database?persistent=false $this->_dbh = new PDO($dbparams['dsn'], $this->_parsedDSN['username'], $this->_parsedDSN['password'], array(PDO_ATTR_AUTOCOMMIT => true, PDO_ATTR_TIMEOUT => DATABASE_TIMEOUT, PDO_ATTR_PERSISTENT => !empty($parsed['persistent']) or DATABASE_PERSISTENT)); } catch (PDOException $e) { echo "<br>\nDB Connection failed: " . $e->getMessage(); if (DEBUG & _DEBUG_VERBOSE or DEBUG & _DEBUG_SQL) { echo "<br>\nDSN: '", $dbparams['dsn'], "'"; echo "<br>\n_parsedDSN: '", print_r($this->_parsedDSN), "'"; echo "<br>\nparsed: '", print_r($parsed), "'"; } exit; } if (DEBUG & _DEBUG_SQL) { // not yet implemented $this->_dbh->debug = true; } $this->_dsn = $dbparams['dsn']; $this->_dbh->databaseType = $driver; $this->_dbh->setAttribute(PDO_ATTR_CASE, PDO_CASE_NATURAL); // Use the faster FETCH_NUM, with some special ASSOC based exceptions. $this->_hasTransactions = true; try { $this->_dbh->beginTransaction(); } catch (PDOException $e) { $this->_hasTransactions = false; } $sth = $this->_dbh->prepare("SELECT version()"); $sth->execute(); $this->_serverinfo['version'] = $sth->fetchSingle(); $this->commit(); // required to match the try catch block above! $prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : ''; $this->_table_names = array('page_tbl' => $prefix . 'page', 'version_tbl' => $prefix . 'version', 'link_tbl' => $prefix . 'link', 'recent_tbl' => $prefix . 'recent', 'nonempty_tbl' => $prefix . 'nonempty'); $page_tbl = $this->_table_names['page_tbl']; $version_tbl = $this->_table_names['version_tbl']; $this->page_tbl_fields = "{$page_tbl}.id AS id, {$page_tbl}.pagename AS pagename, " . "{$page_tbl}.hits hits"; $this->page_tbl_field_list = array('id', 'pagename', 'hits'); $this->version_tbl_fields = "{$version_tbl}.version AS version, " . "{$version_tbl}.mtime AS mtime, " . "{$version_tbl}.minor_edit AS minor_edit, {$version_tbl}.content AS content, " . "{$version_tbl}.versiondata AS versiondata"; $this->version_tbl_field_list = array('version', 'mtime', 'minor_edit', 'content', 'versiondata'); $this->_expressions = array('maxmajor' => "MAX(CASE WHEN minor_edit=0 THEN version END)", 'maxminor' => "MAX(CASE WHEN minor_edit<>0 THEN version END)", 'maxversion' => "MAX(version)", 'notempty' => "<>''", 'iscontent' => "{$version_tbl}.content<>''"); $this->_lock_count = 0; }
function exeversion_resopen($file) { if (function_exists('res_list_type') or loadPhpExtension('win32std')) { // See http://msdn.microsoft.com/workshop/networking/predefined/res.asp $v = file_get_contents('res://' . realpath($file) . urlencode('/RT_VERSION/#1')); if ($v) { // This is really a binary VERSIONINFO block, with lots of // nul bytes (widechar) which cannot be transported as string. return "{$v}"; } else { $h = res_open(realpath($file)); $v = res_get($h, 'RT_VERSION', 'FileVersion'); res_close($h); if ($v) { return $v; } $h = res_open(realpath($file)); $v = res_get($h, '#1', 'RT_VERSION', 1); res_close($h); if ($v) { return $v; } } /* The version consists of two 32-bit integers, defined by four 16-bit integers. For example, "FILEVERSION 3,10,0,61" is translated into two doublewords: 0x0003000a and 0x0000003d, in that order. */ /* $h = res_open(realpath($file)); echo "Res list of '$file': \n"; $list= res_list_type($h, true); if( $list===FALSE ) err( "Can't list type" ); for( $i= 0; $i<count($list); $i++ ) { echo $list[$i]."\n"; $res= res_list($h, $list[$i]); for( $j= 0; $j<count($res); $j++ ) { echo "\t".$res[$j]."\n"; } } echo "Res get: ".res_get( $h, 'A_TYPE', 'A_RC_NAME' )."\n\n"; res_close( $h ); */ if ($v) { return "{$v}"; } else { return ""; } } else { return ""; } }
function charset_convert($from, $to, $data) { //global $CHARSET; //$wikicharset = strtolower($CHARSET); //$systemcharset = strtolower(get_cfg_var('iconv.internal_encoding')); // 'iso-8859-1'; if (strtolower($from) == 'utf-8' and strtolower($to) == 'iso-8859-1') { return utf8_decode($data); } if (strtolower($to) == 'utf-8' and strtolower($from) == 'iso-8859-1') { return utf8_encode($data); } if (loadPhpExtension("iconv")) { $tmpdata = iconv($from, $to, $data); if (!$tmpdata) { trigger_error("charset conversion {$from} => {$to} failed. Wrong source charset?", E_USER_WARNING); } else { $data = $tmpdata; } } else { trigger_error("The iconv extension cannot be loaded", E_USER_WARNING); } return $data; }
function replace_inside_html() { global $charset; $this->clean_links(); $this->clean_plugin_name(); $this->replace_known_plugins(); $this->replace_unknown_plugins(); // $this->replace_tags(); $this->clean_plugin(); if ($charset != 'utf-8') { if ($charset == 'iso-8959-1') { $this->_html = utf8_decode($this->_html); } else { // check for iconv support loadPhpExtension("iconv"); $this->_html = iconv("UTF-8", $charset, $this->_html); } } $this->html_content = $this->_html; }
// All these global declarations that this file // XmlRpcClient.php can be included within a function body // (not in global scope), and things will still work. global $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString; global $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct; global $xmlrpcTypes; global $xmlEntities; global $xmlrpcerr, $xmlrpcstr; global $xmlrpc_defencoding; global $xmlrpcName, $xmlrpcVersion; global $xmlrpcerruser, $xmlrpcerrxml; global $xmlrpc_backslash; global $_xh; global $_xmlrpcs_debug; define('XMLRPC_EXT_LOADED', true); if (loadPhpExtension('xmlrpc')) { // fast c lib global $xmlrpc_util_path; $xmlrpc_util_path = dirname(__FILE__) . "/XMLRPC/"; include_once "lib/XMLRPC/xmlrpc_emu.inc"; } else { // slow php lib // Include the php XML-RPC library include_once "lib/XMLRPC/xmlrpc.inc"; } // API version // See http://www.jspwiki.org/wiki/WikiRPCInterface for version 1 // See http://www.jspwiki.org/wiki/WikiRPCInterface2 for version 2 (we support 80%) define("WIKI_XMLRPC_VERSION", 1); /* * Helper functions for encoding/decoding strings.
function run($dbi, $argstr, $request) { if (!function_exists('ldap_connect')) { if (!loadPhpExtension('ldap')) { return $this->error(_("Missing ldap extension")); } } $args = $this->getArgs($argstr, $request); extract($args); //include_once("lib/WikiUser/LDAP.php"); if (!$host) { if (defined('LDAP_AUTH_HOST')) { $host = LDAP_AUTH_HOST; if (strstr(LDAP_AUTH_HOST, '://')) { $port = null; } } else { $host = 'localhost'; } } else { if (strstr($host, '://')) { $port = null; } } $html = HTML(); if (is_null($port)) { $connect = ldap_connect($host); } else { $connect = ldap_connect($host, $port); } if (!$connect) { return $this->error(_("Failed to connect to LDAP host")); } if (!$options and defined('LDAP_AUTH_HOST') and $args['host'] == LDAP_AUTH_HOST) { if (!empty($GLOBALS['LDAP_SET_OPTION'])) { $options = $GLOBALS['LDAP_SET_OPTION']; } } if ($options) { foreach ($options as $key => $value) { if (!ldap_set_option($connect, $key, $value)) { $this->error(_("Failed to set LDAP {$key} {$value}")); } } } // special convenience: if host = LDAP_AUTH_HOST // then take user and password from config.ini also if ($user) { if ($password) { // required for Windows Active Directory Server $bind = ldap_bind($connect, $user, $password); } else { $bind = ldap_bind($connect, $user); } } elseif (defined('LDAP_AUTH_HOST') and $args['host'] == LDAP_AUTH_HOST) { if (LDAP_AUTH_USER) { if (LDAP_AUTH_PASSWORD) { // Windows Active Directory Server is strict $r = ldap_bind($connect, LDAP_AUTH_USER, LDAP_AUTH_PASSWORD); } else { $r = ldap_bind($connect, LDAP_AUTH_USER); } } else { // anonymous bind $bind = ldap_bind($connect); } } else { // other anonymous bind $bind = ldap_bind($connect); } if (!$bind) { return $this->error(_("Failed to bind LDAP host")); } if (!$basedn) { $basedn = LDAP_BASE_DN; } $attr_array = array(""); if (!$attributes) { $res = ldap_search($connect, $basedn, $filter); } else { $attr_array = explode(" ", $attributes); $res = ldap_search($connect, $basedn, $filter, $attr_array); } $entries = ldap_get_entries($connect, $res); // If we were given attributes then we return them in the order given // else take all if (!$attributes) { $attr_array = array(); for ($ii = 0; $ii < $entries[0]["count"]; $ii++) { $data = $entries[0][$ii]; $attr_array[] = $data; } } for ($i = 0; $i < count($attr_array); $i++) { $attrcols[$i] = 0; } // Work out how many columns we need for each attribute. objectclass has more for ($i = 0; $i < $entries[0]["count"]; $i++) { $data = $entries[0][$i]; $datalen = $entries[0][$data]["count"]; if ($attrcols[$i] < $datalen) { $attrcols[$i] = $datalen; } } // Print the headers $row = HTML::tr(); for ($i = 0; $i < count($attr_array); $i++) { // span subcolumns, like objectclass if ($attrcols[$i] > 1) { $row->pushContent(HTML::th(array('colspan' => $attrcols[$i]), $attr_array[$i])); } else { $row->pushContent(HTML::th(array(), $attr_array[$i])); } } $html->pushContent($row); // Print the data rows for ($currow = 0; $currow < $entries["count"]; $currow++) { $row = HTML::tr(); $nc = 0; // columns for ($i = 0; $i < count($attr_array); $i++) { $colname = $attr_array[$i]; $data = @$entries[$currow][$colname]; if ($data and $data["count"] > 0) { // subcolumns, e.g. for objectclass for ($iii = 0; $iii < $data["count"]; $iii++) { $row->pushContent(HTML::td($data[$iii])); $nc++; } } else { $row->pushContent(HTML::td("")); $nc++; } // Make up some blank cells if required to pad this row /*for ( $j=0 ; $j < ($attrcols[$ii] - $nc); $j++ ) { $row->pushContent(HTML::td("")); }*/ } $html->pushContent($row); } return HTML::table(array('cellpadding' => 1, 'cellspacing' => 1, 'border' => 1), $html); }
function IniConfig($file) { // check config/config.php dump for faster startup $dump = substr($file, 0, -3) . "php"; if (isWindows($dump)) { $dump = str_replace("/", "\\", $dump); } if (file_exists($dump) and is_readable($dump) and sort_file_mtime($dump, $file) < 0) { @(include $dump); if (function_exists('wiki_configrestore') and wiki_configrestore() === 'noerr') { fixup_dynamic_configs(); return; } } // First-time installer detection here... // Similar to SetupWiki() if (!file_exists($file)) { // We need to DATA_PATH for configurator, or pass the posted values // somewhow to the script include_once dirname(__FILE__) . "/install.php"; run_install("_part1"); if (!defined("_PHPWIKI_INSTALL_RUNNING")) { trigger_error("Datasource file '{$file}' does not exist", E_USER_ERROR); } exit; } // List of all valid config options to be define()d which take "values" (not // booleans). Needs to be categorised, and generally made a lot tidier. $_IC_VALID_VALUE = array('WIKI_NAME', 'ADMIN_USER', 'ADMIN_PASSWD', 'DEFAULT_DUMP_DIR', 'HTML_DUMP_DIR', 'HTML_DUMP_SUFFIX', 'MAX_UPLOAD_SIZE', 'MINOR_EDIT_TIMEOUT', 'ACCESS_LOG', 'CACHE_CONTROL', 'CACHE_CONTROL_MAX_AGE', 'COOKIE_EXPIRATION_DAYS', 'COOKIE_DOMAIN', 'PASSWORD_LENGTH_MINIMUM', 'USER_AUTH_POLICY', 'GROUP_METHOD', 'EDITING_POLICY', 'THEME', 'CHARSET', 'WIKI_PGSRC', 'DEFAULT_WIKI_PGSRC', 'ALLOWED_PROTOCOLS', 'INLINE_IMAGES', 'SUBPAGE_SEPARATOR', 'DATABASE_OPTIMISE_FREQUENCY', 'INTERWIKI_MAP_FILE', 'COPYRIGHTPAGE_TITLE', 'COPYRIGHTPAGE_URL', 'AUTHORPAGE_TITLE', 'AUTHORPAGE_URL', 'WIKI_NAME_REGEXP', 'PLUGIN_CACHED_DATABASE', 'PLUGIN_CACHED_FILENAME_PREFIX', 'PLUGIN_CACHED_HIGHWATER', 'PLUGIN_CACHED_LOWWATER', 'PLUGIN_CACHED_MAXLIFETIME', 'PLUGIN_CACHED_MAXARGLEN', 'PLUGIN_CACHED_IMGTYPES', 'SERVER_NAME', 'SERVER_PORT', 'SCRIPT_NAME', 'DATA_PATH', 'PHPWIKI_DIR', 'VIRTUAL_PATH'); // Optional values which need to be defined. // These are not defined in config-default.ini and empty if not defined. $_IC_OPTIONAL_VALUE = array('DEBUG', 'TEMP_DIR', 'DEFAULT_LANGUAGE', 'LDAP_AUTH_HOST', 'LDAP_SET_OPTION', 'LDAP_BASE_DN', 'LDAP_AUTH_USER', 'LDAP_AUTH_PASSWORD', 'LDAP_SEARCH_FIELD', 'LDAP_OU_GROUP', 'LDAP_OU_USERS', 'AUTH_USER_FILE', 'DBAUTH_AUTH_DSN', 'IMAP_AUTH_HOST', 'POP3_AUTH_HOST', 'AUTH_USER_FILE', 'AUTH_GROUP_FILE', 'AUTH_SESS_USER', 'AUTH_SESS_LEVEL', 'GOOGLE_LICENSE_KEY', 'FORTUNE_DIR', 'DISABLE_GETIMAGESIZE', 'DBADMIN_USER', 'DBADMIN_PASSWD', 'SESSION_SAVE_PATH', 'TOOLBAR_PAGELINK_PULLDOWN', 'TOOLBAR_TEMPLATE_PULLDOWN', 'EXTERNAL_LINK_TARGET', 'ACCESS_LOG_SQL', 'ENABLE_MARKUP_TEMPLATE'); // List of all valid config options to be define()d which take booleans. $_IC_VALID_BOOL = array('ENABLE_USER_NEW', 'ENABLE_PAGEPERM', 'ENABLE_EDIT_TOOLBAR', 'JS_SEARCHREPLACE', 'ENABLE_XHTML_XML', 'ENABLE_DOUBLECLICKEDIT', 'ENABLE_LIVESEARCH', 'USECACHE', 'WIKIDB_NOCACHE_MARKUP', 'ENABLE_REVERSE_DNS', 'ENCRYPTED_PASSWD', 'ZIPDUMP_AUTH', 'ENABLE_RAW_HTML', 'ENABLE_RAW_HTML_LOCKEDONLY', 'ENABLE_RAW_HTML_SAFE', 'STRICT_MAILABLE_PAGEDUMPS', 'COMPRESS_OUTPUT', 'ALLOW_ANON_USER', 'ALLOW_ANON_EDIT', 'ALLOW_BOGO_LOGIN', 'ALLOW_USER_PASSWORDS', 'AUTH_USER_FILE_STORABLE', 'ALLOW_HTTP_AUTH_LOGIN', 'ALLOW_USER_LOGIN', 'ALLOW_LDAP_LOGIN', 'ALLOW_IMAP_LOGIN', 'WARN_NONPUBLIC_INTERWIKIMAP', 'USE_PATH_INFO', 'DISABLE_HTTP_REDIRECT', 'PLUGIN_CACHED_USECACHE', 'PLUGIN_CACHED_FORCE_SYNCMAP', 'BLOG_EMPTY_DEFAULT_PREFIX', 'DATABASE_PERSISTENT', 'ENABLE_DISCUSSION_LINK', 'ENABLE_CAPTCHA', 'USE_CAPTCHA_RANDOM_WORD'); $rs = @parse_ini_file($file); $rsdef = @parse_ini_file(dirname(__FILE__) . "/../config/config-default.ini"); foreach ($rsdef as $k => $v) { if (defined($k)) { $rs[$k] = constant($k); } elseif (!isset($rs[$k])) { $rs[$k] = $v; } } unset($k); unset($v); foreach ($_IC_VALID_VALUE as $item) { if (defined($item)) { unset($rs[$item]); continue; } if (array_key_exists($item, $rs)) { define($item, $rs[$item]); unset($rs[$item]); //} elseif (array_key_exists($item, $rsdef)) { // define($item, $rsdef[$item]); // calculate them later or not at all: } elseif (in_array($item, array('DATABASE_PREFIX', 'SERVER_NAME', 'SERVER_PORT', 'SCRIPT_NAME', 'DATA_PATH', 'PHPWIKI_DIR', 'VIRTUAL_PATH', 'LDAP_AUTH_HOST', 'IMAP_AUTH_HOST', 'POP3_AUTH_HOST', 'PLUGIN_CACHED_CACHE_DIR'))) { } elseif (!defined("_PHPWIKI_INSTALL_RUNNING")) { trigger_error(sprintf("missing config setting for %s", $item)); } } unset($item); // Boolean options are slightly special - if they're set to any of // '', 'false', '0', or 'no' (all case-insensitive) then the value will // be a boolean false, otherwise if there is anything set it'll // be true. foreach ($_IC_VALID_BOOL as $item) { if (defined($item)) { unset($rs[$item]); continue; } if (array_key_exists($item, $rs)) { $val = $rs[$item]; //} elseif (array_key_exists($item, $rsdef)) { // $val = $rsdef[$item]; } else { $val = false; //trigger_error(sprintf("missing boolean config setting for %s",$item)); } // calculate them later: old or dynamic constants if (!array_key_exists($item, $rs) and in_array($item, array('USE_PATH_INFO', 'USE_DB_SESSION', 'ALLOW_HTTP_AUTH_LOGIN', 'ALLOW_LDAP_LOGIN', 'ALLOW_IMAP_LOGIN', 'ALLOW_USER_LOGIN', 'REQUIRE_SIGNIN_BEFORE_EDIT', 'WIKIDB_NOCACHE_MARKUP', 'COMPRESS_OUTPUT'))) { } elseif (!$val) { define($item, false); } elseif (strtolower($val) == 'false' || strtolower($val) == 'no' || $val == '' || $val == false || $val == '0') { define($item, false); } else { define($item, true); } unset($rs[$item]); } unset($item); // Database global $DBParams; foreach (array('DATABASE_TYPE' => 'dbtype', 'DATABASE_DSN' => 'dsn', 'DATABASE_SESSION_TABLE' => 'db_session_table', 'DATABASE_DBA_HANDLER' => 'dba_handler', 'DATABASE_DIRECTORY' => 'directory', 'DATABASE_TIMEOUT' => 'timeout', 'DATABASE_PREFIX' => 'prefix') as $item => $k) { if (defined($item)) { $DBParams[$k] = constant($item); unset($rs[$item]); } elseif (array_key_exists($item, $rs)) { $DBParams[$k] = $rs[$item]; define($item, $rs[$item]); unset($rs[$item]); } elseif (array_key_exists($item, $rsdef)) { $DBParams[$k] = $rsdef[$item]; define($item, $rsdef[$item]); unset($rsdef[$item]); } } if (!in_array(DATABASE_TYPE, array('SQL', 'ADODB', 'PDO', 'dba', 'file', 'cvs'))) { trigger_error(sprintf("Invalid DATABASE_TYPE=%s. Choose one of %s", DATABASE_TYPE, "SQL,ADODB,PDO,dba,file,cvs"), E_USER_ERROR); } if (DATABASE_TYPE == 'PDO') { if (!check_php_version(5)) { trigger_error("Invalid DATABASE_TYPE=PDO. PDO requires at least php-5.0!", E_USER_ERROR); } // try to load it dynamically (unix only) if (!loadPhpExtension("pdo")) { echo $GLOBALS['php_errormsg'], "<br>\n"; trigger_error(sprintf("dl() problem: Required extension '%s' could not be loaded!", "pdo"), E_USER_ERROR); } } // USE_DB_SESSION default logic: if (!defined('USE_DB_SESSION')) { if ($DBParams['db_session_table'] and in_array($DBParams['dbtype'], array('SQL', 'ADODB', 'PDO'))) { define('USE_DB_SESSION', true); } elseif ($DBParams['dbtype'] == 'dba' and check_php_version(4, 1, 2)) { define('USE_DB_SESSION', true); // Depends on db handler as well. // BerkeleyDB on older php has problems // with multiple db handles. } else { define('USE_DB_SESSION', false); } } unset($item); unset($k); // Expiry stuff global $ExpireParams; foreach (array('major', 'minor', 'author') as $major) { foreach (array('max_age', 'min_age', 'min_keep', 'keep', 'max_keep') as $max) { $item = strtoupper($major) . '_' . strtoupper($max); if (defined($item)) { $val = constant($item); } elseif (array_key_exists($item, $rs)) { $val = $rs[$item]; } elseif (array_key_exists($item, $rsdef)) { $val = $rsdef[$item]; } if (!isset($ExpireParams[$major])) { $ExpireParams[$major] = array(); } $ExpireParams[$major][$max] = $val; unset($rs[$item]); } } unset($item); unset($major); unset($max); // User authentication if (!isset($GLOBALS['USER_AUTH_ORDER'])) { if (isset($rs['USER_AUTH_ORDER'])) { $GLOBALS['USER_AUTH_ORDER'] = preg_split('/\\s*:\\s*/', $rs['USER_AUTH_ORDER']); } else { $GLOBALS['USER_AUTH_ORDER'] = array("PersonalPage"); } } // Now it's the external DB authentication stuff's turn if (in_array('Db', $GLOBALS['USER_AUTH_ORDER']) && empty($rs['DBAUTH_AUTH_DSN'])) { $rs['DBAUTH_AUTH_DSN'] = $DBParams['dsn']; } global $DBAuthParams; $DBAP_MAP = array('DBAUTH_AUTH_DSN' => 'auth_dsn', 'DBAUTH_AUTH_CHECK' => 'auth_check', 'DBAUTH_AUTH_USER_EXISTS' => 'auth_user_exists', 'DBAUTH_AUTH_CRYPT_METHOD' => 'auth_crypt_method', 'DBAUTH_AUTH_UPDATE' => 'auth_update', 'DBAUTH_AUTH_CREATE' => 'auth_create', 'DBAUTH_PREF_SELECT' => 'pref_select', 'DBAUTH_PREF_INSERT' => 'pref_insert', 'DBAUTH_PREF_UPDATE' => 'pref_update', 'DBAUTH_IS_MEMBER' => 'is_member', 'DBAUTH_GROUP_MEMBERS' => 'group_members', 'DBAUTH_USER_GROUPS' => 'user_groups'); foreach ($DBAP_MAP as $rskey => $apkey) { if (defined($rskey)) { $DBAuthParams[$apkey] = constant($rskey); } elseif (isset($rs[$rskey])) { $DBAuthParams[$apkey] = $rs[$rskey]; define($rskey, $rs[$rskey]); } elseif (isset($rsdef[$rskey])) { $DBAuthParams[$apkey] = $rsdef[$rskey]; define($rskey, $rsdef[$rskey]); } unset($rs[$rskey]); } unset($rskey); unset($apkey); // TODO: Currently unsupported on non-SQL // CHECKME: PDO if (!defined('ACCESS_LOG_SQL')) { if (array_key_exists('ACCESS_LOG_SQL', $rs)) { // WikiDB_backend::isSql() not yet loaded if (!in_array(DATABASE_TYPE, array('SQL', 'ADODB', 'PDO'))) { // override false config setting on no SQL WikiDB database. define('ACCESS_LOG_SQL', 0); } } else { define('ACCESS_LOG_SQL', in_array(DATABASE_TYPE, array('SQL', 'ADODB', 'PDO')) ? 2 : 0); } } // optional values will be set to '' to simplify the logic. foreach ($_IC_OPTIONAL_VALUE as $item) { if (defined($item)) { unset($rs[$item]); continue; } if (array_key_exists($item, $rs)) { define($item, $rs[$item]); unset($rs[$item]); } else { define($item, ''); } } unset($item); // LDAP bind options global $LDAP_SET_OPTION; if (defined('LDAP_SET_OPTION') and LDAP_SET_OPTION) { $optlist = preg_split('/\\s*:\\s*/', LDAP_SET_OPTION); foreach ($optlist as $opt) { $bits = preg_split('/\\s*=\\s*/', $opt, 2); if (count($bits) == 2) { if (is_string($bits[0]) and defined($bits[0])) { $bits[0] = constant($bits[0]); } $LDAP_SET_OPTION[$bits[0]] = $bits[1]; } else { // Possibly throw some sort of error? } } unset($opt); unset($bits); } // Default Wiki pages to force loading from pgsrc global $GenericPages; $GenericPages = preg_split('/\\s*:\\s*/', @$rs['DEFAULT_WIKI_PAGES']); // Wiki name regexp: Should be a define(), but might needed to be changed at runtime // (different LC_CHAR need different posix classes) global $WikiNameRegexp; $WikiNameRegexp = constant('WIKI_NAME_REGEXP'); if (!trim($WikiNameRegexp)) { $WikiNameRegexp = '(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])'; } // Got rid of global $KeywordLinkRegexp by using a TextSearchQuery instead // of "Category:Topic" if (!isset($rs['KEYWORDS'])) { $rs['KEYWORDS'] = @$rsdef['KEYWORDS']; } if (!isset($rs['KEYWORDS'])) { $rs['KEYWORDS'] = "Category* OR Topic*"; } if ($rs['KEYWORDS'] == 'Category:Topic') { $rs['KEYWORDS'] = "Category* OR Topic*"; } if (!defined('KEYWORDS')) { define('KEYWORDS', $rs['KEYWORDS']); } //if (empty($keywords)) $keywords = array("Category","Topic"); //$KeywordLinkRegexp = '(?<=' . implode('|^', $keywords) . ')[[:upper:]].*$'; // TODO: can this be a constant? global $DisabledActions; if (!array_key_exists('DISABLED_ACTIONS', $rs) and array_key_exists('DISABLED_ACTIONS', $rsdef)) { $rs['DISABLED_ACTIONS'] = @$rsdef['DISABLED_ACTIONS']; } if (array_key_exists('DISABLED_ACTIONS', $rs)) { $DisabledActions = preg_split('/\\s*:\\s*/', $rs['DISABLED_ACTIONS']); } global $PLUGIN_CACHED_IMGTYPES; $PLUGIN_CACHED_IMGTYPES = preg_split('/\\s*[|:]\\s*/', PLUGIN_CACHED_IMGTYPES); if (empty($rs['PLUGIN_CACHED_CACHE_DIR']) and !empty($rsdef['PLUGIN_CACHED_CACHE_DIR'])) { $rs['PLUGIN_CACHED_CACHE_DIR'] = $rsdef['PLUGIN_CACHED_CACHE_DIR']; } if (empty($rs['PLUGIN_CACHED_CACHE_DIR'])) { if (!empty($rs['INCLUDE_PATH'])) { @ini_set('include_path', $rs['INCLUDE_PATH']); } if (empty($rs['TEMP_DIR'])) { $rs['TEMP_DIR'] = "/tmp"; if (getenv("TEMP")) { $rs['TEMP_DIR'] = getenv("TEMP"); } } $rs['PLUGIN_CACHED_CACHE_DIR'] = $rs['TEMP_DIR'] . '/cache'; if (!FindFile($rs['PLUGIN_CACHED_CACHE_DIR'], 1)) { // [29ms] FindFile($rs['TEMP_DIR'], false, 1); // TEMP must exist! mkdir($rs['PLUGIN_CACHED_CACHE_DIR'], 777); } // will throw an error if not exists. define('PLUGIN_CACHED_CACHE_DIR', FindFile($rs['PLUGIN_CACHED_CACHE_DIR'], false, 1)); } else { define('PLUGIN_CACHED_CACHE_DIR', $rs['PLUGIN_CACHED_CACHE_DIR']); // will throw an error if not exists. FindFile(PLUGIN_CACHED_CACHE_DIR); } // process the rest of the config.ini settings: foreach ($rs as $item => $v) { if (defined($item)) { continue; } else { define($item, $v); } } unset($item); unset($v); unset($rs); unset($rsdef); fixup_static_configs($file); //[1ms] // Dump all globals and constants // The question is if reading this is faster then doing IniConfig() + fixup_static_configs() if (is_writable($dump)) { save_dump($dump); } // store locale[] in config.php? This is too problematic. fixup_dynamic_configs($file); // [100ms] }
function displayPage(&$request, $template = false) { global $WikiTheme; global $robots; $pagename = $request->getArg('pagename'); $version = $request->getArg('version'); $page = $request->getPage(); if ($version) { $revision = $page->getRevision($version); if (!$revision) { NoSuchRevision($request, $page, $version); } /* Tell Google (and others) to ignore old versions of pages */ $robots = "noindex,nofollow"; $toks['ROBOTS_META'] = $robots; } else { $revision = $page->getCurrentRevision(); } $format = $request->getArg('format'); if ($format == 'xml') { // fast ajax: include page content asynchronously global $charset; header("Content-Type: text/xml"); echo "<", "?xml version=\"1.0\" encoding=\"{$charset}\"?", ">\n"; // DOCTYPE html needed to allow unencoded entities like without !CDATA[] echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', "\n"; if ($page->exists()) { header("Last-Modified: " . Rfc1123DateTime($revision->get('mtime'))); $request->cacheControl(); $request->setArg('format', ''); $page_content = $revision->getTransformedContent(); $page_content->printXML(); $request->_is_buffering_output = false; // avoid wrong Content-Length with errors $request->finish(); } else { $request->cacheControl(); echo '<div style="display:none;" />'; $request->_is_buffering_output = false; // avoid wrong Content-Length with errors $request->finish(); exit; } } if (isSubPage($pagename)) { $pages = explode(SUBPAGE_SEPARATOR, $pagename); $last_page = array_pop($pages); // deletes last element from array as side-effect $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]), 'class' => 'pagetitle'), $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR))); $first_pages = $pages[0] . SUBPAGE_SEPARATOR; array_shift($pages); foreach ($pages as $p) { $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR))); $first_pages .= $p . SUBPAGE_SEPARATOR; } $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page)); $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); $pageheader->pushContent($backlink); } else { $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename)); $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); if ($request->getArg('frame')) { $pageheader->setAttr('target', '_top'); } } $pagetitle = SplitPagename($pagename); if ($redirect_from = $request->getArg('redirectfrom')) { $redirect_message = HTML::span(array('class' => 'redirectfrom'), fmt("(Redirected from %s)", RedirectorLink($redirect_from))); // abuse the $redirected template var for some status update notice } elseif ($request->getArg('errormsg')) { $redirect_message = $request->getArg('errormsg'); $request->setArg('errormsg', false); } $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime'))); /* // FIXME: This is also in the template... if ($request->getArg('action') != 'pdf' and !headers_sent()) { // FIXME: enable MathML/SVG/... support if (ENABLE_XHTML_XML and (!isBrowserIE() and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml'))) header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']); else header("Content-Type: text/html; charset=" . $GLOBALS['charset']); } */ $toks['TITLE'] = $pagetitle; // <title> tag $toks['HEADER'] = $pageheader; // h1 with backlink $toks['revision'] = $revision; // On external searchengine (google) referrer, highlight the searchterm and // pass through the Searchhighlight actionpage. if ($result = isExternalReferrer($request)) { if (!empty($result['query'])) { if (ENABLE_SEARCHHIGHLIGHT) { $request->_searchhighlight = $result; $request->appendValidators(array('%mtime' => time())); // force no cache(?) // Should be changed to check the engine and search term only // $request->setArg('nocache', 1); $page_content = new TransformedText($revision->getPage(), $revision->getPackedContent(), $revision->getMetaData()); /* Now add the SearchHighlight plugin to the top of the page, in memory only. You can parametrize this by changing the SearchHighlight action page. */ if ($actionpage = $request->findActionPage('SearchHighlight')) { $actionpage = $request->getPage($actionpage); $actionrev = $actionpage->getCurrentRevision(); $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(), $WikiTheme->linkExistingWikiWord($pagename, false, $version))); $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(), '%mtime' => $actionrev->get('mtime'))); $toks['SEARCH_ENGINE'] = $result['engine']; $toks['SEARCH_ENGINE_URL'] = $result['engine_url']; $toks['SEARCH_TERM'] = $result['query']; //$toks['HEADER'] = HTML($actionpage->getName(),": ",$pageheader); // h1 with backlink $actioncontent = new TransformedText($actionrev->getPage(), $actionrev->getPackedContent(), $actionrev->getMetaData()); // prepend the actionpage in front of the hightlighted content $toks['CONTENT'] = HTML($actioncontent, $page_content); } } } else { $page_content = $revision->getTransformedContent(); } } else { $page_content = $revision->getTransformedContent(); } /* Check for special pagenames, which are no actionpages. */ /* if ( $pagename == _("RecentVisitors")) { $robots = "noindex,follow"; $toks['ROBOTS_META'] = $robots; } else */ if ($pagename == _("SandBox")) { $robots = "noindex,nofollow"; $toks['ROBOTS_META'] = $robots; } else { if (isActionPage($pagename)) { // AllPages must not be indexed, but must be followed to get all pages $robots = "noindex,follow"; $toks['ROBOTS_META'] = $robots; } else { if (!isset($toks['ROBOTS_META'])) { $robots = "index,follow"; $toks['ROBOTS_META'] = $robots; } } } if (!isset($toks['CONTENT'])) { $toks['CONTENT'] = new Template('browse', $request, $page_content); } if (!empty($redirect_message)) { $toks['redirected'] = $redirect_message; } // Massive performance problem parsing at run-time into all xml objects // looking for p's. Should be optional, if not removed at all. //$toks['PAGE_DESCRIPTION'] = $page_content->getDescription(); $toks['PAGE_KEYWORDS'] = GleanKeywords($page); if (!$template) { $template = new Template('html', $request); } // Handle other formats: So far we had html only. // xml is requested by loaddump, rss is handled by RecentChanges, // pdf is a special action, but should be a format to dump multiple pages // if the actionpage plugin returns a pagelist. // rdf, owl, kbmodel, daml, ... are handled by SemanticWeb. /* Only single page versions. rss only if not already handled by RecentChanges. */ if (!$format or $format == 'html' or $format == 'sidebar' or $format == 'contribs') { $template->printExpansion($toks); } else { // No pagelist here. Single page version only require_once "lib/PageList.php"; $pagelist = new PageList(); $pagelist->addPage($page); if ($format == 'pdf') { require_once "lib/pdf.php"; $request->setArg('format', ''); ConvertAndDisplayPdfPageList($request, $pagelist); // time-sorted rdf a la RecentChanges } elseif (in_array($format, array("rss91", "rss2", "rss", "atom"))) { //$request->setArg('format',''); if ($pagename == _("RecentChanges")) { $template->printExpansion($toks); } else { require_once "lib/plugin/RecentChanges.php"; $plugin = new WikiPlugin_RecentChanges(); $args = $request->getArgs(); return $plugin->format($plugin->getChanges($request->_dbi, $args), $args); } } elseif ($format == 'rdf') { // all semantic relations and attributes require_once "lib/SemanticWeb.php"; $rdf = new RdfWriter($request, $pagelist); $rdf->format(); } elseif ($format == 'owl') { // or daml? require_once "lib/SemanticWeb.php"; $rdf = new OwlWriter($request, $pagelist); $rdf->format(); } elseif ($format == 'json') { // include page content asynchronously $request->setArg('format', ''); if ($page->exists()) { $content = $page_content->asXML(); } else { $content = ''; } $req_args = $request->args; unset($req_args['format']); // no meta-data so far, just the content $json = array('content' => $content, 'args' => $req_args, 'phpwiki-version' => PHPWIKI_VERSION); if (loadPhpExtension('json')) { $json_enc = json_encode($json); } else { require_once "lib/pear/JSON.php"; $j = new Services_JSON(); $json_enc = $j->encode($json); } header("Content-Type: application/json"); die($json_enc); } else { if (!in_array($pagename, array(_("LinkDatabase")))) { trigger_error(sprintf(_("Unsupported argument: %s=%s"), "format", $format), E_USER_WARNING); } $template->printExpansion($toks); } } $page->increaseHitCount(); if ($request->getArg('action') != 'pdf') { $request->checkValidators(); flush(); } return ''; }
break; } $width = @imagesx($img); $height = @imagesy($img); $newwidth = $_REQUEST['width']; if (empty($newidth)) { $newidth = 50; } $newheight = $_REQUEST['height']; if (empty($newheight)) { $newheight = round($newwidth * ($height / $width)); } // php-4.2.x is stupid enough to define on gd only a stub for imagecopyresampled. // So function_exists('imagecopyresampled') will fail. if (!extension_loaded('gd2') and substr(PHP_OS, 0, 3) != 'WIN') { loadPhpExtension('gd2'); } if (extension_loaded('gd2')) { $thumb = imagecreatetruecolor($newwidth, $newheight); $img = imagecopyresampled($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } else { $thumb = imagecreate($newwidth, $newheight); $img = imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } if ($remove == 1) { unlink($file); } header("Content-type: image/png"); imagepng($thumb); function show_plain() {