function WikiDB_backend_PearDB($dbparams) { // Find and include PEAR's DB.php. maybe we should force our private version again... // if DB would have exported its version number, it would be easier. @(require_once 'DB/common.php'); // Either our local pear copy or the system one // check the version! $name = check_php_version(5) ? "escapeSimple" : strtolower("escapeSimple"); // TODO: apparently some Pear::Db version adds LIMIT 1,0 to getOne(), // which is invalid for "select version()" if (!in_array($name, get_class_methods("DB_common"))) { $finder = new FileFinder(); $dir = dirname(__FILE__) . "/../../pear"; $finder->_prepend_to_include_path($dir); include_once "{$dir}/DB/common.php"; // use our version instead. if (!in_array($name, get_class_methods("DB_common"))) { $pearFinder = new PearFileFinder("lib/pear"); $pearFinder->includeOnce('DB.php'); } else { include_once "{$dir}/DB.php"; } } else { include_once "DB.php"; } // Install filter to handle bogus error notices from buggy DB.php's. // TODO: check the Pear_DB version, but how? if (DEBUG) { global $ErrorManager; $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_pear_notice_filter')); $this->_pearerrhandler = true; } // Open connection to database $this->_dsn = $dbparams['dsn']; $this->_dbparams = $dbparams; $this->_lock_count = 0; // persistent is usually a DSN option: we override it with a config value. // phptype://username:password@hostspec/database?persistent=false $dboptions = array('persistent' => DATABASE_PERSISTENT, 'debug' => 2); //if (preg_match('/^pgsql/', $this->_dsn)) $dboptions['persistent'] = false; $this->_dbh = DB::connect($this->_dsn, $dboptions); $dbh =& $this->_dbh; if (DB::isError($dbh)) { trigger_error(sprintf("Can't connect to database: %s", $this->_pear_error_message($dbh)), isset($dbparams['_tryroot_from_upgrade']) ? E_USER_WARNING : E_USER_ERROR); if (isset($dbparams['_tryroot_from_upgrade'])) { return; } } $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, array($this, '_pear_error_callback')); $dbh->setFetchMode(DB_FETCHMODE_ASSOC); $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 AS 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->_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' => "content<>''"); }
/** * Creates one static PEAR Cache object and returns copies afterwards. * FIXME: There should be references returned * * @access static protected * @return Cache copy of the cache object */ function newCache() { static $staticcache; if (!is_object($staticcache)) { if (!class_exists('Cache')) { // uuh, pear not in include_path! should print a warning. // search some possible pear paths. $pearFinder = new PearFileFinder(); if ($lib = $pearFinder->findFile('Cache.php', 'missing_ok')) { require_once $lib; } else { // fall back to our own copy require_once 'lib/pear/Cache.php'; } } $cacheparams = array(); foreach (explode(':', 'database:cache_dir:filename_prefix:highwater:lowwater' . ':maxlifetime:maxarglen:usecache:force_syncmap') as $key) { $cacheparams[$key] = constant('PLUGIN_CACHED_' . strtoupper($key)); } $cacheparams['imgtypes'] = preg_split('/\\s*:\\s*/', PLUGIN_CACHED_IMGTYPES); $staticcache = new Cache(PLUGIN_CACHED_DATABASE, $cacheparams); $staticcache->gc_maxlifetime = PLUGIN_CACHED_MAXLIFETIME; if (!PLUGIN_CACHED_USECACHE) { $staticcache->setCaching(false); } } return $staticcache; // FIXME: use references ? }