]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentComments.php
No underscore for private function
[SourceForge/phpwiki.git] / lib / plugin / RecentComments.php
1 <?php
2
3 /*
4  * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
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.
12  *
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.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /**
24  * List of basepages with recently added comments.
25  * Idea from http://www.wakkawiki.com/RecentlyCommented
26  * @author: Reini Urban
27  */
28
29 require_once 'lib/plugin/RecentChanges.php';
30 require_once 'lib/plugin/WikiBlog.php';
31
32 class WikiPlugin_RecentComments
33     extends WikiPlugin_RecentChanges
34 {
35     function getName()
36     {
37         return _("RecentComments");
38     }
39
40     function getDescription()
41     {
42         return _("List basepages with recently added comments.");
43     }
44
45     function getDefaultArguments()
46     {
47         $args = parent::getDefaultArguments();
48         $args['show_minor'] = false;
49         $args['show_all'] = true;
50         $args['caption'] = _("Recent Comments");
51         return $args;
52     }
53
54     function format($changes, $args)
55     {
56         $fmt = new _RecentChanges_CommentFormatter($args);
57         $fmt->action = _("RecentComments");
58         return $fmt->format($changes);
59     }
60
61     function run($dbi, $argstr, &$request, $basepage)
62     {
63         $args = $this->getArgs($argstr, $request);
64         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
65         // to be enough for anyone.)
66         $args['days'] = min($args['days'], 365000);
67         return $this->format($this->getChanges($request->_dbi, $args), $args);
68     }
69
70     function getChanges($dbi, $args)
71     {
72         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
73         $show_deleted = $args['show_deleted'];
74         if ($show_deleted == 'sometimes')
75             $show_deleted = $args['show_minor'];
76         if (!$show_deleted)
77             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
78         // sort out pages with no comments
79         $changes = new RecentCommentsRevisionIterator($changes, $dbi);
80         return $changes;
81     }
82 }
83
84 class _RecentChanges_CommentFormatter
85     extends _RecentChanges_HtmlFormatter
86 {
87
88     function empty_message()
89     {
90         return _("No comments found");
91     }
92
93     function title()
94     {
95         return;
96     }
97
98     function format_revision($rev)
99     {
100         static $doublettes = array();
101         if (isset($doublettes[$rev->getPageName()])) {
102             return HTML::raw('');
103         }
104         $doublettes[$rev->getPageName()] = 1;
105         $args = &$this->_args;
106         $class = 'rc-' . $this->importance($rev);
107         $time = $this->time($rev);
108         if (!$rev->get('is_minor_edit'))
109             $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
110         $line = HTML::li(array('class' => $class));
111         if ($args['difflinks'])
112             $line->pushContent($this->diffLink($rev), ' ');
113
114         if ($args['historylinks'])
115             $line->pushContent($this->historyLink($rev), ' ');
116
117         $line->pushContent($this->pageLink($rev), ' ',
118             $time, ' ',
119             ' . . . . ',
120             _("latest comment by "),
121             $this->authorLink($rev));
122         return $line;
123     }
124 }
125
126 /**
127  * List of pages which have comments
128  * i.e. sort out all non-commented pages.
129  */
130 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
131 {
132     function RecentCommentsRevisionIterator($revisions, &$dbi)
133     {
134         $this->_revisions = $revisions;
135         $this->_wikidb = $dbi;
136         $this->_current = 0;
137         $this->_blog = new WikiPlugin_WikiBlog();
138     }
139
140     function next()
141     {
142         if (!empty($this->comments) and $this->_current) {
143             if (isset($this->comments[$this->_current])) {
144                 return $this->comments[$this->_current++];
145             } else {
146                 $this->_current = 0;
147             }
148         }
149         while (($rev = $this->_revisions->next())) {
150             $this->comments = $this->_blog->findBlogs($this->_wikidb, $rev->getPageName(), 'comment');
151             if ($this->comments) {
152                 if (count($this->comments) > 2)
153                     usort($this->comments, array("WikiPlugin_WikiBlog",
154                         "cmp"));
155                 if (isset($this->comments[$this->_current])) {
156                     //$this->_current++;
157                     return $this->comments[$this->_current++];
158                 }
159             } else {
160                 $this->_current = 0;
161             }
162         }
163         $this->free();
164         return false;
165     }
166
167 }
168
169 // Local Variables:
170 // mode: php
171 // tab-width: 8
172 // c-basic-offset: 4
173 // c-hanging-comment-ender-p: nil
174 // indent-tabs-mode: nil
175 // End: