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