2 // $Id: WantedPagesIter.php 7956 2011-03-03 17:08:31Z vargenau $
4 //require_once('lib/WikiDB/backend.php');
7 * This iterator will work with any WikiDB_backend
8 * which has a working get_links(,'links_from') method.
10 * This is mostly here for testing, 'cause it's slow,slow,slow.
12 class WikiDB_backend_dumb_WantedPagesIter
13 extends WikiDB_backend_iterator
15 function WikiDB_backend_dumb_WantedPagesIter(&$backend, &$all_pages, $exclude='', $sortby='', $limit='') {
16 $this->_allpages = $all_pages;
17 $this->_allpages_array = $all_pages->asArray();
18 $this->_backend = &$backend;
19 if (!is_array($exclude))
20 $this->exclude = $exclude ? PageList::explodePageList($exclude) : array();
22 $this->exclude = $exclude;
23 $this->sortby = $sortby; // ignored
24 if ($limit) { // extract from,count from limit
25 list($this->from, $this->limit) = $backend->limit($limit);
31 $this->pagelinks = array();
35 while ($page = $this->_allpages->next()) {
36 while ($this->pagelinks) { // deferred return
37 return array_pop($this->pagelinks);
39 $this->pagelinks = array();
40 if ($this->limit and $this->pos > $this->limit) break;
41 $pagename = $page['pagename'];
42 $links = $this->_backend->get_links($pagename, false);
43 while ($link = $links->next()) {
44 if ($this->limit and $this->pos > $this->limit) break;
45 if ($this->exclude and in_array($link['pagename'], $this->exclude)) continue;
46 // better membership for a pageiterator?
47 if (! in_array($link['pagename'], $this->_allpages_array)) {
48 if ($this->from and $this->pos < $this->from) continue;
49 // collect all links per page and return them deferred
50 $link['wantedfrom'] = $pagename;
51 $this->pagelinks[] = $link;
57 if ($this->pagelinks) return array_pop($this->pagelinks);
63 unset($this->_allpages_array);
64 $this->_allpages->free();
65 unset($this->_allpages);
66 unset($this->_backend);
74 // c-hanging-comment-ender-p: nil
75 // indent-tabs-mode: nil