2 rcs_id('$Id: RecentChanges.php,v 1.69 2003-01-18 22:01:43 carstenklapp Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 class _RecentChanges_Formatter
27 var $_absurls = false;
29 function _RecentChanges_Formatter ($rc_args) {
30 $this->_args = $rc_args;
31 $this->_diffargs = array('action' => 'diff');
33 if ($rc_args['show_minor'] || !$rc_args['show_major'])
34 $this->_diffargs['previous'] = 'minor';
36 // PageHistoryPlugin doesn't have a 'daylist' arg.
37 if (!isset($this->_args['daylist']))
38 $this->_args['daylist'] = false;
41 function include_versions_in_URLs() {
42 return (bool) $this->_args['show_all'];
45 function date ($rev) {
47 return $Theme->getDay($rev->get('mtime'));
50 function time ($rev) {
52 return $Theme->formatTime($rev->get('mtime'));
55 function diffURL ($rev) {
56 $args = $this->_diffargs;
57 if ($this->include_versions_in_URLs())
58 $args['version'] = $rev->getVersion();
59 $page = $rev->getPage();
60 return WikiURL($page->getName(), $args, $this->_absurls);
63 function historyURL ($rev) {
64 $page = $rev->getPage();
65 return WikiURL($page, array('action' => _("PageHistory")),
69 function pageURL ($rev) {
70 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
74 function authorHasPage ($author) {
75 global $WikiNameRegexp, $request;
76 $dbi = $request->getDbh();
77 return preg_match("/^$WikiNameRegexp\$/", $author) && $dbi->isWikiPage($author);
80 function authorURL ($author) {
81 return $this->authorHasPage() ? WikiURL($author) : false;
85 function status ($rev) {
86 if ($rev->hasDefaultContents())
88 $page = $rev->getPage();
89 $prev = $page->getRevisionBefore($rev->getVersion());
90 if ($prev->hasDefaultContents())
95 function importance ($rev) {
96 return $rev->get('is_minor_edit') ? 'minor' : 'major';
99 function summary($rev) {
100 if ( ($summary = $rev->get('summary')) )
103 switch ($this->status($rev)) {
105 return _("Deleted.");
107 return _("New page.");
113 function http_lastmodified_header($mtime) {
114 static $mostrecentlymodified = false;
115 if (! $mostrecentlymodified) {
116 // set http header to date of most recently modified page
117 $mostrecentlymodified = $mtime; //$rev->get('mtime');
118 header("Last-Modified: " . Rfc2822DateTime($mostrecentlymodified));
123 class _RecentChanges_HtmlFormatter
124 extends _RecentChanges_Formatter
126 function diffLink ($rev) {
128 return $Theme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
131 function historyLink ($rev) {
133 return $Theme->makeButton(_("(hist)"), $this->historyURL($rev), 'wiki-rc-action');
136 function pageLink ($rev) {
137 $page = $rev->getPage();
139 if ($this->include_versions_in_URLs()) {
140 $version = $rev->getVersion();
141 $exists = !$rev->hasDefaultContents();
145 $cur = $page->getCurrentRevision();
146 $exists = !$cur->hasDefaultContents();
149 return $Theme->linkExistingWikiWord($page->getName(), false, $version);
151 return $Theme->linkUnknownWikiWord($page->getName(), false, $version);
154 function authorLink ($rev) {
155 $author = $rev->get('author');
156 if ( $this->authorHasPage($author) ) {
157 return WikiLink($author);
162 function summaryAsHTML ($rev) {
163 if ( !($summary = $this->summary($rev)) )
165 return HTML::strong( array('class' => 'wiki-summary'),
167 TransformLinks($summary, $rev->get('markup')),
171 function rss_icon () {
172 global $request, $Theme;
174 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
175 return $Theme->makeButton("RSS", $rss_url, 'rssicon');
178 function description () {
179 extract($this->_args);
180 // FIXME: say something about show_all.
181 if ($show_major && $show_minor)
184 $edits = _("major edits");
186 $edits = _("minor edits");
188 if ($timespan = $days > 0) {
189 if (intval($days) != $days)
190 $days = sprintf("%.1f", $days);
194 * Depending how this text is split up it can be tricky or
195 * impossible to translate with good grammar. So the seperate
196 * strings for 1 day and %s days are necessary in this case
197 * for translating to multiple languages, due to differing
198 * overlapping ideal word cutting points.
200 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
201 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
202 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
204 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
205 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
206 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
210 if (intval($days) == 1)
211 $desc = fmt("The %d most recent %s during the past day are listed below.",
214 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
215 $limit, $edits, $days);
217 $desc = fmt("The %d most recent %s are listed below.",
220 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
222 if (intval($days) == 1)
223 $desc = fmt("The %d oldest %s during the past day are listed below.",
226 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
227 $lmt, $edits, $days);
229 $desc = fmt("The %d oldest %s are listed below.",
235 if (intval($days) == 1)
236 $desc = fmt("The most recent %s during the past day are listed below.",
239 $desc = fmt("The most recent %s during the past %s days are listed below.",
242 $desc = fmt("All %s are listed below.", $edits);
249 extract($this->_args);
250 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
253 $this->sidebar_link());
256 function sidebar_link() {
257 extract($this->_args);
258 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
261 $sidebarurl = WikiURL($pagetitle, false, 'absurl') . "?format=sidebar";
264 "function addPanel() {\n"
265 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
266 ." \"$sidebarurl\",\"\");\n"
268 $jsf = $this->_javascript($addsidebarjsfunc);
270 $addsidebarjsclick = " " . "<small style=\"font-weight:normal;\"><a href=\"javascript:addPanel();\">sidebar</a></small>";
271 $jsc = $this->_javascript("if ((typeof window.sidebar == 'object') &&\n"
272 ." (typeof window.sidebar.addPanel == 'function'))\n"
274 ." document.write('$addsidebarjsclick');\n"
277 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
280 function _javascript($script) {
281 return HTML::script(array('language' => 'JavaScript',
282 'type' => 'text/javascript'),
283 new RawXml("<!-- //\n$script\n// -->"));
286 function format ($changes) {
287 $html = HTML(HTML::h2(false, $this->title()));
288 if (($desc = $this->description()))
289 $html->pushContent(HTML::p(false, $desc));
291 if ($this->_args['daylist'])
292 $html->pushContent(new DayButtonBar($this->_args));
297 while ($rev = $changes->next()) {
298 if (($date = $this->date($rev)) != $last_date) {
300 $html->pushContent($lines);
301 $html->pushContent(HTML::h3($date));
305 $this->http_lastmodified_header($rev->get('mtime'));
306 $lines->pushContent($this->format_revision($rev));
309 $html->pushContent($lines);
313 function format_revision ($rev) {
314 $args = &$this->_args;
316 $class = 'rc-' . $this->importance($rev);
318 $time = $this->time($rev);
319 if (! $rev->get('is_minor_edit'))
320 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
322 $line = HTML::li(array('class' => $class));
325 if ($args['difflinks'])
326 $line->pushContent($this->diffLink($rev), ' ');
328 if ($args['historylinks'])
329 $line->pushContent($this->historyLink($rev), ' ');
331 $line->pushContent($this->pageLink($rev), ' ',
333 $this->summaryAsHTML($rev),
335 $this->authorLink($rev));
341 class _RecentChanges_SideBarFormatter
342 extends _RecentChanges_HtmlFormatter
344 function description () {
347 function rss_icon () {
351 //title click opens the normal RC or RE page in the main browser frame
352 extract($this->_args);
353 $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
354 $titlelink->setAttr('target', '_content');
355 return HTML($this->logo(), $titlelink);
358 //logo click opens the HomePage in the main browser frame
360 $img = HTML::img(array('src' => $Theme->getImageURL('logo'),
365 $linkurl = WikiLink(HOME_PAGE, false, $img);
366 $linkurl->setAttr('target', '_content');
370 function authorLink ($rev) {
371 $author = $rev->get('author');
372 if ( $this->authorHasPage($author) ) {
373 $linkurl = WikiLink($author);
374 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
379 function diffLink ($rev) {
380 $linkurl = parent::diffLink($rev);
381 $linkurl->setAttr('target', '_content');
384 function historyLink ($rev) {
385 $linkurl = parent::historyLink($rev);
386 $linkurl->setAttr('target', '_content');
389 function pageLink ($rev) {
390 $linkurl = parent::pageLink($rev);
391 $linkurl->setAttr('target', '_content');
394 // Overriding summaryAsHTML, because there is no way yet to
395 // return summary as transformed text with
396 // links setAttr('target', '_content') in Mozilla sidebar.
397 // So for now don't create clickable links inside summary
398 // in the sidebar, or else they target the sidebar and not the
399 // main content window.
400 function summaryAsHTML ($rev) {
401 if ( !($summary = $this->summary($rev)) )
403 return HTML::strong(array('class' => 'wiki-summary'),
405 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
410 function format ($changes) {
411 $this->_args['daylist'] = false; //only 1 day for Mozilla sidebar
412 $html = _RecentChanges_HtmlFormatter::format ($changes);
413 $html = HTML::div(array('class' => 'wikitext'), $html);
415 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", CHARSET);
416 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
417 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
418 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
421 extract($this->_args);
422 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
423 printf("<title>" . $title . "</title>\n");
425 $css = $Theme->getCSS();
429 printf("<body class=\"sidebar\">\n");
431 printf("\n</body>\n");
437 $request->finish(); // cut rest of page processing short
442 class _RecentChanges_RssFormatter
443 extends _RecentChanges_Formatter
445 var $_absurls = true;
447 function time ($rev) {
448 return Iso8601DateTime($rev->get('mtime'));
451 function pageURI ($rev) {
452 return WikiURL($rev, '', 'absurl');
455 function format ($changes) {
456 include_once('lib/RssWriter.php');
457 $rss = new RssWriter;
460 $rss->channel($this->channel_properties());
462 if (($props = $this->image_properties()))
464 if (($props = $this->textinput_properties()))
465 $rss->textinput($props);
467 while ($rev = $changes->next()) {
468 $rss->addItem($this->item_properties($rev),
469 $this->pageURI($rev));
470 $this->http_lastmodified_header($rev->get('mtime'));
474 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
476 // Flush errors in comment, otherwise it's invalid XML.
477 global $ErrorManager;
478 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
479 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
481 global $request; // FIXME
482 $request->finish(); // NORETURN!!!!
485 function image_properties () {
488 $img_url = SERVER_URL . $Theme->getImageURL('logo');
492 return array('title' => WIKI_NAME,
493 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
497 function textinput_properties () {
498 return array('title' => _("Search"),
499 'description' => _("Title Search"),
501 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
504 function channel_properties () {
507 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
509 return array('title' => WIKI_NAME,
511 'description' => _("RecentChanges"),
512 'dc:date' => Iso8601DateTime(time()));
514 /* FIXME: other things one might like in <channel>:
523 * rss091:managingEditor
525 * rss091:lastBuildDate
533 function item_properties ($rev) {
534 $page = $rev->getPage();
535 $pagename = $page->getName();
537 return array( 'title' => split_pagename($pagename),
538 'description' => $this->summary($rev),
539 'link' => $this->pageURL($rev),
540 'dc:date' => $this->time($rev),
541 'dc:contributor' => $rev->get('author'),
542 'wiki:version' => $rev->getVersion(),
543 'wiki:importance' => $this->importance($rev),
544 'wiki:status' => $this->status($rev),
545 'wiki:diff' => $this->diffURL($rev),
546 'wiki:history' => $this->historyURL($rev)
551 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
555 * @param $revisions object a WikiDB_PageRevisionIterator.
557 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
558 $this->_revisions = $revisions;
559 $this->_check_current_revision = $check_current_revision;
563 while (($rev = $this->_revisions->next())) {
564 if ($this->_check_current_revision) {
565 $page = $rev->getPage();
566 $check_rev = $page->getCurrentRevision();
571 if (! $check_rev->hasDefaultContents())
579 $this->_revisions->free();
583 class WikiPlugin_RecentChanges
586 function getName () {
587 return _("RecentChanges");
590 function getVersion() {
591 return preg_replace("/[Revision: $]/", '',
592 "\$Revision: 1.69 $");
595 function getDefaultArguments() {
596 return array('days' => 2,
597 'show_minor' => false,
598 'show_major' => true,
600 'show_deleted' => 'sometimes',
605 'historylinks' => false,
610 function getArgs ($argstr, $request, $defaults = false) {
611 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
613 $action = $request->getArg('action');
614 if ($action != 'browse' && ! $request->isActionPage($action))
615 $args['format'] = false; // default -> HTML
617 if ($args['format'] == 'rss' && empty($args['limit']))
618 $args['limit'] = 15; // Fix default value for RSS.
620 if ($args['format'] == 'sidebar' && empty($args['limit']))
621 $args['limit'] = 1; // Fix default value for sidebar.
626 function getMostRecentParams ($args) {
629 $params = array('include_minor_revisions' => $show_minor,
630 'exclude_major_revisions' => !$show_major,
631 'include_all_revisions' => !empty($show_all));
634 $params['limit'] = $limit;
637 $params['since'] = time() - 24 * 3600 * $days;
639 $params['since'] = 24 * 3600 * $days - time();
645 function getChanges ($dbi, $args) {
646 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
648 $show_deleted = $args['show_deleted'];
649 if ($show_deleted == 'sometimes')
650 $show_deleted = $args['show_minor'];
653 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
658 function format ($changes, $args) {
660 $format = $args['format'];
662 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
664 if ($format == 'rss')
665 $fmt_class = '_RecentChanges_RssFormatter';
666 elseif ($format == 'rss091') {
667 include_once "lib/RSSWriter091.php";
668 $fmt_class = '_RecentChanges_RssFormatter091';
670 elseif ($format == 'sidebar')
671 $fmt_class = '_RecentChanges_SideBarFormatter';
673 $fmt_class = '_RecentChanges_HtmlFormatter';
676 $fmt = new $fmt_class($args);
677 return $fmt->format($changes);
680 function run ($dbi, $argstr, $request) {
681 $args = $this->getArgs($argstr, $request);
683 // Hack alert: format() is a NORETURN for rss formatters.
684 return $this->format($this->getChanges($dbi, $args), $args);
689 class DayButtonBar extends HtmlElement {
691 function DayButtonBar ($plugin_args) {
692 $this->HtmlElement('p', array('class' => 'wiki-rc-action'));
694 // Display days selection buttons
695 extract($plugin_args);
700 $caption = _("Show minor edits for:");
702 $caption = _("Show all changes for:");
704 $caption = _("Show changes for:");
707 $this->pushContent($caption, ' ');
710 $sep = $Theme->getButtonSeparator();
713 foreach (explode(",", $daylist) as $days) {
715 $this->pushContent($sep);
716 $this->pushContent($this->_makeDayButton($days));
720 function _makeDayButton ($days) {
721 global $Theme, $request;
726 $label = "..."; //alldays
728 $label = sprintf(_("%s days"), abs($days));
730 $url = $request->getURLtoSelf(array('action' => 'browse', 'days' => $days));
732 return $Theme->makeButton($label, $url, 'wiki-rc-action');
736 // $Log: not supported by cvs2svn $
738 // (c-file-style: "gnu")
743 // c-hanging-comment-ender-p: nil
744 // indent-tabs-mode: nil