3 * This iterator will work with any WikiDB_backend
4 * which has a working get_links(,'links_from') method.
6 * This is mostly here for testing, 'cause it's slow,slow,slow.
8 class WikiDB_backend_dumb_WantedPagesIter
9 extends WikiDB_backend_iterator
11 function WikiDB_backend_dumb_WantedPagesIter(&$backend, &$all_pages, $exclude = '', $sortby = '', $limit = '')
13 $this->_allpages = $all_pages;
14 $this->_allpages_array = $all_pages->asArray();
15 $this->_backend = &$backend;
16 if (!is_array($exclude))
17 $this->exclude = $exclude ? PageList::explodePageList($exclude) : array();
19 $this->exclude = $exclude;
20 $this->sortby = $sortby; // ignored
21 if ($limit) { // extract from,count from limit
22 list($this->from, $this->limit) = $backend->limit($limit);
28 $this->pagelinks = array();
33 while ($page = $this->_allpages->next()) {
34 while ($this->pagelinks) { // deferred return
35 return array_pop($this->pagelinks);
37 $this->pagelinks = array();
38 if ($this->limit and $this->pos > $this->limit) break;
39 $pagename = $page['pagename'];
40 $links = $this->_backend->get_links($pagename, false);
41 while ($link = $links->next()) {
42 if ($this->limit and $this->pos > $this->limit) break;
43 if ($this->exclude and in_array($link['pagename'], $this->exclude)) continue;
44 // better membership for a pageiterator?
45 if (!in_array($link['pagename'], $this->_allpages_array)) {
46 if ($this->from and $this->pos < $this->from) continue;
47 // collect all links per page and return them deferred
48 $link['wantedfrom'] = $pagename;
49 $this->pagelinks[] = $link;
55 if ($this->pagelinks) return array_pop($this->pagelinks);
62 unset($this->_allpages_array);
63 $this->_allpages->free();
64 unset($this->_allpages);
65 unset($this->_backend);
73 // c-hanging-comment-ender-p: nil
74 // indent-tabs-mode: nil