]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentComments.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / RecentComments.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3
4 /**
5  * List of basepages with recently added comments.
6  * Idea from http://www.wakkawiki.com/RecentlyCommented
7  * @author: Reini Urban
8  */
9
10 require_once("lib/plugin/RecentChanges.php");
11 require_once("lib/plugin/WikiBlog.php");
12
13 class WikiPlugin_RecentComments
14 extends WikiPlugin_RecentChanges
15 {
16     function getName () {
17         return _("RecentComments");
18     }
19     function getVersion() {
20         return preg_replace("/[Revision: $]/", '',
21                             "\$Revision$");
22     }
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");
32         return $args;
33     }
34
35     function format ($changes, $args) {
36         $fmt = new _RecentChanges_CommentFormatter($args);
37         $fmt->action = _("RecentComments");
38         return $fmt->format($changes);
39     }
40
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);
47     }
48
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'];
54         if (!$show_deleted)
55             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
56         // sort out pages with no comments
57         $changes = new RecentCommentsRevisionIterator($changes, $dbi);
58         return $changes;
59     }
60 }
61
62 class _RecentChanges_CommentFormatter
63 extends _RecentChanges_HtmlFormatter {
64
65     function empty_message () {
66         return _("No comments found");
67     }
68
69     function title() {
70         return;
71     }
72
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), ' ');
85
86         if ($args['historylinks'])
87             $line->pushContent($this->historyLink($rev), ' ');
88
89         $line->pushContent($this->pageLink($rev), ' ',
90                            $time, ' ',
91                            ' . . . . ',
92                            _("latest comment by "),
93                            $this->authorLink($rev));
94         return $line;
95     }
96 }
97
98 /**
99  * List of pages which have comments
100  * i.e. sort out all non-commented pages.
101  */
102 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
103 {
104     function RecentCommentsRevisionIterator ($revisions, &$dbi) {
105         $this->_revisions = $revisions;
106         $this->_wikidb = $dbi;
107         $this->_current = 0;
108         $this->_blog = new WikiPlugin_WikiBlog();
109     }
110
111     function next () {
112         if (!empty($this->comments) and $this->_current) {
113             if (isset($this->comments[$this->_current])) {
114                 return $this->comments[$this->_current++];
115             } else {
116                 $this->_current = 0;
117             }
118         }
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",
124                                                  "cmp"));
125                 if (isset($this->comments[$this->_current])) {
126                     //$this->_current++;
127                     return $this->comments[$this->_current++];
128                 }
129             } else {
130                 $this->_current = 0;
131             }
132         }
133         $this->free();
134         return false;
135     }
136
137 }
138
139 // $Log: not supported by cvs2svn $
140 // Revision 1.3  2004/05/14 20:55:03  rurban
141 // simplified RecentComments
142 //
143
144 // (c-file-style: "gnu")
145 // Local Variables:
146 // mode: php
147 // tab-width: 8
148 // c-basic-offset: 4
149 // c-hanging-comment-ender-p: nil
150 // indent-tabs-mode: nil
151 // End:
152 ?>