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");
20 function getDescription () {
21 return _("List basepages with recently added comments.");
24 function getVersion() {
25 return preg_replace("/[Revision: $]/", '',
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");
41 function format ($changes, $args) {
42 $fmt = new _RecentChanges_CommentFormatter($args);
43 $fmt->action = _("RecentComments");
44 return $fmt->format($changes);
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);
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'];
61 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
62 // sort out pages with no comments
63 $changes = new RecentCommentsRevisionIterator($changes, $dbi);
68 class _RecentChanges_CommentFormatter
69 extends _RecentChanges_HtmlFormatter {
71 function empty_message () {
72 return _("No comments found");
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), ' ');
92 if ($args['historylinks'])
93 $line->pushContent($this->historyLink($rev), ' ');
95 $line->pushContent($this->pageLink($rev), ' ',
98 _("latest comment by "),
99 $this->authorLink($rev));
105 * List of pages which have comments
106 * i.e. sort out all non-commented pages.
108 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
110 function RecentCommentsRevisionIterator ($revisions, &$dbi) {
111 $this->_revisions = $revisions;
112 $this->_wikidb = $dbi;
114 $this->_blog = new WikiPlugin_WikiBlog();
118 if (!empty($this->comments) and $this->_current) {
119 if (isset($this->comments[$this->_current])) {
120 return $this->comments[$this->_current++];
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",
131 if (isset($this->comments[$this->_current])) {
133 return $this->comments[$this->_current++];
145 // (c-file-style: "gnu")
150 // c-hanging-comment-ender-p: nil
151 // indent-tabs-mode: nil