From 70458054176c774a242a840e16268152c332b206 Mon Sep 17 00:00:00 2001 From: rurban Date: Tue, 8 Jun 2010 10:41:29 +0000 Subject: [PATCH] fix paging: almost all backends do now slice by themselves, so do not slice in PageList. simplify constants new AllPages default: include_empty is faster git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@7494 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/PageList.php | 62 ++++++++++++++++++----------------------- lib/WikiDB.php | 7 +++-- lib/plugin/AllPages.php | 34 ++++++++++++---------- 3 files changed, 51 insertions(+), 52 deletions(-) diff --git a/lib/PageList.php b/lib/PageList.php index 07a99f638..1245b616d 100644 --- a/lib/PageList.php +++ b/lib/PageList.php @@ -1,5 +1,5 @@ 50, // number of rows (pagesize) - 'limit' => 5000, // number of rows (pagesize) + 'limit' => 50, // number of rows (pagesize) 'paging' => 'auto', // 'auto' top + bottom rows if applicable // // 'top' top only if applicable // // 'bottom' bottom only if applicable @@ -844,23 +842,25 @@ class PageList { /* ignore from, but honor limit */ function addPages ($page_iter) { // TODO: if limit check max(strlen(pagename)) - $i = 0; $from = 0; - if (isa($page_iter->_iter, "WikiDB_backend_dbaBase_pageiter")) { - $limit = 0; - } - elseif (isset($this->_options['limit'])) { // extract from,count from limit - list($from, $limit) = WikiDB_backend::limit($this->_options['limit']); + $limit = $page_iter->limit(); + if ($limit) { + list($from, $limit) = $this->limit($limit); + $this->_options['slice'] = 0; $limit += $from; - } else { - $limit = 0; - } - while ($page = $page_iter->next()) { - $i++; - if ($from and $i < $from) - continue; - if (!$limit or ($limit and $i < $limit)) + $i = 0; + while ($page = $page_iter->next()) { + $i++; + if ($from and $i < $from) + continue; + if (!$limit or ($limit and $i < $limit)) + $this->addPage($page); + } + } else { + $this->_options['slice'] = 0; + while ($page = $page_iter->next()) { $this->addPage($page); - } + } + } if (empty($this->_options['count'])) $this->_options['count'] = $i; } @@ -873,6 +873,7 @@ class PageList { } else { $limit = 0; } + $this->_options['slice'] = 0; $i = 0; foreach ($list as $page) { $i++; @@ -1445,18 +1446,19 @@ class PageList { $tokens['LIMIT'] = $prev['limit']; $tokens['PREV'] = true; $tokens['PREV_LINK'] = WikiURL($pagename, $prev); - $prev['limit'] = "0,$pagesize"; + $prev['limit'] = "0,$pagesize"; // FIRST_LINK $tokens['FIRST_LINK'] = WikiURL($pagename, $prev); } $next = $defargs; $tokens['NEXT'] = false; $tokens['NEXT_LINK'] = ""; if (($offset + $pagesize) < $numrows) { - $next['limit'] = min($offset + $pagesize, $numrows - $pagesize) . ",$pagesize"; + $next['limit'] = min($offset + $pagesize, $numrows - $pagesize) + . ",$pagesize"; $next['count'] = $numrows; $tokens['LIMIT'] = $next['limit']; $tokens['NEXT'] = true; $tokens['NEXT_LINK'] = WikiURL($pagename, $next); - $next['limit'] = $numrows - $pagesize . ",$pagesize"; + $next['limit'] = $numrows - $pagesize . ",$pagesize"; // LAST_LINK $tokens['LAST_LINK'] = WikiURL($pagename, $next); } return $tokens; @@ -1478,14 +1480,12 @@ class PageList { $tokens = $this->pagingTokens($count, count($this->_columns), $this->_options['limit']); - if ($tokens) + if ($tokens and $this->_options['slice']) $this->_pages = array_slice($this->_pages, $tokens['OFFSET'], $tokens['COUNT']); } - $nb_row = 0; foreach ($this->_pages as $pagenum => $page) { - $one_row = $this->_renderPageRow($page, $i++); + $one_row = $this->_renderPageRow($page, $i++); $rows[] = $one_row; - if ($one_row) $nb_row++; } $table = HTML::table(array('cellpadding' => 0, 'cellspacing' => 1, @@ -1494,8 +1494,6 @@ class PageList { 'class' => 'pagelist', )); if ($caption) { - if (is_string($caption)) - $caption = preg_replace('/{total}/', $nb_row, asString($caption)); $table->pushContent(HTML::caption(array('align'=>'top'), $caption)); } @@ -1570,16 +1568,12 @@ class PageList { if (empty($this->_pages)) return; // stop recursion if (!isset($this->_options['listtype'])) $this->_options['listtype'] = ''; - $nb_row = 0; foreach ($this->_pages as $pagenum => $page) { $one_row = $this->_renderPageRow($page); $rows[] = array('header' => WikiLink($page), 'render' => $one_row); - if ($one_row) $nb_row++; } $out = HTML(); if ($caption) { - if (is_string($caption)) - $caption = preg_replace('/{total}/', $nb_row, asString($caption)); $out->pushContent(HTML::p($caption)); } // Semantic Search et al: only unique list entries, esp. with nopage @@ -1602,7 +1596,7 @@ class PageList { } } - if (!empty($this->_options['limit'])) + if (!empty($this->_options['limit']) and $this->_options['slice']) list($offset, $count) = $this->limit($this->_options['limit']); else { $offset = 0; $count = count($this->_pages); @@ -1756,8 +1750,6 @@ class PageList { function _emptyList($caption) { $html = HTML(); if ($caption) { - if (is_string($caption)) - $caption = preg_replace('/{total}/', '0', asString($caption)); $html->pushContent(HTML::p($caption)); } if ($this->_messageIfEmpty) diff --git a/lib/WikiDB.php b/lib/WikiDB.php index 678f11d2f..d930c4ec5 100644 --- a/lib/WikiDB.php +++ b/lib/WikiDB.php @@ -286,12 +286,10 @@ class WikiDB { } $result = $this->_backend->get_all_pages($include_empty, $sortby, $limit, $exclude); - if (isa($this->_backend, "WikiDB_backend_dba")) - $limit = false; return new WikiDB_PageIterator($this, $result, array('include_empty' => $include_empty, 'exclude' => $exclude, - 'limit' => $limit)); + 'limit' => $result->limit())); } /** @@ -1821,6 +1819,9 @@ class WikiDB_PageIterator function count () { return $this->_iter->count(); } + function limit () { + return empty($this->_options['limit']) ? 0 : $this->_options['limit']; + } /** * Get next WikiDB_Page in sequence. diff --git a/lib/plugin/AllPages.php b/lib/plugin/AllPages.php index bc58b75be..0e609a09c 100644 --- a/lib/plugin/AllPages.php +++ b/lib/plugin/AllPages.php @@ -44,7 +44,7 @@ extends WikiPlugin PageList::supportedArgs(), array( 'noheader' => false, - 'include_empty' => false, + 'include_empty' => true, // is faster //'pages' => false, // DONT, this would be ListPages then. 'info' => '', 'debug' => false, @@ -63,49 +63,55 @@ extends WikiPlugin $pages = false; // Todo: extend given _GET args - if (defined('DEBUG') && DEBUG && $args['debug']) { + if (DEBUG && $args['debug']) { $timer = new DebugTimer; } - $caption = _("All pages in this wiki ({total} total):"); + $caption = _("All pages in this wiki (%d total):"); if ( !empty($args['userpages']) ) { $pages = PageList::allUserPages($args['include_empty'], $args['sortby'], '' ); - $caption = _("List of user-created pages ({total} total):"); + $caption = _("List of user-created pages (%d total):"); $args['count'] = $request->getArg('count'); } elseif ( !empty($args['owner']) ) { $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'], $args['sortby'], '' ); - $caption = fmt("List of pages owned by [%s] ({total} total):", + $args['count'] = $request->getArg('count'); + if (!$args['count']) + $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']); + $caption = fmt("List of pages owned by [%s] (%d total):", WikiLink($args['owner'] == '[]' ? $request->_user->getAuthenticatedId() : $args['owner'], - 'if_known')); - $args['count'] = $request->getArg('count'); + 'if_known'), $args['count']); $pages->_options['count'] = $args['count']; } elseif ( !empty($args['author']) ) { $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'], $args['sortby'], '' ); - $caption = fmt("List of pages last edited by [%s] ({total} total):", + $args['count'] = $request->getArg('count'); + if (!$args['count']) + $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']); + $caption = fmt("List of pages last edited by [%s] (%d total):", WikiLink($args['author'] == '[]' ? $request->_user->getAuthenticatedId() : $args['author'], - 'if_known')); - $args['count'] = $request->getArg('count'); + 'if_known'), $args['count']); $pages->_options['count'] = $args['count']; } elseif ( !empty($args['creator']) ) { $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'], $args['sortby'], '' ); - $caption = fmt("List of pages created by [%s] ({total} total):", + $args['count'] = $request->getArg('count'); + if (!$args['count']) + $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']); + $caption = fmt("List of pages created by [%s] (%d total):", WikiLink($args['creator'] == '[]' ? $request->_user->getAuthenticatedId() : $args['creator'], - 'if_known')); - $args['count'] = $request->getArg('count'); + 'if_known'), $args['count']); $pages->_options['count'] = $args['count']; //} elseif ($pages) { // $args['count'] = count($pages); @@ -129,7 +135,7 @@ extends WikiPlugin else $pagelist->addPages( $dbi->getAllPages($args['include_empty'], $args['sortby'], $args['limit']) ); - if (defined('DEBUG') && DEBUG && $args['debug']) { + if (DEBUG && $args['debug']) { return HTML($pagelist, HTML::p(fmt("Elapsed time: %s s", $timer->getStats()))); } else { -- 2.45.0