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 $fmt->action = _("RecentComments");
38 return $fmt->format($changes);
41 function run($dbi, $argstr, &$request, $basepage) {
42 $args = $this->getArgs($argstr, $request);
43 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
44 // to be enough for anyone.)
45 $args['days'] = min($args['days'], 365000);
46 return $this->format($this->getChanges($request->_dbi, $args), $args);
49 function getChanges ($dbi, $args) {
50 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
51 $show_deleted = $args['show_deleted'];
52 if ($show_deleted == 'sometimes')
53 $show_deleted = $args['show_minor'];
55 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
56 // sort out pages with no comments
57 $changes = new RecentCommentsRevisionIterator($changes, $dbi);
62 class _RecentChanges_CommentFormatter
63 extends _RecentChanges_HtmlFormatter {
65 function empty_message () {
66 return _("No comments found");
73 function format_revision ($rev) {
74 static $doublettes = array();
75 if (isset($doublettes[$rev->getPageName()])) return;
76 $doublettes[$rev->getPageName()] = 1;
77 $args = &$this->_args;
78 $class = 'rc-' . $this->importance($rev);
79 $time = $this->time($rev);
80 if (! $rev->get('is_minor_edit'))
81 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
82 $line = HTML::li(array('class' => $class));
83 if ($args['difflinks'])
84 $line->pushContent($this->diffLink($rev), ' ');
86 if ($args['historylinks'])
87 $line->pushContent($this->historyLink($rev), ' ');
89 $line->pushContent($this->pageLink($rev), ' ',
92 _("latest comment by "),
93 $this->authorLink($rev));
99 * List of pages which have comments
100 * i.e. sort out all non-commented pages.
102 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
104 function RecentCommentsRevisionIterator ($revisions, &$dbi) {
105 $this->_revisions = $revisions;
106 $this->_wikidb = $dbi;
108 $this->_blog = new WikiPlugin_WikiBlog();
112 if (!empty($this->comments) and $this->_current) {
113 if (isset($this->comments[$this->_current])) {
114 return $this->comments[$this->_current++];
119 while (($rev = $this->_revisions->next())) {
120 $this->comments = $this->_blog->findBlogs($this->_wikidb, $rev->getPageName(), 'comment');
121 if ($this->comments) {
122 if (count($this->comments) > 2)
123 usort($this->comments, array("WikiPlugin_WikiBlog",
125 if (isset($this->comments[$this->_current])) {
127 return $this->comments[$this->_current++];
139 // (c-file-style: "gnu")
144 // c-hanging-comment-ender-p: nil
145 // indent-tabs-mode: nil