2 rcs_id('$Id: RecentChanges.php,v 1.32 2002-01-25 08:36:09 carstenklapp Exp $');
8 class _RecentChanges_Formatter
10 var $_absurls = false;
12 function _RecentChanges_Formatter ($rc_args) {
13 $this->_args = $rc_args;
14 $this->_diffargs = array('action' => 'diff');
16 if ($rc_args['show_major'] && !$rc_args['show_minor'])
17 $this->_diffargs['previous'] = 'major';
20 function include_versions_in_URLs() {
21 return (bool) $this->_args['show_all'];
24 function date ($rev) {
26 return $Theme->formatDate($rev->get('mtime'));
29 function time ($rev) {
31 return $Theme->formatTime($rev->get('mtime'));
34 function diffURL ($rev) {
35 $args = $this->_diffargs;
36 if ($this->include_versions_in_URLs())
37 $args['version'] = $rev->getVersion();
38 $page = $rev->getPage();
39 return WikiURL($page->getName(), $args, $this->_absurls);
42 function historyURL ($rev) {
43 $page = $rev->getPage();
44 return WikiURL(_("PageHistory"),
45 array('page' => $page->getName()),
49 function pageURL ($rev) {
51 if ($this->include_versions_in_URLs())
52 $params['version'] = $rev->getVersion();
53 $page = $rev->getPage();
54 return WikiURL($page->getName(), $params, $this->_absurls);
57 function authorURL($author) {
58 global $WikiNameRegexp, $request;
59 $dbi = $request->getDbh();
60 if (preg_match("/^$WikiNameRegexp\$/", $author) && $dbi->isWikiPage($author))
66 function status ($rev) {
67 if ($rev->hasDefaultContents())
69 $page = $rev->getPage();
70 $prev = $page->getRevisionBefore($rev->getVersion());
71 if ($prev->hasDefaultContents())
76 function importance ($rev) {
77 return $rev->get('is_minor_edit') ? 'minor' : 'major';
80 function summary($rev) {
81 if ( ($summary = $rev->get('summary')) )
84 switch ($this->status($rev)) {
88 return _("New page.");
95 class _RecentChanges_HtmlFormatter
96 extends _RecentChanges_Formatter
98 function diffLink ($rev) {
100 return $Theme->makeButton(_("(diff)"), $this->diffURL($rev), 'wikiaction');
103 function pageLink ($rev) {
104 $page = $rev->getPage();
105 return HTML::a(array('href' => $this->pageURL($rev), 'class' => 'wiki'),
109 function authorLink ($rev) {
110 $author = $rev->get('author');
111 if ( ($url = $this->authorURL($author)) ) {
113 return $Theme->LinkExistingWikiWord($author);
118 function summaryAsHTML ($rev) {
119 if ( !($summary = $this->summary($rev)) )
121 return HTML::strong( array('class' => 'wiki-summary'),
123 do_transform($summary, 'LinkTransform'),
127 function rss_icon () {
128 global $request, $Theme;
130 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
131 return $Theme->makeButton("RSS", $rss_url, 'rssicion');
134 function description () {
135 extract($this->_args);
137 // FIXME: say something about show_all.
139 if ($show_major && $show_minor)
142 $edits = _("major edits");
144 $edits = _("minor edits");
148 $desc = fmt("The %d most recent %s during the past %.1f days are listed below.",
149 $limit, $edits, $days);
151 $desc = fmt("The %d most recent %s are listed below.",
156 $desc = fmt("The most recent %s during the past %.1f days are listed below.",
159 $desc = fmt("All %s are listed below.", $edits);
166 extract($this->_args);
167 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
172 function format ($changes) {
173 $html[] = HTML::h2(false, $this->title());
174 if (($desc = $this->description()))
175 $html[] = HTML::p(false, $desc);
180 while ($rev = $changes->next()) {
181 if (($date = $this->date($rev)) != $last_date) {
184 $html[] = HTML::h3($date);
188 $lines->pushContent($this->format_revision($rev));
195 function format_revision ($rev) {
196 $class = 'rc-' . $this->importance($rev);
198 return HTML::li(array('class' => $class),
199 $this->diffLink($rev), ' ',
200 $this->pageLink($rev), ' ',
201 $this->time($rev), ' ',
202 $this->summaryAsHTML($rev),
204 $this->authorLink($rev));
209 class _RecentChanges_RssFormatter
210 extends _RecentChanges_Formatter
212 var $_absurls = true;
214 function time ($rev) {
215 return Iso8601DateTime($rev->get('mtime'));
218 function pageURI ($rev) {
219 $page = $rev->getPage();
220 return WikiURL($page->getName(),
221 array('version' => $rev->getVersion()),
225 function format ($changes) {
226 include_once('lib/RssWriter.php');
227 $rss = new RssWriter;
230 $rss->channel($this->channel_properties());
232 if (($props = $this->image_properties()))
234 if (($props = $this->textinput_properties()))
235 $rss->textinput($props);
237 while ($rev = $changes->next()) {
238 $rss->addItem($this->item_properties($rev),
239 $this->pageURI($rev));
243 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
245 global $request; // FIXME
246 $request->finish(); // NORETURN!!!!
249 function image_properties () {
252 $img_url = $Theme->getImageURL('logo');
256 return array('title' => WIKI_NAME,
257 'link' => WikiURL(_("HomePage"), false, 'absurl'),
261 function textinput_properties () {
262 return array('title' => _("Search"),
263 'description' => _("Title Search"),
265 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
268 function channel_properties () {
271 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
273 return array('title' => WIKI_NAME,
274 'dc:description' => _("RecentChanges"),
276 'dc:date' => Iso8601DateTime(time()));
278 /* FIXME: other things one might like in <channel>:
287 * rss091:managingEditor
289 * rss091:lastBuildDate
297 function item_properties ($rev) {
298 $page = $rev->getPage();
299 $pagename = $page->getName();
301 return array( 'title' => split_pagename($pagename),
302 'description' => $this->summary($rev),
303 'link' => $this->pageURL($rev),
304 'dc:date' => $this->time($rev),
305 'dc:contributor' => $rev->get('author'),
306 'wiki:version' => $rev->getVersion(),
307 'wiki:importance' => $this->importance($rev),
308 'wiki:status' => $this->status($rev),
309 'wiki:diff' => $this->diffURL($rev),
310 'wiki:history' => $this->historyURL($rev)
315 class WikiPlugin_RecentChanges
318 function getName () {
319 return _("RecentChanges");
322 function getDefaultArguments() {
323 return array('days' => 2,
324 'show_minor' => false,
325 'show_major' => true,
334 function getArgs ($argstr, $request, $defaults = false) {
335 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
337 if ($request->getArg('action') != 'browse')
338 $args['format'] = false; // default -> HTML
340 if ($args['format'] == 'rss' && empty($args['limit']))
341 $args['limit'] = 15; // Fix default value for RSS.
346 function getMostRecentParams ($args) {
349 $params = array('include_minor_revisions' => $show_minor,
350 'exclude_major_revisions' => !$show_major,
351 'include_all_revisions' => !empty($show_all));
354 $params['limit'] = $limit;
357 $params['since'] = time() - 24 * 3600 * $days;
362 function getChanges ($dbi, $args) {
363 return $dbi->mostRecent($this->getMostRecentParams($args));
366 function format ($changes, $args) {
368 $format = $args['format'];
370 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
372 if ($format == 'rss')
373 $fmt_class = '_RecentChanges_RssFormatter';
374 elseif ($format == 'rss091') {
375 include_once "lib/RSSWriter091.php";
376 $fmt_class = '_RecentChanges_RssFormatter091';
379 $fmt_class = '_RecentChanges_HtmlFormatter';
382 $fmt = new $fmt_class($args);
383 return $fmt->format($changes);
386 function run ($dbi, $argstr, $request) {
387 $args = $this->getArgs($argstr, $request);
389 if (! $args['daylist']) {
390 // Display RecentChanges
392 // Hack alert: format() is a NORETURN for rss formatters.
393 return $this->format($this->getChanges($dbi, $args), $args);
395 // Display days selection buttons
398 $daysarray = explode(",", $daylist);
401 $url_show_minor = "";
405 if (($show_minor == 1)||($show_minor == true))
406 $url_show_minor = "&show_minor=1";
407 if (($show_all == 1)||($show_all == true))
408 $url_show_all = "&show_all=1";
412 $caption = _("Show changes for:");
415 $caption = _("Show all changes for:");
417 $caption = _("Show minor edits for:");
421 $b = new buttonSet();
422 $b->caption = $caption;
424 foreach ($daysarray as $daynum) {
429 $label = "..."; //alldays
431 $label = sprintf(_("%s days"), $daynum);
433 // Build the button's url
434 $b->addButton($label, "RecentChanges?days=" .$daynum
435 .$url_show_minor .$url_show_all,
438 return $b->getContent();
445 function buttonSet() {
451 function addButton($label, $url, $action) {
453 $this->_b[] = $Theme->makeButton($label, $url, $action);
456 function getContent() {
457 if (empty($this->content))
458 $this->_generateContent();
459 return $this->content;
462 function _generateContent() {
463 $this->content = HTML::p($this->caption . " ");
464 // Avoid an extraneous ButtonSeparator
465 $this->content->pushContent(array_shift($this->_b));
468 foreach ($this->_b as $button) {
469 $this->content->pushContent($Theme->getButtonSeparator());
470 $this->content->pushContent($button);
477 // (c-file-style: "gnu")
482 // c-hanging-comment-ender-p: nil
483 // indent-tabs-mode: nil