]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/dumb/WantedPagesIter.php
improved WantedPages SQL backends
[SourceForge/phpwiki.git] / lib / WikiDB / backend / dumb / WantedPagesIter.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WantedPagesIter.php,v 1.1 2004-11-20 17:35:58 rurban Exp $');
3
4 //require_once('lib/WikiDB/backend.php');
5
6 /**
7  * This iterator will work with any WikiDB_backend
8  * which has a working get_links(,'links_from') method.
9  *
10  * This is mostly here for testing, 'cause it's slow,slow,slow.
11  */
12 class WikiDB_backend_dumb_WantedPagesIter
13 extends WikiDB_backend_iterator
14 {
15     function WikiDB_backend_dumb_WantedPagesIter(&$backend, &$all_pages, $exclude='', $sortby=false, $limit=false) {
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();
21         else 
22             $this->exclude = $exclude;
23     }
24
25     function next() {
26         while ($page = $this->_allpages->next()) {
27             $pagename = $page['pagename'];
28             $links = $this->_backend->get_links($pagename, false);
29             while ($link = $links->next()) {
30                 if ($this->exclude and in_array($link['pagename'], $this->exclude)) continue;
31                 // better membership for a pageiterator???
32                 if (! in_array($link['pagename'], $this->_allpages_array)) {
33                     $links->free();
34                     $link['wantedfrom'] = $pagename;
35                     return $link;
36                 }
37             }
38             $links->free();
39         }
40         return false;
41     }
42
43     function free() {
44         unset($this->_allpages_array);
45         $this->_allpages->free();
46     }
47 }
48
49 // For emacs users
50 // Local Variables:
51 // mode: php
52 // tab-width: 8
53 // c-basic-offset: 4
54 // c-hanging-comment-ender-p: nil
55 // indent-tabs-mode: nil
56 // End:
57 ?>