2 rcs_id('$Id: RecentChanges.php,v 1.49 2002-02-01 19:17:21 carstenklapp 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");
161 $desc = fmt("The %d most recent %s during the past %.1f days are listed below.",
162 $limit, $edits, $days);
164 $desc = fmt("The %d most recent %s are listed below.",
169 $desc = fmt("The most recent %s during the past %.1f days are listed below.",
172 $desc = fmt("All %s are listed below.", $edits);
179 extract($this->_args);
180 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
185 function format ($changes) {
186 $html = HTML(HTML::h2(false, $this->title()));
187 if (($desc = $this->description()))
188 $html->pushContent(HTML::p(false, $desc));
193 while ($rev = $changes->next()) {
194 if (($date = $this->date($rev)) != $last_date) {
196 $html->pushContent($lines);
197 $html->pushContent(HTML::h3($date));
201 $lines->pushContent($this->format_revision($rev));
204 $html->pushContent($lines);
208 function format_revision ($rev) {
209 $class = 'rc-' . $this->importance($rev);
212 $historylink = false;
213 if ($this->_show_difflinks)
214 $difflink = $this->diffLink($rev);
215 if ($this->_show_historylinks)
216 $historylink = $this->historyLink($rev);
218 return HTML::li(array('class' => $class),
221 $this->pageLink($rev), ' ',
222 $rev->get('is_minor_edit') ? $this->time($rev) : HTML::strong($this->time($rev)), ' ',
223 $this->summaryAsHTML($rev),
225 $this->authorLink($rev));
230 class _RecentChanges_RssFormatter
231 extends _RecentChanges_Formatter
233 var $_absurls = true;
235 function time ($rev) {
236 return Iso8601DateTime($rev->get('mtime'));
239 function pageURI ($rev) {
240 return WikiURL($rev, '', 'absurl');
243 function format ($changes) {
244 include_once('lib/RssWriter.php');
245 $rss = new RssWriter;
248 $rss->channel($this->channel_properties());
250 if (($props = $this->image_properties()))
252 if (($props = $this->textinput_properties()))
253 $rss->textinput($props);
255 while ($rev = $changes->next()) {
256 $rss->addItem($this->item_properties($rev),
257 $this->pageURI($rev));
261 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
263 global $request; // FIXME
264 $request->finish(); // NORETURN!!!!
267 function image_properties () {
270 $img_url = $Theme->getImageURL('logo');
274 return array('title' => WIKI_NAME,
275 'link' => WikiURL(HomePage, false, 'absurl'),
279 function textinput_properties () {
280 return array('title' => _("Search"),
281 'description' => _("Title Search"),
283 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
286 function channel_properties () {
289 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
291 return array('title' => WIKI_NAME,
292 'dc:description' => _("RecentChanges"),
294 'dc:date' => Iso8601DateTime(time()));
296 /* FIXME: other things one might like in <channel>:
305 * rss091:managingEditor
307 * rss091:lastBuildDate
315 function item_properties ($rev) {
316 $page = $rev->getPage();
317 $pagename = $page->getName();
319 return array( 'title' => split_pagename($pagename),
320 'description' => $this->summary($rev),
321 'link' => $this->pageURL($rev),
322 'dc:date' => $this->time($rev),
323 'dc:contributor' => $rev->get('author'),
324 'wiki:version' => $rev->getVersion(),
325 'wiki:importance' => $this->importance($rev),
326 'wiki:status' => $this->status($rev),
327 'wiki:diff' => $this->diffURL($rev),
328 'wiki:history' => $this->historyURL($rev)
333 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
337 * @param $revisions object a WikiDB_PageRevisionIterator.
339 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
340 $this->_revisions = $revisions;
341 $this->_check_current_revision = $check_current_revision;
345 while (($rev = $this->_revisions->next())) {
346 if ($this->_check_current_revision) {
347 $page = $rev->getPage();
348 $check_rev = $page->getCurrentRevision();
353 if (! $check_rev->hasDefaultContents())
361 $this->_revisions->free();
365 class WikiPlugin_RecentChanges
368 function getName () {
369 return _("RecentChanges");
372 function getDefaultArguments() {
373 return array('days' => 2,
374 'show_minor' => false,
375 'show_major' => true,
377 'show_deleted' => 'sometimes',
382 'historylinks' => false,
387 function getArgs ($argstr, $request, $defaults = false) {
388 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
390 $action = $request->getArg('action');
391 if ($action != 'browse' && ! $request->isActionPage($action))
392 $args['format'] = false; // default -> HTML
394 if ($args['format'] == 'rss' && empty($args['limit']))
395 $args['limit'] = 15; // Fix default value for RSS.
400 function getMostRecentParams ($args) {
403 $params = array('include_minor_revisions' => $show_minor,
404 'exclude_major_revisions' => !$show_major,
405 'include_all_revisions' => !empty($show_all));
408 $params['limit'] = $limit;
411 $params['since'] = time() - 24 * 3600 * $days;
416 function getChanges ($dbi, $args) {
417 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
419 $show_deleted = $args['show_deleted'];
420 if ($show_deleted == 'sometimes')
421 $show_deleted = $args['show_minor'];
424 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
429 function format ($changes, $args) {
431 $format = $args['format'];
433 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
435 if ($format == 'rss')
436 $fmt_class = '_RecentChanges_RssFormatter';
437 elseif ($format == 'rss091') {
438 include_once "lib/RSSWriter091.php";
439 $fmt_class = '_RecentChanges_RssFormatter091';
442 $fmt_class = '_RecentChanges_HtmlFormatter';
445 $fmt = new $fmt_class($args);
446 $fmt->_show_difflinks = $args['difflinks'];
447 $fmt->_show_historylinks = $args['historylinks'];
449 return $fmt->format($changes);
452 function run ($dbi, $argstr, $request) {
453 $args = $this->getArgs($argstr, $request);
455 if (! $args['daylist']) {
456 // Display RecentChanges
458 // Hack alert: format() is a NORETURN for rss formatters.
459 return $this->format($this->getChanges($dbi, $args), $args);
461 // Display days selection buttons
464 $daysarray = explode(",", $daylist);
467 $url_show_minor = "";
471 if (($show_minor == 1)||($show_minor == true))
472 $url_show_minor = "&show_minor=1";
473 if (($show_all == 1)||($show_all == true))
474 $url_show_all = "&show_all=1";
478 $caption = _("Show changes for:");
481 $caption = _("Show all changes for:");
483 $caption = _("Show minor edits for:");
487 $b = new buttonSet();
488 $b->caption = $caption;
490 foreach ($daysarray as $daynum) {
495 $label = "..."; //alldays
497 $label = sprintf(_("%s days"), $daynum);
499 // Build the button's url
500 $b->addButton($label, "RecentChanges?days=" .$daynum
501 .$url_show_minor .$url_show_all,
504 return HTML::div(array('class'=>'wiki-rc-action'), $b->getContent());
511 function buttonSet() {
517 function addButton($label, $url, $action) {
519 $this->_b[] = $Theme->makeButton($label, $url, $action);
522 function getContent() {
523 if (empty($this->content))
524 $this->_generateContent();
525 return $this->content;
528 function _generateContent() {
529 $this->content = HTML::p($this->caption . " ");
530 // Avoid an extraneous ButtonSeparator
531 $this->content->pushContent(array_shift($this->_b));
534 foreach ($this->_b as $button) {
535 $this->content->pushContent($Theme->getButtonSeparator());
536 $this->content->pushContent($button);
543 // (c-file-style: "gnu")
548 // c-hanging-comment-ender-p: nil
549 // indent-tabs-mode: nil