2 rcs_id('$Id: RecentChanges.php,v 1.113 2007-02-17 14:15:52 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
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 $WikiTheme->getDay($rev->get('mtime'));
50 function time ($rev) {
52 return $WikiTheme->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 isWikiWord($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)) {
107 return _("New page");
113 function setValidators($most_recent_rev) {
114 $rev = $most_recent_rev;
115 $validators = array('RecentChanges-top' =>
116 array($rev->getPageName(), $rev->getVersion()),
117 '%mtime' => $rev->get('mtime'));
119 $request->appendValidators($validators);
123 class _RecentChanges_HtmlFormatter
124 extends _RecentChanges_Formatter
126 function diffLink ($rev) {
128 $button = $WikiTheme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
129 $button->setAttr('rel', 'nofollow');
133 function historyLink ($rev) {
135 return $WikiTheme->makeButton(_("(hist)"), $this->historyURL($rev), 'wiki-rc-action');
138 function pageLink ($rev, $link_text=false) {
140 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),'auto',$link_text);
142 $page = $rev->getPage();
144 if ($this->include_versions_in_URLs()) {
145 $version = $rev->getVersion();
146 if ($rev->isCurrent())
148 $exists = !$rev->hasDefaultContents();
152 $cur = $page->getCurrentRevision();
153 $exists = !$cur->hasDefaultContents();
156 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
158 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
162 function authorLink ($rev) {
163 $author = $rev->get('author');
164 if ( $this->authorHasPage($author) ) {
165 return WikiLink($author);
170 function summaryAsHTML ($rev) {
171 if ( !($summary = $this->summary($rev)) )
173 return HTML::strong( array('class' => 'wiki-summary'),
175 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
179 function rss_icon () {
180 global $request, $WikiTheme;
182 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
183 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
184 $WikiTheme->makeButton("RSS", $rss_url, 'rssicon'));
186 function rss2_icon () {
187 global $request, $WikiTheme;
189 $rss_url = $request->getURLtoSelf(array('format' => 'rss2'));
190 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
191 $WikiTheme->makeButton("xml", $rss_url, 'rssicon'));
193 function atom_icon () {
194 global $request, $WikiTheme;
196 $rss_url = $request->getURLtoSelf(array('format' => 'atom'));
197 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
198 $WikiTheme->makeButton("atom", $rss_url, 'rssicon'));
201 function grazr_icon () {
202 global $request, $WikiTheme;
203 $rss_url = 'http://grazr.com/gzpanel.html?' .
204 WikiURL($request->getArg('pagename'),array('format' => 'rss2'),true);
205 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
206 $WikiTheme->makeButton("grazr-it", $rss_url, 'rssicon'));
209 function pre_description () {
210 extract($this->_args);
211 // FIXME: say something about show_all.
212 if ($show_major && $show_minor)
215 $edits = _("major edits");
217 $edits = _("minor edits");
218 if (isset($caption) and $caption == _("Recent Comments"))
219 $edits = _("comments");
220 if (!empty($only_new)) {
221 $edits = _("created new pages");
223 if (!empty($author)) {
226 $author = $request->_user->getID();
227 $edits .= sprintf(_(" from author %s"), $author);
229 if (!empty($owner)) {
232 $owner = $request->_user->getID();
233 $edits .= sprintf(_(" from owner %s"), $owner);
235 if ($timespan = $days > 0) {
236 if (intval($days) != $days)
237 $days = sprintf("%.1f", $days);
241 * Depending how this text is split up it can be tricky or
242 * impossible to translate with good grammar. So the seperate
243 * strings for 1 day and %s days are necessary in this case
244 * for translating to multiple languages, due to differing
245 * overlapping ideal word cutting points.
247 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
248 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
249 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
251 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
252 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
253 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
257 if (intval($days) == 1)
258 $desc = fmt("The %d most recent %s during the past day are listed below.",
261 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
262 $limit, $edits, $days);
264 $desc = fmt("The %d most recent %s are listed below.",
267 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
269 if (intval($days) == 1)
270 $desc = fmt("The %d oldest %s during the past day are listed below.",
273 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
274 $lmt, $edits, $days);
276 $desc = fmt("The %d oldest %s are listed below.",
282 if (intval($days) == 1)
283 $desc = fmt("The most recent %s during the past day are listed below.",
286 $desc = fmt("The most recent %s during the past %s days are listed below.",
289 $desc = fmt("All %s are listed below.", $edits);
294 function description() {
295 return HTML::p(false, $this->pre_description());
300 extract($this->_args);
301 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
304 HTML::raw(' '), $this->rss2_icon(),
305 HTML::raw(' '), $this->grazr_icon(),
306 HTML::raw(' '), $this->atom_icon(),
307 $this->sidebar_link());
310 function empty_message () {
311 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
312 return _("No comments found");
314 return _("No changes found");
317 function sidebar_link() {
318 extract($this->_args);
319 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
322 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
325 "function addPanel() {\n"
326 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
327 ." \"$sidebarurl\",\"\");\n"
329 $jsf = JavaScript($addsidebarjsfunc);
332 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon');
333 $addsidebarjsclick = asXML(HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), $sidebar_button));
334 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
335 ." (typeof window.sidebar.addPanel == 'function'))\n"
337 ." document.write('$addsidebarjsclick');\n"
340 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
343 function format ($changes) {
344 include_once('lib/InlineParser.php');
346 $html = HTML(HTML::h2(false, $this->title()));
347 if (($desc = $this->description()))
348 $html->pushContent($desc);
350 if ($this->_args['daylist'])
351 $html->pushContent(new DayButtonBar($this->_args));
357 while ($rev = $changes->next()) {
358 if (($date = $this->date($rev)) != $last_date) {
360 $html->pushContent($lines);
361 $html->pushContent(HTML::h3($date));
366 // enforce view permission
367 if (mayAccessPage('view', $rev->_pagename)) {
368 $lines->pushContent($this->format_revision($rev));
371 $this->setValidators($rev);
376 $html->pushContent($lines);
378 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
379 $this->empty_message()));
384 function format_revision ($rev) {
385 $args = &$this->_args;
387 $class = 'rc-' . $this->importance($rev);
389 $time = $this->time($rev);
390 if (! $rev->get('is_minor_edit'))
391 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
393 $line = HTML::li(array('class' => $class));
396 if ($args['difflinks'])
397 $line->pushContent($this->diffLink($rev), ' ');
399 if ($args['historylinks'])
400 $line->pushContent($this->historyLink($rev), ' ');
402 $line->pushContent($this->pageLink($rev), ' ',
404 $this->summaryAsHTML($rev),
406 $this->authorLink($rev));
412 class _RecentChanges_SideBarFormatter
413 extends _RecentChanges_HtmlFormatter
415 function rss_icon () {
418 function rss2_icon () { }
420 //title click opens the normal RC or RE page in the main browser frame
421 extract($this->_args);
422 $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
423 $titlelink->setAttr('target', '_content');
424 return HTML($this->logo(), $titlelink);
427 //logo click opens the HomePage in the main browser frame
429 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
432 'style' => 'height:2.5ex'
434 $linkurl = WikiLink(HOME_PAGE, false, $img);
435 $linkurl->setAttr('target', '_content');
439 function authorLink ($rev) {
440 $author = $rev->get('author');
441 if ( $this->authorHasPage($author) ) {
442 $linkurl = WikiLink($author);
443 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
449 function diffLink ($rev) {
450 $linkurl = parent::diffLink($rev);
451 $linkurl->setAttr('target', '_content');
452 $linkurl->setAttr('rel', 'nofollow');
453 // FIXME: Smelly hack to get smaller diff buttons in sidebar
454 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
457 function historyLink ($rev) {
458 $linkurl = parent::historyLink($rev);
459 $linkurl->setAttr('target', '_content');
460 // FIXME: Smelly hack to get smaller history buttons in sidebar
461 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
464 function pageLink ($rev) {
465 $linkurl = parent::pageLink($rev);
466 $linkurl->setAttr('target', '_content');
469 // Overriding summaryAsHTML, because there is no way yet to
470 // return summary as transformed text with
471 // links setAttr('target', '_content') in Mozilla sidebar.
472 // So for now don't create clickable links inside summary
473 // in the sidebar, or else they target the sidebar and not the
474 // main content window.
475 function summaryAsHTML ($rev) {
476 if ( !($summary = $this->summary($rev)) )
478 return HTML::strong(array('class' => 'wiki-summary'),
480 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
485 function format ($changes) {
486 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
487 $html = _RecentChanges_HtmlFormatter::format ($changes);
488 $html = HTML::div(array('class' => 'wikitext'), $html);
490 $request->discardOutput();
492 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
493 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
494 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
495 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
498 extract($this->_args);
499 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
500 printf("<title>" . $title . "</title>\n");
502 $css = $WikiTheme->getCSS();
506 printf("<body class=\"sidebar\">\n");
508 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>';
509 printf("\n</body>\n");
512 $request->finish(); // cut rest of page processing short
516 class _RecentChanges_BoxFormatter
517 extends _RecentChanges_HtmlFormatter
519 function rss_icon () {
521 function rss2_icon () {
525 function authorLink ($rev) {
527 function diffLink ($rev) {
529 function historyLink ($rev) {
531 function summaryAsHTML ($rev) {
533 function description () {
535 function format ($changes) {
536 include_once('lib/InlineParser.php');
541 $sp = HTML::Raw("\n · ");
542 while ($rev = $changes->next()) {
543 // enforce view permission
544 if (mayAccessPage('view',$rev->_pagename)) {
545 if ($link = $this->pageLink($rev)) // some entries may be empty
546 // (/Blog/.. interim pages)
547 $html->pushContent($sp, $link, HTML::br());
549 $this->setValidators($rev);
554 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
555 $this->empty_message()));
560 class _RecentChanges_RssFormatter
561 extends _RecentChanges_Formatter
563 var $_absurls = true;
565 function time ($rev) {
566 return Iso8601DateTime($rev->get('mtime'));
569 function pageURI ($rev) {
570 return WikiURL($rev, '', 'absurl');
573 function format ($changes) {
575 include_once('lib/RssWriter.php');
576 $rss = new RssWriter;
578 $rss->channel($this->channel_properties());
580 if (($props = $this->image_properties()))
582 if (($props = $this->textinput_properties()))
583 $rss->textinput($props);
586 while ($rev = $changes->next()) {
587 // enforce view permission
588 if (mayAccessPage('view', $rev->_pagename)) {
589 $rss->addItem($this->item_properties($rev),
590 $this->pageURI($rev));
592 $this->setValidators($rev);
598 $request->discardOutput();
600 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
602 // Flush errors in comment, otherwise it's invalid XML.
603 global $ErrorManager;
604 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
605 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
607 $request->finish(); // NORETURN!!!!
610 function image_properties () {
613 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
617 return array('title' => WIKI_NAME,
618 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
622 function textinput_properties () {
623 return array('title' => _("Search"),
624 'description' => _("Title Search"),
626 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
629 function channel_properties () {
632 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
633 return array('title' => WIKI_NAME,
635 'description' => _("RecentChanges"),
636 'dc:date' => Iso8601DateTime(time()),
637 'dc:language' => $GLOBALS['LANG']);
639 /* FIXME: other things one might like in <channel>:
648 * rss091:managingEditor
650 * rss091:lastBuildDate
655 function item_properties ($rev) {
656 $page = $rev->getPage();
657 $pagename = $page->getName();
659 return array( 'title' => SplitPagename($pagename),
660 'description' => $this->summary($rev),
661 'link' => $this->pageURL($rev),
662 'dc:date' => $this->time($rev),
663 'dc:contributor' => $rev->get('author'),
664 'wiki:version' => $rev->getVersion(),
665 'wiki:importance' => $this->importance($rev),
666 'wiki:status' => $this->status($rev),
667 'wiki:diff' => $this->diffURL($rev),
668 'wiki:history' => $this->historyURL($rev)
673 /** explicit application/rss+xml Content-Type,
674 * simplified xml structure (no namespace),
675 * support for xml-rpc cloud registerProcedure (not yet)
677 class _RecentChanges_Rss2Formatter
678 extends _RecentChanges_RssFormatter {
680 function format ($changes) {
681 include_once('lib/RssWriter2.php');
682 $rss = new RssWriter2;
684 $rss->channel($this->channel_properties());
685 if (($props = $this->cloud_properties()))
687 if (($props = $this->image_properties()))
689 if (($props = $this->textinput_properties()))
690 $rss->textinput($props);
692 while ($rev = $changes->next()) {
693 // enforce view permission
694 if (mayAccessPage('view', $rev->_pagename)) {
695 $rss->addItem($this->item_properties($rev),
696 $this->pageURI($rev));
698 $this->setValidators($rev);
704 $request->discardOutput();
706 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
707 // Flush errors in comment, otherwise it's invalid XML.
708 global $ErrorManager;
709 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
710 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
712 $request->finish(); // NORETURN!!!!
715 function channel_properties () {
716 $chann_10 = parent::channel_properties();
717 return array_merge($chann_10,
718 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
719 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
720 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
721 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
722 'copyright' => COPYRIGHTPAGE_URL
726 // xml-rpc registerProcedure not yet implemented
727 function cloud_properties () { return false; }
728 function cloud_properties_test () {
729 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
730 'registerProcedure' => 'wiki.rssPleaseNotify',
731 'path' => DATA_PATH.'/RPC2.php',
732 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
733 'domain' => SERVER_NAME);
738 * Filter by non-empty
740 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
744 * @param $revisions object a WikiDB_PageRevisionIterator.
746 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
747 $this->_revisions = $revisions;
748 $this->_check_current_revision = $check_current_revision;
752 while (($rev = $this->_revisions->next())) {
753 if ($this->_check_current_revision) {
754 $page = $rev->getPage();
755 $check_rev = $page->getCurrentRevision();
760 if (! $check_rev->hasDefaultContents())
770 * Filter by only_new.
771 * Only new created pages
773 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
777 * @param $revisions object a WikiDB_PageRevisionIterator.
779 function NewPageRevisionIterator ($revisions) {
780 $this->_revisions = $revisions;
784 while (($rev = $this->_revisions->next())) {
785 if ($rev->getVersion() == 1)
796 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
798 function AuthorPageRevisionIterator ($revisions, $author) {
799 $this->_revisions = $revisions;
800 $this->_author = $author;
804 while (($rev = $this->_revisions->next())) {
805 if ($rev->get('author_id') == $this->_author)
816 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
818 function OwnerPageRevisionIterator ($revisions, $owner) {
819 $this->_revisions = $revisions;
820 $this->_owner = $owner;
824 while (($rev = $this->_revisions->next())) {
825 $page = $rev->getPage();
826 if ($page->getOwner() == $this->_owner)
834 class WikiPlugin_RecentChanges
837 function getName () {
838 return _("RecentChanges");
841 function getVersion() {
842 return preg_replace("/[Revision: $]/", '',
843 "\$Revision: 1.113 $");
846 function managesValidators() {
847 // Note that this is a bit of a fig.
848 // We set validators based on the most recently changed page,
849 // but this fails when the most-recent page is deleted.
850 // (Consider that the Last-Modified time will decrease
851 // when this happens.)
853 // We might be better off, leaving this as false (and junking
854 // the validator logic above) and just falling back to the
855 // default behavior (handled by WikiPlugin) of just using
856 // the WikiDB global timestamp as the mtime.
858 // Nevertheless, for now, I leave this here, mostly as an
859 // example for how to use appendValidators() and managesValidators().
864 function getDefaultArguments() {
865 return array('days' => 2,
866 'show_minor' => false,
867 'show_major' => true,
869 'show_deleted' => 'sometimes',
877 'historylinks' => false,
882 function getArgs ($argstr, $request, $defaults = false) {
883 if (!$defaults) $defaults = $this->getDefaultArguments();
884 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
886 $action = $request->getArg('action');
887 if ($action != 'browse' && ! $request->isActionPage($action))
888 $args['format'] = false; // default -> HTML
890 if ($args['format'] == 'rss' && empty($args['limit']))
891 $args['limit'] = 15; // Fix default value for RSS.
892 if ($args['format'] == 'rss2' && empty($args['limit']))
893 $args['limit'] = 15; // Fix default value for RSS2.
895 if ($args['format'] == 'sidebar' && empty($args['limit']))
896 $args['limit'] = 10; // Fix default value for sidebar.
901 function getMostRecentParams (&$args) {
904 $params = array('include_minor_revisions' => $show_minor,
905 'exclude_major_revisions' => !$show_major,
906 'include_all_revisions' => !empty($show_all));
908 $params['limit'] = $limit;
909 if (!empty($args['author'])) {
911 if ($args['author'] == '[]')
912 $args['author'] = $request->_user->getID();
913 $params['author'] = $args['author'];
915 if (!empty($args['owner'])) {
917 if ($args['owner'] == '[]')
918 $args['owner'] = $request->_user->getID();
919 $params['owner'] = $args['owner'];
923 $params['since'] = time() - 24 * 3600 * $days;
925 $params['since'] = 24 * 3600 * $days - time();
930 function getChanges ($dbi, $args) {
931 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
933 $show_deleted = $args['show_deleted'];
934 if ($show_deleted == 'sometimes')
935 $show_deleted = $args['show_minor'];
937 if (!empty($args['only_new']))
938 $changes = new NewPageRevisionIterator($changes);
939 elseif (!empty($args['author']))
940 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
941 elseif (!empty($args['owner']))
942 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
943 elseif (!$show_deleted)
944 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
949 function format ($changes, $args) {
951 $format = $args['format'];
953 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
955 if ($format == 'rss')
956 $fmt_class = '_RecentChanges_RssFormatter';
957 elseif ($format == 'rss2')
958 $fmt_class = '_RecentChanges_Rss2Formatter';
959 elseif ($format == 'rss091') {
960 include_once "lib/RSSWriter091.php";
961 $fmt_class = '_RecentChanges_RssFormatter091';
963 elseif ($format == 'sidebar')
964 $fmt_class = '_RecentChanges_SideBarFormatter';
965 elseif ($format == 'box')
966 $fmt_class = '_RecentChanges_BoxFormatter';
968 $fmt_class = '_RecentChanges_HtmlFormatter';
971 $fmt = new $fmt_class($args);
972 return $fmt->format($changes);
975 function run($dbi, $argstr, &$request, $basepage) {
976 $args = $this->getArgs($argstr, $request);
978 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
979 // to be enough for anyone.)
980 $args['days'] = min($args['days'], 365000);
982 // Hack alert: format() is a NORETURN for rss formatters.
983 return $this->format($this->getChanges($dbi, $args), $args);
986 // box is used to display a fixed-width, narrow version with common header.
987 // just a numbered list of limit pagenames, without date.
988 function box($args = false, $request = false, $basepage = false) {
989 if (!$request) $request =& $GLOBALS['request'];
990 if (!isset($args['limit'])) $args['limit'] = 15;
991 $args['format'] = 'box';
992 $args['show_minor'] = false;
993 $args['show_major'] = true;
994 $args['show_deleted'] = 'sometimes';
995 $args['show_all'] = false;
997 return $this->makeBox(WikiLink($this->getName(),'',
998 SplitPagename($this->getName())),
1000 ($this->getChanges($request->_dbi, $args), $args));
1006 class DayButtonBar extends HtmlElement {
1008 function DayButtonBar ($plugin_args) {
1009 $this->__construct('p', array('class' => 'wiki-rc-action'));
1011 // Display days selection buttons
1012 extract($plugin_args);
1017 $caption = _("Show minor edits for:");
1019 $caption = _("Show all changes for:");
1021 $caption = _("Show changes for:");
1023 $caption = _("All new pages since:");
1026 $this->pushContent($caption, ' ');
1029 $sep = $WikiTheme->getButtonSeparator();
1032 foreach (explode(",", $daylist) as $days) {
1034 $this->pushContent($sep);
1035 $this->pushContent($this->_makeDayButton($days));
1039 function _makeDayButton ($days) {
1040 global $WikiTheme, $request;
1043 $label = _("1 day");
1045 $label = "..."; //alldays
1047 $label = sprintf(_("%s days"), abs($days));
1049 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1051 return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
1055 // $Log: not supported by cvs2svn $
1056 // Revision 1.112 2007/01/28 20:32:07 rurban
1057 // silence empty warning
1059 // Revision 1.111 2007/01/25 21:48:52 rurban
1060 // new argument author=[]
1062 // Revision 1.110 2007/01/22 23:51:36 rurban
1063 // new arg: only_new
1065 // Revision 1.109 2006/03/19 14:26:29 rurban
1066 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
1068 // Revision 1.108 2005/04/01 16:09:35 rurban
1069 // fix defaults in RecentChanges plugins: e.g. invalid pagenames for PageHistory
1071 // Revision 1.107 2005/02/04 13:45:28 rurban
1072 // improve box layout a bit
1074 // Revision 1.106 2005/02/02 19:39:10 rurban
1075 // honor show_all=false
1077 // Revision 1.105 2005/01/25 03:50:54 uckelman
1078 // pre_description is a member function, so call with $this->.
1080 // Revision 1.104 2005/01/24 23:15:16 uckelman
1081 // The extra description for RelatedChanges was appearing in RecentChanges
1082 // and PageHistory due to a bad test in _RecentChanges_HtmlFormatter. Fixed.
1084 // Revision 1.103 2004/12/15 17:45:09 rurban
1087 // Revision 1.102 2004/12/06 19:29:24 rurban
1088 // simplify RSS: add RSS2 link (rss tag only, new content-type)
1090 // Revision 1.101 2004/11/10 19:32:24 rurban
1091 // * optimize increaseHitCount, esp. for mysql.
1092 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1093 // * Pear_DB version logic (awful but needed)
1094 // * fix broken ADODB quote
1095 // * _extract_page_data simplification
1097 // Revision 1.100 2004/06/28 16:35:12 rurban
1098 // prevent from shell commands
1100 // Revision 1.99 2004/06/20 14:42:54 rurban
1101 // various php5 fixes (still broken at blockparser)
1103 // Revision 1.98 2004/06/14 11:31:39 rurban
1104 // renamed global $Theme to $WikiTheme (gforge nameclash)
1105 // inherit PageList default options from PageList
1106 // default sortby=pagename
1107 // use options in PageList_Selectable (limit, sortby, ...)
1108 // added action revert, with button at action=diff
1109 // added option regex to WikiAdminSearchReplace
1111 // Revision 1.97 2004/06/03 18:58:27 rurban
1112 // days links requires action=RelatedChanges arg
1114 // Revision 1.96 2004/05/18 16:23:40 rurban
1115 // rename split_pagename to SplitPagename
1117 // Revision 1.95 2004/05/16 22:07:35 rurban
1118 // check more config-default and predefined constants
1119 // various PagePerm fixes:
1120 // fix default PagePerms, esp. edit and view for Bogo and Password users
1121 // implemented Creator and Owner
1122 // BOGOUSERS renamed to BOGOUSER
1123 // fixed syntax errors in signin.tmpl
1125 // Revision 1.94 2004/05/14 20:55:03 rurban
1126 // simplified RecentComments
1128 // Revision 1.93 2004/05/14 17:33:07 rurban
1129 // new plugin RecentChanges
1131 // Revision 1.92 2004/04/21 04:29:10 rurban
1132 // Two convenient RecentChanges extensions
1133 // RelatedChanges (only links from current page)
1134 // RecentEdits (just change the default args)
1136 // Revision 1.91 2004/04/19 18:27:46 rurban
1137 // Prevent from some PHP5 warnings (ref args, no :: object init)
1138 // php5 runs now through, just one wrong XmlElement object init missing
1139 // Removed unneccesary UpgradeUser lines
1140 // Changed WikiLink to omit version if current (RecentChanges)
1142 // Revision 1.90 2004/04/18 01:11:52 rurban
1143 // more numeric pagename fixes.
1144 // fixed action=upload with merge conflict warnings.
1145 // charset changed from constant to global (dynamic utf-8 switching)
1147 // Revision 1.89 2004/04/10 02:30:49 rurban
1148 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1149 // Fixed "cannot setlocale..." (sf.net problem)
1151 // Revision 1.88 2004/04/01 15:57:10 rurban
1152 // simplified Sidebar theme: table, not absolute css positioning
1153 // added the new box methods.
1154 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1156 // Revision 1.87 2004/03/30 02:14:03 rurban
1157 // fixed yet another Prefs bug
1158 // added generic PearDb_iter
1159 // $request->appendValidators no so strict as before
1160 // added some box plugin methods
1161 // PageList commalist for condensed output
1163 // Revision 1.86 2004/03/12 13:31:43 rurban
1164 // enforce PagePermissions, errormsg if not Admin
1166 // Revision 1.85 2004/02/17 12:11:36 rurban
1167 // 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, ...)
1169 // Revision 1.84 2004/02/15 22:29:42 rurban
1170 // revert premature performance fix
1172 // Revision 1.83 2004/02/15 21:34:37 rurban
1173 // PageList enhanced and improved.
1174 // fixed new WikiAdmin... plugins
1175 // editpage, Theme with exp. htmlarea framework
1176 // (htmlarea yet committed, this is really questionable)
1177 // WikiUser... code with better session handling for prefs
1178 // enhanced UserPreferences (again)
1179 // RecentChanges for show_deleted: how should pages be deleted then?
1181 // Revision 1.82 2004/01/25 03:58:43 rurban
1182 // use stdlib:isWikiWord()
1184 // Revision 1.81 2003/11/28 21:06:31 carstenklapp
1185 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
1186 // instead of 1. Make diff buttons smaller with css. Added description
1187 // line back in at the top.
1189 // Revision 1.80 2003/11/27 15:17:01 carstenklapp
1190 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
1191 // button, to allow an image button for it to be added to Themes. Output
1192 // RSS button in small text size when theme has no button image.
1194 // Revision 1.79 2003/04/29 14:34:20 dairiki
1195 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
1197 // Revision 1.78 2003/03/04 01:55:05 dairiki
1198 // Fix to ensure absolute URL for logo in RSS recent changes.
1200 // Revision 1.77 2003/02/27 23:23:38 dairiki
1201 // Fix my breakage of CSS and sidebar RecentChanges output.
1203 // Revision 1.76 2003/02/27 22:48:44 dairiki
1204 // Fixes invalid HTML generated by PageHistory plugin.
1206 // (<noscript> is block-level and not allowed within <p>.)
1208 // Revision 1.75 2003/02/22 21:39:05 dairiki
1209 // Hackish fix for SF bug #622784.
1211 // (The root of the problem is clearly a PHP bug.)
1213 // Revision 1.74 2003/02/21 22:52:21 dairiki
1214 // Make sure to interpret relative links (like [/Subpage]) in summary
1215 // relative to correct basepage.
1217 // Revision 1.73 2003/02/21 04:12:06 dairiki
1218 // Minor fixes for new cached markup.
1220 // Revision 1.72 2003/02/17 02:19:01 dairiki
1221 // Fix so that PageHistory will work when the current revision
1222 // of a page has been "deleted".
1224 // Revision 1.71 2003/02/16 20:04:48 dairiki
1225 // Refactor the HTTP validator generation/checking code.
1227 // This also fixes a number of bugs with yesterdays validator mods.
1229 // Revision 1.70 2003/02/16 05:09:43 dairiki
1230 // Starting to fix handling of the HTTP validator headers, Last-Modified,
1233 // Last-Modified was being set incorrectly (but only when DEBUG was not
1234 // defined!) Setting a Last-Modified without setting an appropriate
1235 // Expires: and/or Cache-Control: header results in browsers caching
1236 // the page unconditionally (for a certain period of time).
1237 // This is generally bad, since it means people don't see updated
1238 // page contents right away --- this is particularly confusing to
1239 // the people who are editing pages since their edits don't show up
1240 // next time they browse the page.
1242 // Now, we don't allow caching of pages without revalidation
1243 // (via the If-Modified-Since and/or If-None-Match request headers.)
1244 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
1245 // appropriate value in index.php, but I advise against it.)
1249 // o Even when request is aborted due to the content not being
1250 // modified, we currently still do almost all the work involved
1251 // in producing the page. So the only real savings from all
1252 // this logic is in network bandwidth.
1254 // o Plugins which produce "dynamic" output need to be inspected
1255 // and made to call $request->addToETag() and
1256 // $request->setModificationTime() appropriately, otherwise the
1257 // page can change without the change being detected.
1258 // This leads to stale pages in cache again...
1260 // Revision 1.69 2003/01/18 22:01:43 carstenklapp
1262 // Reformatting & tabs to spaces;
1263 // Added copyleft, getVersion, getDescription, rcs_id.
1266 // (c-file-style: "gnu")
1270 // c-basic-offset: 4
1271 // c-hanging-comment-ender-p: nil
1272 // indent-tabs-mode: nil