2 rcs_id('$Id: RecentChanges.php,v 1.58 2002-02-08 22:51:26 lakka 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';
18 // PageHistoryPlugin doesn't have a 'daylist' arg.
19 if (!isset($this->_args['daylist']))
20 $this->_args['daylist'] = false;
23 function include_versions_in_URLs() {
24 return (bool) $this->_args['show_all'];
27 function date ($rev) {
29 return $Theme->getDay($rev->get('mtime'));
32 function time ($rev) {
34 return $Theme->formatTime($rev->get('mtime'));
37 function diffURL ($rev) {
38 $args = $this->_diffargs;
39 if ($this->include_versions_in_URLs())
40 $args['version'] = $rev->getVersion();
41 $page = $rev->getPage();
42 return WikiURL($page->getName(), $args, $this->_absurls);
45 function historyURL ($rev) {
46 $page = $rev->getPage();
47 return WikiURL($page, array('action' => _("PageHistory")),
51 function pageURL ($rev) {
52 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
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 historyLink ($rev) {
106 return $Theme->makeButton(_("(hist)"), $this->historyURL($rev), 'wiki-rc-action');
109 function pageLink ($rev) {
110 $page = $rev->getPage();
112 if ($this->include_versions_in_URLs()) {
113 $version = $rev->getVersion();
114 $exists = !$rev->hasDefaultContents();
118 $cur = $page->getCurrentRevision();
119 $exists = !$cur->hasDefaultContents();
122 return $Theme->linkExistingWikiWord($page->getName(), false, $version);
124 return $Theme->linkUnknownWikiWord($page->getName(), false, $version);
127 function authorLink ($rev) {
128 $author = $rev->get('author');
129 if ( $this->authorHasPage($author) ) {
130 return WikiLink($author);
135 function summaryAsHTML ($rev) {
136 if ( !($summary = $this->summary($rev)) )
138 return HTML::strong( array('class' => 'wiki-summary'),
140 TransformLinks($summary, $rev->get('markup')),
144 function rss_icon () {
145 global $request, $Theme;
147 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
148 return $Theme->makeButton("RSS", $rss_url, 'rssicion');
151 function description () {
152 extract($this->_args);
154 // FIXME: say something about show_all.
156 if ($show_major && $show_minor)
159 $edits = _("major edits");
161 $edits = _("minor edits");
163 if ($timespan = $days != 0) {
164 if (intval($days) != $days)
165 $days = sprintf("%.1f", $days);
169 * Depending how this text is split up it can be tricky or
170 * impossible to translate with good grammar. So the seperate
171 * strings for 1 day and %s days are necessary in this case
172 * for translating to multiple languages, due to differing
173 * overlapping ideal word cutting points.
175 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
176 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
177 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
179 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
180 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
181 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
185 if (intval($days) == 1)
186 $desc = fmt("The %d most recent %s during the past day are listed below.",
188 elseif (intval($days) == -1)
189 $desc = fmt("The %d oldest %s during the past day are listed below.",
192 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
193 $limit, $edits, $days);
195 $desc = fmt("The %d oldest %s from the first %s days are listed below.",
196 $limit, $edits, -$days);
199 $desc = fmt("The %d most recent %s are listed below.",
204 if (intval($days) == 1)
205 $desc = fmt("The most recent %s during the past day are listed below.",
207 elseif (intval($days) == -1)
208 $desc = fmt("The oldest %s during the past day are listed below.",
210 elseif (intval($days) < -1)
211 $desc = fmt("The oldest %s from the first %s days are listed below.",
214 $desc = fmt("The most recent %s during the past %s days are listed below.",
217 $desc = fmt("All %s are listed below.", $edits);
224 extract($this->_args);
225 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
230 function format ($changes) {
231 $html = HTML(HTML::h2(false, $this->title()));
232 if (($desc = $this->description()))
233 $html->pushContent(HTML::p(false, $desc));
235 if ($this->_args['daylist'])
236 $html->pushContent(new DayButtonBar($this->_args));
241 while ($rev = $changes->next()) {
242 if (($date = $this->date($rev)) != $last_date) {
244 $html->pushContent($lines);
245 $html->pushContent(HTML::h3($date));
249 $lines->pushContent($this->format_revision($rev));
252 $html->pushContent($lines);
256 function format_revision ($rev) {
257 $args = &$this->_args;
259 $class = 'rc-' . $this->importance($rev);
261 $time = $this->time($rev);
262 if (! $rev->get('is_minor_edit'))
263 $time = HTML::strong($time);
265 $line = HTML::li(array('class' => $class));
268 if ($args['difflinks'])
269 $line->pushContent($this->diffLink($rev), ' ');
271 if ($args['historylinks'])
272 $line->pushContent($this->historyLink($rev), ' ');
274 $line->pushContent($this->pageLink($rev), ' ',
276 $this->summaryAsHTML($rev),
278 $this->authorLink($rev));
284 class _RecentChanges_RssFormatter
285 extends _RecentChanges_Formatter
287 var $_absurls = true;
289 function time ($rev) {
290 return Iso8601DateTime($rev->get('mtime'));
293 function pageURI ($rev) {
294 return WikiURL($rev, '', 'absurl');
297 function format ($changes) {
298 include_once('lib/RssWriter.php');
299 $rss = new RssWriter;
302 $rss->channel($this->channel_properties());
304 if (($props = $this->image_properties()))
306 if (($props = $this->textinput_properties()))
307 $rss->textinput($props);
309 while ($rev = $changes->next()) {
310 $rss->addItem($this->item_properties($rev),
311 $this->pageURI($rev));
315 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
317 // Flush errors in comment, otherwise it's invalid XML.
318 global $ErrorManager;
319 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
320 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
322 global $request; // FIXME
323 $request->finish(); // NORETURN!!!!
326 function image_properties () {
329 $img_url = $Theme->getImageURL('logo');
333 return array('title' => WIKI_NAME,
334 'link' => WikiURL(HomePage, false, 'absurl'),
338 function textinput_properties () {
339 return array('title' => _("Search"),
340 'description' => _("Title Search"),
342 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
345 function channel_properties () {
348 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
350 return array('title' => WIKI_NAME,
351 'dc:description' => _("RecentChanges"),
353 'dc:date' => Iso8601DateTime(time()));
355 /* FIXME: other things one might like in <channel>:
364 * rss091:managingEditor
366 * rss091:lastBuildDate
374 function item_properties ($rev) {
375 $page = $rev->getPage();
376 $pagename = $page->getName();
378 return array( 'title' => split_pagename($pagename),
379 'description' => $this->summary($rev),
380 'link' => $this->pageURL($rev),
381 'dc:date' => $this->time($rev),
382 'dc:contributor' => $rev->get('author'),
383 'wiki:version' => $rev->getVersion(),
384 'wiki:importance' => $this->importance($rev),
385 'wiki:status' => $this->status($rev),
386 'wiki:diff' => $this->diffURL($rev),
387 'wiki:history' => $this->historyURL($rev)
392 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
396 * @param $revisions object a WikiDB_PageRevisionIterator.
398 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
399 $this->_revisions = $revisions;
400 $this->_check_current_revision = $check_current_revision;
404 while (($rev = $this->_revisions->next())) {
405 if ($this->_check_current_revision) {
406 $page = $rev->getPage();
407 $check_rev = $page->getCurrentRevision();
412 if (! $check_rev->hasDefaultContents())
420 $this->_revisions->free();
424 class WikiPlugin_RecentChanges
427 function getName () {
428 return _("RecentChanges");
431 function getDefaultArguments() {
432 return array('days' => 2,
433 'show_minor' => false,
434 'show_major' => true,
436 'show_deleted' => 'sometimes',
441 'historylinks' => false,
446 function getArgs ($argstr, $request, $defaults = false) {
447 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
449 $action = $request->getArg('action');
450 if ($action != 'browse' && ! $request->isActionPage($action))
451 $args['format'] = false; // default -> HTML
453 if ($args['format'] == 'rss' && empty($args['limit']))
454 $args['limit'] = 15; // Fix default value for RSS.
459 function getMostRecentParams ($args) {
462 $params = array('include_minor_revisions' => $show_minor,
463 'exclude_major_revisions' => !$show_major,
464 'include_all_revisions' => !empty($show_all));
467 $params['limit'] = $limit;
470 $params['since'] = time() - 24 * 3600 * $days;
472 $params['since'] = 24 * 3600 * $days - time();
478 function getChanges ($dbi, $args) {
479 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
481 $show_deleted = $args['show_deleted'];
482 if ($show_deleted == 'sometimes')
483 $show_deleted = $args['show_minor'];
486 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
491 function format ($changes, $args) {
493 $format = $args['format'];
495 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
497 if ($format == 'rss')
498 $fmt_class = '_RecentChanges_RssFormatter';
499 elseif ($format == 'rss091') {
500 include_once "lib/RSSWriter091.php";
501 $fmt_class = '_RecentChanges_RssFormatter091';
504 $fmt_class = '_RecentChanges_HtmlFormatter';
507 $fmt = new $fmt_class($args);
508 return $fmt->format($changes);
511 function run ($dbi, $argstr, $request) {
512 $args = $this->getArgs($argstr, $request);
514 // Hack alert: format() is a NORETURN for rss formatters.
515 return $this->format($this->getChanges($dbi, $args), $args);
520 class DayButtonBar extends HtmlElement {
522 function DayButtonBar ($plugin_args) {
523 $this->HtmlElement('p', array('class' => 'wiki-rc-action'));
525 // Display days selection buttons
526 extract($plugin_args);
531 $caption = _("Show minor edits for:");
533 $caption = _("Show all changes for:");
535 $caption = _("Show changes for:");
538 $this->pushContent($caption, ' ');
541 $sep = $Theme->getButtonSeparator();
544 foreach (explode(",", $daylist) as $days) {
546 $this->pushContent($sep);
547 $this->pushContent($this->_makeDayButton($days));
551 function _makeDayButton ($days) {
552 global $Theme, $request;
557 $label = "..."; //alldays
559 $label = sprintf(_("%s days"), abs($days));
561 $url = $request->getURLtoSelf(array('action' => 'browse', 'days' => $days));
563 return $Theme->makeButton($label, $url, 'wiki-rc-action');
569 // (c-file-style: "gnu")
574 // c-hanging-comment-ender-p: nil
575 // indent-tabs-mode: nil