From b26fa766757af4a8ceeba4c0d9aa139c7c554ece Mon Sep 17 00:00:00 2001 From: rurban Date: Fri, 9 Jul 2004 10:06:50 +0000 Subject: [PATCH] Use backend specific sortby and sortable_columns method, to be able to select between native (Db backend) and custom (PageList) sorting. Fixed PageList::AddPageList (missed the first) Added the author/creator.. name to AllPagesBy... display no pages if none matched. Improved dba and file sortby(). Use &$request reference git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@3889 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/PageList.php | 65 ++++++++++++--------- lib/WikiDB.php | 73 ++++++++--------------- lib/WikiDB/backend.php | 85 ++++++++++++++++++++++++--- lib/WikiDB/backend/ADODB.php | 14 +++-- lib/WikiDB/backend/PearDB.php | 23 ++++---- lib/WikiDB/backend/cvs.php | 14 ++--- lib/WikiDB/backend/dba.php | 3 +- lib/WikiDB/backend/dbaBase.php | 77 ++++++++++++++++++------ lib/WikiDB/backend/file.php | 104 ++++++++------------------------- lib/plugin/AllPages.php | 36 +++++++----- 10 files changed, 273 insertions(+), 221 deletions(-) diff --git a/lib/PageList.php b/lib/PageList.php index c68dfd14f..bbfa773cf 100644 --- a/lib/PageList.php +++ b/lib/PageList.php @@ -1,4 +1,4 @@ -_field, PageList::sortable_columns())) { + if (1 /* or in_array($this->_field, PageList::sortable_columns())*/) { // multiple comma-delimited sortby args: "+hits,+pagename" // asc or desc: +pagename, -pagename $sortby = PageList::sortby($this->_field, 'flip_order'); @@ -119,7 +119,7 @@ class _PageList_Column_base { function button_heading ($pagelist, $colNum) { global $WikiTheme, $request; // allow sorting? - if (1 or in_array($this->_field, PageList::sortable_columns())) { + if (1 /* or in_array($this->_field, PageList::sortable_columns()) */) { // multiple comma-delimited sortby args: "+hits,+pagename" $src = false; $noimg_src = $WikiTheme->getButtonURL('no_order'); @@ -660,7 +660,7 @@ class PageList { return; } // enforce view permission - if (!mayAccessPage('view',$page_handle->getName())) + if (!mayAccessPage('view', $page_handle->getName())) return; $group = (int)($i / $this->_group_rows); @@ -683,15 +683,16 @@ class PageList { function addPages ($page_iter) { //Todo: if limit check max(strlen(pagename)) - while ($page = $page_iter->next()) + while ($page = $page_iter->next()) { $this->addPage($page); + } } function addPageList (&$list) { - if (!isset($list)) return; // Protect reset from a null arg - reset ($list); - while ($page = next($list)) + if (empty($list)) return; // Protect reset from a null arg + foreach ($list as $page) { $this->addPage((string)$page); + } } function maxLen() { @@ -731,11 +732,12 @@ class PageList { } /** Now all columns are sortable. - * These are the colums which have native WikiDB backend methods. + * These are the colums which have native WikiDB backend methods. + * FIXME: use this method at the db backends */ - function sortable_columns() { - return array('pagename','mtime','hits'); - } + //function sortable_columns() { + // return array('pagename','mtime','hits'); + //} /** * Handle sortby requests for the DB iterator and table header links. @@ -775,8 +777,15 @@ class PageList { ($GLOBALS['request']->getArg('sortby') and strstr($GLOBALS['request']->getArg('sortby'),$column))); } elseif ($action == 'db') { - // native sort possible? - if (in_array($column, PageList::sortable_columns())) + // native sort possible? + $sortable_columns = $GLOBALS['request']->_dbi->_backend->sortable_columns(); + /* + if (method_exists($this,'sortable_columns')) + $sortable_columns = $this->sortable_columns(); + else + $sortable_columns = PageList::sortable_columns(); + */ + if (in_array($column, $sortable_columns)) // asc or desc: +pagename, -pagename return $column . ($order == '+' ? ' ASC' : ' DESC'); else @@ -786,11 +795,11 @@ class PageList { } // echo implode(":",explodeList("Test*",array("xx","Test1","Test2"))); - function explodePageList($input, $perm = false, $sortby=false, $limit=false) { + function explodePageList($input, $include_empty = false, $sortby=false, $limit=false) { // expand wildcards from list of all pages if (preg_match('/[\?\*]/',$input)) { $dbi = $GLOBALS['request']->getDbh(); - $allPagehandles = $dbi->getAllPages($perm,$sortby,$limit); + $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit); while ($pagehandle = $allPagehandles->next()) { $allPages[] = $pagehandle->getName(); } @@ -801,9 +810,9 @@ class PageList { } } - function allPagesByAuthor($wildcard, $perm=false, $sortby=false, $limit=false) { + function allPagesByAuthor(&$wildcard, $include_empty=false, $sortby=false, $limit=false) { $dbi = $GLOBALS['request']->getDbh(); - $allPagehandles = $dbi->getAllPages($perm, $sortby, $limit); + $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit); $allPages = array(); if ($wildcard === '[]') { $wildcard = $GLOBALS['request']->_user->getAuthenticatedId(); @@ -821,13 +830,14 @@ class PageList { $allPages[] = $name; } } + // TODO: purge versiondata_cache } return $allPages; } - function allPagesByOwner($wildcard, $perm=false, $sortby=false, $limit=false) { + function allPagesByOwner(&$wildcard, $include_empty=false, $sortby=false, $limit=false) { $dbi = $GLOBALS['request']->getDbh(); - $allPagehandles = $dbi->getAllPages($perm, $sortby, $limit); + $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit); $allPages = array(); if ($wildcard === '[]') { $wildcard = $GLOBALS['request']->_user->getAuthenticatedId(); @@ -849,9 +859,9 @@ class PageList { return $allPages; } - function allPagesByCreator($wildcard, $perm=false, $sortby=false, $limit=false) { + function allPagesByCreator(&$wildcard, $include_empty=false, $sortby=false, $limit=false) { $dbi = $GLOBALS['request']->getDbh(); - $allPagehandles = $dbi->getAllPages($perm, $sortby, $limit); + $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit); $allPages = array(); if ($wildcard === '[]') { $wildcard = $GLOBALS['request']->_user->getAuthenticatedId(); @@ -1080,7 +1090,7 @@ class PageList { if (count($this->_sortby) > 0) { $need_sort = 0; foreach ($this->_sortby as $col) { - if (!$this->sortby($col,'db')) + if (!$this->sortby($col, 'db')) $need_sort = 1; } if ($need_sort) { @@ -1091,10 +1101,10 @@ class PageList { } function limit($limit) { - if (strstr($limit,',')) - return split(',',$limit); + if (strstr($limit, ',')) + return split(',', $limit); else - return array(0,$limit); + return array(0, $limit); } // make a table given the caption @@ -1282,6 +1292,9 @@ extends PageList { } // $Log: not supported by cvs2svn $ +// Revision 1.102 2004/07/08 21:32:35 rurban +// Prevent from more warnings, minor db and sort optimizations +// // Revision 1.101 2004/07/08 19:04:41 rurban // more unittest fixes (file backend, metadata RatingsDb) // diff --git a/lib/WikiDB.php b/lib/WikiDB.php index 66205ea13..3fc50e47b 100644 --- a/lib/WikiDB.php +++ b/lib/WikiDB.php @@ -1,5 +1,5 @@ The back-end type. Current supported types are: *
*
SQL - *
Generic SQL backend based on the PEAR/DB database abstraction - * library. + *
Generic SQL backend based on the PEAR/DB database abstraction + * library. (More stable and conservative) + *
ADODB + *
Another generic SQL backend. (More current features are tested here. Much faster) *
dba - *
Dba based backend. + *
Dba based backend. The default and by far the fastest. + *
cvs + *
+ *
file + *
flat files *
* *
dsn - *
(Used by the SQL backend.) + *
(Used by the SQL and ADODB backends.) * The DSN specifying which database to connect to. * *
prefix - *
Prefix to be prepended to database table (and file names). + *
Prefix to be prepended to database tables (and file names). * *
directory *
(Used by the dba backend.) * Which directory db files reside in. * *
timeout - *
(Used only by the dba backend so far. FIXME!) - * Timeout in seconds for opening (and obtaining lock) on the - * db files. + *
Used only by the dba backend so far. + * And: When optimizing mysql it closes timed out mysql processes. + * otherwise only used for dba: Timeout in seconds for opening (and + * obtaining lock) on the dbm file. * *
dba_handler *
(Used by the dba backend.) @@ -239,9 +246,6 @@ class WikiDB { * * Gets the set of all pages with non-default contents. * - * FIXME: do we need this? I think so. The simple searches - * need this stuff. - * * @access public * * @param boolean $include_defaulted Normally pages whose most @@ -252,8 +256,8 @@ class WikiDB { * @return WikiDB_PageIterator A WikiDB_PageIterator which contains all pages * in the WikiDB which have non-default contents. */ - function getAllPages($include_defaulted=false, $sortby=false, $limit=false) { - $result = $this->_backend->get_all_pages($include_defaulted,$sortby,$limit); + function getAllPages($include_empty=false, $sortby=false, $limit=false) { + $result = $this->_backend->get_all_pages($include_empty, $sortby, $limit); return new WikiDB_PageIterator($this, $result); } @@ -328,11 +332,8 @@ class WikiDB { * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching * pages. */ - function mostPopular($limit = 20, $sortby = '') { - // we don't support sortby=mtime here - if (strstr($sortby,'mtime')) - $sortby = ''; - $result = $this->_backend->most_popular($limit, $sortby); + function mostPopular($limit = 20) { + $result = $this->_backend->most_popular($limit); return new WikiDB_PageIterator($this, $result); } @@ -1601,36 +1602,7 @@ class WikiDB_PageIterator $this->free(); return $result; } - - // Not yet used and problematic. Order should be set in the query, not afterwards. - // See PageList::sortby - function setSortby ($arg = false) { - if (!$arg) { - $arg = @$_GET['sortby']; - if ($arg) { - $sortby = substr($arg,1); - $order = substr($arg,0,1)=='+' ? 'ASC' : 'DESC'; - } - } - if (is_array($arg)) { // array('mtime' => 'desc') - $sortby = $arg[0]; - $order = $arg[1]; - } else { - $sortby = $arg; - $order = 'ASC'; - } - // available column types to sort by: - // todo: we must provide access methods for the generic dumb/iterator - $this->_types = explode(',','pagename,mtime,hits,version,author,locked,minor,markup'); - if (in_array($sortby,$this->_types)) - $this->_options['sortby'] = $sortby; - else - trigger_error(sprintf("Argument %s '%s' ignored",'sortby',$sortby), E_USER_WARNING); - if (in_array(strtoupper($order),'ASC','DESC')) - $this->_options['order'] = strtoupper($order); - else - trigger_error(sprintf("Argument %s '%s' ignored",'order',$order), E_USER_WARNING); - } + }; @@ -1892,6 +1864,9 @@ class WikiDB_cache }; // $Log: not supported by cvs2svn $ +// Revision 1.78 2004/07/08 21:32:35 rurban +// Prevent from more warnings, minor db and sort optimizations +// // Revision 1.77 2004/07/08 19:04:42 rurban // more unittest fixes (file backend, metadata RatingsDb) // diff --git a/lib/WikiDB/backend.php b/lib/WikiDB/backend.php index c2e2a24e4..fcf6cc6e9 100644 --- a/lib/WikiDB/backend.php +++ b/lib/WikiDB/backend.php @@ -1,5 +1,5 @@ get_all_pages(false,'hits DESC'); + $pages = $this->get_all_pages(false, 'hits DESC', $limit); return new WikiDB_backend_dumb_MostPopularIter($this, $pages, $limit); } @@ -443,21 +443,92 @@ class WikiDB_backend } return array($words, $exclude); } - + + /** + * Split the given limit parameter into offset,pagesize. (offset is optional. default: 0) + * Duplicate the PageList function here to avoid loading the whole PageList.php + * Usage: + * list($offset,$pagesize) = $this->limit($args['limit']); + */ + function limit($limit) { + if (strstr($limit, ',')) + return split(',', $limit); + else + return array(0, $limit); + } + + /** + * Handle sortby requests for the DB iterator and table header links. + * Prefix the column with + or - like "+pagename","-mtime", ... + * supported actions: 'flip_order' "mtime" => "+mtime" => "-mtime" ... + * 'db' "-pagename" => "pagename DESC" + * In PageList all columns are sortable. (patch by DanFr) + * Here with the backend only some, the rest is delayed to PageList. + * (some kind of DumbIter) + * Duplicate the PageList function here to avoid loading the whole + * PageList.php, and it forces the backend specific sortable_columns() + */ + function sortby ($column, $action) { + if (empty($column)) return ''; + //support multiple comma-delimited sortby args: "+hits,+pagename" + if (strstr($column,',')) { + $result = array(); + foreach (explode(',',$column) as $col) { + $result[] = $this->sortby($col,$action); + } + return join(",",$result); + } + if (substr($column,0,1) == '+') { + $order = '+'; $column = substr($column,1); + } elseif (substr($column,0,1) == '-') { + $order = '-'; $column = substr($column,1); + } + // default order: +pagename, -mtime, -hits + if (empty($order)) + if (in_array($column,array('mtime','hits'))) + $order = '-'; + else + $order = '+'; + if ($action == 'flip_order') { + return ($order == '+' ? '-' : '+') . $column; + } elseif ($action == 'init') { + $this->_sortby[$column] = $order; + return $order . $column; + } elseif ($action == 'check') { + return (!empty($this->_sortby[$column]) or + ($GLOBALS['request']->getArg('sortby') and + strstr($GLOBALS['request']->getArg('sortby'),$column))); + } elseif ($action == 'db') { + // native sort possible? + $sortable_columns = $this->sortable_columns(); + if (in_array($column, $sortable_columns)) + // asc or desc: +pagename, -pagename + return $column . ($order == '+' ? ' ASC' : ' DESC'); + else + return ''; + } + return ''; + } + + function sortable_columns() { + return array('pagename'/*,'mtime','author_id','author'*/); + } + }; /** * Iterator returned by backend methods which (possibly) return * multiple records. * - * FIXME: this should be two seperate classes: page_iter and version_iter. + * FIXME: This might be two seperate classes: page_iter and version_iter. + * For the versions we have WikiDB_backend_dumb_AllRevisionsIter. */ class WikiDB_backend_iterator { /** * Get the next record in the iterator set. * - * This returns a hash. The has may contain the following keys: + * This returns a hash. The hash may contain the following keys: *
*
pagename
(string) the page name *
version
(int) the version number diff --git a/lib/WikiDB/backend/ADODB.php b/lib/WikiDB/backend/ADODB.php index 1155fe4b5..09030f766 100644 --- a/lib/WikiDB/backend/ADODB.php +++ b/lib/WikiDB/backend/ADODB.php @@ -1,5 +1,5 @@ _dbh; extract($this->_table_names); //if ($limit) $limit = "LIMIT $limit"; //else $limit = ''; - $orderby = PageList::sortby($sortby,'db'); + $orderby = $this->sortby($sortby, 'db'); if ($orderby) $orderby = 'ORDER BY ' . $orderby; $dbh->SetFetchMode(ADODB_FETCH_ASSOC); if (strstr($orderby, 'mtime')) { // was ' mtime' @@ -569,8 +569,7 @@ extends WikiDB_backend } if ($limit) { // extract from,count from limit - require_once("lib/PageList.php"); - list($offset,$count) = PageList::limit($limit); + list($offset,$count) = $this->limit($limit); $result = $dbh->SelectLimit($sql, $count, $offset); } else { $result = $dbh->Execute($sql); @@ -648,7 +647,7 @@ extends WikiDB_backend } else { $where = " AND hits > 0"; } - if ($sortby) $orderby = " ORDER BY " . PageList::sortby($sortby,'db'); + if ($sortby) $orderby = " ORDER BY " . $this->sortby($sortby, 'db'); else $orderby = " ORDER BY hits $order"; $limit = $limit ? $limit : -1; @@ -1143,6 +1142,9 @@ extends WikiDB_backend_ADODB_generic_iter } // $Log: not supported by cvs2svn $ +// Revision 1.41 2004/07/08 21:32:35 rurban +// Prevent from more warnings, minor db and sort optimizations +// // Revision 1.40 2004/07/08 16:56:16 rurban // use the backendType abstraction // diff --git a/lib/WikiDB/backend/PearDB.php b/lib/WikiDB/backend/PearDB.php index c7df39ad2..5d2dcddb5 100644 --- a/lib/WikiDB/backend/PearDB.php +++ b/lib/WikiDB/backend/PearDB.php @@ -1,5 +1,5 @@ quoteString($pagename); @@ -463,15 +462,15 @@ extends WikiDB_backend return new WikiDB_backend_PearDB_iter($this, $result); } - function get_all_pages($include_deleted=false,$sortby=false,$limit=false) { + function get_all_pages($include_deleted=false, $sortby=false, $limit=false) { $dbh = &$this->_dbh; extract($this->_table_names); // Limit clause is NOT portable! // if ($limit) $limit = "LIMIT $limit"; // else $limit = ''; - $orderby = PageList::sortby($sortby,'db'); + $orderby = $this->sortby($sortby, 'db'); if ($orderby) $orderby = 'ORDER BY ' . $orderby; - if (strstr($orderby,'mtime')) { // multiple columns possible + if (strstr($orderby, 'mtime ')) { // multiple columns possible if ($include_deleted) { $sql = "SELECT " . $this->page_tbl_fields @@ -505,8 +504,7 @@ extends WikiDB_backend } if ($limit) { // extract from,count from limit - require_once("lib/PageList.php"); - list($from,$count) = PageList::limit($limit); + list($from,$count) = $this->limit($limit); $result = $dbh->limitQuery($sql, $from, $count); } else { $result = $dbh->query($sql); @@ -570,7 +568,7 @@ extends WikiDB_backend /** * Find highest or lowest hit counts. */ - function most_popular($limit=false,$sortby = '') { + function most_popular($limit=false) { $dbh = &$this->_dbh; extract($this->_table_names); $order = "DESC"; @@ -581,8 +579,7 @@ extends WikiDB_backend } else { $where = " AND hits > 0"; } - if ($sortby) $orderby = ' ORDER BY ' . PageList::sortby($sortby,'db'); - else $orderby = " ORDER BY hits $order"; + $orderby = " ORDER BY hits $order"; //$limitclause = $limit ? " LIMIT $limit" : ''; $sql = "SELECT " . $this->page_tbl_fields @@ -591,8 +588,7 @@ extends WikiDB_backend . $where . $orderby; if ($limit) { - require_once("lib/PageList.php"); - list($from,$count) = PageList::limit($limit); + list($from,$count) = $this->limit($limit); $result = $dbh->limitQuery($sql, $from, $count); } else { $result = $dbh->query($sql); @@ -1034,6 +1030,9 @@ extends WikiDB_backend_PearDB_generic_iter } } // $Log: not supported by cvs2svn $ +// Revision 1.59 2004/07/08 21:32:36 rurban +// Prevent from more warnings, minor db and sort optimizations +// // Revision 1.58 2004/07/08 16:56:16 rurban // use the backendType abstraction // diff --git a/lib/WikiDB/backend/cvs.php b/lib/WikiDB/backend/cvs.php index 9693d7f0d..50d0e2be1 100644 --- a/lib/WikiDB/backend/cvs.php +++ b/lib/WikiDB/backend/cvs.php @@ -1,5 +1,5 @@ _getAllFileNamesInDir( $this->_docDir )); } @@ -421,7 +419,7 @@ extends WikiDB_backend } } - function most_popular($limit,$sortby = '') { + function most_popular($limit) { // TODO: needs to be tested ... $mp = $this->_getMostPopular(); if ($limit < 0){ diff --git a/lib/WikiDB/backend/dba.php b/lib/WikiDB/backend/dba.php index 86c0367af..2f08d76ab 100644 --- a/lib/WikiDB/backend/dba.php +++ b/lib/WikiDB/backend/dba.php @@ -1,7 +1,6 @@ -_db = &$dba; - // FIXME: page and version tables should be in their own files, probably. + // TODO: page and version tables should be in their own files, probably. // We'll pack them all in one for now (testing). + // 2004-07-09 10:07:30 rurban: It's fast enough this way. $this->_pagedb = new DbaPartition($dba, 'p'); $this->_versiondb = new DbaPartition($dba, 'v'); $linkdbpart = new DbaPartition($dba, 'l'); @@ -55,6 +55,10 @@ extends WikiDB_backend $this->_dbdb = new DbaPartition($dba, 'd'); } + function sortable_columns() { + return array('pagename','mtime'/*,'author_id','author'*/); + } + function close() { $this->_db->close(); } @@ -84,7 +88,6 @@ extends WikiDB_backend $data = unserialize($packed); return $data; } - function update_pagedata($pagename, $newdata) { $result = $this->_pagedb->get($pagename); @@ -122,10 +125,17 @@ extends WikiDB_backend } return false; } - - function get_versiondata($pagename, $version, $want_content = false) { + + //check $want_content + function get_versiondata($pagename, $version, $want_content=false) { $data = $this->_versiondb->get((int)$version . ":$pagename"); - return $data ? unserialize($data) : false; + if (empty($data)) return false; + else { + $data = unserialize($data); + if (!$want_content) + $data['%content'] = !empty($data['%content']); + return $data; + } } /** @@ -202,9 +212,9 @@ extends WikiDB_backend $pagedb->set($pagename, (int)$latest . ':' . (int)$flags . ":$pagedata"); } - function get_all_pages($include_deleted = false, $orderby='pagename') { + //FIXME: support limit + function get_all_pages($include_deleted = false, $sortby=false, $limit=false) { $pagedb = &$this->_pagedb; - $pages = array(); for ($page = $pagedb->firstkey(); $page!== false; $page = $pagedb->nextkey()) { if (!$page) { @@ -215,19 +225,22 @@ extends WikiDB_backend if (!$include_deleted) { if (!($data = $pagedb->get($page))) continue; list($latestversion,$flags,) = explode(':', $data, 3); + unset($data); if ($latestversion == 0 || $flags != 0) continue; // current content is empty } $pages[] = $page; } - usort($pages, 'WikiDB_backend_dbaBase_sortbypagename'); + $sortby = $this->sortby($sortby, 'db'); + if ($sortby and !strstr($sortby, "hits ")) { // check for which column to sortby + usort($pages, 'WikiDB_backend_dbaBase_sortby_'.str_replace(' ','_',$sortby)); + } return new WikiDB_backend_dbaBase_pageiter($this, $pages); } function set_links($pagename, $links) { $this->_linkdb->set_links($pagename, $links); } - function get_links($pagename, $reversed = true) { /* @@ -242,12 +255,42 @@ extends WikiDB_backend } }; -function WikiDB_backend_dbaBase_sortbypagename ($a, $b) { - $aname = $a['pagename']; - $bname = $b['pagename']; - return strcasecmp($aname, $bname); +function WikiDB_backend_dbaBase_sortby_pagename_ASC ($a, $b) { + return strcasecmp($a, $b); +} +function WikiDB_backend_dbaBase_sortby_pagename_DESC ($a, $b) { + return strcasecmp($b, $a); +} +function WikiDB_backend_dbaBase_sortby_mtime_ASC ($a, $b) { + return WikiDB_backend_dbaBase_sortby_num($a, $b, 'mtime'); +} +function WikiDB_backend_dbaBase_sortby_mtime_DESC ($a, $b) { + return WikiDB_backend_dbaBase_sortby_num($b, $a, 'mtime'); +} +/* +function WikiDB_backend_dbaBase_sortby_hits_ASC ($a, $b) { + return WikiDB_backend_dbaBase_sortby_num($a, $b, 'hits'); +} +function WikiDB_backend_dbaBase_sortby_hits_DESC ($a, $b) { + return WikiDB_backend_dbaBase_sortby_num($b, $a, 'hits'); +} +*/ +function WikiDB_backend_dbaBase_sortby_num($aname, $bname, $field) { + global $request; + $dbi = $request->getDbh(); + // fields are stored in versiondata + $av = $dbi->_backend->get_latest_version($aname); + $bv = $dbi->_backend->get_latest_version($bname); + $a = $dbi->_backend->get_versiondata($aname, $av, false); + if (!$a) return 0; + $b = $dbi->_backend->get_versiondata($bname, $bv, false); + if (!$b) return 0; + if ((!isset($a[$field]) && !isset($b[$field])) || ($a[$field] === $b[$field])) { + return 0; + } else { + return (!isset($a[$field]) || ($a[$field] < $b[$field])) ? -1 : 1; + } } - class WikiDB_backend_dbaBase_pageiter extends WikiDB_backend_iterator diff --git a/lib/WikiDB/backend/file.php b/lib/WikiDB/backend/file.php index 183d84948..fcb6a2e48 100644 --- a/lib/WikiDB/backend/file.php +++ b/lib/WikiDB/backend/file.php @@ -1,5 +1,5 @@ _loadLatestVersions(); $a = array_keys($this->_latest_versions); - + if (empty($a)) + return new WikiDB_backend_file_iter($this, $a); + $sortby = $this->sortby($sortby, 'db'); + switch ($sortby) { + case '': break; + case 'pagename ASC': sort($a); break; + case 'pagename DESC': rsort($a); break; + } return new WikiDB_backend_file_iter($this, $a); } + function sortable_columns() { + return array('pagename'); + } + function numPages($filter=false, $exclude='') { $this->_loadLatestVersions(); return count($this->_latest_versions); } - - /** - * Title or full text search. - * - * Pages should be returned in alphabetical order if that is - * feasable. - * - * @access protected - * - * @param $search object A TextSearchQuery object describing what pages - * are to be searched for. - * - * @param $fullsearch boolean If true, a full text search is performed, - * otherwise a title search is performed. - * - * @return object A WikiDB_backend_iterator. - * - * @see WikiDB::titleSearch - */ - function text_search($search = '', $fullsearch = false) { - // This is method implements a simple linear search - // through all the pages in the database. - // - // It is expected that most backends will overload - // method with something more efficient. - include_once('lib/WikiDB/backend/dumb/TextSearchIter.php'); - $pages = $this->get_all_pages(false); - return new WikiDB_backend_dumb_TextSearchIter($this, $pages, $search, $fullsearch); - } - - /** - * Find pages with highest hit counts. - * - * Find the pages with the highest hit counts. The pages should - * be returned in reverse order by hit count. - * - * @access protected - * @param $limit integer No more than this many pages - * @return object A WikiDB_backend_iterator. - */ - function most_popular($limit,$sortby = '') { - // This is method fetches all pages, then - // sorts them by hit count. - // (Not very efficient.) - // - // It is expected that most backends will overload - // method with something more efficient. - include_once('lib/WikiDB/backend/dumb/MostPopularIter.php'); - $pages = $this->get_all_pages(false,'hits DESC'); - - return new WikiDB_backend_dumb_MostPopularIter($this, $pages, $limit); - } - - /** - * Find recent changes. - * - * @access protected - * @param $params hash See WikiDB::mostRecent for a description - * of parameters which can be included in this hash. - * @return object A WikiDB_backend_iterator. - * @see WikiDB::mostRecent - */ - function most_recent($params) { - // This method is very inefficient and searches through - // all pages for the most recent changes. - // - // It is expected that most backends will overload - // method with something more efficient. - include_once('lib/WikiDB/backend/dumb/MostRecentIter.php'); - $pages = $this->get_all_pages(true,'mtime DESC'); - return new WikiDB_backend_dumb_MostRecentIter($this, $pages, $params); - } /** * Lock backend database. @@ -693,7 +632,7 @@ extends WikiDB_backend * Optimize the database. */ function optimize() { - //trigger_error("optimize: Not Implemented", E_USER_WARNING); + return 0;//trigger_error("optimize: Not Implemented", E_USER_WARNING); } /** @@ -786,6 +725,9 @@ class WikiDB_backend_file_iter extends WikiDB_backend_iterator } // $Log: not supported by cvs2svn $ +// Revision 1.14 2004/07/08 17:31:43 rurban +// improve numPages for file (fixing AllPagesTest) +// // Revision 1.13 2004/07/08 15:23:59 rurban // less verbose for tests // diff --git a/lib/plugin/AllPages.php b/lib/plugin/AllPages.php index b6a255ed9..8e0fbd00d 100644 --- a/lib/plugin/AllPages.php +++ b/lib/plugin/AllPages.php @@ -1,5 +1,5 @@ getArg('count')) $args['count'] = $dbi->numPages(false,$args['exclude']); else $args['count'] = $request->getArg('count'); @@ -93,19 +106,13 @@ extends WikiPlugin if (empty($args['count']) and !empty($pages)) $args['count'] = count($pages); $pagelist = new PageList($args['info'], $args['exclude'], $args); - //if (!$sortby) $sorted='pagename'; - if (!$args['noheader']) { - if (empty($pages)) - $pagelist->setCaption(_("All pages in this wiki (%d total):")); - else - $pagelist->setCaption(_("List of pages (%d total):")); - } + if (!$args['noheader']) $pagelist->setCaption($caption); // deleted pages show up as version 0. if ($args['include_empty']) $pagelist->_addColumn('version'); - if (!empty($pages)) + if ($pages !== false) $pagelist->addPageList($pages); else $pagelist->addPages( $dbi->getAllPages($args['include_empty'], $args['sortby'], $args['limit']) ); @@ -124,6 +131,9 @@ extends WikiPlugin }; // $Log: not supported by cvs2svn $ +// Revision 1.29 2004/07/08 21:32:36 rurban +// Prevent from more warnings, minor db and sort optimizations +// // Revision 1.28 2004/07/08 20:30:07 rurban // plugin->run consistency: request as reference, added basepage. // encountered strange bug in AllPages (and the test) which destroys ->_dbi -- 2.45.0