2 rcs_id('$Id: RecentChanges.php,v 1.120 2007-07-14 12:04:50 rurban Exp $');
4 Copyright 1999,2000,2001,2002,2007 $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
23 include_once("lib/WikiPlugin.php");
27 class _RecentChanges_Formatter
29 var $_absurls = false;
30 var $action = "RecentChanges";
32 function _RecentChanges_Formatter ($rc_args) {
33 $this->_args = $rc_args;
34 $this->_diffargs = array('action' => 'diff');
36 if ($rc_args['show_minor'] || !$rc_args['show_major'])
37 $this->_diffargs['previous'] = 'minor';
39 // PageHistoryPlugin doesn't have a 'daylist' arg.
40 if (!isset($this->_args['daylist']))
41 $this->_args['daylist'] = false;
44 function include_versions_in_URLs() {
45 return (bool) $this->_args['show_all'];
48 function date ($rev) {
50 return $WikiTheme->getDay($rev->get('mtime'));
53 function time ($rev) {
55 return $WikiTheme->formatTime($rev->get('mtime'));
58 function diffURL ($rev) {
59 $args = $this->_diffargs;
60 if ($this->include_versions_in_URLs())
61 $args['version'] = $rev->getVersion();
62 $page = $rev->getPage();
63 return WikiURL($page->getName(), $args, $this->_absurls);
66 function historyURL ($rev) {
67 $page = $rev->getPage();
68 return WikiURL($page, array('action' => _("PageHistory")),
72 function pageURL ($rev) {
73 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
77 function authorHasPage ($author) {
78 global $WikiNameRegexp, $request;
79 $dbi = $request->getDbh();
80 return isWikiWord($author) && $dbi->isWikiPage($author);
83 function authorURL ($author) {
84 return $this->authorHasPage() ? WikiURL($author) : false;
88 function status ($rev) {
89 if ($rev->hasDefaultContents())
91 $page = $rev->getPage();
92 $prev = $page->getRevisionBefore($rev->getVersion());
93 if ($prev->hasDefaultContents())
98 function importance ($rev) {
99 return $rev->get('is_minor_edit') ? 'minor' : 'major';
102 function summary($rev) {
103 if ( ($summary = $rev->get('summary')) )
106 switch ($this->status($rev)) {
110 return _("New page");
116 function setValidators($most_recent_rev) {
117 $rev = $most_recent_rev;
118 $validators = array('RecentChanges-top' =>
119 array($rev->getPageName(), $rev->getVersion()),
120 '%mtime' => $rev->get('mtime'));
122 $request->appendValidators($validators);
126 class _RecentChanges_HtmlFormatter
127 extends _RecentChanges_Formatter
129 function diffLink ($rev) {
131 $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
132 $button->setAttr('rel', 'nofollow');
133 return HTML("(",$button,")");
136 /* deletions: red, additions: green */
137 function diffSummary ($rev) {
138 $html = $this->diffURL($rev);
142 function historyLink ($rev) {
144 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
145 $button->setAttr('rel', 'nofollow');
146 return HTML("(",$button,")");
149 function pageLink ($rev, $link_text=false) {
151 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),'auto',$link_text);
153 $page = $rev->getPage();
155 if ($this->include_versions_in_URLs()) {
156 $version = $rev->getVersion();
157 if ($rev->isCurrent())
159 $exists = !$rev->hasDefaultContents();
163 $cur = $page->getCurrentRevision();
164 $exists = !$cur->hasDefaultContents();
167 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
169 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
173 function authorLink ($rev) {
174 return WikiLink($rev->get('author'), 'if_known');
177 /* Link to all users contributions (contribs and owns) */
178 function authorContribs ($rev) {
179 $author = $rev->get('author');
180 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
182 Button(array('action' => _("RecentChanges"),
183 'format' => 'contribs',
189 Button(array('action' => _("RecentChanges"),
190 'format' => 'contribs',
198 function summaryAsHTML ($rev) {
199 if ( !($summary = $this->summary($rev)) )
201 return HTML::span( array('class' => 'wiki-summary'),
203 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
207 function rss_icon () {
208 global $request, $WikiTheme;
210 $rss_url = $request->getURLtoSelf(array('action' => $this->action, 'format' => 'rss'));
211 return HTML::small(array('style' => 'font-weight:normal; vertical-align:middle;'),
212 $WikiTheme->makeButton("RSS", $rss_url, 'rssicon'));
215 function rss2_icon () {
216 global $request, $WikiTheme;
218 $rss_url = $request->getURLtoSelf(array('action' => $this->action, 'format' => 'rss2'));
219 return HTML::small(array('style' => 'font-weight:normal; vertical-align:middle;'),
220 $WikiTheme->makeButton("xml", $rss_url, 'rssicon'));
222 function atom_icon () {
223 global $request, $WikiTheme;
225 $rss_url = $request->getURLtoSelf(array('action' => $this->action, 'format' => 'atom'));
226 return HTML::small(array('style' => 'font-weight:normal; vertical-align:middle;'),
227 $WikiTheme->makeButton("atom", $rss_url, 'rssicon'));
230 function grazr_icon () {
231 global $request, $WikiTheme;
232 $rss_url = 'http://grazr.com/gzpanel.html?' .
233 WikiURL($request->getArg('pagename'),array('action' => $this->action, 'format' => 'rss2'),true);
234 return HTML::small(array('style' => 'font-weight:normal; vertical-align:middle;'),
235 $WikiTheme->makeButton("grazr-it", $rss_url, 'rssicon'));
238 function pre_description () {
239 extract($this->_args);
240 // FIXME: say something about show_all.
241 if ($show_major && $show_minor)
244 $edits = _("major edits");
246 $edits = _("minor edits");
247 if (isset($caption) and $caption == _("Recent Comments"))
248 $edits = _("comments");
249 if (!empty($only_new)) {
250 $edits = _("created new pages");
252 if (!empty($author)) {
255 $author = $request->_user->getID();
256 $edits .= sprintf(_(" for pages changed by %s"), $author);
258 if (!empty($owner)) {
261 $owner = $request->_user->getID();
262 $edits .= sprintf(_(" for pages owned by %s"), $owner);
264 if ($timespan = $days > 0) {
265 if (intval($days) != $days)
266 $days = sprintf("%.1f", $days);
270 * Depending how this text is split up it can be tricky or
271 * impossible to translate with good grammar. So the seperate
272 * strings for 1 day and %s days are necessary in this case
273 * for translating to multiple languages, due to differing
274 * overlapping ideal word cutting points.
276 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
277 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
278 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
280 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
281 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
282 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
286 if (intval($days) == 1)
287 $desc = fmt("The %d most recent %s during the past day are listed below.",
290 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
291 $limit, $edits, $days);
293 $desc = fmt("The %d most recent %s are listed below.",
296 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
298 if (intval($days) == 1)
299 $desc = fmt("The %d oldest %s during the past day are listed below.",
302 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
303 $lmt, $edits, $days);
305 $desc = fmt("The %d oldest %s are listed below.",
311 if (intval($days) == 1)
312 $desc = fmt("The most recent %s during the past day are listed below.",
315 $desc = fmt("The most recent %s during the past %s days are listed below.",
318 $desc = fmt("All %s are listed below.", $edits);
323 function description() {
324 return HTML::p(false, $this->pre_description());
329 extract($this->_args);
330 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
333 HTML::raw(' '), $this->rss2_icon(),
334 HTML::raw(' '), $this->grazr_icon(),
335 HTML::raw(' '), $this->atom_icon(),
336 $this->sidebar_link());
339 function empty_message() {
340 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
341 return _("No comments found");
343 return _("No changes found");
346 function sidebar_link() {
347 extract($this->_args);
348 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
351 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
354 "function addPanel() {\n"
355 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
356 ." \"$sidebarurl\",\"\");\n"
358 $jsf = JavaScript($addsidebarjsfunc);
361 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon');
362 $addsidebarjsclick = asXML(HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), $sidebar_button));
363 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
364 ." (typeof window.sidebar.addPanel == 'function'))\n"
366 ." document.write('$addsidebarjsclick');\n"
369 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
372 function format ($changes) {
373 include_once('lib/InlineParser.php');
375 $html = HTML(HTML::h2(false, $this->title()));
376 if (($desc = $this->description()))
377 $html->pushContent($desc);
379 if ($this->_args['daylist'])
380 $html->pushContent(new DayButtonBar($this->_args));
386 while ($rev = $changes->next()) {
387 if (($date = $this->date($rev)) != $last_date) {
389 $html->pushContent($lines);
390 // for user contributions no extra date line
391 $html->pushContent(HTML::h3($date));
396 // enforce view permission
397 if (mayAccessPage('view', $rev->_pagename)) {
398 $lines->pushContent($this->format_revision($rev));
400 $this->setValidators($rev);
405 $html->pushContent($lines);
407 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
408 $this->empty_message()));
413 function format_revision ($rev) {
415 $args = &$this->_args;
417 $class = 'rc-' . $this->importance($rev);
419 $time = $this->time($rev);
420 if (! $rev->get('is_minor_edit'))
421 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
423 $line = HTML::li(array('class' => $class));
425 if ($args['difflinks'])
426 $line->pushContent($this->diffLink($rev), ' ');
428 if ($args['historylinks'])
429 $line->pushContent($this->historyLink($rev), ' ');
431 if (isa($WikiTheme, 'Theme_MonoBook')) {
433 $args['historylinks'] ? '' : $this->historyLink($rev),
434 ' . . ', $this->pageLink($rev), '; ',
436 $this->authorLink($rev),' ',
437 $this->authorContribs($rev),' ',
438 $this->summaryAsHTML($rev));
440 $line->pushContent($this->pageLink($rev), ' ',
442 $this->summaryAsHTML($rev),
444 $this->authorLink($rev));
451 /* format=contribs: no seperation into extra dates
452 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
454 class _RecentChanges_UserContribsFormatter
455 extends _RecentChanges_HtmlFormatter
458 extract($this->_args);
459 return array(_("UserContribs"),":",$author ? $author : $owner,
462 HTML::raw(' '), $this->rss2_icon(),
463 //HTML::raw(' '), $this->grazr_icon(),
464 HTML::raw(' '), $this->atom_icon());
467 function format ($changes) {
468 include_once('lib/InlineParser.php');
470 $html = HTML(HTML::h2(false, $this->title()));
472 $first = true; $count = 0;
473 while ($rev = $changes->next()) {
474 if (mayAccessPage('view', $rev->_pagename)) {
475 $lines->pushContent($this->format_revision($rev));
477 $this->setValidators($rev);
482 $this->_args['limit'] = $count;
483 if (($desc = $this->description()))
484 $html->pushContent($desc);
485 if ($this->_args['daylist'])
486 $html->pushContent(new DayButtonBar($this->_args));
488 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
489 $this->empty_message()));
491 $html->pushContent($lines);
496 function format_revision ($rev) {
497 $args = &$this->_args;
498 $class = 'rc-' . $this->importance($rev);
499 $time = $this->time($rev);
500 if (! $rev->get('is_minor_edit'))
501 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
503 $line = HTML::li(array('class' => $class));
505 $line->pushContent($this->time($rev),", ");
506 $line->pushContent($this->date($rev)," ");
507 $line->pushContent($this->diffLink($rev), ' ');
508 $line->pushContent($this->historyLink($rev), ' ');
509 $line->pushContent($this->pageLink($rev), ' ',
510 $this->summaryAsHTML($rev));
515 class _RecentChanges_SideBarFormatter
516 extends _RecentChanges_HtmlFormatter
518 function rss_icon () {
521 function rss2_icon () { }
523 //title click opens the normal RC or RE page in the main browser frame
524 extract($this->_args);
525 $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
526 $titlelink->setAttr('target', '_content');
527 return HTML($this->logo(), $titlelink);
530 //logo click opens the HomePage in the main browser frame
532 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
535 'style' => 'height:2.5ex'
537 $linkurl = WikiLink(HOME_PAGE, false, $img);
538 $linkurl->setAttr('target', '_content');
542 function authorLink ($rev) {
543 $author = $rev->get('author');
544 if ( $this->authorHasPage($author) ) {
545 $linkurl = WikiLink($author);
546 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
552 function diffLink ($rev) {
553 $linkurl = parent::diffLink($rev);
554 $linkurl->setAttr('target', '_content');
555 $linkurl->setAttr('rel', 'nofollow');
556 // FIXME: Smelly hack to get smaller diff buttons in sidebar
557 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
560 function historyLink ($rev) {
561 $linkurl = parent::historyLink($rev);
562 $linkurl->setAttr('target', '_content');
563 // FIXME: Smelly hack to get smaller history buttons in sidebar
564 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
567 function pageLink ($rev) {
568 $linkurl = parent::pageLink($rev);
569 $linkurl->setAttr('target', '_content');
572 // Overriding summaryAsHTML, because there is no way yet to
573 // return summary as transformed text with
574 // links setAttr('target', '_content') in Mozilla sidebar.
575 // So for now don't create clickable links inside summary
576 // in the sidebar, or else they target the sidebar and not the
577 // main content window.
578 function summaryAsHTML ($rev) {
579 if ( !($summary = $this->summary($rev)) )
581 return HTML::span(array('class' => 'wiki-summary'),
583 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
588 function format ($changes) {
589 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
590 $html = _RecentChanges_HtmlFormatter::format ($changes);
591 $html = HTML::div(array('class' => 'wikitext'), $html);
593 $request->discardOutput();
595 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
596 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
597 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
598 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
601 extract($this->_args);
602 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
603 printf("<title>" . $title . "</title>\n");
605 $css = $WikiTheme->getCSS();
609 printf("<body class=\"sidebar\">\n");
611 echo '<a href="http://www.feedvalidator.org/check.cgi?url=http://phpwiki.org/RecentChanges?format=rss"><img src="themes/default/buttons/valid-rss.png" alt="[Valid RSS]" title="Validate the RSS feed" width="44" height="15" /></a>';
612 printf("\n</body>\n");
615 $request->finish(); // cut rest of page processing short
619 class _RecentChanges_BoxFormatter
620 extends _RecentChanges_HtmlFormatter
622 function rss_icon () {
624 function rss2_icon () {
628 function authorLink ($rev) {
630 function diffLink ($rev) {
632 function historyLink ($rev) {
634 function summaryAsHTML ($rev) {
636 function description () {
638 function format ($changes) {
639 include_once('lib/InlineParser.php');
644 $sp = HTML::Raw("\n · ");
645 while ($rev = $changes->next()) {
646 // enforce view permission
647 if (mayAccessPage('view',$rev->_pagename)) {
648 if ($link = $this->pageLink($rev)) // some entries may be empty
649 // (/Blog/.. interim pages)
650 $html->pushContent($sp, $link, HTML::br());
652 $this->setValidators($rev);
657 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
658 $this->empty_message()));
663 class _RecentChanges_RssFormatter
664 extends _RecentChanges_Formatter
666 var $_absurls = true;
668 function time ($rev) {
669 return Iso8601DateTime($rev->get('mtime'));
672 function pageURI ($rev) {
673 return WikiURL($rev, '', 'absurl');
676 function format ($changes) {
678 include_once('lib/RssWriter.php');
679 $rss = new RssWriter;
680 $rss->channel($this->channel_properties());
682 if (($props = $this->image_properties()))
684 if (($props = $this->textinput_properties()))
685 $rss->textinput($props);
688 while ($rev = $changes->next()) {
689 // enforce view permission
690 if (mayAccessPage('view', $rev->_pagename)) {
691 $rss->addItem($this->item_properties($rev),
692 $this->pageURI($rev));
694 $this->setValidators($rev);
700 $request->discardOutput();
702 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
704 // Flush errors in comment, otherwise it's invalid XML.
705 global $ErrorManager;
706 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
707 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
709 $request->finish(); // NORETURN!!!!
712 function image_properties () {
715 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
719 return array('title' => WIKI_NAME,
720 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
724 function textinput_properties () {
725 return array('title' => _("Search"),
726 'description' => _("Title Search"),
728 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
731 function channel_properties () {
734 extract($this->_args);
735 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
736 if ($author) $description = _("UserContribs").":$author";
737 elseif ($owner) $description = _("UserContribs").":$owner";
738 elseif ($only_new) $description = _("RecentNewPages");
739 elseif ($show_minor) $description = _("RecentEdits");
740 else $description = _("RecentChanges");
741 return array('title' => WIKI_NAME,
743 'description' => $description,
744 'dc:date' => Iso8601DateTime(time()),
745 'dc:language' => $GLOBALS['LANG']);
747 /* FIXME: other things one might like in <channel>:
756 * rss091:managingEditor
758 * rss091:lastBuildDate
763 function item_properties ($rev) {
764 $page = $rev->getPage();
765 $pagename = $page->getName();
767 return array( 'title' => SplitPagename($pagename),
768 'description' => $this->summary($rev),
769 'link' => $this->pageURL($rev),
770 'dc:date' => $this->time($rev),
771 'dc:contributor' => $rev->get('author'),
772 'wiki:version' => $rev->getVersion(),
773 'wiki:importance' => $this->importance($rev),
774 'wiki:status' => $this->status($rev),
775 'wiki:diff' => $this->diffURL($rev),
776 'wiki:history' => $this->historyURL($rev)
781 /** explicit application/rss+xml Content-Type,
782 * simplified xml structure (no namespace),
783 * support for xml-rpc cloud registerProcedure (not yet)
785 class _RecentChanges_Rss2Formatter
786 extends _RecentChanges_RssFormatter {
788 function format ($changes) {
789 include_once('lib/RssWriter2.php');
790 $rss = new RssWriter2;
792 $rss->channel($this->channel_properties());
793 if (($props = $this->cloud_properties()))
795 if (($props = $this->image_properties()))
797 if (($props = $this->textinput_properties()))
798 $rss->textinput($props);
800 while ($rev = $changes->next()) {
801 // enforce view permission
802 if (mayAccessPage('view', $rev->_pagename)) {
803 $rss->addItem($this->item_properties($rev),
804 $this->pageURI($rev));
806 $this->setValidators($rev);
812 $request->discardOutput();
814 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
815 // Flush errors in comment, otherwise it's invalid XML.
816 global $ErrorManager;
817 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
818 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
820 $request->finish(); // NORETURN!!!!
823 function channel_properties () {
824 $chann_10 = parent::channel_properties();
825 return array_merge($chann_10,
826 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
827 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
828 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
829 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
830 'copyright' => COPYRIGHTPAGE_URL
834 // xml-rpc registerProcedure not yet implemented
835 function cloud_properties () { return false; }
836 function cloud_properties_test () {
837 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
838 'registerProcedure' => 'wiki.rssPleaseNotify',
839 'path' => DATA_PATH.'/RPC2.php',
840 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
841 'domain' => SERVER_NAME);
845 /** Explicit application/atom+xml Content-Type
846 * A weird, questionable format
848 class _RecentChanges_AtomFormatter
849 extends _RecentChanges_RssFormatter {
851 function format ($changes) {
853 include_once('lib/RssWriter.php');
856 // "channel" is called "feed" in atom
857 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
858 $feed_props = array('title' => WIKI_NAME,
859 'link' => array('rel'=>"alternate",
862 'id' => md5($rc_url),
863 'modified' => Iso8601DateTime(time()),
864 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
866 $rss->feed($feed_props);
868 while ($rev = $changes->next()) {
869 // enforce view permission
870 if (mayAccessPage('view', $rev->_pagename)) {
871 $props = $this->item_properties($rev);
872 $rss->addItem($props,
874 $this->pageURI($rev));
876 $this->setValidators($rev);
881 $request->discardOutput();
883 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
884 // Flush errors in comment, otherwise it's invalid XML.
885 global $ErrorManager;
886 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
887 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
889 $request->finish(); // NORETURN!!!!
892 function item_properties ($rev) {
893 $page = $rev->getPage();
894 $pagename = $page->getName();
895 return array( 'title' => $pagename,
896 'link' => array('rel' => 'alternate',
897 'type' => 'text/html',
898 'href' => $this->pageURL($rev)),
899 'summary' => $this->summary($rev),
900 'modified' => $this->time($rev)."Z",
901 'issued' => $this->time($rev),
902 'created' => $this->time($rev)."Z",
903 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
909 * Filter by non-empty
911 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
915 * @param $revisions object a WikiDB_PageRevisionIterator.
917 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
918 $this->_revisions = $revisions;
919 $this->_check_current_revision = $check_current_revision;
923 while (($rev = $this->_revisions->next())) {
924 if ($this->_check_current_revision) {
925 $page = $rev->getPage();
926 $check_rev = $page->getCurrentRevision();
931 if (! $check_rev->hasDefaultContents())
941 * Filter by only_new.
942 * Only new created pages
944 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
948 * @param $revisions object a WikiDB_PageRevisionIterator.
950 function NewPageRevisionIterator ($revisions) {
951 $this->_revisions = $revisions;
955 while (($rev = $this->_revisions->next())) {
956 if ($rev->getVersion() == 1)
967 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
969 function AuthorPageRevisionIterator ($revisions, $author) {
970 $this->_revisions = $revisions;
971 $this->_author = $author;
975 while (($rev = $this->_revisions->next())) {
976 if ($rev->get('author_id') == $this->_author)
987 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
989 function OwnerPageRevisionIterator ($revisions, $owner) {
990 $this->_revisions = $revisions;
991 $this->_owner = $owner;
995 while (($rev = $this->_revisions->next())) {
996 $page = $rev->getPage();
997 if ($page->getOwner() == $this->_owner)
1005 class WikiPlugin_RecentChanges
1008 function getName () {
1009 return _("RecentChanges");
1012 function getVersion() {
1013 return preg_replace("/[Revision: $]/", '',
1014 "\$Revision: 1.120 $");
1017 function managesValidators() {
1018 // Note that this is a bit of a fig.
1019 // We set validators based on the most recently changed page,
1020 // but this fails when the most-recent page is deleted.
1021 // (Consider that the Last-Modified time will decrease
1022 // when this happens.)
1024 // We might be better off, leaving this as false (and junking
1025 // the validator logic above) and just falling back to the
1026 // default behavior (handled by WikiPlugin) of just using
1027 // the WikiDB global timestamp as the mtime.
1029 // Nevertheless, for now, I leave this here, mostly as an
1030 // example for how to use appendValidators() and managesValidators().
1035 function getDefaultArguments() {
1036 return array('days' => 2,
1037 'show_minor' => false,
1038 'show_major' => true,
1039 'show_all' => false,
1040 'show_deleted' => 'sometimes',
1041 'only_new' => false,
1047 'difflinks' => true,
1048 'historylinks' => false,
1053 function getArgs ($argstr, $request, $defaults = false) {
1054 if (!$defaults) $defaults = $this->getDefaultArguments();
1055 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1057 $action = $request->getArg('action');
1058 if ($action != 'browse' && ! $request->isActionPage($action))
1059 $args['format'] = false; // default -> HTML
1061 if ($args['format'] == 'rss' && empty($args['limit']))
1062 $args['limit'] = 15; // Fix default value for RSS.
1063 if ($args['format'] == 'rss2' && empty($args['limit']))
1064 $args['limit'] = 15; // Fix default value for RSS2.
1066 if ($args['format'] == 'sidebar' && empty($args['limit']))
1067 $args['limit'] = 10; // Fix default value for sidebar.
1072 function getMostRecentParams (&$args) {
1073 $show_all = false; $show_minor = false; $show_major = false;
1077 $params = array('include_minor_revisions' => $show_minor,
1078 'exclude_major_revisions' => !$show_major,
1079 'include_all_revisions' => !empty($show_all));
1081 $params['limit'] = $limit;
1082 if (!empty($args['author'])) {
1084 if ($args['author'] == '[]')
1085 $args['author'] = $request->_user->getID();
1086 $params['author'] = $args['author'];
1088 if (!empty($args['owner'])) {
1090 if ($args['owner'] == '[]')
1091 $args['owner'] = $request->_user->getID();
1092 $params['owner'] = $args['owner'];
1094 if (!empty($days)) {
1096 $params['since'] = time() - 24 * 3600 * $days;
1097 elseif ($days < 0.0)
1098 $params['since'] = 24 * 3600 * $days - time();
1104 function getChanges ($dbi, $args) {
1105 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1107 $show_deleted = @$args['show_deleted'];
1108 $show_all = @$args['show_all'];
1109 if ($show_deleted == 'sometimes')
1110 $show_deleted = @$args['show_minor'];
1112 if (!empty($args['only_new']))
1113 $changes = new NewPageRevisionIterator($changes);
1114 if (!empty($args['author']))
1115 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1116 if (!empty($args['owner']))
1117 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1119 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1124 function format ($changes, $args) {
1126 $format = $args['format'];
1128 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1130 if ($format == 'rss')
1131 $fmt_class = '_RecentChanges_RssFormatter';
1132 elseif ($format == 'rss2')
1133 $fmt_class = '_RecentChanges_Rss2Formatter';
1134 elseif ($format == 'atom')
1135 $fmt_class = '_RecentChanges_AtomFormatter';
1136 elseif ($format == 'rss091') {
1137 include_once "lib/RSSWriter091.php";
1138 $fmt_class = '_RecentChanges_RssFormatter091';
1140 elseif ($format == 'sidebar')
1141 $fmt_class = '_RecentChanges_SideBarFormatter';
1142 elseif ($format == 'box')
1143 $fmt_class = '_RecentChanges_BoxFormatter';
1144 elseif ($format == 'contribs')
1145 $fmt_class = '_RecentChanges_UserContribsFormatter';
1147 $fmt_class = '_RecentChanges_HtmlFormatter';
1150 $fmt = new $fmt_class($args);
1151 return $fmt->format($changes);
1154 function run($dbi, $argstr, &$request, $basepage) {
1155 $args = $this->getArgs($argstr, $request);
1157 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1158 // to be enough for anyone.)
1159 $args['days'] = min($args['days'], 365000);
1161 // Hack alert: format() is a NORETURN for rss formatters.
1162 return $this->format($this->getChanges($dbi, $args), $args);
1165 // box is used to display a fixed-width, narrow version with common header.
1166 // just a numbered list of limit pagenames, without date.
1167 function box($args = false, $request = false, $basepage = false) {
1168 if (!$request) $request =& $GLOBALS['request'];
1169 if (!isset($args['limit'])) $args['limit'] = 15;
1170 $args['format'] = 'box';
1171 $args['show_minor'] = false;
1172 $args['show_major'] = true;
1173 $args['show_deleted'] = 'sometimes';
1174 $args['show_all'] = false;
1176 return $this->makeBox(WikiLink($this->getName(),'',
1177 SplitPagename($this->getName())),
1179 ($this->getChanges($request->_dbi, $args), $args));
1185 class DayButtonBar extends HtmlElement {
1187 function DayButtonBar ($plugin_args) {
1188 $this->__construct('p', array('class' => 'wiki-rc-action'));
1190 // Display days selection buttons
1191 extract($plugin_args);
1196 $caption = _("Show minor edits for:");
1198 $caption = _("Show all changes for:");
1200 $caption = _("Show changes for:");
1202 $caption = _("All new pages since:");
1205 $this->pushContent($caption, ' ');
1208 $sep = $WikiTheme->getButtonSeparator();
1211 foreach (explode(",", $daylist) as $days) {
1213 $this->pushContent($sep);
1214 $this->pushContent($this->_makeDayButton($days));
1218 function _makeDayButton ($days) {
1219 global $WikiTheme, $request;
1222 $label = _("1 day");
1224 $label = "..."; //alldays
1226 $label = sprintf(_("%s days"), abs($days));
1228 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1230 return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
1234 // $Log: not supported by cvs2svn $
1235 // Revision 1.119 2007/07/01 09:17:45 rurban
1236 // add ATOM support, a very questionable format
1238 // Revision 1.118 2007/06/02 18:24:59 rurban
1241 // Revision 1.117 2007/05/30 20:43:31 rurban
1242 // added MonoBook UserContribs
1244 // Revision 1.116 2007/05/13 18:13:41 rurban
1245 // use all filters, not just the first, ignoring the others. improve wording a bit
1247 // Revision 1.115 2007/04/08 16:24:10 rurban
1248 // Remove redundant code in ->authorLink(): 'if_known' does the same
1250 // Revision 1.114 2007/02/17 22:39:44 rurban
1251 // format=rss overhaul
1253 // Revision 1.113 2007/02/17 14:15:52 rurban
1254 // new argument owner=[] for RecentChangesMyPages
1256 // Revision 1.112 2007/01/28 20:32:07 rurban
1257 // silence empty warning
1259 // Revision 1.111 2007/01/25 21:48:52 rurban
1260 // new argument author=[]
1262 // Revision 1.110 2007/01/22 23:51:36 rurban
1263 // new arg: only_new
1265 // Revision 1.109 2006/03/19 14:26:29 rurban
1266 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
1268 // Revision 1.108 2005/04/01 16:09:35 rurban
1269 // fix defaults in RecentChanges plugins: e.g. invalid pagenames for PageHistory
1271 // Revision 1.107 2005/02/04 13:45:28 rurban
1272 // improve box layout a bit
1274 // Revision 1.106 2005/02/02 19:39:10 rurban
1275 // honor show_all=false
1277 // Revision 1.105 2005/01/25 03:50:54 uckelman
1278 // pre_description is a member function, so call with $this->.
1280 // Revision 1.104 2005/01/24 23:15:16 uckelman
1281 // The extra description for RelatedChanges was appearing in RecentChanges
1282 // and PageHistory due to a bad test in _RecentChanges_HtmlFormatter. Fixed.
1284 // Revision 1.103 2004/12/15 17:45:09 rurban
1287 // Revision 1.102 2004/12/06 19:29:24 rurban
1288 // simplify RSS: add RSS2 link (rss tag only, new content-type)
1290 // Revision 1.101 2004/11/10 19:32:24 rurban
1291 // * optimize increaseHitCount, esp. for mysql.
1292 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1293 // * Pear_DB version logic (awful but needed)
1294 // * fix broken ADODB quote
1295 // * _extract_page_data simplification
1297 // Revision 1.100 2004/06/28 16:35:12 rurban
1298 // prevent from shell commands
1300 // Revision 1.99 2004/06/20 14:42:54 rurban
1301 // various php5 fixes (still broken at blockparser)
1303 // Revision 1.98 2004/06/14 11:31:39 rurban
1304 // renamed global $Theme to $WikiTheme (gforge nameclash)
1305 // inherit PageList default options from PageList
1306 // default sortby=pagename
1307 // use options in PageList_Selectable (limit, sortby, ...)
1308 // added action revert, with button at action=diff
1309 // added option regex to WikiAdminSearchReplace
1311 // Revision 1.97 2004/06/03 18:58:27 rurban
1312 // days links requires action=RelatedChanges arg
1314 // Revision 1.96 2004/05/18 16:23:40 rurban
1315 // rename split_pagename to SplitPagename
1317 // Revision 1.95 2004/05/16 22:07:35 rurban
1318 // check more config-default and predefined constants
1319 // various PagePerm fixes:
1320 // fix default PagePerms, esp. edit and view for Bogo and Password users
1321 // implemented Creator and Owner
1322 // BOGOUSERS renamed to BOGOUSER
1323 // fixed syntax errors in signin.tmpl
1325 // Revision 1.94 2004/05/14 20:55:03 rurban
1326 // simplified RecentComments
1328 // Revision 1.93 2004/05/14 17:33:07 rurban
1329 // new plugin RecentChanges
1331 // Revision 1.92 2004/04/21 04:29:10 rurban
1332 // Two convenient RecentChanges extensions
1333 // RelatedChanges (only links from current page)
1334 // RecentEdits (just change the default args)
1336 // Revision 1.91 2004/04/19 18:27:46 rurban
1337 // Prevent from some PHP5 warnings (ref args, no :: object init)
1338 // php5 runs now through, just one wrong XmlElement object init missing
1339 // Removed unneccesary UpgradeUser lines
1340 // Changed WikiLink to omit version if current (RecentChanges)
1342 // Revision 1.90 2004/04/18 01:11:52 rurban
1343 // more numeric pagename fixes.
1344 // fixed action=upload with merge conflict warnings.
1345 // charset changed from constant to global (dynamic utf-8 switching)
1347 // Revision 1.89 2004/04/10 02:30:49 rurban
1348 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1349 // Fixed "cannot setlocale..." (sf.net problem)
1351 // Revision 1.88 2004/04/01 15:57:10 rurban
1352 // simplified Sidebar theme: table, not absolute css positioning
1353 // added the new box methods.
1354 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1356 // Revision 1.87 2004/03/30 02:14:03 rurban
1357 // fixed yet another Prefs bug
1358 // added generic PearDb_iter
1359 // $request->appendValidators no so strict as before
1360 // added some box plugin methods
1361 // PageList commalist for condensed output
1363 // Revision 1.86 2004/03/12 13:31:43 rurban
1364 // enforce PagePermissions, errormsg if not Admin
1366 // Revision 1.85 2004/02/17 12:11:36 rurban
1367 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
1369 // Revision 1.84 2004/02/15 22:29:42 rurban
1370 // revert premature performance fix
1372 // Revision 1.83 2004/02/15 21:34:37 rurban
1373 // PageList enhanced and improved.
1374 // fixed new WikiAdmin... plugins
1375 // editpage, Theme with exp. htmlarea framework
1376 // (htmlarea yet committed, this is really questionable)
1377 // WikiUser... code with better session handling for prefs
1378 // enhanced UserPreferences (again)
1379 // RecentChanges for show_deleted: how should pages be deleted then?
1381 // Revision 1.82 2004/01/25 03:58:43 rurban
1382 // use stdlib:isWikiWord()
1384 // Revision 1.81 2003/11/28 21:06:31 carstenklapp
1385 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
1386 // instead of 1. Make diff buttons smaller with css. Added description
1387 // line back in at the top.
1389 // Revision 1.80 2003/11/27 15:17:01 carstenklapp
1390 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
1391 // button, to allow an image button for it to be added to Themes. Output
1392 // RSS button in small text size when theme has no button image.
1394 // Revision 1.79 2003/04/29 14:34:20 dairiki
1395 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
1397 // Revision 1.78 2003/03/04 01:55:05 dairiki
1398 // Fix to ensure absolute URL for logo in RSS recent changes.
1400 // Revision 1.77 2003/02/27 23:23:38 dairiki
1401 // Fix my breakage of CSS and sidebar RecentChanges output.
1403 // Revision 1.76 2003/02/27 22:48:44 dairiki
1404 // Fixes invalid HTML generated by PageHistory plugin.
1406 // (<noscript> is block-level and not allowed within <p>.)
1408 // Revision 1.75 2003/02/22 21:39:05 dairiki
1409 // Hackish fix for SF bug #622784.
1411 // (The root of the problem is clearly a PHP bug.)
1413 // Revision 1.74 2003/02/21 22:52:21 dairiki
1414 // Make sure to interpret relative links (like [/Subpage]) in summary
1415 // relative to correct basepage.
1417 // Revision 1.73 2003/02/21 04:12:06 dairiki
1418 // Minor fixes for new cached markup.
1420 // Revision 1.72 2003/02/17 02:19:01 dairiki
1421 // Fix so that PageHistory will work when the current revision
1422 // of a page has been "deleted".
1424 // Revision 1.71 2003/02/16 20:04:48 dairiki
1425 // Refactor the HTTP validator generation/checking code.
1427 // This also fixes a number of bugs with yesterdays validator mods.
1429 // Revision 1.70 2003/02/16 05:09:43 dairiki
1430 // Starting to fix handling of the HTTP validator headers, Last-Modified,
1433 // Last-Modified was being set incorrectly (but only when DEBUG was not
1434 // defined!) Setting a Last-Modified without setting an appropriate
1435 // Expires: and/or Cache-Control: header results in browsers caching
1436 // the page unconditionally (for a certain period of time).
1437 // This is generally bad, since it means people don't see updated
1438 // page contents right away --- this is particularly confusing to
1439 // the people who are editing pages since their edits don't show up
1440 // next time they browse the page.
1442 // Now, we don't allow caching of pages without revalidation
1443 // (via the If-Modified-Since and/or If-None-Match request headers.)
1444 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
1445 // appropriate value in index.php, but I advise against it.)
1449 // o Even when request is aborted due to the content not being
1450 // modified, we currently still do almost all the work involved
1451 // in producing the page. So the only real savings from all
1452 // this logic is in network bandwidth.
1454 // o Plugins which produce "dynamic" output need to be inspected
1455 // and made to call $request->addToETag() and
1456 // $request->setModificationTime() appropriately, otherwise the
1457 // page can change without the change being detected.
1458 // This leads to stale pages in cache again...
1460 // Revision 1.69 2003/01/18 22:01:43 carstenklapp
1462 // Reformatting & tabs to spaces;
1463 // Added copyleft, getVersion, getDescription, rcs_id.
1466 // (c-file-style: "gnu")
1470 // c-basic-offset: 4
1471 // c-hanging-comment-ender-p: nil
1472 // indent-tabs-mode: nil