]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/dumb/AllRevisionsIter.php
Remove svn:keywords
[SourceForge/phpwiki.git] / lib / WikiDB / backend / dumb / AllRevisionsIter.php
1 <?php // -*-php-*-
2 // $Id: AllRevisionsIter.php 8286 2012-09-28 11:20:42Z vargenau $
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     if (is_string($vdata) and !empty($vdata)) {
50             $vdata1 =  @unserialize($vdata);
51             if (empty($vdata1)) {
52                 if (DEBUG) // string but unseriazible
53                     trigger_error ("Broken page $pagename ignored. Run Check WikiDB", E_USER_WARNING);
54             return false;
55             }
56             $vdata = $vdata1;
57     }
58         $rev = array('versiondata' => $vdata,
59                      'pagename' => $pagename,
60                      'version' => $version);
61
62         if (!empty($vdata['%pagedata'])) {
63             $rev['pagedata'] = $vdata['%pagedata'];
64         }
65
66         return $rev;
67     }
68 };
69
70 // Local Variables:
71 // mode: php
72 // tab-width: 8
73 // c-basic-offset: 4
74 // c-hanging-comment-ender-p: nil
75 // indent-tabs-mode: nil
76 // End: