1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
<?php // -*-php-*-
rcs_id('$Id: RecentComments.php,v 1.3 2004/05/14 20:55:03 rurban Exp $');
/**
* List of basepages with recently added comments.
* Idea from http://www.wakkawiki.com/RecentlyCommented
* @author: Reini Urban
*/
require_once("lib/plugin/RecentChanges.php");
require_once("lib/plugin/WikiBlog.php");
class WikiPlugin_RecentComments
extends WikiPlugin_RecentChanges
{
function getName () {
return _("RecentComments");
}
function getVersion() {
return preg_replace("/[Revision: $]/", '',
"\$Revision: 1.3 $");
}
function getDefaultArguments() {
//php-4.0.4pl1 breaks at the parent:: line even if the
// code doesn't reach this line
//if (!check_php_version(4,0,6))
$args = WikiPlugin_RecentChanges::getDefaultArguments();
//else $args = parent::getDefaultArguments();
$args['show_minor'] = false;
$args['show_all'] = true;
$args['caption'] = _("Recent Comments");
return $args;
}
function format ($changes, $args) {
$fmt = new _RecentChanges_CommentFormatter($args);
return $fmt->format($changes);
}
function run($dbi, $argstr, &$request, $basepage) {
$args = $this->getArgs($argstr, $request);
// HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
// to be enough for anyone.)
$args['days'] = min($args['days'], 365000);
return $this->format($this->getChanges($request->_dbi, $args), $args);
}
function getChanges ($dbi, $args) {
$changes = $dbi->mostRecent($this->getMostRecentParams($args));
$show_deleted = $args['show_deleted'];
if ($show_deleted == 'sometimes')
$show_deleted = $args['show_minor'];
if (!$show_deleted)
$changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
// sort out pages with no comments
$changes = new RecentCommentsRevisionIterator($changes, $dbi);
return $changes;
}
}
class _RecentChanges_CommentFormatter
extends _RecentChanges_HtmlFormatter {
function empty_message () {
return _("No comments found");
}
function title() {
return;
}
function format_revision ($rev) {
static $doublettes = array();
if (isset($doublettes[$rev->getPageName()])) return;
$doublettes[$rev->getPageName()] = 1;
$args = &$this->_args;
$class = 'rc-' . $this->importance($rev);
$time = $this->time($rev);
if (! $rev->get('is_minor_edit'))
$time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
$line = HTML::li(array('class' => $class));
if ($args['difflinks'])
$line->pushContent($this->diffLink($rev), ' ');
if ($args['historylinks'])
$line->pushContent($this->historyLink($rev), ' ');
$line->pushContent($this->pageLink($rev), ' ',
$time, ' ',
' . . . . ',
_("latest comment by "),
$this->authorLink($rev));
return $line;
}
}
/**
* List of pages which have comments
* i.e. sort out all non-commented pages.
*/
class RecentCommentsRevisionIterator extends WikiDB_PageRevisionIterator
{
function RecentCommentsRevisionIterator ($revisions, &$dbi) {
$this->_revisions = $revisions;
$this->_wikidb = $dbi;
$this->_current = 0;
$this->_blog = new WikiPlugin_WikiBlog();
}
function next () {
if (!empty($this->comments) and $this->_current) {
if (isset($this->comments[$this->_current])) {
return $this->comments[$this->_current++];
} else {
$this->_current = 0;
}
}
while (($rev = $this->_revisions->next())) {
$this->comments = $this->_blog->findBlogs($this->_wikidb, $rev->getPageName(), 'comment');
if ($this->comments) {
if (count($this->comments) > 2)
usort($this->comments, array("WikiPlugin_WikiBlog",
"cmp"));
if (isset($this->comments[$this->_current])) {
//$this->_current++;
return $this->comments[$this->_current++];
}
} else {
$this->_current = 0;
}
}
$this->free();
return false;
}
}
// $Log: RecentComments.php,v $
// Revision 1.3 2004/05/14 20:55:03 rurban
// simplified RecentComments
//
// (c-file-style: "gnu")
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:
?>
|