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
19 * along with PhpWiki; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
36 return _("RecentComments");
39 function getDescription () {
40 return _("List basepages with recently added comments.");
43 function getDefaultArguments() {
44 $args = parent::getDefaultArguments();
45 $args['show_minor'] = false;
46 $args['show_all'] = true;
47 $args['caption'] = _("Recent Comments");
51 function format ($changes, $args) {
52 $fmt = new _RecentChanges_CommentFormatter($args);
53 $fmt->action = _("RecentComments");
54 return $fmt->format($changes);
57 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) {
66 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
67 $show_deleted = $args['show_deleted'];
68 if ($show_deleted == 'sometimes')
69 $show_deleted = $args['show_minor'];
71 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
72 // sort out pages with no comments
73 $changes = new RecentCommentsRevisionIterator($changes, $dbi);
78 class _RecentChanges_CommentFormatter
79 extends _RecentChanges_HtmlFormatter {
81 function empty_message () {
82 return _("No comments found");
89 function format_revision ($rev) {
90 static $doublettes = array();
91 if (isset($doublettes[$rev->getPageName()])) return;
92 $doublettes[$rev->getPageName()] = 1;
93 $args = &$this->_args;
94 $class = 'rc-' . $this->importance($rev);
95 $time = $this->time($rev);
96 if (! $rev->get('is_minor_edit'))
97 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
98 $line = HTML::li(array('class' => $class));
99 if ($args['difflinks'])
100 $line->pushContent($this->diffLink($rev), ' ');
102 if ($args['historylinks'])
103 $line->pushContent($this->historyLink($rev), ' ');
105 $line->pushContent($this->pageLink($rev), ' ',
108 _("latest comment by "),
109 $this->authorLink($rev));
115 * List of pages which have comments
116 * i.e. sort out all non-commented pages.
118 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
120 function RecentCommentsRevisionIterator ($revisions, &$dbi) {
121 $this->_revisions = $revisions;
122 $this->_wikidb = $dbi;
124 $this->_blog = new WikiPlugin_WikiBlog();
128 if (!empty($this->comments) and $this->_current) {
129 if (isset($this->comments[$this->_current])) {
130 return $this->comments[$this->_current++];
135 while (($rev = $this->_revisions->next())) {
136 $this->comments = $this->_blog->findBlogs($this->_wikidb, $rev->getPageName(), 'comment');
137 if ($this->comments) {
138 if (count($this->comments) > 2)
139 usort($this->comments, array("WikiPlugin_WikiBlog",
141 if (isset($this->comments[$this->_current])) {
143 return $this->comments[$this->_current++];
159 // c-hanging-comment-ender-p: nil
160 // indent-tabs-mode: nil