2 rcs_id('$Id: RecentChanges.php,v 1.52 2002-02-01 22:01:42 dairiki Exp $');
7 class _RecentChanges_Formatter
11 function _RecentChanges_Formatter ($rc_args) {
12 $this->_args = $rc_args;
13 $this->_diffargs = array('action' => 'diff');
15 if ($rc_args['show_minor'] || !$rc_args['show_major'])
16 $this->_diffargs['previous'] = 'minor';
19 function include_versions_in_URLs() {
20 return (bool) $this->_args['show_all'];
23 function date ($rev) {
25 return $Theme->formatDate($rev->get('mtime'));
28 function time ($rev) {
30 return $Theme->formatTime($rev->get('mtime'));
33 function diffURL ($rev) {
34 $args = $this->_diffargs;
35 if ($this->include_versions_in_URLs())
36 $args['version'] = $rev->getVersion();
37 $page = $rev->getPage();
38 return WikiURL($page->getName(), $args, $this->_absurls);
41 function historyURL ($rev) {
42 $page = $rev->getPage();
43 return WikiURL($page, array('action' => _("PageHistory")),
47 function pageURL ($rev) {
48 return WikiURL($this->include_versions_in_URLs() ? $rev : $page,
52 function authorHasPage ($author) {
53 global $WikiNameRegexp, $request;
54 $dbi = $request->getDbh();
55 return preg_match("/^$WikiNameRegexp\$/", $author) && $dbi->isWikiPage($author);
58 function authorURL ($author) {
59 return $this->authorHasPage() ? WikiURL($author) : false;
63 function status ($rev) {
64 if ($rev->hasDefaultContents())
66 $page = $rev->getPage();
67 $prev = $page->getRevisionBefore($rev->getVersion());
68 if ($prev->hasDefaultContents())
73 function importance ($rev) {
74 return $rev->get('is_minor_edit') ? 'minor' : 'major';
77 function summary($rev) {
78 if ( ($summary = $rev->get('summary')) )
81 switch ($this->status($rev)) {
85 return _("New page.");
92 class _RecentChanges_HtmlFormatter
93 extends _RecentChanges_Formatter
95 function diffLink ($rev) {
97 return $Theme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
100 function historyLink ($rev) {
102 return $Theme->makeButton(_("(hist)"), $this->historyURL($rev), 'wiki-rc-action');
105 function pageLink ($rev) {
106 $page = $rev->getPage();
108 if ($this->include_versions_in_URLs()) {
109 $version = $rev->getVersion();
110 $exists = !$rev->hasDefaultContents();
114 $cur = $page->getCurrentRevision();
115 $exists = !$cur->hasDefaultContents();
118 return $Theme->linkExistingWikiWord($page->getName(), false, $version);
120 return $Theme->linkUnknownWikiWord($page->getName(), false, $version);
123 function authorLink ($rev) {
124 $author = $rev->get('author');
125 if ( $this->authorHasPage($author) ) {
126 return WikiLink($author);
131 function summaryAsHTML ($rev) {
132 if ( !($summary = $this->summary($rev)) )
134 return HTML::strong( array('class' => 'wiki-summary'),
136 do_transform($summary, 'LinkTransform'),
140 function rss_icon () {
141 global $request, $Theme;
143 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
144 return $Theme->makeButton("RSS", $rss_url, 'rssicion');
147 function description () {
148 extract($this->_args);
150 // FIXME: say something about show_all.
152 if ($show_major && $show_minor)
155 $edits = _("major edits");
157 $edits = _("minor edits");
160 if (intval($days) != $days)
161 $days = sprintf("%.1f", $days);
162 $timespan = $days == 1 ? _("day") : sprintf(_("%s days"), $days);
166 if (!empty($timespan))
167 $desc = fmt("The %d most recent %s during the past %s are listed below.",
168 $limit, $edits, $timespan);
170 $desc = fmt("The %d most recent %s are listed below.",
174 if (!empty($timespan))
175 $desc = fmt("The most recent %s during the past %s are listed below.",
178 $desc = fmt("All %s are listed below.", $edits);
185 extract($this->_args);
186 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
191 function format ($changes) {
192 $html = HTML(HTML::h2(false, $this->title()));
193 if (($desc = $this->description()))
194 $html->pushContent(HTML::p(false, $desc));
196 if ($this->_args['daylist'])
197 $html->pushContent(new DayButtonBar($this->_args));
202 while ($rev = $changes->next()) {
203 if (($date = $this->date($rev)) != $last_date) {
205 $html->pushContent($lines);
206 $html->pushContent(HTML::h3($date));
210 $lines->pushContent($this->format_revision($rev));
213 $html->pushContent($lines);
217 function format_revision ($rev) {
218 $args = &$this->_args;
220 $class = 'rc-' . $this->importance($rev);
222 $time = $this->time($rev);
223 if (! $rev->get('is_minor_edit'))
224 $time = HTML::strong($time);
226 $line = HTML::li(array('class' => $class));
229 if ($args['difflinks'])
230 $line->pushContent($this->diffLink($rev), ' ');
232 if ($args['historylinks'])
233 $line->pushContent($this->historyLink($rev), ' ');
235 $line->pushContent($this->pageLink($rev), ' ',
237 $this->summaryAsHTML($rev),
239 $this->authorLink($rev));
245 class _RecentChanges_RssFormatter
246 extends _RecentChanges_Formatter
248 var $_absurls = true;
250 function time ($rev) {
251 return Iso8601DateTime($rev->get('mtime'));
254 function pageURI ($rev) {
255 return WikiURL($rev, '', 'absurl');
258 function format ($changes) {
259 include_once('lib/RssWriter.php');
260 $rss = new RssWriter;
263 $rss->channel($this->channel_properties());
265 if (($props = $this->image_properties()))
267 if (($props = $this->textinput_properties()))
268 $rss->textinput($props);
270 while ($rev = $changes->next()) {
271 $rss->addItem($this->item_properties($rev),
272 $this->pageURI($rev));
276 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
278 global $request; // FIXME
279 $request->finish(); // NORETURN!!!!
282 function image_properties () {
285 $img_url = $Theme->getImageURL('logo');
289 return array('title' => WIKI_NAME,
290 'link' => WikiURL(HomePage, false, 'absurl'),
294 function textinput_properties () {
295 return array('title' => _("Search"),
296 'description' => _("Title Search"),
298 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
301 function channel_properties () {
304 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
306 return array('title' => WIKI_NAME,
307 'dc:description' => _("RecentChanges"),
309 'dc:date' => Iso8601DateTime(time()));
311 /* FIXME: other things one might like in <channel>:
320 * rss091:managingEditor
322 * rss091:lastBuildDate
330 function item_properties ($rev) {
331 $page = $rev->getPage();
332 $pagename = $page->getName();
334 return array( 'title' => split_pagename($pagename),
335 'description' => $this->summary($rev),
336 'link' => $this->pageURL($rev),
337 'dc:date' => $this->time($rev),
338 'dc:contributor' => $rev->get('author'),
339 'wiki:version' => $rev->getVersion(),
340 'wiki:importance' => $this->importance($rev),
341 'wiki:status' => $this->status($rev),
342 'wiki:diff' => $this->diffURL($rev),
343 'wiki:history' => $this->historyURL($rev)
348 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
352 * @param $revisions object a WikiDB_PageRevisionIterator.
354 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
355 $this->_revisions = $revisions;
356 $this->_check_current_revision = $check_current_revision;
360 while (($rev = $this->_revisions->next())) {
361 if ($this->_check_current_revision) {
362 $page = $rev->getPage();
363 $check_rev = $page->getCurrentRevision();
368 if (! $check_rev->hasDefaultContents())
376 $this->_revisions->free();
380 class WikiPlugin_RecentChanges
383 function getName () {
384 return _("RecentChanges");
387 function getDefaultArguments() {
388 return array('days' => 2,
389 'show_minor' => false,
390 'show_major' => true,
392 'show_deleted' => 'sometimes',
397 'historylinks' => false,
402 function getArgs ($argstr, $request, $defaults = false) {
403 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
405 $action = $request->getArg('action');
406 if ($action != 'browse' && ! $request->isActionPage($action))
407 $args['format'] = false; // default -> HTML
409 if ($args['format'] == 'rss' && empty($args['limit']))
410 $args['limit'] = 15; // Fix default value for RSS.
415 function getMostRecentParams ($args) {
418 $params = array('include_minor_revisions' => $show_minor,
419 'exclude_major_revisions' => !$show_major,
420 'include_all_revisions' => !empty($show_all));
423 $params['limit'] = $limit;
426 $params['since'] = time() - 24 * 3600 * $days;
431 function getChanges ($dbi, $args) {
432 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
434 $show_deleted = $args['show_deleted'];
435 if ($show_deleted == 'sometimes')
436 $show_deleted = $args['show_minor'];
439 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
444 function format ($changes, $args) {
446 $format = $args['format'];
448 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
450 if ($format == 'rss')
451 $fmt_class = '_RecentChanges_RssFormatter';
452 elseif ($format == 'rss091') {
453 include_once "lib/RSSWriter091.php";
454 $fmt_class = '_RecentChanges_RssFormatter091';
457 $fmt_class = '_RecentChanges_HtmlFormatter';
460 $fmt = new $fmt_class($args);
461 return $fmt->format($changes);
464 function run ($dbi, $argstr, $request) {
465 $args = $this->getArgs($argstr, $request);
467 // Hack alert: format() is a NORETURN for rss formatters.
468 return $this->format($this->getChanges($dbi, $args), $args);
473 class DayButtonBar extends HtmlElement {
475 function DayButtonBar ($plugin_args) {
476 $this->HtmlElement('p', array('class' => 'wiki-rc-action'));
478 // Display days selection buttons
479 extract($plugin_args);
484 $caption = _("Show minor edits for:");
486 $caption = _("Show all changes for:");
488 $caption = _("Show changes for:");
491 $this->pushContent($caption, ' ');
494 $sep = $Theme->getButtonSeparator();
497 foreach (explode(",", $daylist) as $days) {
499 $this->pushContent($sep);
500 $this->pushContent($this->_makeDayButton($days));
504 function _makeDayButton ($days) {
505 global $Theme, $request;
510 $label = "..."; //alldays
512 $label = sprintf(_("%s days"), $days);
514 $url = $request->getURLtoSelf(array('action' => 'browse', 'days' => $days));
516 return $Theme->makeButton($label, $url, 'wiki-rc-action');
522 // (c-file-style: "gnu")
527 // c-hanging-comment-ender-p: nil
528 // indent-tabs-mode: nil