From: <var...@us...> - 2023-07-14 11:09:41
|
Revision: 11053 http://sourceforge.net/p/phpwiki/code/11053 Author: vargenau Date: 2023-07-14 11:09:38 +0000 (Fri, 14 Jul 2023) Log Message: ----------- lib/WikiDB: PHP 7: add types for function arguments and return Modified Paths: -------------- trunk/lib/WikiDB/PDO.php trunk/lib/WikiDB/SQL.php trunk/lib/WikiDB/backend.php Modified: trunk/lib/WikiDB/PDO.php =================================================================== --- trunk/lib/WikiDB/PDO.php 2023-07-14 11:00:34 UTC (rev 11052) +++ trunk/lib/WikiDB/PDO.php 2023-07-14 11:09:38 UTC (rev 11053) @@ -101,7 +101,7 @@ return str_replace("'", "\'", $in); } - public function isOpen() + public function isOpen(): bool { /** * @var WikiRequest $request Modified: trunk/lib/WikiDB/SQL.php =================================================================== --- trunk/lib/WikiDB/SQL.php 2023-07-14 11:00:34 UTC (rev 11052) +++ trunk/lib/WikiDB/SQL.php 2023-07-14 11:09:38 UTC (rev 11053) @@ -54,7 +54,7 @@ parent::__construct($backend, $dbparams); } - public static function view_dsn($dsn = false) + public static function view_dsn($dsn = false): string { if (!$dsn) { $dsninfo = DB::parseDSN($GLOBALS['DBParams']['dsn']); @@ -97,7 +97,7 @@ return $this->_backend->_dbh->escapeSimple($s); } - public function isOpen() + public function isOpen(): bool { /** * @var WikiRequest $request Modified: trunk/lib/WikiDB/backend.php =================================================================== --- trunk/lib/WikiDB/backend.php 2023-07-14 11:00:34 UTC (rev 11052) +++ trunk/lib/WikiDB/backend.php 2023-07-14 11:09:38 UTC (rev 11053) @@ -91,7 +91,7 @@ * don't think we need this...) * </dl> */ - abstract public function get_pagedata($pagename); + abstract public function get_pagedata(string $pagename): array; /** * Update the page meta-data. @@ -116,7 +116,7 @@ * @param string $pagename Page name. * @param array $newdata hash New meta-data. */ - abstract public function update_pagedata($pagename, $newdata); + abstract public function update_pagedata(string $pagename, array $newdata); /** * Get the current version number for a page. @@ -125,7 +125,7 @@ * @return int The latest version number for the page. Returns zero if * no versions of a page exist. */ - abstract public function get_latest_version($pagename); + abstract public function get_latest_version(string $pagename): int; /** * Get preceding version number. @@ -135,7 +135,7 @@ * @return int The version number of the version in the database which * immediately precedes $version. */ - abstract public function get_previous_version($pagename, $version); + abstract public function get_previous_version(string $pagename, int $version): int; /** * Get revision meta-data and content. @@ -161,7 +161,7 @@ * For description of other version meta-data see WikiDB_PageRevision::get(). * @see WikiDB_PageRevision::get */ - abstract public function get_versiondata($pagename, $version, $want_content = false); + abstract public function get_versiondata(string $pagename, int $version, bool $want_content = false); /** * Create a new page revision. @@ -175,7 +175,7 @@ * * @see get_versiondata */ - abstract public function set_versiondata($pagename, $version, $data); + abstract public function set_versiondata(string $pagename, int $version, array $data); /** * Update page version meta-data. @@ -189,7 +189,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) { @@ -218,7 +218,7 @@ * @param string $pagename Page name. * @param int $version int Version to delete. */ - abstract public function delete_versiondata($pagename, $version); + abstract public function delete_versiondata(string $pagename, int $version); /** * Rename page in the database. @@ -226,7 +226,7 @@ * @param string $pagename Current page name * @param string $to Future page name */ - abstract public function rename_page($pagename, $to); + abstract public function rename_page(string $pagename, string $to); /** * Delete page from the database with backup possibility. @@ -237,7 +237,7 @@ * i.e save_page('') and DELETE nonempty id * Can be undone and is seen in RecentChanges. */ - abstract public function delete_page($pagename); + abstract public function delete_page(string $pagename); /** * Delete page (and all its revisions) from the database. @@ -244,7 +244,7 @@ * * @param string $pagename Page name. */ - abstract public function purge_page($pagename); + abstract public function purge_page(string $pagename); /** * Find pages which link to or are linked from a page. @@ -261,13 +261,13 @@ * @return object A WikiDB_backend_iterator. */ abstract 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 ); /** @@ -276,7 +276,7 @@ * @param string $pagename Page name * @param array $links List of page(names) which page links to. */ - abstract public function set_links($pagename, $links); + abstract public function set_links(string $pagename, array $links); /** * Get all revisions of a page. @@ -284,7 +284,7 @@ * @param string $pagename The page name. * @return object A WikiDB_backend_iterator. */ - public function get_all_revisions($pagename) + public function get_all_revisions(string $pagename) { include_once 'lib/WikiDB/backend/dumb/AllRevisionsIter.php'; return new WikiDB_backend_dumb_AllRevisionsIter($this, $pagename); @@ -311,10 +311,10 @@ * @return object A WikiDB_backend_iterator. */ abstract public function get_all_pages( - $include_empty = false, - $sortby = '', - $limit = '', - $exclude = '' + bool $include_empty = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ); /** @@ -338,11 +338,11 @@ * @see WikiDB::titleSearch */ public function text_search( - $search, - $fulltext = false, - $sortby = '', - $limit = '', - $exclude = '' + object $search, + bool $fulltext = false, + string $sortby = '', + string $limit = '', + string $exclude = '' ) { // This method implements a simple linear search @@ -374,7 +374,7 @@ * @return object A WikiDB_backend_iterator. * @see WikiDB::linkSearch */ - public function link_search($pages, $linkvalue, $linktype, $relation = false, $options = array()) + public function link_search($pages, $linkvalue, string $linktype, $relation = false, array $options = array()) { include_once 'lib/WikiDB/backend/dumb/LinkSearchIter.php'; $pageiter = $this->text_search($pages); @@ -391,7 +391,7 @@ * @param string $sortby * @return object A WikiDB_backend_iterator. */ - public function most_popular($limit = 20, $sortby = '-hits') + public function most_popular(int $limit = 20, string $sortby = '-hits') { // This is method fetches all pages, then // sorts them by hit count. @@ -412,7 +412,7 @@ * @return object A WikiDB_backend_iterator. * @see WikiDB::mostRecent */ - public function most_recent($params) + public function most_recent(array $params) { // This method is very inefficient and searches through // all pages for the most recent changes. @@ -444,7 +444,7 @@ * * All backends <em>should</em> support write locking. */ - abstract public function lock($tables = array(), $write_lock = true); + abstract public function lock(array $tables = array(), bool $write_lock = true); /** * Unlock backend database. @@ -454,7 +454,7 @@ * unlock() is called as many times as lock() has been. If $force is * set to true, the the database is unconditionally unlocked. */ - abstract public function unlock($tables = array(), $force = false); + abstract public function unlock(array $tables = array(), bool $force = false); /** * Close database. @@ -475,7 +475,7 @@ * * @return bool */ - public function optimize() + public function optimize(): bool { return true; } @@ -492,7 +492,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 { return true; } @@ -507,7 +507,7 @@ * @param bool $args * @return bool True iff successful. */ - public function rebuild($args = false) + public function rebuild(bool $args = false): bool { /** * @var WikiRequest $request @@ -534,7 +534,7 @@ return true; } - public function _parse_searchwords($search) + public function _parse_searchwords($search): array { $search = strtolower(trim($search)); if (!$search) { @@ -559,7 +559,7 @@ * Usage: * list($offset,$count) = $this->limit($args['limit']); */ - public static function limit($limit) + public static function limit($limit): array { if (strstr($limit, ',')) { list($from, $limit) = explode(',', $limit); @@ -654,13 +654,13 @@ return ''; } - public function sortable_columns() + public function sortable_columns(): array { return array('pagename' /*,'mtime','author_id','author'*/); } // adds surrounding quotes - public function quote($s) + public function quote($s): string { return "'" . $s . "'"; } @@ -671,7 +671,7 @@ return $s; } - public function isSQL() + public function isSQL(): bool { return in_array(DATABASE_TYPE, array('SQL', 'PDO')); } @@ -746,7 +746,7 @@ */ abstract public function next(); - public function count() + public function count(): int { if (!empty($this->_pages)) { return count($this->_pages); @@ -800,28 +800,28 @@ $this->stoplisted = array(); } - public function _quote($word) + public function _quote($word): string { return preg_quote($word, "/"); } //TODO: use word anchors - public function EXACT($word) + public function EXACT($word): string { return "^" . $this->_quote($word) . "$"; } - public function STARTS_WITH($word) + public function STARTS_WITH($word): string { return "^" . $this->_quote($word); } - public function ENDS_WITH($word) + public function ENDS_WITH($word): string { return $this->_quote($word) . "$"; } - public function WORD($word) + public function WORD($word): string { return $this->_quote($word); } @@ -832,7 +832,7 @@ } //TESTME - public function _pagename_match_clause($node) + public function _pagename_match_clause($node): string { $method = $node->op; $word = $this->$method($node->word); @@ -842,7 +842,7 @@ /* Eliminate stoplist words. * Keep a list of Stoplisted words to inform the poor user. */ - public function isStoplisted($node) + public function isStoplisted($node): bool { // check only on WORD or EXACT fulltext search if ($node->op != 'WORD' and $node->op != 'EXACT') { @@ -861,7 +861,7 @@ */ class WikiDB_backend_search_sql extends WikiDB_backend_search { - public function _pagename_match_clause($node) + public function _pagename_match_clause($node): string { // word already quoted by TextSearchQuery_node_word::sql_quote() $word = $node->sql(); @@ -874,7 +874,7 @@ } } - public function _fulltext_match_clause($node) + public function _fulltext_match_clause($node): string { // force word-style %word% for fulltext search $dbh = &$this->_dbh; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |