2 rcs_id('$Id: RecentChanges.php,v 1.121 2007-08-25 18:54:41 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;
45 extract($this->_args);
46 if ($author) $title = _("UserContribs").":$author";
47 elseif ($owner) $title = _("UserContribs").":$owner";
48 elseif ($only_new) $title = _("RecentNewPages");
49 elseif ($show_minor) $title = _("RecentEdits");
50 else $title = _("RecentChanges");
52 if (!empty($category))
54 elseif (!empty($pagematch))
55 $title .= ":$pagematch";
59 function include_versions_in_URLs() {
60 return (bool) $this->_args['show_all'];
63 function date ($rev) {
65 return $WikiTheme->getDay($rev->get('mtime'));
68 function time ($rev) {
70 return $WikiTheme->formatTime($rev->get('mtime'));
73 function diffURL ($rev) {
74 $args = $this->_diffargs;
75 if ($this->include_versions_in_URLs())
76 $args['version'] = $rev->getVersion();
77 $page = $rev->getPage();
78 return WikiURL($page->getName(), $args, $this->_absurls);
81 function historyURL ($rev) {
82 $page = $rev->getPage();
83 return WikiURL($page, array('action' => _("PageHistory")),
87 function pageURL ($rev) {
88 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
92 function authorHasPage ($author) {
93 global $WikiNameRegexp, $request;
94 $dbi = $request->getDbh();
95 return isWikiWord($author) && $dbi->isWikiPage($author);
98 function authorURL ($author) {
99 return $this->authorHasPage() ? WikiURL($author) : false;
103 function status ($rev) {
104 if ($rev->hasDefaultContents())
106 $page = $rev->getPage();
107 $prev = $page->getRevisionBefore($rev->getVersion());
108 if ($prev->hasDefaultContents())
113 function importance ($rev) {
114 return $rev->get('is_minor_edit') ? 'minor' : 'major';
117 function summary($rev) {
118 if ( ($summary = $rev->get('summary')) )
121 switch ($this->status($rev)) {
125 return _("New page");
131 function setValidators($most_recent_rev) {
132 $rev = $most_recent_rev;
133 $validators = array('RecentChanges-top' =>
134 array($rev->getPageName(), $rev->getVersion()),
135 '%mtime' => $rev->get('mtime'));
137 $request->appendValidators($validators);
141 class _RecentChanges_HtmlFormatter
142 extends _RecentChanges_Formatter
144 function diffLink ($rev) {
146 $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
147 $button->setAttr('rel', 'nofollow');
148 return HTML("(",$button,")");
151 /* deletions: red, additions: green */
152 function diffSummary ($rev) {
153 $html = $this->diffURL($rev);
157 function historyLink ($rev) {
159 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
160 $button->setAttr('rel', 'nofollow');
161 return HTML("(",$button,")");
164 function pageLink ($rev, $link_text=false) {
166 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),'auto',$link_text);
168 $page = $rev->getPage();
170 if ($this->include_versions_in_URLs()) {
171 $version = $rev->getVersion();
172 if ($rev->isCurrent())
174 $exists = !$rev->hasDefaultContents();
178 $cur = $page->getCurrentRevision();
179 $exists = !$cur->hasDefaultContents();
182 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
184 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
188 function authorLink ($rev) {
189 return WikiLink($rev->get('author'), 'if_known');
192 /* Link to all users contributions (contribs and owns) */
193 function authorContribs ($rev) {
194 $author = $rev->get('author');
195 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
197 Button(array('action' => _("RecentChanges"),
198 'format' => 'contribs',
204 Button(array('action' => _("RecentChanges"),
205 'format' => 'contribs',
213 function summaryAsHTML ($rev) {
214 if ( !($summary = $this->summary($rev)) )
216 return HTML::span( array('class' => 'wiki-summary'),
218 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
222 function format_icon ($format) {
223 global $request, $WikiTheme;
224 $rss_url = $request->getURLtoSelf(array('action' => $this->action, 'format' => $format));
225 return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
228 function rss_icon () { return $this->format_icon("rss"); }
229 function rss2_icon () { return $this->format_icon("rss2"); }
230 function atom_icon () { return $this->format_icon("atom"); }
231 function rdf_icon () { return DEBUG ? $this->format_icon("rdf") : ''; }
232 function rdfs_icon () { return DEBUG ? $this->format_icon("rdfs") : ''; }
233 function owl_icon () { return DEBUG ? $this->format_icon("owl") : ''; }
235 function grazr_icon () {
236 global $request, $WikiTheme;
237 if (!DEBUG) return '';
238 $rss_url = 'http://grazr.com/gzpanel.html?' .
239 WikiURL($request->getArg('pagename'),array('action' => $this->action, 'format' => 'rss2'),true);
240 return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
243 function pre_description () {
244 extract($this->_args);
245 // FIXME: say something about show_all.
246 if ($show_major && $show_minor)
249 $edits = _("major edits");
251 $edits = _("minor edits");
252 if (isset($caption) and $caption == _("Recent Comments"))
253 $edits = _("comments");
254 if (!empty($only_new)) {
255 $edits = _("created new pages");
257 if (!empty($author)) {
260 $author = $request->_user->getID();
261 $edits .= sprintf(_(" for pages changed by %s"), $author);
263 if (!empty($owner)) {
266 $owner = $request->_user->getID();
267 $edits .= sprintf(_(" for pages owned by %s"), $owner);
269 if (!empty($category)) {
270 $edits .= sprintf(_(" for all pages linking to %s"), $category);
272 if (!empty($pagematch)) {
273 $edits .= sprintf(_(" for all pages matching '%s'"), $pagematch);
275 if ($timespan = $days > 0) {
276 if (intval($days) != $days)
277 $days = sprintf("%.1f", $days);
281 * Depending how this text is split up it can be tricky or
282 * impossible to translate with good grammar. So the seperate
283 * strings for 1 day and %s days are necessary in this case
284 * for translating to multiple languages, due to differing
285 * overlapping ideal word cutting points.
287 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
288 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
289 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
291 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
292 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
293 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
297 if (intval($days) == 1)
298 $desc = fmt("The %d most recent %s during the past day are listed below.",
301 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
302 $limit, $edits, $days);
304 $desc = fmt("The %d most recent %s are listed below.",
307 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
309 if (intval($days) == 1)
310 $desc = fmt("The %d oldest %s during the past day are listed below.",
313 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
314 $lmt, $edits, $days);
316 $desc = fmt("The %d oldest %s are listed below.",
322 if (intval($days) == 1)
323 $desc = fmt("The most recent %s during the past day are listed below.",
326 $desc = fmt("The most recent %s during the past %s days are listed below.",
329 $desc = fmt("All %s are listed below.", $edits);
334 function description() {
335 return HTML::p(false, $this->pre_description());
339 function headline () {
340 extract($this->_args);
341 return array($this->title(),
347 /*$this->rdfs_icon(),
350 $this->sidebar_link());
353 function empty_message() {
354 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
355 return _("No comments found");
357 return _("No changes found");
360 function sidebar_link() {
361 extract($this->_args);
362 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
365 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
368 "function addPanel() {\n"
369 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
370 ." \"$sidebarurl\",\"\");\n"
372 $jsf = JavaScript($addsidebarjsfunc);
375 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
376 array('title' => _("Click to add this feed to your sidebar"),
377 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
378 $addsidebarjsclick = asXML($sidebar_button);
379 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
380 ." (typeof window.sidebar.addPanel == 'function'))\n"
382 ." document.write('$addsidebarjsclick');\n"
385 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
388 function format ($changes) {
389 include_once('lib/InlineParser.php');
391 $html = HTML(HTML::h2(false, $this->headline()));
392 if (($desc = $this->description()))
393 $html->pushContent($desc);
395 if ($this->_args['daylist'])
396 $html->pushContent(new DayButtonBar($this->_args));
402 while ($rev = $changes->next()) {
403 if (($date = $this->date($rev)) != $last_date) {
405 $html->pushContent($lines);
406 // for user contributions no extra date line
407 $html->pushContent(HTML::h3($date));
412 // enforce view permission
413 if (mayAccessPage('view', $rev->_pagename)) {
414 $lines->pushContent($this->format_revision($rev));
416 $this->setValidators($rev);
421 $html->pushContent($lines);
423 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
424 $this->empty_message()));
429 function format_revision ($rev) {
431 $args = &$this->_args;
433 $class = 'rc-' . $this->importance($rev);
435 $time = $this->time($rev);
436 if (! $rev->get('is_minor_edit'))
437 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
439 $line = HTML::li(array('class' => $class));
441 if ($args['difflinks'])
442 $line->pushContent($this->diffLink($rev), ' ');
444 if ($args['historylinks'])
445 $line->pushContent($this->historyLink($rev), ' ');
447 if (isa($WikiTheme, 'Theme_MonoBook')) {
449 $args['historylinks'] ? '' : $this->historyLink($rev),
450 ' . . ', $this->pageLink($rev), '; ',
452 $this->authorLink($rev),' ',
453 $this->authorContribs($rev),' ',
454 $this->summaryAsHTML($rev));
456 $line->pushContent($this->pageLink($rev), ' ',
458 $this->summaryAsHTML($rev),
460 $this->authorLink($rev));
467 /* format=contribs: no seperation into extra dates
468 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
470 class _RecentChanges_UserContribsFormatter
471 extends _RecentChanges_HtmlFormatter
473 function headline () {
474 extract($this->_args);
475 return array(_("UserContribs"),":",$author ? $author : $owner,
481 $this->grazr_icon());
484 function format ($changes) {
485 include_once('lib/InlineParser.php');
487 $html = HTML(HTML::h2(false, $this->headline()));
489 $first = true; $count = 0;
490 while ($rev = $changes->next()) {
491 if (mayAccessPage('view', $rev->_pagename)) {
492 $lines->pushContent($this->format_revision($rev));
494 $this->setValidators($rev);
499 $this->_args['limit'] = $count;
500 if (($desc = $this->description()))
501 $html->pushContent($desc);
502 if ($this->_args['daylist'])
503 $html->pushContent(new DayButtonBar($this->_args));
505 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
506 $this->empty_message()));
508 $html->pushContent($lines);
513 function format_revision ($rev) {
514 $args = &$this->_args;
515 $class = 'rc-' . $this->importance($rev);
516 $time = $this->time($rev);
517 if (! $rev->get('is_minor_edit'))
518 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
520 $line = HTML::li(array('class' => $class));
522 $line->pushContent($this->time($rev),", ");
523 $line->pushContent($this->date($rev)," ");
524 $line->pushContent($this->diffLink($rev), ' ');
525 $line->pushContent($this->historyLink($rev), ' ');
526 $line->pushContent($this->pageLink($rev), ' ',
527 $this->summaryAsHTML($rev));
532 class _RecentChanges_SideBarFormatter
533 extends _RecentChanges_HtmlFormatter
535 function rss_icon () {
538 function rss2_icon () { }
539 function headline () {
540 //title click opens the normal RC or RE page in the main browser frame
541 extract($this->_args);
542 $titlelink = WikiLink($this->title());
543 $titlelink->setAttr('target', '_content');
544 return HTML($this->logo(), $titlelink);
547 //logo click opens the HomePage in the main browser frame
549 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
552 'style' => 'height:2.5ex'
554 $linkurl = WikiLink(HOME_PAGE, false, $img);
555 $linkurl->setAttr('target', '_content');
559 function authorLink ($rev) {
560 $author = $rev->get('author');
561 if ( $this->authorHasPage($author) ) {
562 $linkurl = WikiLink($author);
563 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
569 function diffLink ($rev) {
570 $linkurl = parent::diffLink($rev);
571 $linkurl->setAttr('target', '_content');
572 $linkurl->setAttr('rel', 'nofollow');
573 // FIXME: Smelly hack to get smaller diff buttons in sidebar
574 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
577 function historyLink ($rev) {
578 $linkurl = parent::historyLink($rev);
579 $linkurl->setAttr('target', '_content');
580 // FIXME: Smelly hack to get smaller history buttons in sidebar
581 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
584 function pageLink ($rev) {
585 $linkurl = parent::pageLink($rev);
586 $linkurl->setAttr('target', '_content');
589 // Overriding summaryAsHTML, because there is no way yet to
590 // return summary as transformed text with
591 // links setAttr('target', '_content') in Mozilla sidebar.
592 // So for now don't create clickable links inside summary
593 // in the sidebar, or else they target the sidebar and not the
594 // main content window.
595 function summaryAsHTML ($rev) {
596 if ( !($summary = $this->summary($rev)) )
598 return HTML::span(array('class' => 'wiki-summary'),
600 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
605 function format ($changes) {
606 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
607 $html = _RecentChanges_HtmlFormatter::format ($changes);
608 $html = HTML::div(array('class' => 'wikitext'), $html);
610 $request->discardOutput();
612 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
613 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
614 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
615 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
618 extract($this->_args);
619 if (!empty($category))
621 elseif (!empty($pagematch))
624 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
625 printf("<title>" . $title . "</title>\n");
627 $css = $WikiTheme->getCSS();
631 printf("<body class=\"sidebar\">\n");
633 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>';
634 printf("\n</body>\n");
637 $request->finish(); // cut rest of page processing short
641 class _RecentChanges_BoxFormatter
642 extends _RecentChanges_HtmlFormatter
644 function rss_icon () {
646 function rss2_icon () {
648 function headline () {
650 function authorLink ($rev) {
652 function diffLink ($rev) {
654 function historyLink ($rev) {
656 function summaryAsHTML ($rev) {
658 function description () {
660 function format ($changes) {
661 include_once('lib/InlineParser.php');
666 $sp = HTML::Raw("\n · ");
667 while ($rev = $changes->next()) {
668 // enforce view permission
669 if (mayAccessPage('view',$rev->_pagename)) {
670 if ($link = $this->pageLink($rev)) // some entries may be empty
671 // (/Blog/.. interim pages)
672 $html->pushContent($sp, $link, HTML::br());
674 $this->setValidators($rev);
679 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
680 $this->empty_message()));
685 class _RecentChanges_RssFormatter
686 extends _RecentChanges_Formatter
688 var $_absurls = true;
690 function time ($rev) {
691 return Iso8601DateTime($rev->get('mtime'));
694 function pageURI ($rev) {
695 return WikiURL($rev, '', 'absurl');
698 function format ($changes) {
700 include_once('lib/RssWriter.php');
701 $rss = new RssWriter;
702 $rss->channel($this->channel_properties());
704 if (($props = $this->image_properties()))
706 if (($props = $this->textinput_properties()))
707 $rss->textinput($props);
710 while ($rev = $changes->next()) {
711 // enforce view permission
712 if (mayAccessPage('view', $rev->_pagename)) {
713 $rss->addItem($this->item_properties($rev),
714 $this->pageURI($rev));
716 $this->setValidators($rev);
722 $request->discardOutput();
724 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
726 // Flush errors in comment, otherwise it's invalid XML.
727 global $ErrorManager;
728 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
729 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
731 $request->finish(); // NORETURN!!!!
734 function image_properties () {
737 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
741 return array('title' => WIKI_NAME,
742 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
746 function textinput_properties () {
747 return array('title' => _("Search"),
748 'description' => _("Title Search"),
750 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
753 function channel_properties () {
756 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
757 extract($this->_args);
759 $description = $this->title();
764 return array('title' => $title,
766 'description' => $description,
767 'dc:date' => Iso8601DateTime(time()),
768 'dc:language' => $GLOBALS['LANG']);
770 /* FIXME: other things one might like in <channel>:
779 * rss091:managingEditor
781 * rss091:lastBuildDate
786 function item_properties ($rev) {
787 $page = $rev->getPage();
788 $pagename = $page->getName();
790 return array( 'title' => SplitPagename($pagename),
791 'description' => $this->summary($rev),
792 'link' => $this->pageURL($rev),
793 'dc:date' => $this->time($rev),
794 'dc:contributor' => $rev->get('author'),
795 'wiki:version' => $rev->getVersion(),
796 'wiki:importance' => $this->importance($rev),
797 'wiki:status' => $this->status($rev),
798 'wiki:diff' => $this->diffURL($rev),
799 'wiki:history' => $this->historyURL($rev)
804 /** explicit application/rss+xml Content-Type,
805 * simplified xml structure (no namespace),
806 * support for xml-rpc cloud registerProcedure (not yet)
808 class _RecentChanges_Rss2Formatter
809 extends _RecentChanges_RssFormatter {
811 function format ($changes) {
812 include_once('lib/RssWriter2.php');
813 $rss = new RssWriter2;
815 $rss->channel($this->channel_properties());
816 if (($props = $this->cloud_properties()))
818 if (($props = $this->image_properties()))
820 if (($props = $this->textinput_properties()))
821 $rss->textinput($props);
823 while ($rev = $changes->next()) {
824 // enforce view permission
825 if (mayAccessPage('view', $rev->_pagename)) {
826 $rss->addItem($this->item_properties($rev),
827 $this->pageURI($rev));
829 $this->setValidators($rev);
835 $request->discardOutput();
837 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
838 // Flush errors in comment, otherwise it's invalid XML.
839 global $ErrorManager;
840 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
841 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
843 $request->finish(); // NORETURN!!!!
846 function channel_properties () {
847 $chann_10 = parent::channel_properties();
848 return array_merge($chann_10,
849 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
850 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
851 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
852 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
853 'copyright' => COPYRIGHTPAGE_URL
857 // xml-rpc registerProcedure not yet implemented
858 function cloud_properties () { return false; }
859 function cloud_properties_test () {
860 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
861 'registerProcedure' => 'wiki.rssPleaseNotify',
862 'path' => DATA_PATH.'/RPC2.php',
863 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
864 'domain' => SERVER_NAME);
868 /** Explicit application/atom+xml Content-Type
869 * A weird, questionable format
871 class _RecentChanges_AtomFormatter
872 extends _RecentChanges_RssFormatter {
874 function format ($changes) {
876 include_once('lib/RssWriter.php');
879 // "channel" is called "feed" in atom
880 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
881 extract($this->_args);
883 $description = $this->title();
888 $feed_props = array('title' => $description,
889 'link' => array('rel'=>"alternate",
892 'id' => md5($rc_url),
893 'modified' => Iso8601DateTime(time()),
894 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
896 $rss->feed($feed_props);
898 while ($rev = $changes->next()) {
899 // enforce view permission
900 if (mayAccessPage('view', $rev->_pagename)) {
901 $props = $this->item_properties($rev);
902 $rss->addItem($props,
904 $this->pageURI($rev));
906 $this->setValidators($rev);
911 $request->discardOutput();
913 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
914 // Flush errors in comment, otherwise it's invalid XML.
915 global $ErrorManager;
916 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
917 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
919 $request->finish(); // NORETURN!!!!
922 function item_properties ($rev) {
923 $page = $rev->getPage();
924 $pagename = $page->getName();
925 return array( 'title' => $pagename,
926 'link' => array('rel' => 'alternate',
927 'type' => 'text/html',
928 'href' => $this->pageURL($rev)),
929 'summary' => $this->summary($rev),
930 'modified' => $this->time($rev)."Z",
931 'issued' => $this->time($rev),
932 'created' => $this->time($rev)."Z",
933 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
939 * Filter by non-empty
941 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
945 * @param $revisions object a WikiDB_PageRevisionIterator.
947 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
948 $this->_revisions = $revisions;
949 $this->_check_current_revision = $check_current_revision;
953 while (($rev = $this->_revisions->next())) {
954 if ($this->_check_current_revision) {
955 $page = $rev->getPage();
956 $check_rev = $page->getCurrentRevision();
961 if (! $check_rev->hasDefaultContents())
971 * Filter by only_new.
972 * Only new created pages
974 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
978 * @param $revisions object a WikiDB_PageRevisionIterator.
980 function NewPageRevisionIterator ($revisions) {
981 $this->_revisions = $revisions;
985 while (($rev = $this->_revisions->next())) {
986 if ($rev->getVersion() == 1)
995 * Only pages with links to a certain category
997 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
999 function LinkRevisionIterator ($revisions, $category) {
1000 $this->_revisions = $revisions;
1001 if (preg_match("/[\?\.\*]/", $category)) {
1002 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1003 (new TextSearchQuery("*", true),
1004 new TextSearchQuery($category, true),
1007 $basepage = $GLOBALS['request']->getPage($category);
1008 $backlinkiter = $basepage->getBackLinks(true);
1010 $this->links = array();
1011 foreach ($backlinkiter->asArray() as $p) {
1012 if (is_object($p)) $this->links[] = $p->getName();
1013 elseif (is_array($p)) $this->links[] = $p['pagename'];
1014 else $this->links[] = $p;
1016 $backlinkiter->free();
1021 while (($rev = $this->_revisions->next())) {
1022 if (binary_search($rev->getName(), $this->links) != false)
1030 unset ($this->links);
1034 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1036 function PageMatchRevisionIterator ($revisions, $match) {
1037 $this->_revisions = $revisions;
1038 $this->search = new TextSearchQuery($match, true);
1042 while (($rev = $this->_revisions->next())) {
1043 if ($this->search->match($rev->getName()))
1051 unset ($this->search);
1058 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1060 function AuthorPageRevisionIterator ($revisions, $author) {
1061 $this->_revisions = $revisions;
1062 $this->_author = $author;
1066 while (($rev = $this->_revisions->next())) {
1067 if ($rev->get('author_id') == $this->_author)
1078 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1080 function OwnerPageRevisionIterator ($revisions, $owner) {
1081 $this->_revisions = $revisions;
1082 $this->_owner = $owner;
1086 while (($rev = $this->_revisions->next())) {
1087 $page = $rev->getPage();
1088 if ($page->getOwner() == $this->_owner)
1096 class WikiPlugin_RecentChanges
1099 function getName () {
1100 return _("RecentChanges");
1103 function getVersion() {
1104 return preg_replace("/[Revision: $]/", '',
1105 "\$Revision: 1.121 $");
1108 function managesValidators() {
1109 // Note that this is a bit of a fig.
1110 // We set validators based on the most recently changed page,
1111 // but this fails when the most-recent page is deleted.
1112 // (Consider that the Last-Modified time will decrease
1113 // when this happens.)
1115 // We might be better off, leaving this as false (and junking
1116 // the validator logic above) and just falling back to the
1117 // default behavior (handled by WikiPlugin) of just using
1118 // the WikiDB global timestamp as the mtime.
1120 // Nevertheless, for now, I leave this here, mostly as an
1121 // example for how to use appendValidators() and managesValidators().
1126 function getDefaultArguments() {
1127 return array('days' => 2,
1128 'show_minor' => false,
1129 'show_major' => true,
1130 'show_all' => false,
1131 'show_deleted' => 'sometimes',
1132 'only_new' => false,
1138 'difflinks' => true,
1139 'historylinks' => false,
1146 function getArgs ($argstr, $request, $defaults = false) {
1147 if (!$defaults) $defaults = $this->getDefaultArguments();
1148 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1150 $action = $request->getArg('action');
1151 if ($action != 'browse' && ! $request->isActionPage($action))
1152 $args['format'] = false; // default -> HTML
1154 if ($args['format'] == 'rss' && empty($args['limit']))
1155 $args['limit'] = 15; // Fix default value for RSS.
1156 if ($args['format'] == 'rss2' && empty($args['limit']))
1157 $args['limit'] = 15; // Fix default value for RSS2.
1159 if ($args['format'] == 'sidebar' && empty($args['limit']))
1160 $args['limit'] = 10; // Fix default value for sidebar.
1165 function getMostRecentParams (&$args) {
1166 $show_all = false; $show_minor = false; $show_major = false;
1170 $params = array('include_minor_revisions' => $show_minor,
1171 'exclude_major_revisions' => !$show_major,
1172 'include_all_revisions' => !empty($show_all));
1174 $params['limit'] = $limit;
1175 if (!empty($args['author'])) {
1177 if ($args['author'] == '[]')
1178 $args['author'] = $request->_user->getID();
1179 $params['author'] = $args['author'];
1181 if (!empty($args['owner'])) {
1183 if ($args['owner'] == '[]')
1184 $args['owner'] = $request->_user->getID();
1185 $params['owner'] = $args['owner'];
1187 if (!empty($days)) {
1189 $params['since'] = time() - 24 * 3600 * $days;
1190 elseif ($days < 0.0)
1191 $params['since'] = 24 * 3600 * $days - time();
1197 function getChanges ($dbi, $args) {
1198 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1200 $show_deleted = @$args['show_deleted'];
1201 $show_all = @$args['show_all'];
1202 if ($show_deleted == 'sometimes')
1203 $show_deleted = @$args['show_minor'];
1205 // only pages (e.g. PageHistory of subpages)
1206 if (!empty($args['pagematch'])) {
1207 require_once("lib/TextSearchQuery.php");
1208 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1210 if (!empty($args['category'])) {
1211 require_once("lib/TextSearchQuery.php");
1212 $changes = new LinkRevisionIterator($changes, $args['category']);
1214 if (!empty($args['only_new']))
1215 $changes = new NewPageRevisionIterator($changes);
1216 if (!empty($args['author']))
1217 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1218 if (!empty($args['owner']))
1219 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1221 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1226 function format ($changes, $args) {
1228 $format = $args['format'];
1230 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1232 if ($format == 'rss')
1233 $fmt_class = '_RecentChanges_RssFormatter';
1234 elseif ($format == 'rss2')
1235 $fmt_class = '_RecentChanges_Rss2Formatter';
1236 elseif ($format == 'atom')
1237 $fmt_class = '_RecentChanges_AtomFormatter';
1238 elseif ($format == 'rss091') {
1239 include_once "lib/RSSWriter091.php";
1240 $fmt_class = '_RecentChanges_RssFormatter091';
1242 elseif ($format == 'sidebar')
1243 $fmt_class = '_RecentChanges_SideBarFormatter';
1244 elseif ($format == 'box')
1245 $fmt_class = '_RecentChanges_BoxFormatter';
1246 elseif ($format == 'contribs')
1247 $fmt_class = '_RecentChanges_UserContribsFormatter';
1249 $fmt_class = '_RecentChanges_HtmlFormatter';
1252 $fmt = new $fmt_class($args);
1253 return $fmt->format($changes);
1256 function run($dbi, $argstr, &$request, $basepage) {
1257 $args = $this->getArgs($argstr, $request);
1259 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1260 // to be enough for anyone.)
1261 $args['days'] = min($args['days'], 365000);
1263 if (empty($args['category']) and empty($args['pagematch'])
1264 and preg_match("/^Category/", $request->getArg('pagename')))
1266 $args['category'] = $request->getArg('pagename');
1269 // Hack alert: format() is a NORETURN for rss formatters.
1270 return $this->format($this->getChanges($dbi, $args), $args);
1273 // box is used to display a fixed-width, narrow version with common header.
1274 // just a numbered list of limit pagenames, without date.
1275 function box($args = false, $request = false, $basepage = false) {
1276 if (!$request) $request =& $GLOBALS['request'];
1277 if (!isset($args['limit'])) $args['limit'] = 15;
1278 $args['format'] = 'box';
1279 $args['show_minor'] = false;
1280 $args['show_major'] = true;
1281 $args['show_deleted'] = 'sometimes';
1282 $args['show_all'] = false;
1284 return $this->makeBox(WikiLink($this->getName(),'',
1285 SplitPagename($this->getName())),
1287 ($this->getChanges($request->_dbi, $args), $args));
1293 class DayButtonBar extends HtmlElement {
1295 function DayButtonBar ($plugin_args) {
1296 $this->__construct('p', array('class' => 'wiki-rc-action'));
1298 // Display days selection buttons
1299 extract($plugin_args);
1304 $caption = _("Show minor edits for:");
1306 $caption = _("Show all changes for:");
1308 $caption = _("Show changes for:");
1310 $caption = _("All new pages since:");
1313 $this->pushContent($caption, ' ');
1316 $sep = $WikiTheme->getButtonSeparator();
1319 foreach (explode(",", $daylist) as $days) {
1321 $this->pushContent($sep);
1322 $this->pushContent($this->_makeDayButton($days));
1326 function _makeDayButton ($days) {
1327 global $WikiTheme, $request;
1330 $label = _("1 day");
1332 $label = "..."; //alldays
1334 $label = sprintf(_("%s days"), abs($days));
1336 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1338 return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
1342 // $Log: not supported by cvs2svn $
1343 // Revision 1.120 2007/07/14 12:04:50 rurban
1344 // fix rss button actions and rss description according the action
1346 // Revision 1.119 2007/07/01 09:17:45 rurban
1347 // add ATOM support, a very questionable format
1349 // Revision 1.118 2007/06/02 18:24:59 rurban
1352 // Revision 1.117 2007/05/30 20:43:31 rurban
1353 // added MonoBook UserContribs
1355 // Revision 1.116 2007/05/13 18:13:41 rurban
1356 // use all filters, not just the first, ignoring the others. improve wording a bit
1358 // Revision 1.115 2007/04/08 16:24:10 rurban
1359 // Remove redundant code in ->authorLink(): 'if_known' does the same
1361 // Revision 1.114 2007/02/17 22:39:44 rurban
1362 // format=rss overhaul
1364 // Revision 1.113 2007/02/17 14:15:52 rurban
1365 // new argument owner=[] for RecentChangesMyPages
1367 // Revision 1.112 2007/01/28 20:32:07 rurban
1368 // silence empty warning
1370 // Revision 1.111 2007/01/25 21:48:52 rurban
1371 // new argument author=[]
1373 // Revision 1.110 2007/01/22 23:51:36 rurban
1374 // new arg: only_new
1376 // Revision 1.109 2006/03/19 14:26:29 rurban
1377 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
1379 // Revision 1.108 2005/04/01 16:09:35 rurban
1380 // fix defaults in RecentChanges plugins: e.g. invalid pagenames for PageHistory
1382 // Revision 1.107 2005/02/04 13:45:28 rurban
1383 // improve box layout a bit
1385 // Revision 1.106 2005/02/02 19:39:10 rurban
1386 // honor show_all=false
1388 // Revision 1.105 2005/01/25 03:50:54 uckelman
1389 // pre_description is a member function, so call with $this->.
1391 // Revision 1.104 2005/01/24 23:15:16 uckelman
1392 // The extra description for RelatedChanges was appearing in RecentChanges
1393 // and PageHistory due to a bad test in _RecentChanges_HtmlFormatter. Fixed.
1395 // Revision 1.103 2004/12/15 17:45:09 rurban
1398 // Revision 1.102 2004/12/06 19:29:24 rurban
1399 // simplify RSS: add RSS2 link (rss tag only, new content-type)
1401 // Revision 1.101 2004/11/10 19:32:24 rurban
1402 // * optimize increaseHitCount, esp. for mysql.
1403 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1404 // * Pear_DB version logic (awful but needed)
1405 // * fix broken ADODB quote
1406 // * _extract_page_data simplification
1408 // Revision 1.100 2004/06/28 16:35:12 rurban
1409 // prevent from shell commands
1411 // Revision 1.99 2004/06/20 14:42:54 rurban
1412 // various php5 fixes (still broken at blockparser)
1414 // Revision 1.98 2004/06/14 11:31:39 rurban
1415 // renamed global $Theme to $WikiTheme (gforge nameclash)
1416 // inherit PageList default options from PageList
1417 // default sortby=pagename
1418 // use options in PageList_Selectable (limit, sortby, ...)
1419 // added action revert, with button at action=diff
1420 // added option regex to WikiAdminSearchReplace
1422 // Revision 1.97 2004/06/03 18:58:27 rurban
1423 // days links requires action=RelatedChanges arg
1425 // Revision 1.96 2004/05/18 16:23:40 rurban
1426 // rename split_pagename to SplitPagename
1428 // Revision 1.95 2004/05/16 22:07:35 rurban
1429 // check more config-default and predefined constants
1430 // various PagePerm fixes:
1431 // fix default PagePerms, esp. edit and view for Bogo and Password users
1432 // implemented Creator and Owner
1433 // BOGOUSERS renamed to BOGOUSER
1434 // fixed syntax errors in signin.tmpl
1436 // Revision 1.94 2004/05/14 20:55:03 rurban
1437 // simplified RecentComments
1439 // Revision 1.93 2004/05/14 17:33:07 rurban
1440 // new plugin RecentChanges
1442 // Revision 1.92 2004/04/21 04:29:10 rurban
1443 // Two convenient RecentChanges extensions
1444 // RelatedChanges (only links from current page)
1445 // RecentEdits (just change the default args)
1447 // Revision 1.91 2004/04/19 18:27:46 rurban
1448 // Prevent from some PHP5 warnings (ref args, no :: object init)
1449 // php5 runs now through, just one wrong XmlElement object init missing
1450 // Removed unneccesary UpgradeUser lines
1451 // Changed WikiLink to omit version if current (RecentChanges)
1453 // Revision 1.90 2004/04/18 01:11:52 rurban
1454 // more numeric pagename fixes.
1455 // fixed action=upload with merge conflict warnings.
1456 // charset changed from constant to global (dynamic utf-8 switching)
1458 // Revision 1.89 2004/04/10 02:30:49 rurban
1459 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1460 // Fixed "cannot setlocale..." (sf.net problem)
1462 // Revision 1.88 2004/04/01 15:57:10 rurban
1463 // simplified Sidebar theme: table, not absolute css positioning
1464 // added the new box methods.
1465 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1467 // Revision 1.87 2004/03/30 02:14:03 rurban
1468 // fixed yet another Prefs bug
1469 // added generic PearDb_iter
1470 // $request->appendValidators no so strict as before
1471 // added some box plugin methods
1472 // PageList commalist for condensed output
1474 // Revision 1.86 2004/03/12 13:31:43 rurban
1475 // enforce PagePermissions, errormsg if not Admin
1477 // Revision 1.85 2004/02/17 12:11:36 rurban
1478 // 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, ...)
1480 // Revision 1.84 2004/02/15 22:29:42 rurban
1481 // revert premature performance fix
1483 // Revision 1.83 2004/02/15 21:34:37 rurban
1484 // PageList enhanced and improved.
1485 // fixed new WikiAdmin... plugins
1486 // editpage, Theme with exp. htmlarea framework
1487 // (htmlarea yet committed, this is really questionable)
1488 // WikiUser... code with better session handling for prefs
1489 // enhanced UserPreferences (again)
1490 // RecentChanges for show_deleted: how should pages be deleted then?
1492 // Revision 1.82 2004/01/25 03:58:43 rurban
1493 // use stdlib:isWikiWord()
1495 // Revision 1.81 2003/11/28 21:06:31 carstenklapp
1496 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
1497 // instead of 1. Make diff buttons smaller with css. Added description
1498 // line back in at the top.
1500 // Revision 1.80 2003/11/27 15:17:01 carstenklapp
1501 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
1502 // button, to allow an image button for it to be added to Themes. Output
1503 // RSS button in small text size when theme has no button image.
1505 // Revision 1.79 2003/04/29 14:34:20 dairiki
1506 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
1508 // Revision 1.78 2003/03/04 01:55:05 dairiki
1509 // Fix to ensure absolute URL for logo in RSS recent changes.
1511 // Revision 1.77 2003/02/27 23:23:38 dairiki
1512 // Fix my breakage of CSS and sidebar RecentChanges output.
1514 // Revision 1.76 2003/02/27 22:48:44 dairiki
1515 // Fixes invalid HTML generated by PageHistory plugin.
1517 // (<noscript> is block-level and not allowed within <p>.)
1519 // Revision 1.75 2003/02/22 21:39:05 dairiki
1520 // Hackish fix for SF bug #622784.
1522 // (The root of the problem is clearly a PHP bug.)
1524 // Revision 1.74 2003/02/21 22:52:21 dairiki
1525 // Make sure to interpret relative links (like [/Subpage]) in summary
1526 // relative to correct basepage.
1528 // Revision 1.73 2003/02/21 04:12:06 dairiki
1529 // Minor fixes for new cached markup.
1531 // Revision 1.72 2003/02/17 02:19:01 dairiki
1532 // Fix so that PageHistory will work when the current revision
1533 // of a page has been "deleted".
1535 // Revision 1.71 2003/02/16 20:04:48 dairiki
1536 // Refactor the HTTP validator generation/checking code.
1538 // This also fixes a number of bugs with yesterdays validator mods.
1540 // Revision 1.70 2003/02/16 05:09:43 dairiki
1541 // Starting to fix handling of the HTTP validator headers, Last-Modified,
1544 // Last-Modified was being set incorrectly (but only when DEBUG was not
1545 // defined!) Setting a Last-Modified without setting an appropriate
1546 // Expires: and/or Cache-Control: header results in browsers caching
1547 // the page unconditionally (for a certain period of time).
1548 // This is generally bad, since it means people don't see updated
1549 // page contents right away --- this is particularly confusing to
1550 // the people who are editing pages since their edits don't show up
1551 // next time they browse the page.
1553 // Now, we don't allow caching of pages without revalidation
1554 // (via the If-Modified-Since and/or If-None-Match request headers.)
1555 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
1556 // appropriate value in index.php, but I advise against it.)
1560 // o Even when request is aborted due to the content not being
1561 // modified, we currently still do almost all the work involved
1562 // in producing the page. So the only real savings from all
1563 // this logic is in network bandwidth.
1565 // o Plugins which produce "dynamic" output need to be inspected
1566 // and made to call $request->addToETag() and
1567 // $request->setModificationTime() appropriately, otherwise the
1568 // page can change without the change being detected.
1569 // This leads to stale pages in cache again...
1571 // Revision 1.69 2003/01/18 22:01:43 carstenklapp
1573 // Reformatting & tabs to spaces;
1574 // Added copyleft, getVersion, getDescription, rcs_id.
1577 // (c-file-style: "gnu")
1581 // c-basic-offset: 4
1582 // c-hanging-comment-ender-p: nil
1583 // indent-tabs-mode: nil