2 rcs_id('$Id: RecentComments.php,v 1.3 2004-05-14 20:55:03 rurban Exp $');
5 * List of basepages with recently added comments.
6 * Idea from http://www.wakkawiki.com/RecentlyCommented
10 require_once("lib/plugin/RecentChanges.php");
11 require_once("lib/plugin/WikiBlog.php");
13 class WikiPlugin_RecentComments
14 extends WikiPlugin_RecentChanges
17 return _("RecentComments");
19 function getVersion() {
20 return preg_replace("/[Revision: $]/", '',
23 function getDefaultArguments() {
24 //php-4.0.4pl1 breaks at the parent:: line even if the
25 // code doesn't reach this line
26 //if (!check_php_version(4,0,6))
27 $args = WikiPlugin_RecentChanges::getDefaultArguments();
28 //else $args = parent::getDefaultArguments();
29 $args['show_minor'] = false;
30 $args['show_all'] = true;
31 $args['caption'] = _("Recent Comments");
35 function format ($changes, $args) {
36 $fmt = new _RecentChanges_CommentFormatter($args);
37 return $fmt->format($changes);
40 function run($dbi, $argstr, &$request, $basepage) {
41 $args = $this->getArgs($argstr, $request);
42 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
43 // to be enough for anyone.)
44 $args['days'] = min($args['days'], 365000);
45 return $this->format($this->getChanges($request->_dbi, $args), $args);
48 function getChanges ($dbi, $args) {
49 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
50 $show_deleted = $args['show_deleted'];
51 if ($show_deleted == 'sometimes')
52 $show_deleted = $args['show_minor'];
54 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
55 // sort out pages with no comments
56 $changes = new RecentCommentsRevisionIterator($changes, $dbi);
61 class _RecentChanges_CommentFormatter
62 extends _RecentChanges_HtmlFormatter {
64 function empty_message () {
65 return _("No comments found");
72 function format_revision ($rev) {
73 static $doublettes = array();
74 if (isset($doublettes[$rev->getPageName()])) return;
75 $doublettes[$rev->getPageName()] = 1;
76 $args = &$this->_args;
77 $class = 'rc-' . $this->importance($rev);
78 $time = $this->time($rev);
79 if (! $rev->get('is_minor_edit'))
80 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
81 $line = HTML::li(array('class' => $class));
82 if ($args['difflinks'])
83 $line->pushContent($this->diffLink($rev), ' ');
85 if ($args['historylinks'])
86 $line->pushContent($this->historyLink($rev), ' ');
88 $line->pushContent($this->pageLink($rev), ' ',
91 _("latest comment by "),
92 $this->authorLink($rev));
98 * List of pages which have comments
99 * i.e. sort out all non-commented pages.
101 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
103 function RecentCommentsRevisionIterator ($revisions, &$dbi) {
104 $this->_revisions = $revisions;
105 $this->_wikidb = $dbi;
107 $this->_blog = new WikiPlugin_WikiBlog();
111 if (!empty($this->comments) and $this->_current) {
112 if (isset($this->comments[$this->_current])) {
113 return $this->comments[$this->_current++];
118 while (($rev = $this->_revisions->next())) {
119 $this->comments = $this->_blog->findBlogs($this->_wikidb, $rev->getPageName(), 'comment');
120 if ($this->comments) {
121 if (count($this->comments) > 2)
122 usort($this->comments, array("WikiPlugin_WikiBlog",
124 if (isset($this->comments[$this->_current])) {
126 return $this->comments[$this->_current++];
138 // $Log: not supported by cvs2svn $
140 // (c-file-style: "gnu")
145 // c-hanging-comment-ender-p: nil
146 // indent-tabs-mode: nil