]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/dumb/AllRevisionsIter.php
Jeff's hacks II.
[SourceForge/phpwiki.git] / lib / WikiDB / backend / dumb / AllRevisionsIter.php
1 <?php // -*-php-*-
2 rcs_id('$Id: AllRevisionsIter.php,v 1.1 2001-09-18 19:16:23 dairiki Exp $');
3     
4 /**
5  * An iterator which returns all revisions of page.
6  *
7  * This iterator uses  only the WikiDB_backend::get_versiondata interface
8  * of a WikiDB_backend, and so it should work with all backends.
9  */
10 class WikiDB_backend_dumb_AllRevisionsIter
11 extends WikiDB_backend_iterator
12 {
13     /**
14      * Constructor.
15      *
16      * @access protected
17      * @param $backend object A WikiDB_backend.
18      * @param $pagename string Page whose revisions to get.
19      */
20     function WikiDB_backend_dumb_AllRevisionsIter(&$backend, $pagename) {
21         $this->_backend = &$backend;
22         $this->_pagename = $pagename;
23         $this->_lastversion = -1;
24     }
25     
26     /**
27      * Get next revision in sequence.
28      *
29      * @see WikiDB_backend_iterator_next;
30      */
31     function next () {
32         $backend = &$this->_backend;
33         $pagename = &$this->_pagename;
34         $version = &$this->_lastversion;
35
36         $backend->lock();
37         if ($this->_lastversion == -1)
38             $version = $backend->get_latest_version($pagename);
39         elseif ($this->_lastversion > 0)
40             $version = $backend->get_previous_version($pagename, $version);
41
42         if ($version)
43             $vdata = $backend->get_versiondata($pagename, $version);
44         $backend->unlock();
45         
46         if ($version == 0)
47             return false;
48
49         $rev = array('versiondata' => $vdata,
50                      'pagename' => $pagename,
51                      'version' => $version);
52         
53         if (!empty($vdata['%pagedata']))
54             $rev['pagedata'] = &$vdata['%pagedata'];
55
56         return $rev;
57     }
58 };
59
60 // (c-file-style: "gnu")
61 // Local Variables:
62 // mode: php
63 // tab-width: 8
64 // c-basic-offset: 4
65 // c-hanging-comment-ender-p: nil
66 // indent-tabs-mode: nil
67 // End:   
68 ?>