2 rcs_id('$Id: RecentChanges.php,v 1.39 2002-01-28 18:44:24 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'])
16 $this->_diffargs['previous'] = 'major';
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(_("PageHistory"),
44 array('page' => $page->getName()),
48 function pageURL ($rev) {
50 if ($this->include_versions_in_URLs())
51 $params['version'] = $rev->getVersion();
52 $page = $rev->getPage();
53 return WikiURL($page->getName(), $params, $this->_absurls);
56 function authorHasPage ($author) {
57 global $WikiNameRegexp, $request;
58 $dbi = $request->getDbh();
59 return preg_match("/^$WikiNameRegexp\$/", $author) && $dbi->isWikiPage($author);
62 function authorURL ($author) {
63 return $this->authorHasPage() ? WikiURL($author) : false;
67 function status ($rev) {
68 if ($rev->hasDefaultContents())
70 $page = $rev->getPage();
71 $prev = $page->getRevisionBefore($rev->getVersion());
72 if ($prev->hasDefaultContents())
77 function importance ($rev) {
78 return $rev->get('is_minor_edit') ? 'minor' : 'major';
81 function summary($rev) {
82 if ( ($summary = $rev->get('summary')) )
85 switch ($this->status($rev)) {
89 return _("New page.");
96 class _RecentChanges_HtmlFormatter
97 extends _RecentChanges_Formatter
99 function diffLink ($rev) {
101 return $Theme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
104 function pageLink ($rev) {
105 $page = $rev->getPage();
107 if ($this->include_versions_in_URLs()) {
108 $version = $rev->getVersion();
109 $exists = !$rev->hasDefaultContents();
113 $cur = $page->getCurrentRevision();
114 $exists = !$cur->hasDefaultContents();
117 return $Theme->linkExistingWikiWord($page->getName(), false, $version);
119 return $Theme->linkUnknownWikiWord($page->getName(), false, $version);
122 function authorLink ($rev) {
123 $author = $rev->get('author');
124 if ( $this->authorHasPage($author) ) {
126 return $Theme->LinkExistingWikiWord($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::h2(false, $this->title());
187 if (($desc = $this->description()))
188 $html[] = HTML::p(false, $desc);
193 while ($rev = $changes->next()) {
194 if (($date = $this->date($rev)) != $last_date) {
197 $html[] = HTML::h3($date);
201 $lines->pushContent($this->format_revision($rev));
208 function format_revision ($rev) {
209 $class = 'rc-' . $this->importance($rev);
211 return HTML::li(array('class' => $class),
212 $this->diffLink($rev), ' ',
213 $this->pageLink($rev), ' ',
214 $this->time($rev), ' ',
215 ($this->importance($rev)=='minor') ? _("(minor edit)") ." " : '',
216 $this->summaryAsHTML($rev),
218 $this->authorLink($rev));
223 class _RecentChanges_RssFormatter
224 extends _RecentChanges_Formatter
226 var $_absurls = true;
228 function time ($rev) {
229 return Iso8601DateTime($rev->get('mtime'));
232 function pageURI ($rev) {
233 $page = $rev->getPage();
234 return WikiURL($page->getName(),
235 array('version' => $rev->getVersion()),
239 function format ($changes) {
240 include_once('lib/RssWriter.php');
241 $rss = new RssWriter;
244 $rss->channel($this->channel_properties());
246 if (($props = $this->image_properties()))
248 if (($props = $this->textinput_properties()))
249 $rss->textinput($props);
251 while ($rev = $changes->next()) {
252 $rss->addItem($this->item_properties($rev),
253 $this->pageURI($rev));
257 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
259 global $request; // FIXME
260 $request->finish(); // NORETURN!!!!
263 function image_properties () {
266 $img_url = $Theme->getImageURL('logo');
270 return array('title' => WIKI_NAME,
271 'link' => WikiURL(HomePage, false, 'absurl'),
275 function textinput_properties () {
276 return array('title' => _("Search"),
277 'description' => _("Title Search"),
279 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
282 function channel_properties () {
285 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
287 return array('title' => WIKI_NAME,
288 'dc:description' => _("RecentChanges"),
290 'dc:date' => Iso8601DateTime(time()));
292 /* FIXME: other things one might like in <channel>:
301 * rss091:managingEditor
303 * rss091:lastBuildDate
311 function item_properties ($rev) {
312 $page = $rev->getPage();
313 $pagename = $page->getName();
315 return array( 'title' => split_pagename($pagename),
316 'description' => $this->summary($rev),
317 'link' => $this->pageURL($rev),
318 'dc:date' => $this->time($rev),
319 'dc:contributor' => $rev->get('author'),
320 'wiki:version' => $rev->getVersion(),
321 'wiki:importance' => $this->importance($rev),
322 'wiki:status' => $this->status($rev),
323 'wiki:diff' => $this->diffURL($rev),
324 'wiki:history' => $this->historyURL($rev)
329 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
333 * @param $revisions object a WikiDB_PageRevisionIterator.
335 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
336 $this->_revisions = $revisions;
337 $this->_check_current_revision = $check_current_revision;
341 while (($rev = $this->_revisions->next())) {
342 if ($this->_check_current_revision) {
343 $page = $rev->getPage();
344 $check_rev = $page->getCurrentRevision();
349 if (! $check_rev->hasDefaultContents())
357 $this->_revisions->free();
361 class WikiPlugin_RecentChanges
364 function getName () {
365 return _("RecentChanges");
368 function getDefaultArguments() {
369 return array('days' => 2,
370 'show_minor' => false,
371 'show_major' => true,
373 'show_deleted' => 'sometimes',
381 function getArgs ($argstr, $request, $defaults = false) {
382 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
384 if ($request->getArg('action') != 'browse')
385 $args['format'] = false; // default -> HTML
387 if ($args['format'] == 'rss' && empty($args['limit']))
388 $args['limit'] = 15; // Fix default value for RSS.
393 function getMostRecentParams ($args) {
396 $params = array('include_minor_revisions' => $show_minor,
397 'exclude_major_revisions' => !$show_major,
398 'include_all_revisions' => !empty($show_all));
401 $params['limit'] = $limit;
404 $params['since'] = time() - 24 * 3600 * $days;
409 function getChanges ($dbi, $args) {
410 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
412 $show_deleted = $args['show_deleted'];
413 if ($show_deleted == 'sometimes')
414 $show_deleted = $args['show_minor'];
417 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
422 function format ($changes, $args) {
424 $format = $args['format'];
426 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
428 if ($format == 'rss')
429 $fmt_class = '_RecentChanges_RssFormatter';
430 elseif ($format == 'rss091') {
431 include_once "lib/RSSWriter091.php";
432 $fmt_class = '_RecentChanges_RssFormatter091';
435 $fmt_class = '_RecentChanges_HtmlFormatter';
438 $fmt = new $fmt_class($args);
439 return $fmt->format($changes);
442 function run ($dbi, $argstr, $request) {
443 $args = $this->getArgs($argstr, $request);
445 if (! $args['daylist']) {
446 // Display RecentChanges
448 // Hack alert: format() is a NORETURN for rss formatters.
449 return $this->format($this->getChanges($dbi, $args), $args);
451 // Display days selection buttons
454 $daysarray = explode(",", $daylist);
457 $url_show_minor = "";
461 if (($show_minor == 1)||($show_minor == true))
462 $url_show_minor = "&show_minor=1";
463 if (($show_all == 1)||($show_all == true))
464 $url_show_all = "&show_all=1";
468 $caption = _("Show changes for:");
471 $caption = _("Show all changes for:");
473 $caption = _("Show minor edits for:");
477 $b = new buttonSet();
478 $b->caption = $caption;
480 foreach ($daysarray as $daynum) {
485 $label = "..."; //alldays
487 $label = sprintf(_("%s days"), $daynum);
489 // Build the button's url
490 $b->addButton($label, "RecentChanges?days=" .$daynum
491 .$url_show_minor .$url_show_all,
494 return HTML::div(array('class'=>'wiki-rc-action'), $b->getContent());
501 function buttonSet() {
507 function addButton($label, $url, $action) {
509 $this->_b[] = $Theme->makeButton($label, $url, $action);
512 function getContent() {
513 if (empty($this->content))
514 $this->_generateContent();
515 return $this->content;
518 function _generateContent() {
519 $this->content = HTML::p($this->caption . " ");
520 // Avoid an extraneous ButtonSeparator
521 $this->content->pushContent(array_shift($this->_b));
524 foreach ($this->_b as $button) {
525 $this->content->pushContent($Theme->getButtonSeparator());
526 $this->content->pushContent($button);
533 // (c-file-style: "gnu")
538 // c-hanging-comment-ender-p: nil
539 // indent-tabs-mode: nil