From: <var...@us...> - 2021-08-16 08:06:58
|
Revision: 10521 http://sourceforge.net/p/phpwiki/code/10521 Author: vargenau Date: 2021-08-16 08:06:55 +0000 (Mon, 16 Aug 2021) Log Message: ----------- Merge lib/WikiDB/backend/PearDB.php lib/WikiDB/backend/ADODB.php lib/WikiDB/backend/PDO.php Modified Paths: -------------- trunk/lib/WikiDB/backend/ADODB.php trunk/lib/WikiDB/backend/PDO.php trunk/lib/WikiDB/backend/PearDB.php Modified: trunk/lib/WikiDB/backend/ADODB.php =================================================================== --- trunk/lib/WikiDB/backend/ADODB.php 2021-08-14 19:35:00 UTC (rev 10520) +++ trunk/lib/WikiDB/backend/ADODB.php 2021-08-16 08:06:55 UTC (rev 10521) @@ -136,8 +136,9 @@ */ function close() { - if (!$this->_dbh) + if (!$this->_dbh) { return; + } if ($this->_lock_count) { trigger_error("WARNING: database still locked " . '(lock_count = $this->_lock_count)' . "\n<br />", @@ -212,12 +213,13 @@ return $row ? $this->_extract_page_data($row[3], $row[2]) : false; } - public function _extract_page_data($data, $hits) + public function _extract_page_data($data, $hits) { - if (empty($data)) + if (empty($data)) { return array('hits' => $hits); - else + } else { return array_merge(array('hits' => $hits), $this->_unserialize($data)); + } } function update_pagedata($pagename, $newdata) @@ -298,6 +300,7 @@ return $cache[$pagename]; } } + // attributes play this game. if ($pagename === '') return 0; @@ -342,9 +345,9 @@ $dbh = &$this->_dbh; extract($this->_table_names); $row = $dbh->GetRow(sprintf("SELECT latestversion" - . " FROM $page_tbl, $recent_tbl" - . " WHERE $page_tbl.id=$recent_tbl.id" - . " AND pagename=%s", + . " FROM $page_tbl, $recent_tbl" + . " WHERE $page_tbl.id=$recent_tbl.id" + . " AND pagename=%s", $dbh->qstr($pagename))); return $row ? (int)$row[0] : false; } @@ -355,11 +358,11 @@ extract($this->_table_names); // Use SELECTLIMIT for maximum portability $rs = $dbh->SelectLimit(sprintf("SELECT version" - . " FROM $version_tbl, $page_tbl" - . " WHERE $version_tbl.id=$page_tbl.id" - . " AND pagename=%s" - . " AND version < %d" - . " ORDER BY version DESC", + . " FROM $version_tbl, $page_tbl" + . " WHERE $version_tbl.id=$page_tbl.id" + . " AND pagename=%s" + . " AND version < %d" + . " ORDER BY version DESC", $dbh->qstr($pagename), $version), 1); @@ -374,7 +377,6 @@ * @param bool $want_content Do we need content? * * @return array|false The version data, or false if specified version does not exist. - */ function get_versiondata($pagename, $version, $want_content = false) { @@ -387,8 +389,9 @@ // FIXME: optimization: sometimes don't get page data? if ($want_content) { - $fields = $this->page_tbl_fields . ", $page_tbl.pagedata AS pagedata" - . ', ' . $this->version_tbl_fields; + $fields = $this->page_tbl_fields + . ",$page_tbl.pagedata AS pagedata," + . $this->version_tbl_fields; } else { $fields = $this->page_tbl_fields . ", '' AS pagedata" . ", $version_tbl.version AS version, $version_tbl.mtime AS mtime, " @@ -396,10 +399,10 @@ . "$version_tbl.versiondata as versiondata"; } $row = $dbh->GetRow(sprintf("SELECT $fields" - . " FROM $page_tbl, $version_tbl" - . " WHERE $page_tbl.id=$version_tbl.id" - . " AND pagename=%s" - . " AND version=%d", + . " FROM $page_tbl, $version_tbl" + . " WHERE $page_tbl.id=$version_tbl.id" + . " AND pagename=%s" + . " AND version=%d", $dbh->qstr($pagename), $version)); return $row ? $this->_extract_version_data_num($row, $want_content) : false; } @@ -480,8 +483,11 @@ $content, $this->_serialize($data))); $this->_update_recent_table($id); $this->_update_nonempty_table($id); - if ($rs) $dbh->CommitTrans(); - else $dbh->RollbackTrans(); + if ($rs) { + $dbh->CommitTrans(); + } else { + $dbh->RollbackTrans(); + } $this->unlock(array('page', 'recent', 'version', 'nonempty')); } @@ -526,7 +532,7 @@ $dbh->BeginTrans(); $dbh->CommitLock($recent_tbl); - if (($id = $this->_get_pageid($pagename, false)) === false) { + if (($id = $this->_get_pageid($pagename)) === false) { $dbh->RollbackTrans(); return false; } @@ -570,7 +576,7 @@ extract($this->_table_names); $this->lock(array('version', 'recent', 'nonempty', 'page', 'link')); - if (($id = $this->_get_pageid($pagename, false))) { + if (($id = $this->_get_pageid($pagename))) { $dbh->Execute("DELETE FROM $nonempty_tbl WHERE id=$id"); $dbh->Execute("DELETE FROM $recent_tbl WHERE id=$id"); $dbh->Execute("DELETE FROM $version_tbl WHERE id=$id"); @@ -618,13 +624,13 @@ if ($links) { foreach ($links as $link) { $linkto = $link['linkto']; + if ($linkto === "") { // ignore attributes + continue; + } if (isset($link['relation'])) $relation = $this->_get_pageid($link['relation'], true); else $relation = 0; - if ($linkto === "") { // ignore attributes - continue; - } // avoid duplicates if (isset($linkseen[$linkto]) and !$relation) { continue; @@ -746,7 +752,9 @@ $dbh = &$this->_dbh; extract($this->_table_names); $orderby = $this->sortby($sortby, 'db'); - if ($orderby) $orderby = ' ORDER BY ' . $orderby; + if ($orderby) { + $orderby = ' ORDER BY ' . $orderby; + } $and = ''; if ($exclude) { // array of pagenames $and = ' AND '; @@ -801,7 +809,7 @@ } /* - * Title and fulltext search. + * Text search (title or full text) */ public function text_search($search, $fulltext = false, $sortby = '', $limit = '', $exclude = '') @@ -809,7 +817,9 @@ $dbh = &$this->_dbh; extract($this->_table_names); $orderby = $this->sortby($sortby, 'db'); - if ($orderby) $orderby = ' ORDER BY ' . $orderby; + if ($orderby) { + $orderby = ' ORDER BY ' . $orderby; + } $table = "$nonempty_tbl, $page_tbl"; $join_clause = "$nonempty_tbl.id=$page_tbl.id"; @@ -824,7 +834,7 @@ $table .= ", $version_tbl"; $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version"; - $fields .= ",$page_tbl.pagedata as pagedata," . $this->version_tbl_fields; + $fields .= ", $page_tbl.pagedata as pagedata, " . $this->version_tbl_fields; $field_list = array_merge($field_list, array('pagedata'), $this->version_tbl_field_list); $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause"); @@ -871,17 +881,18 @@ { $dbh = &$this->_dbh; extract($this->_table_names); - $order = "DESC"; if ($limit < 0) { $order = "ASC"; $limit = -$limit; $where = ""; } else { + $order = "DESC"; $where = " AND hits > 0"; } + $orderby = ''; if ($sortby != '-hits') { - if ($order = $this->sortby($sortby, 'db')) $orderby = " ORDER BY " . $order; - else $orderby = ""; + if ($order = $this->sortby($sortby, 'db')) + $orderby = " ORDER BY " . $order; } else { $orderby = " ORDER BY hits $order"; } @@ -917,8 +928,9 @@ extract($this->_table_names); $pick = array(); - if ($since) + if ($since) { $pick[] = "mtime >= $since"; + } if ($include_all_revisions) { // Include all revisions of each page. @@ -955,8 +967,9 @@ $limit = -$limit; } $where_clause = $join_clause; - if ($pick) + if ($pick) { $where_clause .= " AND " . join(" AND ", $pick); + } $sql = "SELECT " . $this->page_tbl_fields . ", " . $this->version_tbl_fields . " FROM $table" @@ -1030,8 +1043,8 @@ extract($this->_table_names); $this->lock(array('page', 'version', 'recent', 'nonempty', 'link')); - if (($id = $this->_get_pageid($pagename, false))) { - if ($new = $this->_get_pageid($to, false)) { + if (($id = $this->_get_pageid($pagename))) { + if ($new = $this->_get_pageid($to)) { // Cludge Alert! // This page does not exist (already verified before), but exists in the page table. // So we delete this page. @@ -1164,8 +1177,9 @@ */ function _serialize($data) { - if (empty($data)) + if (empty($data)) { return ''; + } assert(is_array($data)); return serialize($data); } @@ -1348,8 +1362,8 @@ * * @return array an associative array with the following keys: * + phptype: Database backend used in PHP (mysql, odbc etc.) - * + dbsyntax: Database used with regards to SQL syntax etc. - * + protocol: Communication protocol to use (tcp, unix etc.) + * + dbsyntax: Database used with regards to SQL syntax etc. (ignored with PDO) + * + protocol: Communication protocol to use (tcp, unix, pipe etc.) * + hostspec: Host specification (hostname[:port]) * + database: Database to use on the DBMS server * + username: User name for login @@ -1398,7 +1412,7 @@ $parsed['dbsyntax'] = $str; } - if (!count($dsn)) { + if ($dsn == null) { return $parsed; } Modified: trunk/lib/WikiDB/backend/PDO.php =================================================================== --- trunk/lib/WikiDB/backend/PDO.php 2021-08-14 19:35:00 UTC (rev 10520) +++ trunk/lib/WikiDB/backend/PDO.php 2021-08-16 08:06:55 UTC (rev 10521) @@ -279,10 +279,11 @@ public function _extract_page_data($data, $hits) { - if (empty($data)) + if (empty($data)) { return array('hits' => $hits); - else + } else { return array_merge(array('hits' => $hits), $this->_unserialize($data)); + } } function update_pagedata($pagename, $newdata) @@ -320,9 +321,9 @@ $data[$key] = $val; } $sth = $dbh->prepare("UPDATE $page_tbl" - . " SET hits=?, pagedata=?" - . " WHERE pagename=?" - . " LIMIT 1"); + . " SET hits=?, pagedata=?" + . " WHERE pagename=?" + . " LIMIT 1"); $sth->bindParam(1, $hits, PDO::PARAM_INT); $serialized_data = $this->_serialize($data); $sth->bindParam(2, $serialized_data, PDO::PARAM_LOB); @@ -352,9 +353,9 @@ $page_tbl = $this->_table_names['page_tbl']; if (empty($data)) $data = ''; $sth = $dbh->prepare("UPDATE $page_tbl" - . " SET cached_html=?" - . " WHERE pagename=?" - . " LIMIT 1"); + . " SET cached_html=?" + . " WHERE pagename=?" + . " LIMIT 1"); $sth->bindParam(1, $data, PDO::PARAM_STR); $sth->bindParam(2, $pagename, PDO::PARAM_STR, 100); $sth->execute(); @@ -433,12 +434,12 @@ $dbh = &$this->_dbh; extract($this->_table_names); $sth = $dbh->prepare("SELECT version" - . " FROM $version_tbl, $page_tbl" - . " WHERE $version_tbl.id=$page_tbl.id" - . " AND pagename=?" - . " AND version < ?" - . " ORDER BY version DESC" - . " LIMIT 1"); + . " FROM $version_tbl, $page_tbl" + . " WHERE $version_tbl.id=$page_tbl.id" + . " AND pagename=?" + . " AND version < ?" + . " ORDER BY version DESC" + . " LIMIT 1"); $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100); $sth->bindParam(2, $version, PDO::PARAM_INT); $sth->execute(); @@ -772,6 +773,10 @@ * (linkExistingWikiWord or linkUnknownWikiWord) * This is called on every page header GleanDescription, so we can store all the * existing links. + * + * relations: $backend->get_links is responsible to add the relation to the pagehash + * as 'linkrelation' key as pagename. See WikiDB_PageIterator::next + * if (isset($next['linkrelation'])) */ function get_links($pagename, $reversed = true, $include_empty = false, $sortby = '', $limit = '', $exclude = '', @@ -917,7 +922,8 @@ $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version"; $fields .= ", $page_tbl.pagedata as pagedata, " . $this->version_tbl_fields; - $field_list = array_merge($field_list, array('pagedata'), $this->version_tbl_field_list); + $field_list = array_merge($field_list, array('pagedata'), + $this->version_tbl_field_list); $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause"); } else { $callback = new WikiMethodCb($searchobj, "_pagename_match_clause"); @@ -1153,11 +1159,11 @@ $backend_type = $this->backendType(); if (substr($backend_type, 0, 5) == 'mysql') { $sth = $dbh->prepare("REPLACE INTO $recent_tbl" - . " (id, latestversion, latestmajor, latestminor)" - . " SELECT id, $maxversion, $maxmajor, $maxminor" - . " FROM $version_tbl" - . ($pageid ? " WHERE id=$pageid" : "") - . " GROUP BY id"); + . " (id, latestversion, latestmajor, latestminor)" + . " SELECT id, $maxversion, $maxmajor, $maxminor" + . " FROM $version_tbl" + . ($pageid ? " WHERE id=$pageid" : "") + . " GROUP BY id"); $sth->execute(); } else { $this->lock(array('recent')); @@ -1179,7 +1185,6 @@ { $dbh = &$this->_dbh; extract($this->_table_names); - extract($this->_expressions); $pageid = (int)$pageid; @@ -1417,6 +1422,7 @@ class WikiDB_backend_PDO_search extends WikiDB_backend_search_sql { + // no surrounding quotes because we know it's a string } // Following function taken from Pear::DB (prev. from adodb-pear.inc.php). Modified: trunk/lib/WikiDB/backend/PearDB.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB.php 2021-08-14 19:35:00 UTC (rev 10520) +++ trunk/lib/WikiDB/backend/PearDB.php 2021-08-16 08:06:55 UTC (rev 10521) @@ -320,7 +320,7 @@ * @param int $version Which version to get * @param bool $want_content Do we need content? * - * @return array The version data, or false if specified version does not exist. + * @return array|false The version data, or false if specified version does not exist. */ function get_versiondata($pagename, $version, $want_content = false) { @@ -982,7 +982,7 @@ . " AND version=latestversion" // We have some specifics here (Oracle) //. " AND content<>''" - . " AND content $notempty" + . " AND content $notempty" // On Oracle not just "<>''" . ($pageid ? " AND $recent_tbl.id=$pageid" : "")); $this->unlock(); } @@ -1188,8 +1188,9 @@ function next() { - if (!$this->_result) + if (!$this->_result) { return false; + } $record = $this->_result->fetchRow(DB_FETCHMODE_ASSOC); if (!$record) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |