2 rcs_id('$Id: MostPopularIter.php,v 1.1 2001-09-18 19:16:23 dairiki Exp $');
4 require_once('lib/WikiDB/backend.php');
8 * An inefficient but general most_popular iterator.
10 * This iterator will work with any backend which implements the
11 * backend::get_all_pages() and backend::get_pagedata()
14 class WikiDB_backend_dumb_MostPopularIter
15 extends WikiDB_backend_iterator
17 function WikiDB_backend_dumb_MostPopularIter($backend, &$all_pages, $limit) {
18 $this->_pages = array();
19 $pages = &$this->_pages;
21 while ($page = & $all_pages->next()) {
22 if (!isset($page['pagedata']))
23 $page['pagedata'] = $backend->get_pagedata($page['pagename']);
27 usort($pages, 'WikiDB_backend_dumb_MostPopularIter_sortf');
29 if ($limit && $limit < count($pages))
30 array_splice($pages, $limit);
34 return array_shift($this->_pages);
42 function WikiDB_backend_dumb_MostPopularIter_sortf($a,$b) {
43 @$ahits = (int)$a['pagedata']['hits'];
44 @$bhits = (int)$b['pagedata']['hits'];
45 return $bhits - $ahits;