2 rcs_id('$Id: RecentChanges.php,v 1.36 2002-01-27 22:00:58 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 authorHasPage ($author) {
58 global $WikiNameRegexp, $request;
59 $dbi = $request->getDbh();
60 return preg_match("/^$WikiNameRegexp\$/", $author) && $dbi->isWikiPage($author);
63 function authorURL ($author) {
64 return $this->authorHasPage() ? WikiURL($author) : false;
68 function status ($rev) {
69 if ($rev->hasDefaultContents())
71 $page = $rev->getPage();
72 $prev = $page->getRevisionBefore($rev->getVersion());
73 if ($prev->hasDefaultContents())
78 function importance ($rev) {
79 return $rev->get('is_minor_edit') ? 'minor' : 'major';
82 function summary($rev) {
83 if ( ($summary = $rev->get('summary')) )
86 switch ($this->status($rev)) {
90 return _("New page.");
97 class _RecentChanges_HtmlFormatter
98 extends _RecentChanges_Formatter
100 function diffLink ($rev) {
102 return $Theme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
105 function pageLink ($rev) {
106 $page = $rev->getPage();
108 if ($this->include_versions_in_URLs())
109 return $Theme->LinkExistingWikiWord($page->getName(), false, $rev->getVersion());
111 return $Theme->LinkExistingWikiWord($page->getName());
114 function authorLink ($rev) {
115 $author = $rev->get('author');
116 if ( $this->authorHasPage($author) ) {
118 return $Theme->LinkExistingWikiWord($author);
123 function summaryAsHTML ($rev) {
124 if ( !($summary = $this->summary($rev)) )
126 return HTML::strong( array('class' => 'wiki-summary'),
128 do_transform($summary, 'LinkTransform'),
132 function rss_icon () {
133 global $request, $Theme;
135 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
136 return $Theme->makeButton("RSS", $rss_url, 'rssicion');
139 function description () {
140 extract($this->_args);
142 // FIXME: say something about show_all.
144 if ($show_major && $show_minor)
147 $edits = _("major edits");
149 $edits = _("minor edits");
153 $desc = fmt("The %d most recent %s during the past %.1f days are listed below.",
154 $limit, $edits, $days);
156 $desc = fmt("The %d most recent %s are listed below.",
161 $desc = fmt("The most recent %s during the past %.1f days are listed below.",
164 $desc = fmt("All %s are listed below.", $edits);
171 extract($this->_args);
172 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
177 function format ($changes) {
178 $html[] = HTML::h2(false, $this->title());
179 if (($desc = $this->description()))
180 $html[] = HTML::p(false, $desc);
185 while ($rev = $changes->next()) {
186 if (($date = $this->date($rev)) != $last_date) {
189 $html[] = HTML::h3($date);
193 $lines->pushContent($this->format_revision($rev));
200 function format_revision ($rev) {
201 $class = 'rc-' . $this->importance($rev);
203 return HTML::li(array('class' => $class),
204 $this->diffLink($rev), ' ',
205 $this->pageLink($rev), ' ',
206 $this->time($rev), ' ',
207 $this->summaryAsHTML($rev),
209 $this->authorLink($rev));
214 class _RecentChanges_RssFormatter
215 extends _RecentChanges_Formatter
217 var $_absurls = true;
219 function time ($rev) {
220 return Iso8601DateTime($rev->get('mtime'));
223 function pageURI ($rev) {
224 $page = $rev->getPage();
225 return WikiURL($page->getName(),
226 array('version' => $rev->getVersion()),
230 function format ($changes) {
231 include_once('lib/RssWriter.php');
232 $rss = new RssWriter;
235 $rss->channel($this->channel_properties());
237 if (($props = $this->image_properties()))
239 if (($props = $this->textinput_properties()))
240 $rss->textinput($props);
242 while ($rev = $changes->next()) {
243 $rss->addItem($this->item_properties($rev),
244 $this->pageURI($rev));
248 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
250 global $request; // FIXME
251 $request->finish(); // NORETURN!!!!
254 function image_properties () {
257 $img_url = $Theme->getImageURL('logo');
261 return array('title' => WIKI_NAME,
262 'link' => WikiURL(HomePage, false, 'absurl'),
266 function textinput_properties () {
267 return array('title' => _("Search"),
268 'description' => _("Title Search"),
270 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
273 function channel_properties () {
276 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
278 return array('title' => WIKI_NAME,
279 'dc:description' => _("RecentChanges"),
281 'dc:date' => Iso8601DateTime(time()));
283 /* FIXME: other things one might like in <channel>:
292 * rss091:managingEditor
294 * rss091:lastBuildDate
302 function item_properties ($rev) {
303 $page = $rev->getPage();
304 $pagename = $page->getName();
306 return array( 'title' => split_pagename($pagename),
307 'description' => $this->summary($rev),
308 'link' => $this->pageURL($rev),
309 'dc:date' => $this->time($rev),
310 'dc:contributor' => $rev->get('author'),
311 'wiki:version' => $rev->getVersion(),
312 'wiki:importance' => $this->importance($rev),
313 'wiki:status' => $this->status($rev),
314 'wiki:diff' => $this->diffURL($rev),
315 'wiki:history' => $this->historyURL($rev)
320 class WikiPlugin_RecentChanges
323 function getName () {
324 return _("RecentChanges");
327 function getDefaultArguments() {
328 return array('days' => 2,
329 'show_minor' => false,
330 'show_major' => true,
339 function getArgs ($argstr, $request, $defaults = false) {
340 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
342 if ($request->getArg('action') != 'browse')
343 $args['format'] = false; // default -> HTML
345 if ($args['format'] == 'rss' && empty($args['limit']))
346 $args['limit'] = 15; // Fix default value for RSS.
351 function getMostRecentParams ($args) {
354 $params = array('include_minor_revisions' => $show_minor,
355 'exclude_major_revisions' => !$show_major,
356 'include_all_revisions' => !empty($show_all));
359 $params['limit'] = $limit;
362 $params['since'] = time() - 24 * 3600 * $days;
367 function getChanges ($dbi, $args) {
368 return $dbi->mostRecent($this->getMostRecentParams($args));
371 function format ($changes, $args) {
373 $format = $args['format'];
375 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
377 if ($format == 'rss')
378 $fmt_class = '_RecentChanges_RssFormatter';
379 elseif ($format == 'rss091') {
380 include_once "lib/RSSWriter091.php";
381 $fmt_class = '_RecentChanges_RssFormatter091';
384 $fmt_class = '_RecentChanges_HtmlFormatter';
387 $fmt = new $fmt_class($args);
388 return $fmt->format($changes);
391 function run ($dbi, $argstr, $request) {
392 $args = $this->getArgs($argstr, $request);
394 if (! $args['daylist']) {
395 // Display RecentChanges
397 // Hack alert: format() is a NORETURN for rss formatters.
398 return $this->format($this->getChanges($dbi, $args), $args);
400 // Display days selection buttons
403 $daysarray = explode(",", $daylist);
406 $url_show_minor = "";
410 if (($show_minor == 1)||($show_minor == true))
411 $url_show_minor = "&show_minor=1";
412 if (($show_all == 1)||($show_all == true))
413 $url_show_all = "&show_all=1";
417 $caption = _("Show changes for:");
420 $caption = _("Show all changes for:");
422 $caption = _("Show minor edits for:");
426 $b = new buttonSet();
427 $b->caption = $caption;
429 foreach ($daysarray as $daynum) {
434 $label = "..."; //alldays
436 $label = sprintf(_("%s days"), $daynum);
438 // Build the button's url
439 $b->addButton($label, "RecentChanges?days=" .$daynum
440 .$url_show_minor .$url_show_all,
443 return HTML::div(array('class'=>'wiki-rc-action'), $b->getContent());
450 function buttonSet() {
456 function addButton($label, $url, $action) {
458 $this->_b[] = $Theme->makeButton($label, $url, $action);
461 function getContent() {
462 if (empty($this->content))
463 $this->_generateContent();
464 return $this->content;
467 function _generateContent() {
468 $this->content = HTML::p($this->caption . " ");
469 // Avoid an extraneous ButtonSeparator
470 $this->content->pushContent(array_shift($this->_b));
473 foreach ($this->_b as $button) {
474 $this->content->pushContent($Theme->getButtonSeparator());
475 $this->content->pushContent($button);
482 // (c-file-style: "gnu")
487 // c-hanging-comment-ender-p: nil
488 // indent-tabs-mode: nil