]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentComments.php
new plugin RecentChanges
[SourceForge/phpwiki.git] / lib / plugin / RecentComments.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RecentComments.php,v 1.1 2004-05-14 17:33:12 rurban Exp $');
3
4 /**
5  * List of basepages with recently added comments
6  */
7
8 require_once("lib/plugin/RecentChanges.php");
9 require_once("lib/plugin/WikiBlog.php");
10
11 class WikiPlugin_RecentComments
12 extends WikiPlugin_RecentChanges
13 {
14     function getName () {
15         return _("RecentComments");
16     }
17     function getVersion() {
18         return preg_replace("/[Revision: $]/", '',
19                             "\$Revision: 1.1 $");
20     }
21     function getDefaultArguments() {
22         //php-4.0.4pl1 breaks at the parent:: line even if the 
23         // code doesn't reach this line
24         //if (!check_php_version(4,0,6))
25         $args = WikiPlugin_RecentChanges::getDefaultArguments();
26         //else $args = parent::getDefaultArguments();
27         $args['type'] = 'RecentComments';
28         $args['show_minor'] = false;
29         $args['show_all'] = true;
30         $args['caption'] = _("Recent Comments");
31         return $args;
32     }
33
34     function getChanges ($dbi, $args) {
35         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
36
37         $show_deleted = $args['show_deleted'];
38         if ($show_deleted == 'sometimes')
39             $show_deleted = $args['show_minor'];
40         if (!$show_deleted)
41             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
42
43         // sort out pages with no comments
44         $changes = new RecentCommentsRevisionIterator($changes, $dbi);
45         return $changes;
46     }
47
48     // box is used to display a fixed-width, narrow version with common header.
49     // just a numbered list of limit pagenames, without date.
50     function box($args = false, $request = false, $basepage = false) {
51         if (!$request) $request =& $GLOBALS['request'];
52         if (!isset($args['limit'])) $args['limit'] = 15;
53         $args['format'] = 'box';
54         $args['show_minor'] = false;
55         $args['show_major'] = true;
56         $args['show_deleted'] = false;
57         $args['show_all'] = false;
58         $args['days'] = 90;
59         return $this->makeBox(WikiLink(_("RecentComments"),'',_("Recent Comments")),
60                               $this->format($this->getChanges($request->_dbi, $args), $args));
61     }
62 }
63
64 /**
65  * List of pages which have comments
66  * i.e. sort out all non-commented pages.
67  */
68 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
69 {
70     function RecentCommentsRevisionIterator ($revisions, &$dbi) {
71         $this->_revisions = $revisions;
72         $this->_wikidb = $dbi;
73         $this->_current = 0;
74         $this->_blog = new WikiPlugin_WikiBlog();
75     }
76
77     function next () {
78         if (!empty($this->comments) and $this->_current) {
79             if (isset($this->comments[$this->_current])) {
80                 $this->_current++;
81                 return $this->comments[$this->_current];
82             } else {
83                 $this->_current = 0;
84             }
85         }
86         while (($rev = $this->_revisions->next())) {
87             $this->comments = $this->_blog->findBlogs($this->_wikidb, $rev->getPageName(), 'comment');
88             if ($this->comments) {
89                 usort($this->comments, array("WikiPlugin_WikiBlog",
90                                          "cmp"));
91                 if (isset($this->comments[$this->_current])) {
92                     $this->_current++;
93                     return $this->comments[$this->_current];
94                 }
95             } else {
96                 $this->_current = 0;
97             }
98         }
99         $this->free();
100         return false;
101     }
102
103 }
104
105 // $Log: not supported by cvs2svn $
106
107 // (c-file-style: "gnu")
108 // Local Variables:
109 // mode: php
110 // tab-width: 8
111 // c-basic-offset: 4
112 // c-hanging-comment-ender-p: nil
113 // indent-tabs-mode: nil
114 // End:
115 ?>