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='') {
12 $this->_allpages = $all_pages;
13 $this->_allpages_array = $all_pages->asArray();
14 $this->_backend = &$backend;
15 if (!is_array($exclude))
16 $this->exclude = $exclude ? PageList::explodePageList($exclude) : array();
18 $this->exclude = $exclude;
19 $this->sortby = $sortby; // ignored
20 if ($limit) { // extract from,count from limit
21 list($this->from, $this->limit) = $backend->limit($limit);
27 $this->pagelinks = array();
31 while ($page = $this->_allpages->next()) {
32 while ($this->pagelinks) { // deferred return
33 return array_pop($this->pagelinks);
35 $this->pagelinks = array();
36 if ($this->limit and $this->pos > $this->limit) break;
37 $pagename = $page['pagename'];
38 $links = $this->_backend->get_links($pagename, false);
39 while ($link = $links->next()) {
40 if ($this->limit and $this->pos > $this->limit) break;
41 if ($this->exclude and in_array($link['pagename'], $this->exclude)) continue;
42 // better membership for a pageiterator?
43 if (! in_array($link['pagename'], $this->_allpages_array)) {
44 if ($this->from and $this->pos < $this->from) continue;
45 // collect all links per page and return them deferred
46 $link['wantedfrom'] = $pagename;
47 $this->pagelinks[] = $link;
53 if ($this->pagelinks) return array_pop($this->pagelinks);
59 unset($this->_allpages_array);
60 $this->_allpages->free();
61 unset($this->_allpages);
62 unset($this->_backend);
70 // c-hanging-comment-ender-p: nil
71 // indent-tabs-mode: nil