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. |