2 rcs_id('$Id: RecentChanges.php,v 1.70 2003-02-16 05:09:43 dairiki 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 setValidators($rev) {
115 if ($request->hasETag()) {
116 $request->addToETag('RecentChanges-top',
117 array($rev->getPageName(), $rev->getVersion()));
118 $request->setModificationTime($rev->get('mtime'));
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));
298 while ($rev = $changes->next()) {
299 if (($date = $this->date($rev)) != $last_date) {
301 $html->pushContent($lines);
302 $html->pushContent(HTML::h3($date));
307 $lines->pushContent($this->format_revision($rev));
310 $this->setValidators($rev);
314 $html->pushContent($lines);
318 function format_revision ($rev) {
319 $args = &$this->_args;
321 $class = 'rc-' . $this->importance($rev);
323 $time = $this->time($rev);
324 if (! $rev->get('is_minor_edit'))
325 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
327 $line = HTML::li(array('class' => $class));
330 if ($args['difflinks'])
331 $line->pushContent($this->diffLink($rev), ' ');
333 if ($args['historylinks'])
334 $line->pushContent($this->historyLink($rev), ' ');
336 $line->pushContent($this->pageLink($rev), ' ',
338 $this->summaryAsHTML($rev),
340 $this->authorLink($rev));
346 class _RecentChanges_SideBarFormatter
347 extends _RecentChanges_HtmlFormatter
349 function description () {
352 function rss_icon () {
356 //title click opens the normal RC or RE page in the main browser frame
357 extract($this->_args);
358 $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
359 $titlelink->setAttr('target', '_content');
360 return HTML($this->logo(), $titlelink);
363 //logo click opens the HomePage in the main browser frame
365 $img = HTML::img(array('src' => $Theme->getImageURL('logo'),
370 $linkurl = WikiLink(HOME_PAGE, false, $img);
371 $linkurl->setAttr('target', '_content');
375 function authorLink ($rev) {
376 $author = $rev->get('author');
377 if ( $this->authorHasPage($author) ) {
378 $linkurl = WikiLink($author);
379 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
384 function diffLink ($rev) {
385 $linkurl = parent::diffLink($rev);
386 $linkurl->setAttr('target', '_content');
389 function historyLink ($rev) {
390 $linkurl = parent::historyLink($rev);
391 $linkurl->setAttr('target', '_content');
394 function pageLink ($rev) {
395 $linkurl = parent::pageLink($rev);
396 $linkurl->setAttr('target', '_content');
399 // Overriding summaryAsHTML, because there is no way yet to
400 // return summary as transformed text with
401 // links setAttr('target', '_content') in Mozilla sidebar.
402 // So for now don't create clickable links inside summary
403 // in the sidebar, or else they target the sidebar and not the
404 // main content window.
405 function summaryAsHTML ($rev) {
406 if ( !($summary = $this->summary($rev)) )
408 return HTML::strong(array('class' => 'wiki-summary'),
410 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
415 function format ($changes) {
416 $this->_args['daylist'] = false; //only 1 day for Mozilla sidebar
417 $html = _RecentChanges_HtmlFormatter::format ($changes);
418 $html = HTML::div(array('class' => 'wikitext'), $html);
420 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", CHARSET);
421 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
422 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
423 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
426 extract($this->_args);
427 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
428 printf("<title>" . $title . "</title>\n");
430 $css = $Theme->getCSS();
434 printf("<body class=\"sidebar\">\n");
436 printf("\n</body>\n");
442 $request->finish(); // cut rest of page processing short
447 class _RecentChanges_RssFormatter
448 extends _RecentChanges_Formatter
450 var $_absurls = true;
452 function time ($rev) {
453 return Iso8601DateTime($rev->get('mtime'));
456 function pageURI ($rev) {
457 return WikiURL($rev, '', 'absurl');
460 function format ($changes) {
461 include_once('lib/RssWriter.php');
462 $rss = new RssWriter;
465 $rss->channel($this->channel_properties());
467 if (($props = $this->image_properties()))
469 if (($props = $this->textinput_properties()))
470 $rss->textinput($props);
473 while ($rev = $changes->next()) {
474 $rss->addItem($this->item_properties($rev),
475 $this->pageURI($rev));
477 $this->setValidators($rev);
482 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
484 // Flush errors in comment, otherwise it's invalid XML.
485 global $ErrorManager;
486 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
487 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
489 global $request; // FIXME
490 $request->finish(); // NORETURN!!!!
493 function image_properties () {
496 $img_url = SERVER_URL . $Theme->getImageURL('logo');
500 return array('title' => WIKI_NAME,
501 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
505 function textinput_properties () {
506 return array('title' => _("Search"),
507 'description' => _("Title Search"),
509 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
512 function channel_properties () {
515 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
517 return array('title' => WIKI_NAME,
519 'description' => _("RecentChanges"),
520 'dc:date' => Iso8601DateTime(time()));
522 /* FIXME: other things one might like in <channel>:
531 * rss091:managingEditor
533 * rss091:lastBuildDate
541 function item_properties ($rev) {
542 $page = $rev->getPage();
543 $pagename = $page->getName();
545 return array( 'title' => split_pagename($pagename),
546 'description' => $this->summary($rev),
547 'link' => $this->pageURL($rev),
548 'dc:date' => $this->time($rev),
549 'dc:contributor' => $rev->get('author'),
550 'wiki:version' => $rev->getVersion(),
551 'wiki:importance' => $this->importance($rev),
552 'wiki:status' => $this->status($rev),
553 'wiki:diff' => $this->diffURL($rev),
554 'wiki:history' => $this->historyURL($rev)
559 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
563 * @param $revisions object a WikiDB_PageRevisionIterator.
565 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
566 $this->_revisions = $revisions;
567 $this->_check_current_revision = $check_current_revision;
571 while (($rev = $this->_revisions->next())) {
572 if ($this->_check_current_revision) {
573 $page = $rev->getPage();
574 $check_rev = $page->getCurrentRevision();
579 if (! $check_rev->hasDefaultContents())
587 $this->_revisions->free();
591 class WikiPlugin_RecentChanges
594 function getName () {
595 return _("RecentChanges");
598 function getVersion() {
599 return preg_replace("/[Revision: $]/", '',
600 "\$Revision: 1.70 $");
603 function getDefaultArguments() {
604 return array('days' => 2,
605 'show_minor' => false,
606 'show_major' => true,
608 'show_deleted' => 'sometimes',
613 'historylinks' => false,
618 function getArgs ($argstr, $request, $defaults = false) {
619 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
621 $action = $request->getArg('action');
622 if ($action != 'browse' && ! $request->isActionPage($action))
623 $args['format'] = false; // default -> HTML
625 if ($args['format'] == 'rss' && empty($args['limit']))
626 $args['limit'] = 15; // Fix default value for RSS.
628 if ($args['format'] == 'sidebar' && empty($args['limit']))
629 $args['limit'] = 1; // Fix default value for sidebar.
634 function getMostRecentParams ($args) {
637 $params = array('include_minor_revisions' => $show_minor,
638 'exclude_major_revisions' => !$show_major,
639 'include_all_revisions' => !empty($show_all));
642 $params['limit'] = $limit;
645 $params['since'] = time() - 24 * 3600 * $days;
647 $params['since'] = 24 * 3600 * $days - time();
653 function getChanges ($dbi, $args) {
654 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
656 $show_deleted = $args['show_deleted'];
657 if ($show_deleted == 'sometimes')
658 $show_deleted = $args['show_minor'];
661 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
666 function format ($changes, $args) {
668 $format = $args['format'];
670 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
672 if ($format == 'rss')
673 $fmt_class = '_RecentChanges_RssFormatter';
674 elseif ($format == 'rss091') {
675 include_once "lib/RSSWriter091.php";
676 $fmt_class = '_RecentChanges_RssFormatter091';
678 elseif ($format == 'sidebar')
679 $fmt_class = '_RecentChanges_SideBarFormatter';
681 $fmt_class = '_RecentChanges_HtmlFormatter';
684 $fmt = new $fmt_class($args);
685 return $fmt->format($changes);
688 function run ($dbi, $argstr, $request) {
689 $args = $this->getArgs($argstr, $request);
691 // Hack alert: format() is a NORETURN for rss formatters.
692 return $this->format($this->getChanges($dbi, $args), $args);
697 class DayButtonBar extends HtmlElement {
699 function DayButtonBar ($plugin_args) {
700 $this->HtmlElement('p', array('class' => 'wiki-rc-action'));
702 // Display days selection buttons
703 extract($plugin_args);
708 $caption = _("Show minor edits for:");
710 $caption = _("Show all changes for:");
712 $caption = _("Show changes for:");
715 $this->pushContent($caption, ' ');
718 $sep = $Theme->getButtonSeparator();
721 foreach (explode(",", $daylist) as $days) {
723 $this->pushContent($sep);
724 $this->pushContent($this->_makeDayButton($days));
728 function _makeDayButton ($days) {
729 global $Theme, $request;
734 $label = "..."; //alldays
736 $label = sprintf(_("%s days"), abs($days));
738 $url = $request->getURLtoSelf(array('action' => 'browse', 'days' => $days));
740 return $Theme->makeButton($label, $url, 'wiki-rc-action');
744 // $Log: not supported by cvs2svn $
745 // Revision 1.69 2003/01/18 22:01:43 carstenklapp
747 // Reformatting & tabs to spaces;
748 // Added copyleft, getVersion, getDescription, rcs_id.
751 // (c-file-style: "gnu")
756 // c-hanging-comment-ender-p: nil
757 // indent-tabs-mode: nil