?? peardb.php
字號:
$order = "hits DESC"; $where = " AND hits > 0"; } $orderby = ''; if ($sortby != '-hits') { if ($order = $this->sortby($sortby, 'db')) $orderby = " ORDER BY " . $order; } else { $orderby = " ORDER BY $order"; } //$limitclause = $limit ? " LIMIT $limit" : ''; $sql = "SELECT " . $this->page_tbl_fields . " FROM $nonempty_tbl, $page_tbl" . " WHERE $nonempty_tbl.id=$page_tbl.id" . $where . $orderby; if ($limit) { list($from, $count) = $this->limit($limit); $result = $dbh->limitQuery($sql, $from, $count); } else { $result = $dbh->query($sql); } return new WikiDB_backend_PearDB_iter($this, $result); } /** * Find recent changes. */ function most_recent($params) { $limit = 0; $since = 0; $include_minor_revisions = false; $exclude_major_revisions = false; $include_all_revisions = false; extract($params); $dbh = &$this->_dbh; extract($this->_table_names); $pick = array(); if ($since) $pick[] = "mtime >= $since"; if ($include_all_revisions) { // Include all revisions of each page. $table = "$page_tbl, $version_tbl"; $join_clause = "$page_tbl.id=$version_tbl.id"; if ($exclude_major_revisions) { // Include only minor revisions $pick[] = "minor_edit <> 0"; } elseif (!$include_minor_revisions) { // Include only major revisions $pick[] = "minor_edit = 0"; } } else { $table = "$page_tbl, $recent_tbl"; $join_clause = "$page_tbl.id=$recent_tbl.id"; $table .= ", $version_tbl"; $join_clause .= " AND $version_tbl.id=$page_tbl.id"; if ($exclude_major_revisions) { // Include only most recent minor revision $pick[] = 'version=latestminor'; } elseif (!$include_minor_revisions) { // Include only most recent major revision $pick[] = 'version=latestmajor'; } else { // Include only the latest revision (whether major or minor). $pick[] ='version=latestversion'; } } $order = "DESC"; if($limit < 0){ $order = "ASC"; $limit = -$limit; } // $limitclause = $limit ? " LIMIT $limit" : ''; $where_clause = $join_clause; if ($pick) $where_clause .= " AND " . join(" AND ", $pick); // FIXME: use SQL_BUFFER_RESULT for mysql? $sql = "SELECT " . $this->page_tbl_fields . ", " . $this->version_tbl_fields . " FROM $table" . " WHERE $where_clause" . " ORDER BY mtime $order"; if ($limit) { list($from, $count) = $this->limit($limit); $result = $dbh->limitQuery($sql, $from, $count); } else { $result = $dbh->query($sql); } return new WikiDB_backend_PearDB_iter($this, $result); } /** * Find referenced empty pages. */ function wanted_pages($exclude_from='', $exclude='', $sortby=false, $limit=false) { $dbh = &$this->_dbh; extract($this->_table_names); if ($orderby = $this->sortby($sortby, 'db', array('pagename','wantedfrom'))) $orderby = 'ORDER BY ' . $orderby; if ($exclude_from) // array of pagenames $exclude_from = " AND linked.pagename NOT IN ".$this->_sql_set($exclude_from); if ($exclude) // array of pagenames $exclude = " AND $page_tbl.pagename NOT IN ".$this->_sql_set($exclude); $sql = "SELECT $page_tbl.pagename,linked.pagename as wantedfrom" . " FROM $link_tbl,$page_tbl as linked " . " LEFT JOIN $page_tbl ON($link_tbl.linkto=$page_tbl.id)" . " LEFT JOIN $nonempty_tbl ON($link_tbl.linkto=$nonempty_tbl.id)" . " WHERE ISNULL($nonempty_tbl.id) AND linked.id=$link_tbl.linkfrom" . $exclude_from . $exclude . $orderby; if ($limit) { list($from, $count) = $this->limit($limit); $result = $dbh->limitQuery($sql, $from, $count * 3); } else { $result = $dbh->query($sql); } return new WikiDB_backend_PearDB_generic_iter($this, $result); } function _sql_set(&$pagenames) { $s = '('; foreach ($pagenames as $p) { $s .= ("'".$this->_dbh->escapeSimple($p)."',"); } return substr($s,0,-1).")"; } /** * Rename page in the database. */ function rename_page($pagename, $to) { $dbh = &$this->_dbh; extract($this->_table_names); $this->lock(); if (($id = $this->_get_pageid($pagename, false)) ) { if ($new = $this->_get_pageid($to, false)) { // Cludge Alert! // This page does not exist (already verified before), but exists in the page table. // So we delete this page. $dbh->query("DELETE FROM $page_tbl WHERE id=$new"); $dbh->query("DELETE FROM $version_tbl WHERE id=$new"); $dbh->query("DELETE FROM $recent_tbl WHERE id=$new"); $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$new"); // We have to fix all referring tables to the old id $dbh->query("UPDATE $link_tbl SET linkfrom=$id WHERE linkfrom=$new"); $dbh->query("UPDATE $link_tbl SET linkto=$id WHERE linkto=$new"); } $dbh->query(sprintf("UPDATE $page_tbl SET pagename='%s' WHERE id=$id", $dbh->escapeSimple($to))); } $this->unlock(); return $id; } function _update_recent_table($pageid = false) { $dbh = &$this->_dbh; extract($this->_table_names); extract($this->_expressions); $pageid = (int)$pageid; $this->lock(); $dbh->query("DELETE FROM $recent_tbl" . ( $pageid ? " WHERE id=$pageid" : "")); $dbh->query( "INSERT INTO $recent_tbl" . " (id, latestversion, latestmajor, latestminor)" . " SELECT id, $maxversion, $maxmajor, $maxminor" . " FROM $version_tbl" . ( $pageid ? " WHERE id=$pageid" : "") . " GROUP BY id" ); $this->unlock(); } function _update_nonempty_table($pageid = false) { $dbh = &$this->_dbh; extract($this->_table_names); $pageid = (int)$pageid; extract($this->_expressions); $this->lock(); $dbh->query("DELETE FROM $nonempty_tbl" . ( $pageid ? " WHERE id=$pageid" : "")); $dbh->query("INSERT INTO $nonempty_tbl (id)" . " SELECT $recent_tbl.id" . " FROM $recent_tbl, $version_tbl" . " WHERE $recent_tbl.id=$version_tbl.id" . " AND version=latestversion" // We have some specifics here (Oracle) //. " AND content<>''" . " AND content $notempty" . ( $pageid ? " AND $recent_tbl.id=$pageid" : "")); $this->unlock(); } /** * Grab a write lock on the tables in the SQL database. * * Calls can be nested. The tables won't be unlocked until * _unlock_database() is called as many times as _lock_database(). * * @access protected */ function lock($tables = false, $write_lock = true) { if ($this->_lock_count++ == 0) $this->_lock_tables($write_lock); } /** * Actually lock the required tables. */ function _lock_tables($write_lock) { trigger_error("virtual", E_USER_ERROR); } /** * Release a write lock on the tables in the SQL database. * * @access protected * * @param $force boolean Unlock even if not every call to lock() has been matched * by a call to unlock(). * * @see _lock_database */ function unlock($tables = false, $force = false) { if ($this->_lock_count == 0) return; if (--$this->_lock_count <= 0 || $force) { $this->_unlock_tables(); $this->_lock_count = 0; } } /** * Actually unlock the required tables. */ function _unlock_tables($write_lock) { trigger_error("virtual", E_USER_ERROR); } /** * Serialize data */ function _serialize($data) { if (empty($data)) return ''; assert(is_array($data)); return serialize($data); } /** * Unserialize data */ function _unserialize($data) { return empty($data) ? array() : unserialize($data); } /** * Callback for PEAR (DB) errors. * * @access protected * * @param A PEAR_error object. */ function _pear_error_callback($error) { if ($this->_is_false_error($error)) return; $this->_dbh->setErrorHandling(PEAR_ERROR_PRINT); // prevent recursive loops. $this->close(); trigger_error($this->_pear_error_message($error), E_USER_ERROR); } /** * Detect false errors messages from PEAR DB. * * The version of PEAR DB which ships with PHP 4.0.6 has a bug in that * it doesn't recognize "LOCK" and "UNLOCK" as SQL commands which don't * return any data. (So when a "LOCK" command doesn't return any data, * DB reports it as an error, when in fact, it's not.) * * @access private * @return bool True iff error is not really an error. */ function _is_false_error($error) { if ($error->getCode() != DB_ERROR) return false; $query = $this->_dbh->last_query; if (! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE' . '|DROP|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s/', $query)) { // Last query was not of the sort which doesn't return any data. //" <--kludge for brain-dead syntax coloring return false; } if (! in_array('ismanip', get_class_methods('DB'))) { // Pear shipped with PHP 4.0.4pl1 (and before, presumably) // does not have the DB::isManip method. return true; } if (DB::isManip($query)) { // If Pear thinks it's an isManip then it wouldn't have thrown // the error we're testing for.... return false; } return true; } function _pear_error_message($error) { $class = get_class($this); $message = "$class: fatal database error\n" . "\t" . $error->getMessage() . "\n" . "\t(" . $error->getDebugInfo() . ")\n"; // Prevent password from being exposed during a connection error $safe_dsn = preg_replace('| ( :// .*? ) : .* (?=@) |xs', '\\1:XXXXXXXX', $this->_dsn); return str_replace($this->_dsn, $safe_dsn, $message); } /** * Filter PHP errors notices from PEAR DB code. * * The PEAR DB code which ships with PHP 4.0.6 produces spurious * errors and notices. This is an error callback (for use with * ErrorManager which will filter out those spurious messages.) * @see _is_false_error, ErrorManager * @access private */ function _pear_notice_filter($err) { return ( $err->isNotice() && preg_match('|DB[/\\\\]common.php$|', $err->errfile) && $err->errline == 126 && preg_match('/Undefined offset: +0\b/', $err->errstr) ); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -