2 rcs_id('$Id: RecentChanges.php,v 1.60 2002-02-09 23:07:01 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, 'rssicon');
151 function description () {
152 extract($this->_args);
153 // FIXME: say something about show_all.
154 if ($show_major && $show_minor)
157 $edits = _("major edits");
159 $edits = _("minor edits");
161 if ($timespan = $days != 0) {
162 if (intval($days) != $days)
163 $days = sprintf("%.1f", $days);
167 * Depending how this text is split up it can be tricky or
168 * impossible to translate with good grammar. So the seperate
169 * strings for 1 day and %s days are necessary in this case
170 * for translating to multiple languages, due to differing
171 * overlapping ideal word cutting points.
173 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
174 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
175 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
177 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
178 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
179 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
183 if (intval($days) == 1)
184 $desc = fmt("The %d most recent %s during the past day are listed below.",
186 elseif (intval($days) == -1)
187 $desc = fmt("The %d oldest %s during the past day are listed below.",
190 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
191 $limit, $edits, $days);
193 $desc = fmt("The %d oldest %s from the first %s days are listed below.",
194 $limit, $edits, -$days);
197 $desc = fmt("The %d most recent %s are listed below.",
200 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
202 if (intval($days) == 1)
203 $desc = fmt("The %d oldest %s during the past day are listed below.",
206 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
207 $lmt, $edits, $days);
209 $desc = fmt("The %d oldest %s are listed below.",
215 if (intval($days) == 1)
216 $desc = fmt("The most recent %s during the past day are listed below.",
218 elseif (intval($days) == -1)
219 $desc = fmt("The oldest %s during the past day are listed below.",
221 elseif (intval($days) < -1)
222 $desc = fmt("The oldest %s from the first %s days are listed below.",
225 $desc = fmt("The most recent %s during the past %s days are listed below.",
228 $desc = fmt("All %s are listed below.", $edits);
235 extract($this->_args);
236 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
241 function format ($changes) {
242 $html = HTML(HTML::h2(false, $this->title()));
243 if (($desc = $this->description()))
244 $html->pushContent(HTML::p(false, $desc));
246 if ($this->_args['daylist'])
247 $html->pushContent(new DayButtonBar($this->_args));
252 while ($rev = $changes->next()) {
253 if (($date = $this->date($rev)) != $last_date) {
255 $html->pushContent($lines);
256 $html->pushContent(HTML::h3($date));
260 $lines->pushContent($this->format_revision($rev));
263 $html->pushContent($lines);
267 function format_revision ($rev) {
268 $args = &$this->_args;
270 $class = 'rc-' . $this->importance($rev);
272 $time = $this->time($rev);
273 if (! $rev->get('is_minor_edit'))
274 $time = HTML::strong($time);
276 $line = HTML::li(array('class' => $class));
279 if ($args['difflinks'])
280 $line->pushContent($this->diffLink($rev), ' ');
282 if ($args['historylinks'])
283 $line->pushContent($this->historyLink($rev), ' ');
285 $line->pushContent($this->pageLink($rev), ' ',
287 $this->summaryAsHTML($rev),
289 $this->authorLink($rev));
295 class _RecentChanges_RssFormatter
296 extends _RecentChanges_Formatter
298 var $_absurls = true;
300 function time ($rev) {
301 return Iso8601DateTime($rev->get('mtime'));
304 function pageURI ($rev) {
305 return WikiURL($rev, '', 'absurl');
308 function format ($changes) {
309 include_once('lib/RssWriter.php');
310 $rss = new RssWriter;
313 $rss->channel($this->channel_properties());
315 if (($props = $this->image_properties()))
317 if (($props = $this->textinput_properties()))
318 $rss->textinput($props);
320 while ($rev = $changes->next()) {
321 $rss->addItem($this->item_properties($rev),
322 $this->pageURI($rev));
326 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
328 // Flush errors in comment, otherwise it's invalid XML.
329 global $ErrorManager;
330 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
331 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
333 global $request; // FIXME
334 $request->finish(); // NORETURN!!!!
337 function image_properties () {
340 $img_url = $Theme->getImageURL('logo');
344 return array('title' => WIKI_NAME,
345 'link' => WikiURL(HomePage, false, 'absurl'),
349 function textinput_properties () {
350 return array('title' => _("Search"),
351 'description' => _("Title Search"),
353 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
356 function channel_properties () {
359 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
361 return array('title' => WIKI_NAME,
362 'dc:description' => _("RecentChanges"),
364 'dc:date' => Iso8601DateTime(time()));
366 /* FIXME: other things one might like in <channel>:
375 * rss091:managingEditor
377 * rss091:lastBuildDate
385 function item_properties ($rev) {
386 $page = $rev->getPage();
387 $pagename = $page->getName();
389 return array( 'title' => split_pagename($pagename),
390 'description' => $this->summary($rev),
391 'link' => $this->pageURL($rev),
392 'dc:date' => $this->time($rev),
393 'dc:contributor' => $rev->get('author'),
394 'wiki:version' => $rev->getVersion(),
395 'wiki:importance' => $this->importance($rev),
396 'wiki:status' => $this->status($rev),
397 'wiki:diff' => $this->diffURL($rev),
398 'wiki:history' => $this->historyURL($rev)
403 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
407 * @param $revisions object a WikiDB_PageRevisionIterator.
409 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
410 $this->_revisions = $revisions;
411 $this->_check_current_revision = $check_current_revision;
415 while (($rev = $this->_revisions->next())) {
416 if ($this->_check_current_revision) {
417 $page = $rev->getPage();
418 $check_rev = $page->getCurrentRevision();
423 if (! $check_rev->hasDefaultContents())
431 $this->_revisions->free();
435 class WikiPlugin_RecentChanges
438 function getName () {
439 return _("RecentChanges");
442 function getDefaultArguments() {
443 return array('days' => 2,
444 'show_minor' => false,
445 'show_major' => true,
447 'show_deleted' => 'sometimes',
452 'historylinks' => false,
457 function getArgs ($argstr, $request, $defaults = false) {
458 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
460 $action = $request->getArg('action');
461 if ($action != 'browse' && ! $request->isActionPage($action))
462 $args['format'] = false; // default -> HTML
464 if ($args['format'] == 'rss' && empty($args['limit']))
465 $args['limit'] = 15; // Fix default value for RSS.
470 function getMostRecentParams ($args) {
473 $params = array('include_minor_revisions' => $show_minor,
474 'exclude_major_revisions' => !$show_major,
475 'include_all_revisions' => !empty($show_all));
478 $params['limit'] = $limit;
481 $params['since'] = time() - 24 * 3600 * $days;
483 $params['since'] = 24 * 3600 * $days - time();
489 function getChanges ($dbi, $args) {
490 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
492 $show_deleted = $args['show_deleted'];
493 if ($show_deleted == 'sometimes')
494 $show_deleted = $args['show_minor'];
497 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
502 function format ($changes, $args) {
504 $format = $args['format'];
506 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
508 if ($format == 'rss')
509 $fmt_class = '_RecentChanges_RssFormatter';
510 elseif ($format == 'rss091') {
511 include_once "lib/RSSWriter091.php";
512 $fmt_class = '_RecentChanges_RssFormatter091';
515 $fmt_class = '_RecentChanges_HtmlFormatter';
518 $fmt = new $fmt_class($args);
519 return $fmt->format($changes);
522 function run ($dbi, $argstr, $request) {
523 $args = $this->getArgs($argstr, $request);
525 // Hack alert: format() is a NORETURN for rss formatters.
526 return $this->format($this->getChanges($dbi, $args), $args);
531 class DayButtonBar extends HtmlElement {
533 function DayButtonBar ($plugin_args) {
534 $this->HtmlElement('p', array('class' => 'wiki-rc-action'));
536 // Display days selection buttons
537 extract($plugin_args);
542 $caption = _("Show minor edits for:");
544 $caption = _("Show all changes for:");
546 $caption = _("Show changes for:");
549 $this->pushContent($caption, ' ');
552 $sep = $Theme->getButtonSeparator();
555 foreach (explode(",", $daylist) as $days) {
557 $this->pushContent($sep);
558 $this->pushContent($this->_makeDayButton($days));
562 function _makeDayButton ($days) {
563 global $Theme, $request;
568 $label = "..."; //alldays
570 $label = sprintf(_("%s days"), abs($days));
572 $url = $request->getURLtoSelf(array('action' => 'browse', 'days' => $days));
574 return $Theme->makeButton($label, $url, 'wiki-rc-action');
580 // (c-file-style: "gnu")
585 // c-hanging-comment-ender-p: nil
586 // indent-tabs-mode: nil