]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentComments.php
Normalize header
[SourceForge/phpwiki.git] / lib / plugin / RecentComments.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4  * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * List of basepages with recently added comments.
25  * Idea from http://www.wakkawiki.com/RecentlyCommented
26  * @author: Reini Urban
27  */
28
29 require_once("lib/plugin/RecentChanges.php");
30 require_once("lib/plugin/WikiBlog.php");
31
32 class WikiPlugin_RecentComments
33 extends WikiPlugin_RecentChanges
34 {
35     function getName () {
36         return _("RecentComments");
37     }
38
39     function getDescription () {
40         return _("List basepages with recently added comments.");
41     }
42
43     function getVersion() {
44         return preg_replace("/[Revision: $]/", '',
45                             "\$Revision$");
46     }
47
48     function getDefaultArguments() {
49         //php-4.0.4pl1 breaks at the parent:: line even if the 
50         // code doesn't reach this line
51         //if (!check_php_version(4,0,6))
52         $args = WikiPlugin_RecentChanges::getDefaultArguments();
53         //else $args = parent::getDefaultArguments();
54         $args['show_minor'] = false;
55         $args['show_all'] = true;
56         $args['caption'] = _("Recent Comments");
57         return $args;
58     }
59
60     function format ($changes, $args) {
61         $fmt = new _RecentChanges_CommentFormatter($args);
62         $fmt->action = _("RecentComments");
63         return $fmt->format($changes);
64     }
65
66     function run($dbi, $argstr, &$request, $basepage) {
67         $args = $this->getArgs($argstr, $request);
68         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
69         // to be enough for anyone.)
70         $args['days'] = min($args['days'], 365000);
71         return $this->format($this->getChanges($request->_dbi, $args), $args);
72     }
73
74     function getChanges ($dbi, $args) {
75         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
76         $show_deleted = $args['show_deleted'];
77         if ($show_deleted == 'sometimes')
78             $show_deleted = $args['show_minor'];
79         if (!$show_deleted)
80             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
81         // sort out pages with no comments
82         $changes = new RecentCommentsRevisionIterator($changes, $dbi);
83         return $changes;
84     }
85 }
86
87 class _RecentChanges_CommentFormatter
88 extends _RecentChanges_HtmlFormatter {
89
90     function empty_message () {
91         return _("No comments found");
92     }
93
94     function title() {
95         return;
96     }
97
98     function format_revision ($rev) {
99         static $doublettes = array();
100         if (isset($doublettes[$rev->getPageName()])) return;
101         $doublettes[$rev->getPageName()] = 1;
102         $args = &$this->_args;
103         $class = 'rc-' . $this->importance($rev);
104         $time = $this->time($rev);
105         if (! $rev->get('is_minor_edit'))
106             $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
107         $line = HTML::li(array('class' => $class));
108         if ($args['difflinks'])
109             $line->pushContent($this->diffLink($rev), ' ');
110
111         if ($args['historylinks'])
112             $line->pushContent($this->historyLink($rev), ' ');
113
114         $line->pushContent($this->pageLink($rev), ' ',
115                            $time, ' ',
116                            ' . . . . ',
117                            _("latest comment by "),
118                            $this->authorLink($rev));
119         return $line;
120     }
121 }
122
123 /**
124  * List of pages which have comments
125  * i.e. sort out all non-commented pages.
126  */
127 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
128 {
129     function RecentCommentsRevisionIterator ($revisions, &$dbi) {
130         $this->_revisions = $revisions;
131         $this->_wikidb = $dbi;
132         $this->_current = 0;
133         $this->_blog = new WikiPlugin_WikiBlog();
134     }
135
136     function next () {
137         if (!empty($this->comments) and $this->_current) {
138             if (isset($this->comments[$this->_current])) {
139                 return $this->comments[$this->_current++];
140             } else {
141                 $this->_current = 0;
142             }
143         }
144         while (($rev = $this->_revisions->next())) {
145             $this->comments = $this->_blog->findBlogs($this->_wikidb, $rev->getPageName(), 'comment');
146             if ($this->comments) {
147                 if (count($this->comments) > 2)
148                     usort($this->comments, array("WikiPlugin_WikiBlog",
149                                                  "cmp"));
150                 if (isset($this->comments[$this->_current])) {
151                     //$this->_current++;
152                     return $this->comments[$this->_current++];
153                 }
154             } else {
155                 $this->_current = 0;
156             }
157         }
158         $this->free();
159         return false;
160     }
161
162 }
163
164 // (c-file-style: "gnu")
165 // Local Variables:
166 // mode: php
167 // tab-width: 8
168 // c-basic-offset: 4
169 // c-hanging-comment-ender-p: nil
170 // indent-tabs-mode: nil
171 // End:
172 ?>