From ab2979e0f829a8260ea723352c615f12cd64d99c Mon Sep 17 00:00:00 2001 From: vargenau Date: Thu, 11 Jun 2009 11:52:32 +0000 Subject: [PATCH] Give exact number of pages listed (number was incorrect in case pages were not listed because of restrictive ACL) git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@6915 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/PageList.php | 26 ++++++++++++++++++++------ lib/plugin/AllPages.php | 28 +++++++++++----------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/lib/PageList.php b/lib/PageList.php index 6df705f08..0f409eca4 100644 --- a/lib/PageList.php +++ b/lib/PageList.php @@ -1436,8 +1436,11 @@ class PageList { if ($tokens) $this->_pages = array_slice($this->_pages, $tokens['OFFSET'], $tokens['COUNT']); } + $nb_row = 0; foreach ($this->_pages as $pagenum => $page) { - $rows[] = $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, @@ -1446,6 +1449,7 @@ class PageList { 'class' => 'pagelist', )); if ($caption) { + $caption = preg_replace('/{total}/', $nb_row, asString($caption)); $table->pushContent(HTML::caption(array('align'=>'top'), $caption)); } @@ -1520,9 +1524,17 @@ 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 ($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 if (!is_array($this->_pages[0]) and is_string($this->_pages[0])) { $this->_pages = array_unique($this->_pages); @@ -1626,15 +1638,15 @@ class PageList { list($offset, $pagesize) = $this->limit($this->_options['limit']); else $pagesize=0; - foreach ($this->_pages as $pagenum => $page) { - $pagehtml = $this->_renderPageRow($page); + foreach (array_reverse($rows) as $one_row) { + $pagehtml = $one_row['render']; if (!$pagehtml) continue; $group = ($i++ / $this->_group_rows); //TODO: here we switch every row, in tables every third. // unification or parametrized? $class = ($group % 2) ? 'oddrow' : 'evenrow'; if ($this->_options['listtype'] == 'dl') { - $header = WikiLink($page); + $header = $one_row['header']; //if ($this->_sortby['hi_content']) $list->pushContent(HTML::dt(array('class' => $class), $header), HTML::dd(array('class' => $class), $pagehtml)); @@ -1688,8 +1700,10 @@ class PageList { function _emptyList($caption) { $html = HTML(); - if ($caption) + if ($caption) { + $caption = preg_replace('/{total}/', '0', asString($caption)); $html->pushContent(HTML::p($caption)); + } if ($this->_messageIfEmpty) $html->pushContent(HTML::blockquote(HTML::p($this->_messageIfEmpty))); return $html; diff --git a/lib/plugin/AllPages.php b/lib/plugin/AllPages.php index fd560e44c..385ad57fa 100644 --- a/lib/plugin/AllPages.php +++ b/lib/plugin/AllPages.php @@ -69,48 +69,45 @@ extends WikiPlugin // Todo: extend given _GET args if ($args['debug']) $timer = new DebugTimer; - $caption = _("All pages in this wiki (%d total):"); + $caption = _("All pages in this wiki ({total} total):"); if ( !empty($args['userpages']) ) { $pages = PageList::allUserPages($args['include_empty'], $args['sortby'], '' ); - $caption = fmt("List of user-created pages (%d total):", count($pages)); + $caption = _("List of user-created pages ({total} 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] (%d total):", + $caption = fmt("List of pages owned by [%s] ({total} total):", WikiLink($args['owner'] == '[]' ? $request->_user->getAuthenticatedId() : $args['owner'], - 'if_known'), - count($pages)); + 'if_known')); $args['count'] = $request->getArg('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] (%d total):", + $caption = fmt("List of pages last edited by [%s] ({total} total):", WikiLink($args['author'] == '[]' ? $request->_user->getAuthenticatedId() : $args['author'], - 'if_known'), - count($pages)); + 'if_known')); $args['count'] = $request->getArg('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] (%d total):", + $caption = fmt("List of pages created by [%s] ({total} total):", WikiLink($args['creator'] == '[]' ? $request->_user->getAuthenticatedId() : $args['creator'], - 'if_known'), - count($pages)); + 'if_known')); $args['count'] = $request->getArg('count'); $pages->_options['count'] = $args['count']; //} elseif ($pages) { @@ -132,11 +129,9 @@ extends WikiPlugin if ($pages !== false) $pagelist->addPageList($pages); - else { - $result = $dbi->getAllPages($args['include_empty'], $args['sortby'], - $args['limit']); - $pagelist->addPages( $result ); - } + else + $pagelist->addPages( $dbi->getAllPages($args['include_empty'], $args['sortby'], + $args['limit']) ); if ($args['debug']) { return HTML($pagelist, HTML::p(fmt("Elapsed time: %s s", $timer->getStats()))); @@ -144,7 +139,6 @@ extends WikiPlugin return $pagelist; } } - }; // Local Variables: -- 2.45.0