File: MostRecentIter.php

package info (click to toggle)
phpwiki 1.3.14-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 15,716 kB
  • ctags: 23,548
  • sloc: php: 88,295; sql: 1,476; sh: 1,378; perl: 765; makefile: 602; awk: 28
file content (91 lines) | stat: -rwxr-xr-x 2,585 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php // -*-php-*-
rcs_id('$Id: MostRecentIter.php,v 1.8 2006/12/22 00:27:37 rurban Exp $');

require_once('lib/WikiDB/backend.php');


/**
 * An inefficient but general most_recent iterator. 
 *
 * This iterator will work with any backends.
 */
class WikiDB_backend_dumb_MostRecentIter
extends WikiDB_backend_iterator
{
    function WikiDB_backend_dumb_MostRecentIter(&$backend, &$pages, $params) {
        $limit = false;
        extract($params);
        if ($exclude_major_revisions)
            $include_minor_revisions = true;

        $reverse = $limit < 0;
        if($reverse){$limit = -$limit;}
        $this->_revisions = array();
        while ($page = $pages->next()) {
            $revs = $backend->get_all_revisions($page['pagename']);
            while ($revision = $revs->next()) {
                $vdata = &$revision['versiondata'];
                assert(is_array($vdata));
                if (!empty($vdata['is_minor_edit'])) {
                    if (!$include_minor_revisions)
                        continue;
                }
                else {
                    if ($exclude_major_revisions)
                        continue;
                }
                if (!empty($since) && $vdata['mtime'] < $since)
                    break;

                $this->_revisions[] = $revision;

                if (!$include_all_revisions)
                    break;
            }
            $revs->free();
        }
        if ($reverse) {
            usort($this->_revisions, 'WikiDB_backend_dumb_MostRecentIter_sortf_rev');
        } else {
            usort($this->_revisions, 'WikiDB_backend_dumb_MostRecentIter_sortf');
        }
        if (!empty($limit) && $limit < count($this->_revisions)) {
            array_splice($this->_revisions, $limit);
        }
    }
    
    function next() {
        return array_shift($this->_revisions);
    }
    
    function free() {
        unset($this->_revisions);
    }
}

function WikiDB_backend_dumb_MostRecentIter_sortf($a, $b) {
    $acreated = $a['versiondata']['mtime'];
    $bcreated = $b['versiondata']['mtime'];
    return $bcreated - $acreated;
}

function WikiDB_backend_dumb_MostRecentIter_sortf_rev($a, $b) {
    $acreated = $a['versiondata']['mtime'];
    $bcreated = $b['versiondata']['mtime'];
    return $acreated - $bcreated;
}

// $Log: MostRecentIter.php,v $
// Revision 1.8  2006/12/22 00:27:37  rurban
// just add Log
//

// (c-file-style: "gnu")
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:   
?>