From: <ru...@us...> - 2010-06-08 10:41:36
|
Revision: 7494 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=7494&view=rev Author: rurban Date: 2010-06-08 10:41:29 +0000 (Tue, 08 Jun 2010) Log Message: ----------- 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 Modified Paths: -------------- trunk/lib/PageList.php trunk/lib/WikiDB.php trunk/lib/plugin/AllPages.php Modified: trunk/lib/PageList.php =================================================================== --- trunk/lib/PageList.php 2010-06-08 08:22:56 UTC (rev 7493) +++ trunk/lib/PageList.php 2010-06-08 10:41:29 UTC (rev 7494) @@ -1,5 +1,5 @@ <?php -// rcs_id('$Id$'); +//rcs_id('$Id$'); /* Copyright (C) 2004-2009 $ThePhpWikiProgrammingTeam * Copyright (C) 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent * @@ -692,9 +692,7 @@ * These options may also be given to _generate(List|Table) later * But limit and offset might help the query WikiDB::getAllPages() */ - // Use big value since paging does not work. - // 'limit' => 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 @@ /* 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 @@ } else { $limit = 0; } + $this->_options['slice'] = 0; $i = 0; foreach ($list as $page) { $i++; @@ -1445,18 +1446,19 @@ $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 @@ $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', )); 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 @@ 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 @@ } } - 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 @@ 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) Modified: trunk/lib/WikiDB.php =================================================================== --- trunk/lib/WikiDB.php 2010-06-08 08:22:56 UTC (rev 7493) +++ trunk/lib/WikiDB.php 2010-06-08 10:41:29 UTC (rev 7494) @@ -286,12 +286,10 @@ } $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 @@ function count () { return $this->_iter->count(); } + function limit () { + return empty($this->_options['limit']) ? 0 : $this->_options['limit']; + } /** * Get next WikiDB_Page in sequence. Modified: trunk/lib/plugin/AllPages.php =================================================================== --- trunk/lib/plugin/AllPages.php 2010-06-08 08:22:56 UTC (rev 7493) +++ trunk/lib/plugin/AllPages.php 2010-06-08 10:41:29 UTC (rev 7494) @@ -44,7 +44,7 @@ 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 @@ $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 @@ 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 { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |