]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentComments.php
php_closing_tag [PSR-2] The closing ?> tag MUST be omitted from files containing...
[SourceForge/phpwiki.git] / lib / plugin / RecentComments.php
1 <?php // -*-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         return _("RecentComments");
37     }
38
39     function getDescription () {
40         return _("List basepages with recently added comments.");
41     }
42
43     function getDefaultArguments() {
44         $args = parent::getDefaultArguments();
45         $args['show_minor'] = false;
46         $args['show_all'] = true;
47         $args['caption'] = _("Recent Comments");
48         return $args;
49     }
50
51     function format ($changes, $args) {
52         $fmt = new _RecentChanges_CommentFormatter($args);
53         $fmt->action = _("RecentComments");
54         return $fmt->format($changes);
55     }
56
57     function run($dbi, $argstr, &$request, $basepage) {
58         $args = $this->getArgs($argstr, $request);
59         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
60         // to be enough for anyone.)
61         $args['days'] = min($args['days'], 365000);
62         return $this->format($this->getChanges($request->_dbi, $args), $args);
63     }
64
65     function getChanges ($dbi, $args) {
66         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
67         $show_deleted = $args['show_deleted'];
68         if ($show_deleted == 'sometimes')
69             $show_deleted = $args['show_minor'];
70         if (!$show_deleted)
71             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
72         // sort out pages with no comments
73         $changes = new RecentCommentsRevisionIterator($changes, $dbi);
74         return $changes;
75     }
76 }
77
78 class _RecentChanges_CommentFormatter
79 extends _RecentChanges_HtmlFormatter {
80
81     function empty_message () {
82         return _("No comments found");
83     }
84
85     function title() {
86         return;
87     }
88
89     function format_revision ($rev) {
90             static $doublettes = array();
91             if (isset($doublettes[$rev->getPageName()])) return;
92             $doublettes[$rev->getPageName()] = 1;
93         $args = &$this->_args;
94         $class = 'rc-' . $this->importance($rev);
95         $time = $this->time($rev);
96         if (! $rev->get('is_minor_edit'))
97             $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
98         $line = HTML::li(array('class' => $class));
99         if ($args['difflinks'])
100             $line->pushContent($this->diffLink($rev), ' ');
101
102         if ($args['historylinks'])
103             $line->pushContent($this->historyLink($rev), ' ');
104
105         $line->pushContent($this->pageLink($rev), ' ',
106                            $time, ' ',
107                            ' . . . . ',
108                            _("latest comment by "),
109                            $this->authorLink($rev));
110         return $line;
111     }
112 }
113
114 /**
115  * List of pages which have comments
116  * i.e. sort out all non-commented pages.
117  */
118 class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
119 {
120     function RecentCommentsRevisionIterator ($revisions, &$dbi) {
121         $this->_revisions = $revisions;
122         $this->_wikidb = $dbi;
123         $this->_current = 0;
124         $this->_blog = new WikiPlugin_WikiBlog();
125     }
126
127     function next () {
128             if (!empty($this->comments) and $this->_current) {
129             if (isset($this->comments[$this->_current])) {
130                 return $this->comments[$this->_current++];
131             } else {
132                     $this->_current = 0;
133             }
134             }
135         while (($rev = $this->_revisions->next())) {
136             $this->comments = $this->_blog->findBlogs($this->_wikidb, $rev->getPageName(), 'comment');
137             if ($this->comments) {
138                 if (count($this->comments) > 2)
139                     usort($this->comments, array("WikiPlugin_WikiBlog",
140                                                  "cmp"));
141                 if (isset($this->comments[$this->_current])) {
142                     //$this->_current++;
143                     return $this->comments[$this->_current++];
144                 }
145             } else {
146                 $this->_current = 0;
147             }
148             }
149         $this->free();
150         return false;
151     }
152
153 }
154
155 // Local Variables:
156 // mode: php
157 // tab-width: 8
158 // c-basic-offset: 4
159 // c-hanging-comment-ender-p: nil
160 // indent-tabs-mode: nil
161 // End: