]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentComments.php
Add getDescription function
[SourceForge/phpwiki.git] / lib / plugin / RecentComments.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3
4 /**
5  * List of basepages with recently added comments.
6  * Idea from http://www.wakkawiki.com/RecentlyCommented
7  * @author: Reini Urban
8  */
9
10 require_once("lib/plugin/RecentChanges.php");
11 require_once("lib/plugin/WikiBlog.php");
12
13 class WikiPlugin_RecentComments
14 extends WikiPlugin_RecentChanges
15 {
16     function getName () {
17         return _("RecentComments");
18     }
19
20     function getDescription () {
21         return _("List basepages with recently added comments.");
22     }
23
24     function getVersion() {
25         return preg_replace("/[Revision: $]/", '',
26                             "\$Revision$");
27     }
28
29     function getDefaultArguments() {
30         //php-4.0.4pl1 breaks at the parent:: line even if the 
31         // code doesn't reach this line
32         //if (!check_php_version(4,0,6))
33         $args = WikiPlugin_RecentChanges::getDefaultArguments();
34         //else $args = parent::getDefaultArguments();
35         $args['show_minor'] = false;
36         $args['show_all'] = true;
37         $args['caption'] = _("Recent Comments");
38         return $args;
39     }
40
41     function format ($changes, $args) {
42         $fmt = new _RecentChanges_CommentFormatter($args);
43         $fmt->action = _("RecentComments");
44         return $fmt->format($changes);
45     }
46
47     function run($dbi, $argstr, &$request, $basepage) {
48         $args = $this->getArgs($argstr, $request);
49         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
50         // to be enough for anyone.)
51         $args['days'] = min($args['days'], 365000);
52         return $this->format($this->getChanges($request->_dbi, $args), $args);
53     }
54
55     function getChanges ($dbi, $args) {
56         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
57         $show_deleted = $args['show_deleted'];
58         if ($show_deleted == 'sometimes')
59             $show_deleted = $args['show_minor'];
60         if (!$show_deleted)
61             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
62         // sort out pages with no comments
63         $changes = new RecentCommentsRevisionIterator($changes, $dbi);
64         return $changes;
65     }
66 }
67
68 class _RecentChanges_CommentFormatter
69 extends _RecentChanges_HtmlFormatter {
70
71     function empty_message () {
72         return _("No comments found");
73     }
74
75     function title() {
76         return;
77     }
78
79     function format_revision ($rev) {
80         static $doublettes = array();
81         if (isset($doublettes[$rev->getPageName()])) return;
82         $doublettes[$rev->getPageName()] = 1;
83         $args = &$this->_args;
84         $class = 'rc-' . $this->importance($rev);
85         $time = $this->time($rev);
86         if (! $rev->get('is_minor_edit'))
87             $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
88         $line = HTML::li(array('class' => $class));
89         if ($args['difflinks'])
90             $line->pushContent($this->diffLink($rev), ' ');
91
92         if ($args['historylinks'])
93             $line->pushContent($this->historyLink($rev), ' ');
94
95         $line->pushContent($this->pageLink($rev), ' ',
96                            $time, ' ',
97                            ' . . . . ',
98                            _("latest comment by "),
99                            $this->authorLink($rev));
100         return $line;
101     }
102 }
103
104 /**
105  * List of pages which have comments
106  * i.e. sort out all non-commented pages.
107  */
108 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
109 {
110     function RecentCommentsRevisionIterator ($revisions, &$dbi) {
111         $this->_revisions = $revisions;
112         $this->_wikidb = $dbi;
113         $this->_current = 0;
114         $this->_blog = new WikiPlugin_WikiBlog();
115     }
116
117     function next () {
118         if (!empty($this->comments) and $this->_current) {
119             if (isset($this->comments[$this->_current])) {
120                 return $this->comments[$this->_current++];
121             } else {
122                 $this->_current = 0;
123             }
124         }
125         while (($rev = $this->_revisions->next())) {
126             $this->comments = $this->_blog->findBlogs($this->_wikidb, $rev->getPageName(), 'comment');
127             if ($this->comments) {
128                 if (count($this->comments) > 2)
129                     usort($this->comments, array("WikiPlugin_WikiBlog",
130                                                  "cmp"));
131                 if (isset($this->comments[$this->_current])) {
132                     //$this->_current++;
133                     return $this->comments[$this->_current++];
134                 }
135             } else {
136                 $this->_current = 0;
137             }
138         }
139         $this->free();
140         return false;
141     }
142
143 }
144
145 // (c-file-style: "gnu")
146 // Local Variables:
147 // mode: php
148 // tab-width: 8
149 // c-basic-offset: 4
150 // c-hanging-comment-ender-p: nil
151 // indent-tabs-mode: nil
152 // End:
153 ?>