]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/dumb/WantedPagesIter.php
Remove svn:keywords
[SourceForge/phpwiki.git] / lib / WikiDB / backend / dumb / WantedPagesIter.php
1 <?php
2 /**
3  * This iterator will work with any WikiDB_backend
4  * which has a working get_links(,'links_from') method.
5  *
6  * This is mostly here for testing, 'cause it's slow,slow,slow.
7  */
8 class WikiDB_backend_dumb_WantedPagesIter
9 extends WikiDB_backend_iterator
10 {
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();
17         else
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);
22         } else {
23             $this->limit = 0;
24             $this->from = 0;
25         }
26         $this->pos = 0;
27         $this->pagelinks = array();
28     }
29
30     function next() {
31         while ($page = $this->_allpages->next()) {
32             while ($this->pagelinks) { // deferred return
33                 return array_pop($this->pagelinks);
34             }
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;
48                     $this->pos++;
49                 }
50             }
51             $links->free();
52             unset($links);
53             if ($this->pagelinks) return array_pop($this->pagelinks);
54         }
55         return false;
56     }
57
58     function free() {
59         unset($this->_allpages_array);
60         $this->_allpages->free();
61         unset($this->_allpages);
62         unset($this->_backend);
63     }
64 }
65
66 // Local Variables:
67 // mode: php
68 // tab-width: 8
69 // c-basic-offset: 4
70 // c-hanging-comment-ender-p: nil
71 // indent-tabs-mode: nil
72 // End: