From: <var...@us...> - 2015-03-06 10:46:45
|
Revision: 9611 http://sourceforge.net/p/phpwiki/code/9611 Author: vargenau Date: 2015-03-06 10:46:43 +0000 (Fri, 06 Mar 2015) Log Message: ----------- Add private, add braces, remove dead code Modified Paths: -------------- trunk/lib/WikiDB/backend/ADODB.php trunk/lib/WikiDB/backend/ADODB_mysql.php trunk/lib/WikiDB/backend/PDO.php trunk/lib/WikiDB/backend/PDO_pgsql.php trunk/lib/WikiDB/backend/PearDB.php trunk/lib/WikiDB/backend/PearDB_mysql.php Modified: trunk/lib/WikiDB/backend/ADODB.php =================================================================== --- trunk/lib/WikiDB/backend/ADODB.php 2015-03-06 09:52:06 UTC (rev 9610) +++ trunk/lib/WikiDB/backend/ADODB.php 2015-03-06 10:46:43 UTC (rev 9611) @@ -210,7 +210,7 @@ return $row ? $this->_extract_page_data($row[3], $row[2]) : false; } - function _extract_page_data($data, $hits) + private function _extract_page_data($data, $hits) { if (empty($data)) return array('hits' => $hits); @@ -230,7 +230,7 @@ // hit count, who cares? $dbh->Execute(sprintf("UPDATE $page_tbl SET hits=%d WHERE pagename=%s", $newdata['hits'], $dbh->qstr($pagename))); - return; + return true; } $where = sprintf("pagename=%s", $dbh->qstr($pagename)); $dbh->BeginTrans(); @@ -402,7 +402,7 @@ return $row ? $this->_extract_version_data_num($row, $want_content) : false; } - function _extract_version_data_num($row, $want_content) + private function _extract_version_data_num($row, $want_content) { if (!$row) return false; @@ -460,7 +460,7 @@ unset($data['mtime']); assert(!empty($mtime)); - @$content = (string)$data['%content']; + $content = isset($data['%content']) ? (string)$data['%content'] : ''; unset($data['%content']); unset($data['%pagedata']); @@ -590,12 +590,6 @@ return $result; } - // The only thing we might be interested in updating which we can - // do fast in the flags (minor_edit). I think the default - // update_versiondata will work fine... - //function update_versiondata($pagename, $version, $data) { - //} - /* * Update link table. * on DEBUG: delete old, deleted links from page @@ -805,11 +799,6 @@ //. " GROUP BY $want.id" . $exclude . $orderby; - /* - echo "SELECT linkee.id AS id, linkee.pagename AS pagename, related.pagename as linkrelation FROM link, page linkee, page linker JOIN page related ON (link.relation=related.id) WHERE linkfrom=linker.id AND linkto=linkee.id AND linker.pagename='SanDiego'" | mysql phpwiki - id pagename linkrelation - 2268 California located_in - */ if ($limit) { // extract from,count from limit list($offset, $count) = $this->limit($limit); @@ -860,8 +849,7 @@ $exclude = ''; } - //$dbh->SetFetchMode(ADODB_FETCH_ASSOC); - if (strstr($orderby, 'mtime ')) { // was ' mtime' + if (strstr($orderby, 'mtime ')) { // multiple columns possible if ($include_empty) { $sql = "SELECT " . $this->page_tbl_fields @@ -903,7 +891,6 @@ } else { $result = $dbh->Execute($sql); } - //$dbh->SetFetchMode(ADODB_FETCH_NUM); return new WikiDB_backend_ADODB_iter($this, $result, $this->page_tbl_field_list); } @@ -989,8 +976,9 @@ if ($sortby != '-hits') { if ($order = $this->sortby($sortby, 'db')) $orderby = " ORDER BY " . $order; else $orderby = ""; - } else + } else { $orderby = " ORDER BY hits $order"; + } $sql = "SELECT " . $this->page_tbl_fields . " FROM $nonempty_tbl, $page_tbl" @@ -1391,6 +1379,14 @@ } } + function free() + { + if ($this->_result) { + $this->_result->Close(); + $this->_result = false; + } + } + function asArray() { $result = array(); @@ -1398,15 +1394,6 @@ $result[] = $page; return $result; } - - function free() - { - if ($this->_result) { - /* call mysql_free_result($this->_queryID) */ - $this->_result->Close(); - $this->_result = false; - } - } } class WikiDB_backend_ADODB_iter @@ -1444,7 +1431,6 @@ class WikiDB_backend_ADODB_search extends WikiDB_backend_search_sql { // no surrounding quotes because we know it's a string - // function _quote($word) { return $this->_dbh->escapeSimple($word); } } // Following function taken from Pear::DB (prev. from adodb-pear.inc.php). @@ -1578,7 +1564,7 @@ $parsed['socket'] = $proto_opts; } - // Get dabase if any + // Get database if any // $dsn => database if ($dsn) { // /database Modified: trunk/lib/WikiDB/backend/ADODB_mysql.php =================================================================== --- trunk/lib/WikiDB/backend/ADODB_mysql.php 2015-03-06 09:52:06 UTC (rev 9610) +++ trunk/lib/WikiDB/backend/ADODB_mysql.php 2015-03-06 10:46:43 UTC (rev 9611) @@ -106,6 +106,7 @@ if (DO_FULL_LOCK) { // if this is not enough: $lock_type = $write_lock ? "WRITE" : "READ"; + $locks = array(); foreach ($this->_table_names as $key => $table) { $locks[] = "$table $lock_type"; } Modified: trunk/lib/WikiDB/backend/PDO.php =================================================================== --- trunk/lib/WikiDB/backend/PDO.php 2015-03-06 09:52:06 UTC (rev 9610) +++ trunk/lib/WikiDB/backend/PDO.php 2015-03-06 10:46:43 UTC (rev 9611) @@ -280,7 +280,7 @@ return $row ? $this->_extract_page_data($row[3], $row[2]) : false; } - function _extract_page_data($data, $hits) + private function _extract_page_data($data, $hits) { if (empty($data)) return array('hits' => $hits); @@ -302,7 +302,7 @@ $sth->bindParam(1, $newdata['hits'], PDO::PARAM_INT); $sth->bindParam(2, $pagename, PDO::PARAM_STR, 100); $sth->execute(); - return; + return true; } $this->beginTransaction(); $data = $this->get_pagedata($pagename); @@ -372,6 +372,7 @@ return $cache[$pagename]; } } + // attributes play this game. if ($pagename === '') return 0; @@ -487,7 +488,7 @@ return $row ? $this->_extract_version_data_num($row, $want_content) : false; } - function _extract_version_data_num($row, $want_content) + private function _extract_version_data_num($row, $want_content) { if (!$row) return false; @@ -543,7 +544,7 @@ unset($data['mtime']); assert(!empty($mtime)); - @$content = (string)$data['%content']; + $content = isset($data['%content']) ? (string)$data['%content'] : ''; unset($data['%content']); unset($data['%pagedata']); @@ -671,6 +672,7 @@ $this->rollBack(); return false; } + return false; } /* @@ -705,12 +707,6 @@ return $result; } - // The only thing we might be interested in updating which we can - // do fast in the flags (minor_edit). I think the default - // update_versiondata will work fine... - //function update_versiondata($pagename, $version, $data) { - //} - /* * Update link table. * on DEBUG: delete old, deleted links from page @@ -907,7 +903,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"); } else { @@ -959,8 +955,9 @@ if ($sortby != '-hits') { if ($order = $this->sortby($sortby, 'db')) $orderby = " ORDER BY " . $order; else $orderby = ""; - } else + } else { $orderby = " ORDER BY hits $order"; + } $sql = "SELECT " . $this->page_tbl_fields . " FROM $nonempty_tbl, $page_tbl" @@ -1536,7 +1533,7 @@ $parsed['socket'] = $proto_opts; } - // Get dabase if any + // Get database if any // $dsn => database if ($dsn) { // /database Modified: trunk/lib/WikiDB/backend/PDO_pgsql.php =================================================================== --- trunk/lib/WikiDB/backend/PDO_pgsql.php 2015-03-06 09:52:06 UTC (rev 9610) +++ trunk/lib/WikiDB/backend/PDO_pgsql.php 2015-03-06 10:46:43 UTC (rev 9611) @@ -37,7 +37,7 @@ if ($limit) { list($offset, $count) = $this->limit($limit); if ($offset) - $limit = " LIMIT $count OFFSET $from"; + $limit = " LIMIT $count OFFSET $offset"; else $limit = " LIMIT $count"; } else Modified: trunk/lib/WikiDB/backend/PearDB.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB.php 2015-03-06 09:52:06 UTC (rev 9610) +++ trunk/lib/WikiDB/backend/PearDB.php 2015-03-06 10:46:43 UTC (rev 9611) @@ -187,7 +187,7 @@ return $result ? $this->_extract_page_data($result) : false; } - function _extract_page_data($data) + private function _extract_page_data($data) { if (empty($data)) return array(); elseif (empty($data['pagedata'])) return $data; else { @@ -219,7 +219,7 @@ $this->_get_pageid($pagename, true); // Creates page record } - $hits = !empty($data['hits']) ? (int)$data['hits'] : 0; + $hits = (empty($data['hits'])) ? 0 : (int)$data['hits']; unset($data['hits']); foreach ($newdata as $key => $val) { @@ -469,29 +469,6 @@ } /* - * Delete page from the database with backup possibility. - * i.e save_page('') and DELETE nonempty id - * Can be undone and is seen in RecentChanges. - */ - /* // see parent backend.php - function delete_page($pagename) { - $mtime = time(); - $user =& $GLOBALS['request']->_user; - $vdata = array('author' => $user->getId(), - 'author_id' => $user->getAuthenticatedId(), - 'mtime' => $mtime); - - $this->lock(); - $version = $this->get_latest_version($pagename); - $this->set_versiondata($pagename, $version+1, $vdata); - $this->set_links($pagename, false); - $pagedata = get_pagedata($pagename); - $this->update_pagedata($pagename, array('hits' => $pagedata['hits'])); - $this->unlock(); - } - */ - - /* * Delete page completely from the database. */ function purge_page($pagename) @@ -524,12 +501,6 @@ return $result; } - // The only thing we might be interested in updating which we can - // do fast in the flags (minor_edit). I think the default - // update_versiondata will work fine... - //function update_versiondata($pagename, $version, $data) { - //} - /* * Update link table. * on DEBUG: delete old, deleted links from page @@ -558,10 +529,12 @@ else $relation = 0; // avoid duplicates - if (isset($linkseen[$linkto]) and !$relation) + if (isset($linkseen[$linkto]) and !$relation) { continue; - if (!$relation) + } + if (!$relation) { $linkseen[$linkto] = true; + } $linkid = $this->_get_pageid($linkto, true); if (!$linkid) { echo("No link for $linkto on page $pagename"); @@ -655,10 +628,11 @@ extract($this->_table_names); $orderby = $this->sortby($sortby, 'db'); if ($orderby) $orderby = ' ORDER BY ' . $orderby; - if ($exclude) // array of pagenames + if ($exclude) { // array of pagenames $exclude = " AND $page_tbl.pagename NOT IN " . $this->_sql_set($exclude); - else + } else { $exclude = ''; + } if (strstr($orderby, 'mtime ')) { // multiple columns possible if ($include_empty) { @@ -708,8 +682,7 @@ } /* - * Text search (title or full text) - * Todo: exclude + * Title and fulltext search. */ public function text_search($search, $fulltext = false, $sortby = '', $limit = '', $exclude = '') @@ -817,7 +790,6 @@ } else { $orderby = " ORDER BY $order"; } - //$limitclause = $limit ? " LIMIT $limit" : ''; $sql = "SELECT " . $this->page_tbl_fields . " FROM $nonempty_tbl, $page_tbl" @@ -886,17 +858,15 @@ $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"; + // FIXME: use SQL_BUFFER_RESULT for mysql? if ($limit) { list($from, $count) = $this->limit($limit); $result = $dbh->limitQuery($sql, $from, $count); @@ -920,6 +890,15 @@ $exclude_from = " AND pp.pagename NOT IN " . $this->_sql_set($exclude_from); if ($exclude) // array of pagenames $exclude = " AND p.pagename NOT IN " . $this->_sql_set($exclude); + + /* + all empty pages, independent of linkstatus: + select pagename as empty from page left join nonempty using(id) where is null(nonempty.id); + only all empty pages, which have a linkto: + select page.pagename, linked.pagename as wantedfrom from link, page linked + left join page on link.linkto=page.id left join nonempty on link.linkto=nonempty.id + where nonempty.id is null and linked.id=link.linkfrom; + */ $sql = "SELECT p.pagename, pp.pagename AS wantedfrom" . " FROM $page_tbl p, $link_tbl linked" . " LEFT JOIN $page_tbl pp ON linked.linkto = pp.id" @@ -1249,8 +1228,9 @@ function count() { - if (!$this->_result) + if (!$this->_result) { return false; + } return $this->_result->numRows(); } @@ -1328,7 +1308,6 @@ class WikiDB_backend_PearDB_search extends WikiDB_backend_search_sql { // no surrounding quotes because we know it's a string - // function _quote($word) { return $this->_dbh->addq($word); } } // Local Variables: Modified: trunk/lib/WikiDB/backend/PearDB_mysql.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB_mysql.php 2015-03-06 09:52:06 UTC (rev 9610) +++ trunk/lib/WikiDB/backend/PearDB_mysql.php 2015-03-06 10:46:43 UTC (rev 9611) @@ -175,6 +175,7 @@ protected function _lock_tables($write_lock = true) { $lock_type = $write_lock ? "WRITE" : "READ"; + $tables = array(); foreach ($this->_table_names as $table) { $tables[] = "$table $lock_type"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |