4 * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
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.
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.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * List of basepages with recently added comments.
25 * Idea from http://www.wakkawiki.com/RecentlyCommented
26 * @author: Reini Urban
29 require_once 'lib/plugin/RecentChanges.php';
30 require_once 'lib/plugin/WikiBlog.php';
32 class WikiPlugin_RecentComments
33 extends WikiPlugin_RecentChanges
35 function getDescription()
37 return _("List basepages with recently added comments.");
40 function getDefaultArguments()
42 $args = parent::getDefaultArguments();
43 $args['show_minor'] = false;
44 $args['show_all'] = true;
45 $args['caption'] = _("Recent Comments");
49 function format($changes, $args)
51 $fmt = new _RecentChanges_CommentFormatter($args);
52 $fmt->action = _("RecentComments");
53 return $fmt->format($changes);
56 function run($dbi, $argstr, &$request, $basepage)
58 $args = $this->getArgs($argstr, $request);
59 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
60 // to be enough for anyone.)
61 $args['days'] = min($args['days'], 365000);
62 return $this->format($this->getChanges($request->_dbi, $args), $args);
65 function getChanges($dbi, $args)
67 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
68 $show_deleted = $args['show_deleted'];
69 if ($show_deleted == 'sometimes')
70 $show_deleted = $args['show_minor'];
72 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
73 // sort out pages with no comments
74 $changes = new RecentCommentsRevisionIterator($changes, $dbi);
79 class _RecentChanges_CommentFormatter
80 extends _RecentChanges_HtmlFormatter
83 function empty_message()
85 return _("No comments found");
93 function format_revision($rev)
95 static $doublettes = array();
96 if (isset($doublettes[$rev->getPageName()])) {
99 $doublettes[$rev->getPageName()] = 1;
100 $args = &$this->_args;
101 $class = 'rc-' . $this->importance($rev);
102 $time = $this->time($rev);
103 if (!$rev->get('is_minor_edit'))
104 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
105 $line = HTML::li(array('class' => $class));
106 if ($args['difflinks'])
107 $line->pushContent($this->diffLink($rev), ' ');
109 if ($args['historylinks'])
110 $line->pushContent($this->historyLink($rev), ' ');
112 $line->pushContent($this->pageLink($rev), ' ',
115 _("latest comment by "),
116 $this->authorLink($rev));
122 * List of pages which have comments
123 * i.e. sort out all non-commented pages.
125 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
127 function RecentCommentsRevisionIterator($revisions, &$dbi)
129 $this->_revisions = $revisions;
130 $this->_wikidb = $dbi;
132 $this->_blog = new WikiPlugin_WikiBlog();
137 if (!empty($this->comments) and $this->_current) {
138 if (isset($this->comments[$this->_current])) {
139 return $this->comments[$this->_current++];
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",
150 if (isset($this->comments[$this->_current])) {
152 return $this->comments[$this->_current++];
168 // c-hanging-comment-ender-p: nil
169 // indent-tabs-mode: nil