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. |
From: <var...@us...> - 2021-09-06 17:10:44
|
Revision: 10544 http://sourceforge.net/p/phpwiki/code/10544 Author: vargenau Date: 2021-09-06 17:10:42 +0000 (Mon, 06 Sep 2021) Log Message: ----------- Add braces, rename $offset to $from Modified Paths: -------------- trunk/lib/WikiDB/backend/PDO_mysql.php trunk/lib/WikiDB/backend/PDO_pgsql.php Modified: trunk/lib/WikiDB/backend/PDO_mysql.php =================================================================== --- trunk/lib/WikiDB/backend/PDO_mysql.php 2021-09-06 17:08:49 UTC (rev 10543) +++ trunk/lib/WikiDB/backend/PDO_mysql.php 2021-09-06 17:10:42 UTC (rev 10544) @@ -99,19 +99,19 @@ /* * offset specific syntax within mysql - * convert from,count to SQL "LIMIT $offset, $count" + * convert from,count to SQL "LIMIT $from, $count" */ function _limit_sql($limit = false) { if ($limit) { - list($offset, $count) = $this->limit($limit); - if ($offset) - // pgsql needs "LIMIT $count OFFSET $from" - $limit = " LIMIT $offset, $count"; - else + list($from, $count) = $this->limit($limit); + if ($from) { + $limit = " LIMIT $from, $count"; + } else { $limit = " LIMIT $count"; - } else + } else { $limit = ''; + } return $limit; } Modified: trunk/lib/WikiDB/backend/PDO_pgsql.php =================================================================== --- trunk/lib/WikiDB/backend/PDO_pgsql.php 2021-09-06 17:08:49 UTC (rev 10543) +++ trunk/lib/WikiDB/backend/PDO_pgsql.php 2021-09-06 17:10:42 UTC (rev 10544) @@ -30,25 +30,27 @@ class WikiDB_backend_PDO_pgsql extends WikiDB_backend_PDO { + function backendType() + { + return 'pgsql'; + } /* + * offset specific syntax within pgsql * convert from,count to SQL "LIMIT $count OFFSET $from" */ function _limit_sql($limit = false) { if ($limit) { - list($offset, $count) = $this->limit($limit); - if ($offset) - $limit = " LIMIT $count OFFSET $offset"; - else + list($from, $count) = $this->limit($limit); + if ($from) { + $limit = " LIMIT $count OFFSET $from"; + } else { $limit = " LIMIT $count"; - } else + } else { $limit = ''; + } return $limit; } - function backendType() - { - return 'pgsql'; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <var...@us...> - 2021-09-06 17:19:50
|
Revision: 10545 http://sourceforge.net/p/phpwiki/code/10545 Author: vargenau Date: 2021-09-06 17:19:47 +0000 (Mon, 06 Sep 2021) Log Message: ----------- Fix syntax error Modified Paths: -------------- trunk/lib/WikiDB/backend/PDO_mysql.php trunk/lib/WikiDB/backend/PDO_pgsql.php Modified: trunk/lib/WikiDB/backend/PDO_mysql.php =================================================================== --- trunk/lib/WikiDB/backend/PDO_mysql.php 2021-09-06 17:10:42 UTC (rev 10544) +++ trunk/lib/WikiDB/backend/PDO_mysql.php 2021-09-06 17:19:47 UTC (rev 10545) @@ -109,10 +109,10 @@ $limit = " LIMIT $from, $count"; } else { $limit = " LIMIT $count"; + } } else { $limit = ''; } return $limit; } - } Modified: trunk/lib/WikiDB/backend/PDO_pgsql.php =================================================================== --- trunk/lib/WikiDB/backend/PDO_pgsql.php 2021-09-06 17:10:42 UTC (rev 10544) +++ trunk/lib/WikiDB/backend/PDO_pgsql.php 2021-09-06 17:19:47 UTC (rev 10545) @@ -47,10 +47,10 @@ $limit = " LIMIT $count OFFSET $from"; } else { $limit = " LIMIT $count"; + } } else { $limit = ''; } return $limit; } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <var...@us...> - 2022-01-27 15:12:18
|
Revision: 10954 http://sourceforge.net/p/phpwiki/code/10954 Author: vargenau Date: 2022-01-27 15:12:17 +0000 (Thu, 27 Jan 2022) Log Message: ----------- Make renaming a page work with "file" Modified Paths: -------------- trunk/lib/WikiDB/backend/file.php trunk/lib/WikiDB/backend/flatfile.php Modified: trunk/lib/WikiDB/backend/file.php =================================================================== --- trunk/lib/WikiDB/backend/file.php 2022-01-27 15:05:43 UTC (rev 10953) +++ trunk/lib/WikiDB/backend/file.php 2022-01-27 15:12:17 UTC (rev 10954) @@ -50,7 +50,6 @@ { public $data_dir; public $_dir_names; - public $_page_data; // temporarily stores the pagedata (via _loadPageData) public $_page_version_data; // temporarily stores the versiondata (via _loadVersionData) public $_latest_versions; // temporarily stores the latest version-numbers (for every pagename) @@ -86,7 +85,7 @@ // ********************************************************************* // common file load / save functions: - protected function _pagename2filename($type, $pagename, $version) + protected function _pagename2filename($type, $pagename, $version = 0) { if ($version == 0) { return $this->_dir_names[$type] . '/' . urlencode($pagename); @@ -418,14 +417,22 @@ function rename_page($pagename, $to) { $version = $this->_getLatestVersion($pagename); - foreach ($this->_dir_names as $type => $path) { - if (is_dir($path)) { - $filename = $this->_pagename2filename($type, $pagename, $version); - $new = $this->_pagename2filename($type, $to, $version); - @rename($filename, $new); - } + // rename page_data + $filename = $this->_pagename2filename('page_data', $pagename); + $new = $this->_pagename2filename('page_data', $to); + rename($filename, $new); + // rename links + $filename = $this->_pagename2filename('links', $pagename); + $new = $this->_pagename2filename('links', $to); + rename($filename, $new); + // rename ver_data + for ($i = 1; $i <= $version; $i++) { + $filename = $this->_pagename2filename('ver_data', $pagename, $i); + $new = $this->_pagename2filename('ver_data', $to, $i); + rename($filename, $new); } - $this->update_pagedata($pagename, array('pagename' => $to)); + $this->_setLatestVersion($pagename, 0); + $this->_setLatestVersion($to, $version); return true; } @@ -517,7 +524,6 @@ { $data = $this->get_versiondata($pagename, $version, true); if (!$data) { - assert($data); return; } foreach ($newdata as $key => $val) { @@ -570,7 +576,7 @@ $links = $this->_loadPageLinks($key); foreach ($links as $key2 => $val2) { if (is_array($val2) and isset($val2['linkto']) and ($val2['linkto'] == $pagename)) { - array_push($out, $key); + $out[] = $key; } } } Modified: trunk/lib/WikiDB/backend/flatfile.php =================================================================== --- trunk/lib/WikiDB/backend/flatfile.php 2022-01-27 15:05:43 UTC (rev 10953) +++ trunk/lib/WikiDB/backend/flatfile.php 2022-01-27 15:12:17 UTC (rev 10954) @@ -42,7 +42,7 @@ // ********************************************************************* // common file load / save functions: // FilenameForPage is from loadsave.php - protected function _pagename2filename($type, $pagename, $version) + protected function _pagename2filename($type, $pagename, $version = 0) { $fpagename = FilenameForPage($pagename); if (strstr($fpagename, "/")) { @@ -60,7 +60,7 @@ } } - $filename = $this->_pagename2filename('page_data', $pagename, 0); + $filename = $this->_pagename2filename('page_data', $pagename); if (!file_exists($filename)) return NULL; if (!filesize($filename)) return array(); if ($fd = @fopen($filename, "rb")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <var...@us...> - 2022-07-12 12:15:26
|
Revision: 11026 http://sourceforge.net/p/phpwiki/code/11026 Author: vargenau Date: 2022-07-12 12:15:24 +0000 (Tue, 12 Jul 2022) Log Message: ----------- Remove & in $cache =& $request->_dbi->_cache->_id_cache; Modified Paths: -------------- trunk/lib/WikiDB/backend/PDO.php trunk/lib/WikiDB/backend/PearDB.php trunk/lib/WikiDB/backend/PearDB_ffpgsql.php Modified: trunk/lib/WikiDB/backend/PDO.php =================================================================== --- trunk/lib/WikiDB/backend/PDO.php 2022-04-19 14:53:46 UTC (rev 11025) +++ trunk/lib/WikiDB/backend/PDO.php 2022-07-12 12:15:24 UTC (rev 11026) @@ -381,7 +381,7 @@ { // check id_cache global $request; - $cache =& $request->_dbi->_cache->_id_cache; + $cache = $request->_dbi->_cache->_id_cache; if (isset($cache[$pagename])) { if ($cache[$pagename] or !$create_if_missing) { return $cache[$pagename]; Modified: trunk/lib/WikiDB/backend/PearDB.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB.php 2022-04-19 14:53:46 UTC (rev 11025) +++ trunk/lib/WikiDB/backend/PearDB.php 2022-07-12 12:15:24 UTC (rev 11026) @@ -266,7 +266,7 @@ { // check id_cache global $request; - $cache =& $request->_dbi->_cache->_id_cache; + $cache = $request->_dbi->_cache->_id_cache; if (isset($cache[$pagename])) { if ($cache[$pagename] or !$create_if_missing) { return $cache[$pagename]; Modified: trunk/lib/WikiDB/backend/PearDB_ffpgsql.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB_ffpgsql.php 2022-04-19 14:53:46 UTC (rev 11025) +++ trunk/lib/WikiDB/backend/PearDB_ffpgsql.php 2022-07-12 12:15:24 UTC (rev 11026) @@ -240,7 +240,7 @@ // check id_cache global $request; - $cache =& $request->_dbi->_cache->_id_cache; + $cache = $request->_dbi->_cache->_id_cache; if (isset($cache[$pagename])) { if ($cache[$pagename] or !$create_if_missing) { return $cache[$pagename]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <var...@us...> - 2023-07-14 11:00:37
|
Revision: 11052 http://sourceforge.net/p/phpwiki/code/11052 Author: vargenau Date: 2023-07-14 11:00:34 +0000 (Fri, 14 Jul 2023) Log Message: ----------- lib/WikiDB/backend: PHP 7: add types for function arguments and return Modified Paths: -------------- trunk/lib/WikiDB/backend/PDO.php trunk/lib/WikiDB/backend/PDO_mysql.php trunk/lib/WikiDB/backend/PDO_oci8.php trunk/lib/WikiDB/backend/PDO_pgsql.php trunk/lib/WikiDB/backend/PearDB.php trunk/lib/WikiDB/backend/PearDB_ffpgsql.php trunk/lib/WikiDB/backend/PearDB_mysqli.php trunk/lib/WikiDB/backend/PearDB_oci8.php trunk/lib/WikiDB/backend/PearDB_pgsql.php trunk/lib/WikiDB/backend/dba.php trunk/lib/WikiDB/backend/dbaBase.php trunk/lib/WikiDB/backend/dumb/AllRevisionsIter.php trunk/lib/WikiDB/backend/dumb/LinkSearchIter.php trunk/lib/WikiDB/backend/dumb/MostPopularIter.php trunk/lib/WikiDB/backend/file.php trunk/lib/WikiDB/backend/flatfile.php Modified: trunk/lib/WikiDB/backend/PDO.php =================================================================== --- trunk/lib/WikiDB/backend/PDO.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/PDO.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -278,7 +278,7 @@ /* * Read page information from database. */ - public function get_pagedata($pagename) + public function get_pagedata(string $pagename): array { $dbh = &$this->_dbh; $page_tbl = $this->_table_names['page_tbl']; @@ -290,7 +290,7 @@ 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): array { if (empty($data)) { return array('hits' => $hits); @@ -299,7 +299,7 @@ } } - public function update_pagedata($pagename, $newdata) + public function update_pagedata(string $pagename, array $newdata): bool { $dbh = &$this->_dbh; $page_tbl = $this->_table_names['page_tbl']; @@ -434,7 +434,7 @@ return $id; } - public function get_latest_version($pagename) + public function get_latest_version(string $pagename): int { $dbh = &$this->_dbh; extract($this->_table_names); @@ -448,7 +448,7 @@ return $sth->fetchColumn(); } - public function get_previous_version($pagename, $version) + public function get_previous_version(string $pagename, int $version): int { $dbh = &$this->_dbh; extract($this->_table_names); @@ -474,7 +474,7 @@ * * @return array|false The version data, or false if specified version does not exist. */ - public function get_versiondata($pagename, $version, $want_content = false) + public function get_versiondata(string $pagename, int $version, bool $want_content = false) { $dbh = &$this->_dbh; extract($this->_table_names); @@ -555,7 +555,7 @@ /* * Create a new revision of a page. */ - public function set_versiondata($pagename, $version, $data) + public function set_versiondata(string $pagename, int $version, array $data) { $dbh = &$this->_dbh; $version_tbl = $this->_table_names['version_tbl']; @@ -611,7 +611,7 @@ /* * Delete an old revision of a page. */ - public function delete_versiondata($pagename, $version) + public function delete_versiondata(string $pagename, int $version) { $dbh = &$this->_dbh; extract($this->_table_names); @@ -637,7 +637,7 @@ * so that get_latest_version returns id+1 and get_previous_version returns prev id * and page->exists returns false. */ - public function delete_page($pagename) + public function delete_page(string $pagename): bool { /** * @var WikiRequest $request @@ -699,7 +699,7 @@ /* * Delete page completely from the database. */ - public function purge_page($pagename) + public function purge_page(string $pagename): int { $dbh = &$this->_dbh; extract($this->_table_names); @@ -734,7 +734,7 @@ * @param string $pagename Page name * @param array $links List of page(names) which page links to. */ - public function set_links($pagename, $links) + public function set_links(string $pagename, array $links) { // Update link table. // FIXME: optimize: mysql can do this all in one big INSERT/REPLACE. @@ -803,13 +803,13 @@ * if (isset($next['linkrelation'])) */ public function get_links( - $pagename, - $reversed = true, - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '', - $want_relations = false + string $pagename, + bool $reversed = true, + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '', + bool $want_relations = false ) { $dbh = &$this->_dbh; @@ -872,10 +872,10 @@ } public function get_all_pages( - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '' + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ) { $dbh = &$this->_dbh; @@ -935,11 +935,11 @@ * Text search (title or full text) */ public function text_search( - $search, - $fulltext = false, - $sortby = '', - $limit = '', - $exclude = '' + object $search, + bool $fulltext = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ) { $dbh = &$this->_dbh; @@ -991,7 +991,7 @@ * This is only for already resolved wildcards: * " WHERE $page_tbl.pagename NOT IN ".$this->_sql_set(array('page1','page2')); */ - public function _sql_set($pagenames) + public function _sql_set($pagenames): string { $s = '('; foreach ($pagenames as $p) { @@ -1003,7 +1003,7 @@ /* * Find highest or lowest hit counts. */ - public function most_popular($limit = 20, $sortby = '-hits') + public function most_popular(int $limit = 20, string $sortby = '-hits') { $dbh = &$this->_dbh; extract($this->_table_names); @@ -1041,7 +1041,7 @@ /* * Find recent changes. */ - public function most_recent($params) + public function most_recent(array $params) { $limit = 0; $since = 0; @@ -1161,7 +1161,7 @@ * @param string $to Future page name */ - public function rename_page($pagename, $to) + public function rename_page(string $pagename, string $to) { $dbh = &$this->_dbh; extract($this->_table_names); @@ -1239,7 +1239,7 @@ * Calls can be nested. The tables won't be unlocked until * _unlock_database() is called as many times as _lock_database(). */ - public function lock($tables = array(), $write_lock = true) + public function lock(array $tables = array(), bool $write_lock = true) { if ($this->_lock_count++ == 0) { $this->_current_lock = $tables; @@ -1270,7 +1270,7 @@ * * @see _lock_database */ - public function unlock($tables = array(), $force = false) + public function unlock(array $tables = array(), bool $force = false) { if ($this->_lock_count == 0) { $this->_current_lock = false; @@ -1330,13 +1330,13 @@ return $this->_dbh->databaseType; } - public function connection() + public function connection(): bool { trigger_error("PDO: connectionID unsupported", E_USER_ERROR); return false; } - public function listOfTables() + public function listOfTables(): array { trigger_error("PDO: virtual listOfTables", E_USER_ERROR); return array(); @@ -1362,7 +1362,7 @@ BETWEEN $offset AND $last ORDER BY $pk $asc_desc */ - public function _limit_sql($limit = false) + public function _limit_sql($limit = false): string { if ($limit) { list($offset, $count) = $this->limit($limit); @@ -1413,7 +1413,7 @@ //$this->_fields = $field_list; } - public function count() + public function count(): int { if (!is_object($this->_result)) { return false; @@ -1467,7 +1467,7 @@ class WikiDB_backend_PDO_search extends WikiDB_backend_search_sql { - public function _pagename_match_clause($node) + public function _pagename_match_clause($node): string { $word = $node->sql(); if ($word == '%') { // ALL shortcut @@ -1481,7 +1481,7 @@ } } - public function _fulltext_match_clause($node) + public function _fulltext_match_clause($node): string { // force word-style %word% for fulltext search $dbh = &$this->_dbh; @@ -1538,7 +1538,7 @@ * * @author Tomas V.V.Cox <co...@id...> */ -function parseDSN($dsn) +function parseDSN(string $dsn): array { $parsed = array( 'phptype' => false, Modified: trunk/lib/WikiDB/backend/PDO_mysql.php =================================================================== --- trunk/lib/WikiDB/backend/PDO_mysql.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/PDO_mysql.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -35,7 +35,7 @@ $this->_dbh->query("SET NAMES 'utf8'"); } - public function backendType() + public function backendType(): string { return 'mysql'; } @@ -66,7 +66,7 @@ /** * Pack tables. */ - public function optimize() + public function optimize(): bool { $this->_timeout(); foreach ($this->_table_names as $table) { @@ -75,7 +75,7 @@ return true; } - public function listOfTables() + public function listOfTables(): array { $sth = $this->_dbh->prepare("SHOW TABLES"); $sth->execute(); @@ -90,7 +90,7 @@ * offset specific syntax within mysql * convert from,count to SQL "LIMIT $from, $count" */ - public function _limit_sql($limit = false) + public function _limit_sql($limit = false): string { if ($limit) { list($from, $count) = $this->limit($limit); Modified: trunk/lib/WikiDB/backend/PDO_oci8.php =================================================================== --- trunk/lib/WikiDB/backend/PDO_oci8.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/PDO_oci8.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -29,12 +29,12 @@ class WikiDB_backend_PDO_oci8 extends WikiDB_backend_PDO { - public function backendType() + public function backendType(): string { return 'oci8'; } - public function optimize() + public function optimize(): bool { // Do nothing here -- Leave that for the DBA // Cost Based Optimizer tuning vary from version to version Modified: trunk/lib/WikiDB/backend/PDO_pgsql.php =================================================================== --- trunk/lib/WikiDB/backend/PDO_pgsql.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/PDO_pgsql.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -29,7 +29,7 @@ class WikiDB_backend_PDO_pgsql extends WikiDB_backend_PDO { - public function backendType() + public function backendType(): string { return 'pgsql'; } @@ -38,7 +38,7 @@ * offset specific syntax within pgsql * convert from,count to SQL "LIMIT $count OFFSET $from" */ - public function _limit_sql($limit = false) + public function _limit_sql($limit = false): string { if ($limit) { list($from, $count) = $this->limit($limit); Modified: trunk/lib/WikiDB/backend/PearDB.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/PearDB.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -166,7 +166,7 @@ /* * Read page information from database. */ - public function get_pagedata($pagename) + public function get_pagedata(string $pagename): array { $dbh = &$this->_dbh; //trigger_error("GET_PAGEDATA $pagename", E_USER_NOTICE); @@ -181,7 +181,7 @@ return $result ? $this->_extract_page_data($result) : false; } - public function _extract_page_data($data) + public function _extract_page_data($data): array { if (empty($data)) { return array(); @@ -194,7 +194,7 @@ } } - public function update_pagedata($pagename, $newdata) + public function update_pagedata(string $pagename, array $newdata) { $dbh = &$this->_dbh; $page_tbl = $this->_table_names['page_tbl']; @@ -309,7 +309,7 @@ return $id; } - public function get_latest_version($pagename) + public function get_latest_version(string $pagename): int { $dbh = &$this->_dbh; extract($this->_table_names); @@ -323,7 +323,7 @@ )); } - public function get_previous_version($pagename, $version) + public function get_previous_version(string $pagename, int $version): int { $dbh = &$this->_dbh; extract($this->_table_names); @@ -353,7 +353,7 @@ * * @return array|false The version data, or false if specified version does not exist. */ - public function get_versiondata($pagename, $version, $want_content = false) + public function get_versiondata(string $pagename, int $version, bool $want_content = false) { $dbh = &$this->_dbh; extract($this->_table_names); @@ -428,7 +428,7 @@ /* * Create a new revision of a page. */ - public function set_versiondata($pagename, $version, $data) + public function set_versiondata(string $pagename, int $version, array $data) { $dbh = &$this->_dbh; $version_tbl = $this->_table_names['version_tbl']; @@ -471,7 +471,7 @@ /* * Delete an old revision of a page. */ - public function delete_versiondata($pagename, $version) + public function delete_versiondata(string $pagename, int $version) { $dbh = &$this->_dbh; extract($this->_table_names); @@ -491,7 +491,7 @@ /* * Delete page completely from the database. */ - public function purge_page($pagename) + public function purge_page(string $pagename): int { $dbh = &$this->_dbh; extract($this->_table_names); @@ -527,7 +527,7 @@ * @param string $pagename Page name * @param array $links List of page(names) which page links to. */ - public function set_links($pagename, $links) + public function set_links(string $pagename, array $links) { // Update link table. // FIXME: optimize: mysql can do this all in one big INSERT/REPLACE. @@ -591,13 +591,13 @@ * if (isset($next['linkrelation'])) */ public function get_links( - $pagename, - $reversed = true, - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '', - $want_relations = false + string $pagename, + bool $reversed = true, + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '', + bool $want_relations = false ) { $dbh = &$this->_dbh; @@ -666,10 +666,10 @@ } public function get_all_pages( - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '' + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ) { $dbh = &$this->_dbh; @@ -733,11 +733,11 @@ * Text search (title or full text) */ public function text_search( - $search, - $fulltext = false, - $sortby = '', - $limit = '', - $exclude = '' + object $search, + bool $fulltext = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ) { $dbh = &$this->_dbh; @@ -788,7 +788,7 @@ //Todo: check if the better Mysql MATCH operator is supported, // (ranked search) and also google like expressions. - public function _sql_match_clause($word) + public function _sql_match_clause($word): string { $word = preg_replace('/(?=[%_\\\\])/', "\\", $word); $word = $this->_dbh->escapeSimple($word); @@ -799,7 +799,7 @@ return "LOWER(pagename) LIKE '%$word%'"; } - public function _sql_casematch_clause($word) + public function _sql_casematch_clause($word): string { $word = preg_replace('/(?=[%_\\\\])/', "\\", $word); $word = $this->_dbh->escapeSimple($word); @@ -806,7 +806,7 @@ return "pagename LIKE '%$word%'"; } - public function _fullsearch_sql_match_clause($word) + public function _fullsearch_sql_match_clause($word): string { $word = preg_replace('/(?=[%_\\\\])/', "\\", $word); $word = $this->_dbh->escapeSimple($word); @@ -815,7 +815,7 @@ return "LOWER(pagename) LIKE '%$word%' OR content LIKE '%$word%'"; } - public function _fullsearch_sql_casematch_clause($word) + public function _fullsearch_sql_casematch_clause($word): string { $word = preg_replace('/(?=[%_\\\\])/', "\\", $word); $word = $this->_dbh->escapeSimple($word); @@ -822,7 +822,7 @@ return "pagename LIKE '%$word%' OR content LIKE '%$word%'"; } - public function _sql_set(&$pagenames) + public function _sql_set(&$pagenames): string { $s = '('; foreach ($pagenames as $p) { @@ -834,7 +834,7 @@ /* * Find highest or lowest hit counts. */ - public function most_popular($limit = 20, $sortby = '-hits') + public function most_popular(int $limit = 20, string $sortby = '-hits') { $dbh = &$this->_dbh; extract($this->_table_names); @@ -872,7 +872,7 @@ /* * Find recent changes. */ - public function most_recent($params) + public function most_recent(array $params) { $limit = 0; $since = 0; @@ -981,7 +981,7 @@ * @param string $to Future page name */ - public function rename_page($pagename, $to) + public function rename_page(string $pagename, string $to) { $dbh = &$this->_dbh; extract($this->_table_names); @@ -1006,7 +1006,7 @@ * Can be undone and is seen in RecentChanges. */ - public function delete_page($pagename) + public function delete_page(string $pagename) { /** * @var WikiRequest $request @@ -1084,7 +1084,7 @@ * Calls can be nested. The tables won't be unlocked until * _unlock_database() is called as many times as _lock_database(). */ - public function lock($tables = array(), $write_lock = true) + public function lock(array $tables = array(), bool $write_lock = true) { if ($this->_lock_count++ == 0) { $this->_lock_tables($write_lock); @@ -1108,7 +1108,7 @@ * * @see _lock_database */ - public function unlock($tables = array(), $force = false) + public function unlock(array $tables = array(), bool $force = false) { if ($this->_lock_count == 0) { return; @@ -1173,7 +1173,7 @@ * * @return bool True iff error is not really an error. */ - private function _is_false_error($error) + private function _is_false_error($error): bool { if ($error->getCode() != DB_ERROR) { return false; @@ -1268,7 +1268,7 @@ $this->_options = $field_list; } - public function count() + public function count(): int { if (!$this->_result) { return false; @@ -1306,7 +1306,7 @@ } } - public function asArray() + public function asArray(): array { $result = array(); while ($page = $this->next()) { Modified: trunk/lib/WikiDB/backend/PearDB_ffpgsql.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB_ffpgsql.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/PearDB_ffpgsql.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -93,13 +93,13 @@ /* * Read page information from database. */ - public function get_pagedata($pagename) + public function get_pagedata(string $pagename) { global $page_prefix; return parent::get_pagedata($page_prefix . $pagename); } - public function update_pagedata($pagename, $newdata) + public function update_pagedata(string $pagename, array $newdata) { $dbh = &$this->_dbh; $page_tbl = $this->_table_names['page_tbl']; @@ -164,13 +164,13 @@ $this->unlock(array($page_tbl)); } - public function get_latest_version($pagename) + public function get_latest_version(string $pagename): int { global $page_prefix; return parent::get_latest_version($page_prefix . $pagename); } - public function get_previous_version($pagename, $version) + public function get_previous_version(string $pagename, int $version): int { global $page_prefix; return parent::get_previous_version($page_prefix . $pagename, $version); @@ -185,7 +185,7 @@ * * @return array The version data, or false if specified version does not exist. */ - public function get_versiondata($pagename, $version, $want_content = false) + public function get_versiondata(string $pagename, int $version, bool $want_content = false): array { $dbh = &$this->_dbh; extract($this->_table_names); @@ -288,7 +288,7 @@ /* * Delete page completely from the database. */ - public function purge_page($pagename) + public function purge_page(string $pagename): int { $dbh = &$this->_dbh; extract($this->_table_names); @@ -335,13 +335,13 @@ * if (isset($next['linkrelation'])) */ public function get_links( - $pagename, - $reversed = true, - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '', - $want_relations = false + string $pagename, + bool $reversed = true, + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '', + bool $want_relations = false ) { $dbh = &$this->_dbh; @@ -393,10 +393,10 @@ } public function get_all_pages( - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '' + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ) { $dbh = &$this->_dbh; @@ -468,7 +468,7 @@ /* * Find highest or lowest hit counts. */ - public function most_popular($limit = 20, $sortby = '-hits') + public function most_popular(int $limit = 20, string $sortby = '-hits') { $dbh = &$this->_dbh; extract($this->_table_names); @@ -510,7 +510,7 @@ /* * Find recent changes. */ - public function most_recent($params) + public function most_recent(array $params) { $limit = 0; $since = 0; @@ -628,7 +628,7 @@ * @param string $to Future page name */ - public function rename_page($pagename, $to) + public function rename_page(string $pagename, string $to) { $dbh = &$this->_dbh; extract($this->_table_names); @@ -681,7 +681,7 @@ * Pack tables. * NOTE: Disable vacuum, wikiuser is not the table owner */ - public function optimize() + public function optimize(): bool { return true; } @@ -690,11 +690,11 @@ * Text search (title or full text) */ public function text_search( - $search, - $fulltext = false, - $sortby = '', - $limit = '', - $exclude = '' + object $search, + bool $fulltext = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ) { $dbh = &$this->_dbh; @@ -757,7 +757,7 @@ return $iter; } - public function exists_link($pagename, $link, $reversed = false) + public function exists_link($pagename, $link, $reversed = false): int { $dbh = &$this->_dbh; extract($this->_table_names); @@ -781,7 +781,7 @@ class WikiDB_backend_PearDB_ffpgsql_search extends WikiDB_backend_PearDB_pgsql_search { - public function _pagename_match_clause($node) + public function _pagename_match_clause($node): string { $word = $node->sql(); // @alu: use _quote maybe instead of direct pg_escape_string Modified: trunk/lib/WikiDB/backend/PearDB_mysqli.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB_mysqli.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/PearDB_mysqli.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -51,7 +51,7 @@ /* * Create a new revision of a page. */ - public function set_versiondata($pagename, $version, $data) + public function set_versiondata(string $pagename, int $version, array $data) { $dbh = &$this->_dbh; $version_tbl = $this->_table_names['version_tbl']; @@ -163,7 +163,7 @@ /** * Pack tables. */ - public function optimize() + public function optimize(): bool { $dbh = &$this->_dbh; $this->_timeout(); @@ -211,7 +211,7 @@ class WikiDB_backend_PearDB_mysqli_search extends WikiDB_backend_PearDB_search { - public function _pagename_match_clause($node) + public function _pagename_match_clause($node): string { $word = $node->sql(); $dbh = &$this->_dbh; Modified: trunk/lib/WikiDB/backend/PearDB_oci8.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB_oci8.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/PearDB_oci8.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -60,7 +60,7 @@ /** * Pack tables. */ - public function optimize() + public function optimize(): bool { // Do nothing here -- Leave that for the DBA // Cost Based Optimizer tuning vary from version to version @@ -89,7 +89,7 @@ } } - public function _quote($s) + public function _quote($s): string { return base64_encode($s); } @@ -135,7 +135,7 @@ // Index on the CLOB. While it is very efficient, it requires the // Intermedia Text option, so let's stick to the 'simple' thing // Note that this does only an exact fulltext search, not using MATCH or LIKE. - public function _fulltext_match_clause($node) + public function _fulltext_match_clause($node): string { if ($this->isStoplisted($node)) { return "1=1"; Modified: trunk/lib/WikiDB/backend/PearDB_pgsql.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB_pgsql.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/PearDB_pgsql.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -43,7 +43,7 @@ * Pack tables. * NOTE: Only the table owner can do this. Either fix the schema or setup autovacuum. */ - public function optimize() + public function optimize(): bool { return true; // if the wikiuser is not the table owner @@ -55,7 +55,7 @@ */ } - public function _quote($s) + public function _quote($s): string { if (USE_BYTEA) { return pg_escape_bytea($s); @@ -166,11 +166,11 @@ * Text search (title or full text) */ public function text_search( - $search, - $fulltext = false, - $sortby = '', - $limit = '', - $exclude = '' + object $search, + bool $fulltext = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ) { $dbh = &$this->_dbh; @@ -230,7 +230,7 @@ class WikiDB_backend_PearDB_pgsql_search extends WikiDB_backend_PearDB_search { - public function _pagename_match_clause($node) + public function _pagename_match_clause($node): string { $word = $node->sql(); if ($node->op == 'REGEX') { // posix regex extensions @@ -258,7 +258,7 @@ * The full-text index will still be used, and the regex will be used to * prune the results afterwards. */ - public function _fulltext_match_clause($node) + public function _fulltext_match_clause($node): string { $word = strtolower($node->word); $word = str_replace(" ", "&", $word); // phrase fix Modified: trunk/lib/WikiDB/backend/dba.php =================================================================== --- trunk/lib/WikiDB/backend/dba.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/dba.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -60,11 +60,11 @@ parent::__construct($db); } - public function lock($tables = array(), $write_lock = true) + public function lock(array $tables = array(), bool $write_lock = true) { } - public function unlock($tables = array(), $force = false) + public function unlock(array $tables = array(), bool $force = false) { } } Modified: trunk/lib/WikiDB/backend/dbaBase.php =================================================================== --- trunk/lib/WikiDB/backend/dbaBase.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/dbaBase.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -82,16 +82,16 @@ $this->_dbdb = new DbaPartition($dba, 'd'); } - public function sortable_columns() + public function sortable_columns(): array { return array('pagename', 'mtime' /*,'author_id','author'*/); } - public function lock($tables = array(), $write_lock = true) + public function lock(array $tables = array(), bool $write_lock = true) { } - public function unlock($tables = array(), $force = false) + public function unlock(array $tables = array(), bool $force = false) { } @@ -100,7 +100,7 @@ $this->_db->close(); } - public function optimize() + public function optimize(): bool { $this->_db->optimize(); return true; @@ -111,7 +111,7 @@ $this->_db->sync(); } - public function rebuild($args = false) + public function rebuild(bool $args = false): bool { if (!empty($args['all'])) { $result = parent::rebuild(); @@ -125,7 +125,7 @@ return true; } - public function check($args = false) + public function check(bool $args = false): bool { // cleanup v?Pagename UNKNOWN0x0 $errs = array(); @@ -162,7 +162,7 @@ return array_merge($errs, $this->_linkdb->check()); } - public function get_pagedata($pagename) + public function get_pagedata(string $pagename): array { $result = $this->_pagedb->get($pagename); if (!$result) { @@ -172,7 +172,7 @@ return unserialize($packed); } - public function update_pagedata($pagename, $newdata) + public function update_pagedata(string $pagename, array $newdata) { $result = $this->_pagedb->get($pagename); if ($result) { @@ -198,12 +198,12 @@ ); } - public function get_latest_version($pagename) + public function get_latest_version(string $pagename): int { return (int)$this->_pagedb->get($pagename); } - public function get_previous_version($pagename, $version) + public function get_previous_version(string $pagename, int $version): int { $versdb = &$this->_versiondb; @@ -224,7 +224,7 @@ * * @return array|false The version data, or false if specified version does not exist */ - public function get_versiondata($pagename, $version, $want_content = false) + public function get_versiondata(string $pagename, int $version, bool $want_content = false) { $data = $this->_versiondb->get((int)$version . ":$pagename"); if (empty($data) or $data == 'UNKNOWN'.chr(0)) { @@ -246,7 +246,7 @@ * Can be undone and is seen in RecentChanges. * See backend.php */ - public function delete_page($pagename) + public function delete_page(string $pagename) { /** * @var WikiRequest $request @@ -275,7 +275,7 @@ /* * Completely delete all page revisions from the database. */ - public function purge_page($pagename) + public function purge_page(string $pagename) { $pagedb = &$this->_pagedb; $versdb = &$this->_versiondb; @@ -296,7 +296,7 @@ * @param string $to Future page name */ - public function rename_page($pagename, $to) + public function rename_page(string $pagename, string $to): bool { /** * @var WikiRequest $request @@ -337,7 +337,7 @@ /* * Delete an old revision of a page. */ - public function delete_versiondata($pagename, $version) + public function delete_versiondata(string $pagename, int $version) { $versdb = &$this->_versiondb; @@ -363,7 +363,7 @@ /* * Create a new revision of a page. */ - public function set_versiondata($pagename, $version, $data) + public function set_versiondata(string $pagename, int $version, array $data) { $versdb = &$this->_versiondb; // fix broken pages @@ -396,7 +396,7 @@ $pagedb->set($pagename, (int)$latest . ':' . (int)$flags . ":$pagedata"); } - public function numPages($include_empty = false, $exclude = '') + public function numPages($include_empty = false, $exclude = ''): int { $pagedb = &$this->_pagedb; $count = 0; @@ -422,7 +422,7 @@ return $count; } - public function get_all_pages($include_empty = false, $sortby = '', $limit = '', $exclude = '') + public function get_all_pages(bool $include_empty = false, string $sortby = '', string $limit = '', string $exclude = '') { $pagedb = &$this->_pagedb; $pages = array(); @@ -473,7 +473,7 @@ * @param string $pagename Page name * @param array $links List of page(names) which page links to. */ - public function set_links($pagename, $links) + public function set_links(string $pagename, array $links) { $this->_linkdb->set_links($pagename, $links); } @@ -494,13 +494,13 @@ */ public function get_links( - $pagename, - $reversed = true, - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '', - $want_relations = false + string $pagename, + bool $reversed = true, + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '', + bool $want_relations = false ) { // optimization: if no relation at all is found, mark it in the iterator. @@ -527,7 +527,7 @@ $also_attributes = false, $only_attributes = false, $sorted = true - ) + ): array { $linkdb = &$this->_linkdb; $relations = array(); @@ -568,7 +568,7 @@ * the link key, we iterate here directly over the * linkdb and check the pagematch there. * - * @param object$pages A TextSearchQuery object for the pagename filter. + * @param object $pages A TextSearchQuery object for the pagename filter. * @param object $linkvalue A SearchQuery object (Text or Numeric) for the linkvalues, * linkto, linkfrom (=backlink), relation or attribute values. * @param string $linktype One of the 4 linktypes "linkto", @@ -580,11 +580,11 @@ * @see WikiDB::linkSearch */ public function link_search( - $pages, - $linkvalue, - $linktype, + object $pages, + object $linkvalue, + string $linktype, $relation = false, - $options = array() + array $options = array() ) { /** @@ -713,7 +713,7 @@ * @return object A WikiDB_backend_iterator. * @see WikiDB::linkSearch */ - public function relation_search($pages, $query, $options = array()) + public function relation_search(object $pages, object $query, array $options = array()) { /** * @var WikiRequest $request @@ -778,22 +778,22 @@ } } -function WikiDB_backend_dbaBase_sortby_pagename_ASC($a, $b) +function WikiDB_backend_dbaBase_sortby_pagename_ASC($a, $b): int { return strcasecmp($a, $b); } -function WikiDB_backend_dbaBase_sortby_pagename_DESC($a, $b) +function WikiDB_backend_dbaBase_sortby_pagename_DESC($a, $b): int { return strcasecmp($b, $a); } -function WikiDB_backend_dbaBase_sortby_mtime_ASC($a, $b) +function WikiDB_backend_dbaBase_sortby_mtime_ASC($a, $b): int { return WikiDB_backend_dbaBase_sortby_num($a, $b, 'mtime'); } -function WikiDB_backend_dbaBase_sortby_mtime_DESC($a, $b) +function WikiDB_backend_dbaBase_sortby_mtime_DESC($a, $b): int { return WikiDB_backend_dbaBase_sortby_num($b, $a, 'mtime'); } @@ -806,7 +806,7 @@ return WikiDB_backend_dbaBase_sortby_num($b, $a, 'hits'); } */ -function WikiDB_backend_dbaBase_sortby_num($aname, $bname, $field) +function WikiDB_backend_dbaBase_sortby_num($aname, $bname, $field): int { global $request; $dbi = $request->getDbh(); @@ -910,7 +910,7 @@ //TODO: try storing link lists as hashes rather than arrays. // backlink deletion would be faster. - public function get_links($page, $reversed = true, $want_relations = false) + public function get_links($page, $reversed = true, $want_relations = false): array { if ($want_relations) { $this->found_relations = 0; @@ -1086,7 +1086,7 @@ $this->_set_links('i', $page, $backlinks); } - public function _has_link($which, $page, $link) + public function _has_link($which, $page, $link): bool { $links = $this->_get_links($which, $page); // NOTE: only backlinks are sorted, so need to do linear search Modified: trunk/lib/WikiDB/backend/dumb/AllRevisionsIter.php =================================================================== --- trunk/lib/WikiDB/backend/dumb/AllRevisionsIter.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/dumb/AllRevisionsIter.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -35,23 +35,23 @@ /** * @var WikiDB_backend */ - private $_backend; + private WikiDB_backend $_backend; /** * @var int */ - private $_lastversion; + private int $_lastversion; /** * @var string */ - private $_pagename; + private string $_pagename; /** * @param WikiDB_backend $backend * @param string $pagename Page whose revisions to get. */ - public function __construct($backend, $pagename) + public function __construct($backend, string $pagename) { $this->_backend = &$backend; $this->_pagename = $pagename; Modified: trunk/lib/WikiDB/backend/dumb/LinkSearchIter.php =================================================================== --- trunk/lib/WikiDB/backend/dumb/LinkSearchIter.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/dumb/LinkSearchIter.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -170,7 +170,7 @@ } // get the links of each page in advance - public function _get_links($pagename) + public function _get_links($pagename): array { $links = array(); if ($this->linktype == 'attribute') { Modified: trunk/lib/WikiDB/backend/dumb/MostPopularIter.php =================================================================== --- trunk/lib/WikiDB/backend/dumb/MostPopularIter.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/dumb/MostPopularIter.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -81,7 +81,7 @@ } } -function WikiDB_backend_dumb_MostPopularIter_sortf($a, $b) +function WikiDB_backend_dumb_MostPopularIter_sortf($a, $b): int { $ahits = $bhits = 0; if (isset($a['pagedata']['hits'])) { @@ -93,7 +93,7 @@ return $bhits - $ahits; } -function WikiDB_backend_dumb_MostPopularIter_sortf_rev($a, $b) +function WikiDB_backend_dumb_MostPopularIter_sortf_rev($a, $b): int { $ahits = $bhits = 0; if (isset($a['pagedata']['hits'])) { Modified: trunk/lib/WikiDB/backend/file.php =================================================================== --- trunk/lib/WikiDB/backend/file.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/file.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -85,7 +85,7 @@ // ********************************************************************* // common file load / save functions: - protected function _pagename2filename($type, $pagename, $version = 0) + protected function _pagename2filename($type, $pagename, $version = 0): string { if ($version == 0) { return $this->_dir_names[$type] . '/' . urlencode($pagename); @@ -276,7 +276,7 @@ // ********************************************************************* // Load/Save Page-Links - protected function _loadPageLinks($pagename) + protected function _loadPageLinks($pagename): array { $pd = $this->_loadPage('links', $pagename, 0, false); if ($pd != null) { @@ -306,7 +306,7 @@ * don't think we need this...) * </dl> */ - public function get_pagedata($pagename) + public function get_pagedata(string $pagename): array { return $this->_loadPageData($pagename); } @@ -335,7 +335,7 @@ * @param array $newdata hash New meta-data. * */ - public function update_pagedata($pagename, $newdata) + public function update_pagedata(string $pagename, array $newdata) { $data = $this->get_pagedata($pagename); if (count($data) == 0) { @@ -364,7 +364,7 @@ * @return int The latest version number for the page. Returns zero if * no versions of a page exist. */ - public function get_latest_version($pagename) + public function get_latest_version(string $pagename): int { return $this->_getLatestVersion($pagename); } @@ -379,7 +379,7 @@ * * FIXED: Check if this version really exists! */ - public function get_previous_version($pagename, $version) + public function get_previous_version(string $pagename, int $version): int { $prev = ($version > 0 ? $version - 1 : 0); while ($prev and !file_exists($this->_pagename2filename('ver_data', $pagename, $prev))) { @@ -412,7 +412,7 @@ * For description of other version meta-data see WikiDB_PageRevision::get(). * @see WikiDB_PageRevision::get */ - public function get_versiondata($pagename, $version, $want_content = false) + public function get_versiondata(string $pagename, int $version, bool $want_content = false) { $vd = $this->_loadVersionData($pagename, $version); if ($vd == null) { @@ -428,7 +428,7 @@ * @param string $to Future page name */ - public function rename_page($pagename, $to) + public function rename_page(string $pagename, string $to): bool { global $request; $version = $this->_getLatestVersion($pagename); @@ -456,7 +456,7 @@ /* * See PDO for a better delete_page(), which can be undone and is seen in RecentChanges. */ - public function delete_page($pagename) + public function delete_page(string $pagename) { $this->purge_page($pagename); } @@ -466,7 +466,7 @@ * * @param string $pagename Page name. */ - public function purge_page($pagename) + public function purge_page(string $pagename) { $ver = $this->get_latest_version($pagename); while ($ver > 0) { @@ -491,7 +491,7 @@ * @param string $pagename Page name. * @param int $version int Version to delete. */ - public function delete_versiondata($pagename, $version) + public function delete_versiondata(string $pagename, int $version) { if ($this->get_latest_version($pagename) == $version) { // try to delete the latest version! @@ -522,7 +522,7 @@ * * @see get_versiondata */ - public function set_versiondata($pagename, $version, $data) + public function set_versiondata(string $pagename, int $version, array $data) { $this->_saveVersionData($pagename, $version, $data); } @@ -539,7 +539,7 @@ * @param array $newdata hash New revision metadata. * @see set_versiondata, get_versiondata */ - public function update_versiondata($pagename, $version, $newdata) + public function update_versiondata(string $pagename, int $version, array $newdata) { $data = $this->get_versiondata($pagename, $version, true); if (!$data) { @@ -561,7 +561,7 @@ * @param string $pagename Page name * @param array $links List of page(names) which page links to. */ - public function set_links($pagename, $links) + public function set_links(string $pagename, array $links) { $this->_savePageLinks($pagename, $links); } @@ -581,13 +581,13 @@ * @return object A WikiDB_backend_iterator. */ public function get_links( - $pagename, - $reversed = true, - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '', - $want_relations = false + string $pagename, + bool $reversed = true, + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '', + bool $want_relations = false ) { if ($reversed == false) { @@ -645,10 +645,10 @@ * @return object A WikiDB_backend_iterator. */ public function get_all_pages( - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '' + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ) { require_once 'lib/PageList.php'; @@ -671,12 +671,12 @@ return new WikiDB_backend_file_iter($this, $a); } - public function sortable_columns() + public function sortable_columns(): array { return array('pagename'); } - public function numPages($filter = false, $exclude = '') + public function numPages($filter = false, $exclude = ''): int { $this->_loadLatestVersions(); return count($this->_latest_versions); @@ -695,7 +695,7 @@ * * All backends <em>should</em> support write locking. */ - public function lock($tables = array(), $write_lock = true) + public function lock(array $tables = array(), bool $write_lock = true) { } @@ -707,7 +707,7 @@ * unlock() is called as many times as lock() has been. If $force is * set to true, the the database is unconditionally unlocked. */ - public function unlock($tables = array(), $force = false) + public function unlock(array $tables = array(), bool $force = false) { } @@ -732,7 +732,7 @@ * * @return bool */ - public function optimize() + public function optimize(): bool { //trigger_error("optimize: Not Implemented", E_USER_WARNING); return true; @@ -750,7 +750,7 @@ * @param bool $args * @return bool True iff database is in a consistent state. */ - public function check($args = false) + public function check(bool $args = false): bool { //trigger_error("check: Not Implemented", E_USER_WARNING); return true; @@ -766,13 +766,13 @@ * @param bool $args * @return bool True iff successful. */ - public function rebuild($args = false) + public function rebuild(bool $args = false): bool { //trigger_error("rebuild: Not Implemented", E_USER_WARNING); return true; } - public function _parse_searchwords($search) + public function _parse_searchwords($search): array { $search = strtolower(trim($search)); if (!$search) { @@ -851,7 +851,7 @@ return $this->_result; } - public function count() + public function count(): int { return count($this->_result); } Modified: trunk/lib/WikiDB/backend/flatfile.php =================================================================== --- trunk/lib/WikiDB/backend/flatfile.php 2023-07-14 10:33:04 UTC (rev 11051) +++ trunk/lib/WikiDB/backend/flatfile.php 2023-07-14 11:00:34 UTC (rev 11052) @@ -41,7 +41,7 @@ // ********************************************************************* // common file load / save functions: // FilenameForPage is from loadsave.php - protected function _pagename2filename($type, $pagename, $version = 0) + protected function _pagename2filename($type, $pagename, $version = 0): string { $fpagename = FilenameForPage($pagename); if (strstr($fpagename, "/")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <var...@us...> - 2023-07-18 14:34:41
|
Revision: 11061 http://sourceforge.net/p/phpwiki/code/11061 Author: vargenau Date: 2023-07-18 14:34:38 +0000 (Tue, 18 Jul 2023) Log Message: ----------- function get_all_pages exclude argument is not always a string, might be an array Modified Paths: -------------- trunk/lib/WikiDB/backend/PDO.php trunk/lib/WikiDB/backend/PearDB.php trunk/lib/WikiDB/backend/PearDB_ffpgsql.php trunk/lib/WikiDB/backend/dbaBase.php trunk/lib/WikiDB/backend/file.php Modified: trunk/lib/WikiDB/backend/PDO.php =================================================================== --- trunk/lib/WikiDB/backend/PDO.php 2023-07-18 14:15:47 UTC (rev 11060) +++ trunk/lib/WikiDB/backend/PDO.php 2023-07-18 14:34:38 UTC (rev 11061) @@ -875,7 +875,7 @@ bool $include_empty = false, string $sortby = '', string $limit = '', - string $exclude = '' + $exclude = '' ) { $dbh = &$this->_dbh; Modified: trunk/lib/WikiDB/backend/PearDB.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB.php 2023-07-18 14:15:47 UTC (rev 11060) +++ trunk/lib/WikiDB/backend/PearDB.php 2023-07-18 14:34:38 UTC (rev 11061) @@ -178,7 +178,7 @@ ), DB_FETCHMODE_ASSOC ); - return $result ? $this->_extract_page_data($result) : false; + return $result ? $this->_extract_page_data($result) : array(); } public function _extract_page_data($data): array @@ -336,7 +336,7 @@ . " AND pagename='%s'" . " AND version < %d" . " ORDER BY version DESC", - /* Non portable and useless anyway with getOne + /* Non-portable and useless anyway with getOne . " LIMIT 1", */ $dbh->escapeSimple($pagename), @@ -596,7 +596,7 @@ bool $include_empty = false, string $sortby = '', string $limit = '', - string $exclude = '', + $exclude = '', bool $want_relations = false ) { @@ -669,7 +669,7 @@ bool $include_empty = false, string $sortby = '', string $limit = '', - string $exclude = '' + $exclude = '' ) { $dbh = &$this->_dbh; @@ -1002,7 +1002,7 @@ * the link database. * * @param string $pagename Page name. - * i.e save_page('') and DELETE nonempty id + * i.e. save_page('') and DELETE nonempty id * Can be undone and is seen in RecentChanges. */ @@ -1108,7 +1108,7 @@ * * @see _lock_database */ - public function unlock(array $tables = array(), bool $force = false) + public function unlock($tables = array(), bool $force = false) { if ($this->_lock_count == 0) { return; Modified: trunk/lib/WikiDB/backend/PearDB_ffpgsql.php =================================================================== --- trunk/lib/WikiDB/backend/PearDB_ffpgsql.php 2023-07-18 14:15:47 UTC (rev 11060) +++ trunk/lib/WikiDB/backend/PearDB_ffpgsql.php 2023-07-18 14:34:38 UTC (rev 11061) @@ -396,7 +396,7 @@ bool $include_empty = false, string $sortby = '', string $limit = '', - string $exclude = '' + $exclude = '' ) { $dbh = &$this->_dbh; Modified: trunk/lib/WikiDB/backend/dbaBase.php =================================================================== --- trunk/lib/WikiDB/backend/dbaBase.php 2023-07-18 14:15:47 UTC (rev 11060) +++ trunk/lib/WikiDB/backend/dbaBase.php 2023-07-18 14:34:38 UTC (rev 11061) @@ -422,7 +422,11 @@ return $count; } - public function get_all_pages(bool $include_empty = false, string $sortby = '', string $limit = '', string $exclude = '') + public function get_all_pages( + bool $include_empty = false, + string $sortby = '', + string $limit = '', + $exclude = '') { $pagedb = &$this->_pagedb; $pages = array(); Modified: trunk/lib/WikiDB/backend/file.php =================================================================== --- trunk/lib/WikiDB/backend/file.php 2023-07-18 14:15:47 UTC (rev 11060) +++ trunk/lib/WikiDB/backend/file.php 2023-07-18 14:34:38 UTC (rev 11061) @@ -648,7 +648,7 @@ bool $include_empty = false, string $sortby = '', string $limit = '', - string $exclude = '' + $exclude = '' ) { require_once 'lib/PageList.php'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |