2 rcs_id('$Id: RecentChanges.php,v 1.67 2002-10-12 09:47:05 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'] || !$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.");
95 function http_lastmodified_header($mtime) {
96 static $mostrecentlymodified = false;
97 if (! $mostrecentlymodified) {
98 // set http header to date of most recently modified page
99 $mostrecentlymodified = $mtime; //$rev->get('mtime');
100 header("Last-Modified: " . Rfc2822DateTime($mostrecentlymodified));
105 class _RecentChanges_HtmlFormatter
106 extends _RecentChanges_Formatter
108 function diffLink ($rev) {
110 return $Theme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
113 function historyLink ($rev) {
115 return $Theme->makeButton(_("(hist)"), $this->historyURL($rev), 'wiki-rc-action');
118 function pageLink ($rev) {
119 $page = $rev->getPage();
121 if ($this->include_versions_in_URLs()) {
122 $version = $rev->getVersion();
123 $exists = !$rev->hasDefaultContents();
127 $cur = $page->getCurrentRevision();
128 $exists = !$cur->hasDefaultContents();
131 return $Theme->linkExistingWikiWord($page->getName(), false, $version);
133 return $Theme->linkUnknownWikiWord($page->getName(), false, $version);
136 function authorLink ($rev) {
137 $author = $rev->get('author');
138 if ( $this->authorHasPage($author) ) {
139 return WikiLink($author);
144 function summaryAsHTML ($rev) {
145 if ( !($summary = $this->summary($rev)) )
147 return HTML::strong( array('class' => 'wiki-summary'),
149 TransformLinks($summary, $rev->get('markup')),
153 function rss_icon () {
154 global $request, $Theme;
156 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
157 return $Theme->makeButton("RSS", $rss_url, 'rssicon');
160 function description () {
161 extract($this->_args);
162 // FIXME: say something about show_all.
163 if ($show_major && $show_minor)
166 $edits = _("major edits");
168 $edits = _("minor edits");
170 if ($timespan = $days > 0) {
171 if (intval($days) != $days)
172 $days = sprintf("%.1f", $days);
176 * Depending how this text is split up it can be tricky or
177 * impossible to translate with good grammar. So the seperate
178 * strings for 1 day and %s days are necessary in this case
179 * for translating to multiple languages, due to differing
180 * overlapping ideal word cutting points.
182 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
183 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
184 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
186 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
187 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
188 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
192 if (intval($days) == 1)
193 $desc = fmt("The %d most recent %s during the past day are listed below.",
196 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
197 $limit, $edits, $days);
199 $desc = fmt("The %d most recent %s are listed below.",
202 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
204 if (intval($days) == 1)
205 $desc = fmt("The %d oldest %s during the past day are listed below.",
208 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
209 $lmt, $edits, $days);
211 $desc = fmt("The %d oldest %s are listed below.",
217 if (intval($days) == 1)
218 $desc = fmt("The most recent %s during the past day are listed below.",
221 $desc = fmt("The most recent %s during the past %s days are listed below.",
224 $desc = fmt("All %s are listed below.", $edits);
231 extract($this->_args);
232 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
235 $this->sidebar_link());
238 function sidebar_link() {
239 extract($this->_args);
240 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
243 $sidebarurl = WikiURL($pagetitle, false, 'absurl') . "?format=sidebar";
246 "function addPanel() {\n"
247 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
248 ." \"$sidebarurl\",\"\");\n"
250 $jsf = $this->_javascript($addsidebarjsfunc);
252 $addsidebarjsclick = " " . "<small style=\"font-weight:normal;\"><a href=\"javascript:addPanel();\">sidebar</a></small>";
253 $jsc = $this->_javascript("if ((typeof window.sidebar == 'object') &&\n"
254 ." (typeof window.sidebar.addPanel == 'function'))\n"
256 ." document.write('$addsidebarjsclick');\n"
259 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
262 function _javascript($script) {
263 return HTML::script(array('language' => 'JavaScript',
264 'type' => 'text/javascript'),
265 new RawXml("<!-- //\n$script\n// -->"));
268 function format ($changes) {
269 $html = HTML(HTML::h2(false, $this->title()));
270 if (($desc = $this->description()))
271 $html->pushContent(HTML::p(false, $desc));
273 if ($this->_args['daylist'])
274 $html->pushContent(new DayButtonBar($this->_args));
279 while ($rev = $changes->next()) {
280 if (($date = $this->date($rev)) != $last_date) {
282 $html->pushContent($lines);
283 $html->pushContent(HTML::h3($date));
287 $this->http_lastmodified_header($rev->get('mtime'));
288 $lines->pushContent($this->format_revision($rev));
291 $html->pushContent($lines);
295 function format_revision ($rev) {
296 $args = &$this->_args;
298 $class = 'rc-' . $this->importance($rev);
300 $time = $this->time($rev);
301 if (! $rev->get('is_minor_edit'))
302 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
304 $line = HTML::li(array('class' => $class));
307 if ($args['difflinks'])
308 $line->pushContent($this->diffLink($rev), ' ');
310 if ($args['historylinks'])
311 $line->pushContent($this->historyLink($rev), ' ');
313 $line->pushContent($this->pageLink($rev), ' ',
315 $this->summaryAsHTML($rev),
317 $this->authorLink($rev));
323 class _RecentChanges_SideBarFormatter
324 extends _RecentChanges_HtmlFormatter
326 function description () {
329 function rss_icon () {
333 //title click opens the normal RC or RE page in the main browser frame
334 extract($this->_args);
335 $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
336 $titlelink->setAttr('target', '_content');
337 return HTML($this->logo(), $titlelink);
340 //logo click opens the HomePage in the main browser frame
342 $img = HTML::img(array('src' => $Theme->getImageURL('logo'),
347 $linkurl = WikiLink(HOME_PAGE, false, $img);
348 $linkurl->setAttr('target', '_content');
352 function authorLink ($rev) {
353 $author = $rev->get('author');
354 if ( $this->authorHasPage($author) ) {
355 $linkurl = WikiLink($author);
356 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
361 function diffLink ($rev) {
362 $linkurl = parent::diffLink($rev);
363 $linkurl->setAttr('target', '_content');
366 function historyLink ($rev) {
367 $linkurl = parent::historyLink($rev);
368 $linkurl->setAttr('target', '_content');
371 function pageLink ($rev) {
372 $linkurl = parent::pageLink($rev);
373 $linkurl->setAttr('target', '_content');
376 // Overriding summaryAsHTML, because there is no way yet to
377 // return summary as transformed text with
378 // links setAttr('target', '_content') in Mozilla sidebar.
379 // So for now don't create clickable links inside summary
380 // in the sidebar, or else they target the sidebar and not the
381 // main content window.
382 function summaryAsHTML ($rev) {
383 if ( !($summary = $this->summary($rev)) )
385 return HTML::strong(array('class' => 'wiki-summary'),
387 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
392 function format ($changes) {
393 $this->_args['daylist'] = false; //only 1 day for Mozilla sidebar
394 $html = _RecentChanges_HtmlFormatter::format ($changes);
395 $html = HTML::div(array('class' => 'wikitext'), $html);
397 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", CHARSET);
398 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
399 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
400 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
403 extract($this->_args);
404 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
405 printf("<title>" . $title . "</title>\n");
407 $css = $Theme->getCSS();
411 printf("<body class=\"sidebar\">\n");
413 printf("\n</body>\n");
419 $request->finish(); // cut rest of page processing short
424 class _RecentChanges_RssFormatter
425 extends _RecentChanges_Formatter
427 var $_absurls = true;
429 function time ($rev) {
430 return Iso8601DateTime($rev->get('mtime'));
433 function pageURI ($rev) {
434 return WikiURL($rev, '', 'absurl');
437 function format ($changes) {
438 include_once('lib/RssWriter.php');
439 $rss = new RssWriter;
442 $rss->channel($this->channel_properties());
444 if (($props = $this->image_properties()))
446 if (($props = $this->textinput_properties()))
447 $rss->textinput($props);
449 while ($rev = $changes->next()) {
450 $rss->addItem($this->item_properties($rev),
451 $this->pageURI($rev));
452 $this->http_lastmodified_header($rev->get('mtime'));
456 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
458 // Flush errors in comment, otherwise it's invalid XML.
459 global $ErrorManager;
460 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
461 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
463 global $request; // FIXME
464 $request->finish(); // NORETURN!!!!
467 function image_properties () {
470 $img_url = $Theme->getImageURL('logo');
474 return array('title' => WIKI_NAME,
475 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
479 function textinput_properties () {
480 return array('title' => _("Search"),
481 'description' => _("Title Search"),
483 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
486 function channel_properties () {
489 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
491 return array('title' => WIKI_NAME,
492 'dc:description' => _("RecentChanges"),
494 'dc:date' => Iso8601DateTime(time()));
496 /* FIXME: other things one might like in <channel>:
505 * rss091:managingEditor
507 * rss091:lastBuildDate
515 function item_properties ($rev) {
516 $page = $rev->getPage();
517 $pagename = $page->getName();
519 return array( 'title' => split_pagename($pagename),
520 'description' => $this->summary($rev),
521 'link' => $this->pageURL($rev),
522 'dc:date' => $this->time($rev),
523 'dc:contributor' => $rev->get('author'),
524 'wiki:version' => $rev->getVersion(),
525 'wiki:importance' => $this->importance($rev),
526 'wiki:status' => $this->status($rev),
527 'wiki:diff' => $this->diffURL($rev),
528 'wiki:history' => $this->historyURL($rev)
533 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
537 * @param $revisions object a WikiDB_PageRevisionIterator.
539 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
540 $this->_revisions = $revisions;
541 $this->_check_current_revision = $check_current_revision;
545 while (($rev = $this->_revisions->next())) {
546 if ($this->_check_current_revision) {
547 $page = $rev->getPage();
548 $check_rev = $page->getCurrentRevision();
553 if (! $check_rev->hasDefaultContents())
561 $this->_revisions->free();
565 class WikiPlugin_RecentChanges
568 function getName () {
569 return _("RecentChanges");
572 function getDefaultArguments() {
573 return array('days' => 2,
574 'show_minor' => false,
575 'show_major' => true,
577 'show_deleted' => 'sometimes',
582 'historylinks' => false,
587 function getArgs ($argstr, $request, $defaults = false) {
588 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
590 $action = $request->getArg('action');
591 if ($action != 'browse' && ! $request->isActionPage($action))
592 $args['format'] = false; // default -> HTML
594 if ($args['format'] == 'rss' && empty($args['limit']))
595 $args['limit'] = 15; // Fix default value for RSS.
597 if ($args['format'] == 'sidebar' && empty($args['limit']))
598 $args['limit'] = 1; // Fix default value for sidebar.
603 function getMostRecentParams ($args) {
606 $params = array('include_minor_revisions' => $show_minor,
607 'exclude_major_revisions' => !$show_major,
608 'include_all_revisions' => !empty($show_all));
611 $params['limit'] = $limit;
614 $params['since'] = time() - 24 * 3600 * $days;
616 $params['since'] = 24 * 3600 * $days - time();
622 function getChanges ($dbi, $args) {
623 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
625 $show_deleted = $args['show_deleted'];
626 if ($show_deleted == 'sometimes')
627 $show_deleted = $args['show_minor'];
630 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
635 function format ($changes, $args) {
637 $format = $args['format'];
639 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
641 if ($format == 'rss')
642 $fmt_class = '_RecentChanges_RssFormatter';
643 elseif ($format == 'rss091') {
644 include_once "lib/RSSWriter091.php";
645 $fmt_class = '_RecentChanges_RssFormatter091';
647 elseif ($format == 'sidebar')
648 $fmt_class = '_RecentChanges_SideBarFormatter';
650 $fmt_class = '_RecentChanges_HtmlFormatter';
653 $fmt = new $fmt_class($args);
654 return $fmt->format($changes);
657 function run ($dbi, $argstr, $request) {
658 $args = $this->getArgs($argstr, $request);
660 // Hack alert: format() is a NORETURN for rss formatters.
661 return $this->format($this->getChanges($dbi, $args), $args);
666 class DayButtonBar extends HtmlElement {
668 function DayButtonBar ($plugin_args) {
669 $this->HtmlElement('p', array('class' => 'wiki-rc-action'));
671 // Display days selection buttons
672 extract($plugin_args);
677 $caption = _("Show minor edits for:");
679 $caption = _("Show all changes for:");
681 $caption = _("Show changes for:");
684 $this->pushContent($caption, ' ');
687 $sep = $Theme->getButtonSeparator();
690 foreach (explode(",", $daylist) as $days) {
692 $this->pushContent($sep);
693 $this->pushContent($this->_makeDayButton($days));
697 function _makeDayButton ($days) {
698 global $Theme, $request;
703 $label = "..."; //alldays
705 $label = sprintf(_("%s days"), abs($days));
707 $url = $request->getURLtoSelf(array('action' => 'browse', 'days' => $days));
709 return $Theme->makeButton($label, $url, 'wiki-rc-action');
715 // (c-file-style: "gnu")
720 // c-hanging-comment-ender-p: nil
721 // indent-tabs-mode: nil