2 rcs_id('$Id: RecentChanges.php,v 1.115 2007-04-08 16:24:10 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;
31 function _RecentChanges_Formatter ($rc_args) {
32 $this->_args = $rc_args;
33 $this->_diffargs = array('action' => 'diff');
35 if ($rc_args['show_minor'] || !$rc_args['show_major'])
36 $this->_diffargs['previous'] = 'minor';
38 // PageHistoryPlugin doesn't have a 'daylist' arg.
39 if (!isset($this->_args['daylist']))
40 $this->_args['daylist'] = false;
43 function include_versions_in_URLs() {
44 return (bool) $this->_args['show_all'];
47 function date ($rev) {
49 return $WikiTheme->getDay($rev->get('mtime'));
52 function time ($rev) {
54 return $WikiTheme->formatTime($rev->get('mtime'));
57 function diffURL ($rev) {
58 $args = $this->_diffargs;
59 if ($this->include_versions_in_URLs())
60 $args['version'] = $rev->getVersion();
61 $page = $rev->getPage();
62 return WikiURL($page->getName(), $args, $this->_absurls);
65 function historyURL ($rev) {
66 $page = $rev->getPage();
67 return WikiURL($page, array('action' => _("PageHistory")),
71 function pageURL ($rev) {
72 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
76 function authorHasPage ($author) {
77 global $WikiNameRegexp, $request;
78 $dbi = $request->getDbh();
79 return isWikiWord($author) && $dbi->isWikiPage($author);
82 function authorURL ($author) {
83 return $this->authorHasPage() ? WikiURL($author) : false;
87 function status ($rev) {
88 if ($rev->hasDefaultContents())
90 $page = $rev->getPage();
91 $prev = $page->getRevisionBefore($rev->getVersion());
92 if ($prev->hasDefaultContents())
97 function importance ($rev) {
98 return $rev->get('is_minor_edit') ? 'minor' : 'major';
101 function summary($rev) {
102 if ( ($summary = $rev->get('summary')) )
105 switch ($this->status($rev)) {
109 return _("New page");
115 function setValidators($most_recent_rev) {
116 $rev = $most_recent_rev;
117 $validators = array('RecentChanges-top' =>
118 array($rev->getPageName(), $rev->getVersion()),
119 '%mtime' => $rev->get('mtime'));
121 $request->appendValidators($validators);
125 class _RecentChanges_HtmlFormatter
126 extends _RecentChanges_Formatter
128 function diffLink ($rev) {
130 $button = $WikiTheme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
131 $button->setAttr('rel', 'nofollow');
135 function historyLink ($rev) {
137 return $WikiTheme->makeButton(_("(hist)"), $this->historyURL($rev), 'wiki-rc-action');
140 function pageLink ($rev, $link_text=false) {
142 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),'auto',$link_text);
144 $page = $rev->getPage();
146 if ($this->include_versions_in_URLs()) {
147 $version = $rev->getVersion();
148 if ($rev->isCurrent())
150 $exists = !$rev->hasDefaultContents();
154 $cur = $page->getCurrentRevision();
155 $exists = !$cur->hasDefaultContents();
158 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
160 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
164 function authorLink ($rev) {
165 return WikiLink($rev->get('author'), 'if_known');
168 function summaryAsHTML ($rev) {
169 if ( !($summary = $this->summary($rev)) )
171 return HTML::strong( array('class' => 'wiki-summary'),
173 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
177 function rss_icon () {
178 global $request, $WikiTheme;
180 $rss_url = $request->getURLtoSelf(array('action' => 'RecentChanges', 'format' => 'rss'));
181 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
182 $WikiTheme->makeButton("RSS", $rss_url, 'rssicon'));
184 function rss2_icon () {
185 global $request, $WikiTheme;
187 $rss_url = $request->getURLtoSelf(array('action' => 'RecentChanges', 'format' => 'rss2'));
188 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
189 $WikiTheme->makeButton("xml", $rss_url, 'rssicon'));
191 function atom_icon () {
192 global $request, $WikiTheme;
194 $rss_url = $request->getURLtoSelf(array('action' => 'RecentChanges', 'format' => 'atom'));
195 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
196 $WikiTheme->makeButton("atom", $rss_url, 'rssicon'));
199 function grazr_icon () {
200 global $request, $WikiTheme;
201 $rss_url = 'http://grazr.com/gzpanel.html?' .
202 WikiURL($request->getArg('pagename'),array('action' => 'RecentChanges', 'format' => 'rss2'),true);
203 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
204 $WikiTheme->makeButton("grazr-it", $rss_url, 'rssicon'));
207 function pre_description () {
208 extract($this->_args);
209 // FIXME: say something about show_all.
210 if ($show_major && $show_minor)
213 $edits = _("major edits");
215 $edits = _("minor edits");
216 if (isset($caption) and $caption == _("Recent Comments"))
217 $edits = _("comments");
218 if (!empty($only_new)) {
219 $edits = _("created new pages");
221 if (!empty($author)) {
224 $author = $request->_user->getID();
225 $edits .= sprintf(_(" from author %s"), $author);
227 if (!empty($owner)) {
230 $owner = $request->_user->getID();
231 $edits .= sprintf(_(" from owner %s"), $owner);
233 if ($timespan = $days > 0) {
234 if (intval($days) != $days)
235 $days = sprintf("%.1f", $days);
239 * Depending how this text is split up it can be tricky or
240 * impossible to translate with good grammar. So the seperate
241 * strings for 1 day and %s days are necessary in this case
242 * for translating to multiple languages, due to differing
243 * overlapping ideal word cutting points.
245 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
246 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
247 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
249 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
250 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
251 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
255 if (intval($days) == 1)
256 $desc = fmt("The %d most recent %s during the past day are listed below.",
259 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
260 $limit, $edits, $days);
262 $desc = fmt("The %d most recent %s are listed below.",
265 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
267 if (intval($days) == 1)
268 $desc = fmt("The %d oldest %s during the past day are listed below.",
271 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
272 $lmt, $edits, $days);
274 $desc = fmt("The %d oldest %s are listed below.",
280 if (intval($days) == 1)
281 $desc = fmt("The most recent %s during the past day are listed below.",
284 $desc = fmt("The most recent %s during the past %s days are listed below.",
287 $desc = fmt("All %s are listed below.", $edits);
292 function description() {
293 return HTML::p(false, $this->pre_description());
298 extract($this->_args);
299 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
302 HTML::raw(' '), $this->rss2_icon(),
303 HTML::raw(' '), $this->grazr_icon(),
304 HTML::raw(' '), $this->atom_icon(),
305 $this->sidebar_link());
308 function empty_message () {
309 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
310 return _("No comments found");
312 return _("No changes found");
315 function sidebar_link() {
316 extract($this->_args);
317 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
320 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
323 "function addPanel() {\n"
324 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
325 ." \"$sidebarurl\",\"\");\n"
327 $jsf = JavaScript($addsidebarjsfunc);
330 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon');
331 $addsidebarjsclick = asXML(HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), $sidebar_button));
332 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
333 ." (typeof window.sidebar.addPanel == 'function'))\n"
335 ." document.write('$addsidebarjsclick');\n"
338 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
341 function format ($changes) {
342 include_once('lib/InlineParser.php');
344 $html = HTML(HTML::h2(false, $this->title()));
345 if (($desc = $this->description()))
346 $html->pushContent($desc);
348 if ($this->_args['daylist'])
349 $html->pushContent(new DayButtonBar($this->_args));
355 while ($rev = $changes->next()) {
356 if (($date = $this->date($rev)) != $last_date) {
358 $html->pushContent($lines);
359 $html->pushContent(HTML::h3($date));
364 // enforce view permission
365 if (mayAccessPage('view', $rev->_pagename)) {
366 $lines->pushContent($this->format_revision($rev));
369 $this->setValidators($rev);
374 $html->pushContent($lines);
376 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
377 $this->empty_message()));
382 function format_revision ($rev) {
383 $args = &$this->_args;
385 $class = 'rc-' . $this->importance($rev);
387 $time = $this->time($rev);
388 if (! $rev->get('is_minor_edit'))
389 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
391 $line = HTML::li(array('class' => $class));
394 if ($args['difflinks'])
395 $line->pushContent($this->diffLink($rev), ' ');
397 if ($args['historylinks'])
398 $line->pushContent($this->historyLink($rev), ' ');
400 $line->pushContent($this->pageLink($rev), ' ',
402 $this->summaryAsHTML($rev),
404 $this->authorLink($rev));
410 class _RecentChanges_SideBarFormatter
411 extends _RecentChanges_HtmlFormatter
413 function rss_icon () {
416 function rss2_icon () { }
418 //title click opens the normal RC or RE page in the main browser frame
419 extract($this->_args);
420 $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
421 $titlelink->setAttr('target', '_content');
422 return HTML($this->logo(), $titlelink);
425 //logo click opens the HomePage in the main browser frame
427 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
430 'style' => 'height:2.5ex'
432 $linkurl = WikiLink(HOME_PAGE, false, $img);
433 $linkurl->setAttr('target', '_content');
437 function authorLink ($rev) {
438 $author = $rev->get('author');
439 if ( $this->authorHasPage($author) ) {
440 $linkurl = WikiLink($author);
441 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
447 function diffLink ($rev) {
448 $linkurl = parent::diffLink($rev);
449 $linkurl->setAttr('target', '_content');
450 $linkurl->setAttr('rel', 'nofollow');
451 // FIXME: Smelly hack to get smaller diff buttons in sidebar
452 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
455 function historyLink ($rev) {
456 $linkurl = parent::historyLink($rev);
457 $linkurl->setAttr('target', '_content');
458 // FIXME: Smelly hack to get smaller history buttons in sidebar
459 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
462 function pageLink ($rev) {
463 $linkurl = parent::pageLink($rev);
464 $linkurl->setAttr('target', '_content');
467 // Overriding summaryAsHTML, because there is no way yet to
468 // return summary as transformed text with
469 // links setAttr('target', '_content') in Mozilla sidebar.
470 // So for now don't create clickable links inside summary
471 // in the sidebar, or else they target the sidebar and not the
472 // main content window.
473 function summaryAsHTML ($rev) {
474 if ( !($summary = $this->summary($rev)) )
476 return HTML::strong(array('class' => 'wiki-summary'),
478 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
483 function format ($changes) {
484 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
485 $html = _RecentChanges_HtmlFormatter::format ($changes);
486 $html = HTML::div(array('class' => 'wikitext'), $html);
488 $request->discardOutput();
490 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
491 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
492 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
493 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
496 extract($this->_args);
497 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
498 printf("<title>" . $title . "</title>\n");
500 $css = $WikiTheme->getCSS();
504 printf("<body class=\"sidebar\">\n");
506 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>';
507 printf("\n</body>\n");
510 $request->finish(); // cut rest of page processing short
514 class _RecentChanges_BoxFormatter
515 extends _RecentChanges_HtmlFormatter
517 function rss_icon () {
519 function rss2_icon () {
523 function authorLink ($rev) {
525 function diffLink ($rev) {
527 function historyLink ($rev) {
529 function summaryAsHTML ($rev) {
531 function description () {
533 function format ($changes) {
534 include_once('lib/InlineParser.php');
539 $sp = HTML::Raw("\n · ");
540 while ($rev = $changes->next()) {
541 // enforce view permission
542 if (mayAccessPage('view',$rev->_pagename)) {
543 if ($link = $this->pageLink($rev)) // some entries may be empty
544 // (/Blog/.. interim pages)
545 $html->pushContent($sp, $link, HTML::br());
547 $this->setValidators($rev);
552 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
553 $this->empty_message()));
558 class _RecentChanges_RssFormatter
559 extends _RecentChanges_Formatter
561 var $_absurls = true;
563 function time ($rev) {
564 return Iso8601DateTime($rev->get('mtime'));
567 function pageURI ($rev) {
568 return WikiURL($rev, '', 'absurl');
571 function format ($changes) {
573 include_once('lib/RssWriter.php');
574 $rss = new RssWriter;
576 $rss->channel($this->channel_properties());
578 if (($props = $this->image_properties()))
580 if (($props = $this->textinput_properties()))
581 $rss->textinput($props);
584 while ($rev = $changes->next()) {
585 // enforce view permission
586 if (mayAccessPage('view', $rev->_pagename)) {
587 $rss->addItem($this->item_properties($rev),
588 $this->pageURI($rev));
590 $this->setValidators($rev);
596 $request->discardOutput();
598 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
600 // Flush errors in comment, otherwise it's invalid XML.
601 global $ErrorManager;
602 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
603 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
605 $request->finish(); // NORETURN!!!!
608 function image_properties () {
611 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
615 return array('title' => WIKI_NAME,
616 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
620 function textinput_properties () {
621 return array('title' => _("Search"),
622 'description' => _("Title Search"),
624 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
627 function channel_properties () {
630 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
631 return array('title' => WIKI_NAME,
633 'description' => _("RecentChanges"),
634 'dc:date' => Iso8601DateTime(time()),
635 'dc:language' => $GLOBALS['LANG']);
637 /* FIXME: other things one might like in <channel>:
646 * rss091:managingEditor
648 * rss091:lastBuildDate
653 function item_properties ($rev) {
654 $page = $rev->getPage();
655 $pagename = $page->getName();
657 return array( 'title' => SplitPagename($pagename),
658 'description' => $this->summary($rev),
659 'link' => $this->pageURL($rev),
660 'dc:date' => $this->time($rev),
661 'dc:contributor' => $rev->get('author'),
662 'wiki:version' => $rev->getVersion(),
663 'wiki:importance' => $this->importance($rev),
664 'wiki:status' => $this->status($rev),
665 'wiki:diff' => $this->diffURL($rev),
666 'wiki:history' => $this->historyURL($rev)
671 /** explicit application/rss+xml Content-Type,
672 * simplified xml structure (no namespace),
673 * support for xml-rpc cloud registerProcedure (not yet)
675 class _RecentChanges_Rss2Formatter
676 extends _RecentChanges_RssFormatter {
678 function format ($changes) {
679 include_once('lib/RssWriter2.php');
680 $rss = new RssWriter2;
682 $rss->channel($this->channel_properties());
683 if (($props = $this->cloud_properties()))
685 if (($props = $this->image_properties()))
687 if (($props = $this->textinput_properties()))
688 $rss->textinput($props);
690 while ($rev = $changes->next()) {
691 // enforce view permission
692 if (mayAccessPage('view', $rev->_pagename)) {
693 $rss->addItem($this->item_properties($rev),
694 $this->pageURI($rev));
696 $this->setValidators($rev);
702 $request->discardOutput();
704 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
705 // Flush errors in comment, otherwise it's invalid XML.
706 global $ErrorManager;
707 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
708 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
710 $request->finish(); // NORETURN!!!!
713 function channel_properties () {
714 $chann_10 = parent::channel_properties();
715 return array_merge($chann_10,
716 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
717 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
718 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
719 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
720 'copyright' => COPYRIGHTPAGE_URL
724 // xml-rpc registerProcedure not yet implemented
725 function cloud_properties () { return false; }
726 function cloud_properties_test () {
727 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
728 'registerProcedure' => 'wiki.rssPleaseNotify',
729 'path' => DATA_PATH.'/RPC2.php',
730 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
731 'domain' => SERVER_NAME);
736 * Filter by non-empty
738 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
742 * @param $revisions object a WikiDB_PageRevisionIterator.
744 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
745 $this->_revisions = $revisions;
746 $this->_check_current_revision = $check_current_revision;
750 while (($rev = $this->_revisions->next())) {
751 if ($this->_check_current_revision) {
752 $page = $rev->getPage();
753 $check_rev = $page->getCurrentRevision();
758 if (! $check_rev->hasDefaultContents())
768 * Filter by only_new.
769 * Only new created pages
771 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
775 * @param $revisions object a WikiDB_PageRevisionIterator.
777 function NewPageRevisionIterator ($revisions) {
778 $this->_revisions = $revisions;
782 while (($rev = $this->_revisions->next())) {
783 if ($rev->getVersion() == 1)
794 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
796 function AuthorPageRevisionIterator ($revisions, $author) {
797 $this->_revisions = $revisions;
798 $this->_author = $author;
802 while (($rev = $this->_revisions->next())) {
803 if ($rev->get('author_id') == $this->_author)
814 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
816 function OwnerPageRevisionIterator ($revisions, $owner) {
817 $this->_revisions = $revisions;
818 $this->_owner = $owner;
822 while (($rev = $this->_revisions->next())) {
823 $page = $rev->getPage();
824 if ($page->getOwner() == $this->_owner)
832 class WikiPlugin_RecentChanges
835 function getName () {
836 return _("RecentChanges");
839 function getVersion() {
840 return preg_replace("/[Revision: $]/", '',
841 "\$Revision: 1.115 $");
844 function managesValidators() {
845 // Note that this is a bit of a fig.
846 // We set validators based on the most recently changed page,
847 // but this fails when the most-recent page is deleted.
848 // (Consider that the Last-Modified time will decrease
849 // when this happens.)
851 // We might be better off, leaving this as false (and junking
852 // the validator logic above) and just falling back to the
853 // default behavior (handled by WikiPlugin) of just using
854 // the WikiDB global timestamp as the mtime.
856 // Nevertheless, for now, I leave this here, mostly as an
857 // example for how to use appendValidators() and managesValidators().
862 function getDefaultArguments() {
863 return array('days' => 2,
864 'show_minor' => false,
865 'show_major' => true,
867 'show_deleted' => 'sometimes',
875 'historylinks' => false,
880 function getArgs ($argstr, $request, $defaults = false) {
881 if (!$defaults) $defaults = $this->getDefaultArguments();
882 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
884 $action = $request->getArg('action');
885 if ($action != 'browse' && ! $request->isActionPage($action))
886 $args['format'] = false; // default -> HTML
888 if ($args['format'] == 'rss' && empty($args['limit']))
889 $args['limit'] = 15; // Fix default value for RSS.
890 if ($args['format'] == 'rss2' && empty($args['limit']))
891 $args['limit'] = 15; // Fix default value for RSS2.
893 if ($args['format'] == 'sidebar' && empty($args['limit']))
894 $args['limit'] = 10; // Fix default value for sidebar.
899 function getMostRecentParams (&$args) {
900 $show_all = false; $show_minor = false; $show_major = false;
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'];
921 if (empty($days)) $days = 2;
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 $show_all = @$args['show_all'];
935 if ($show_deleted == 'sometimes')
936 $show_deleted = @$args['show_minor'];
938 if (!empty($args['only_new']))
939 $changes = new NewPageRevisionIterator($changes);
940 elseif (!empty($args['author']))
941 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
942 elseif (!empty($args['owner']))
943 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
944 elseif (!$show_deleted)
945 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
950 function format ($changes, $args) {
952 $format = $args['format'];
954 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
956 if ($format == 'rss')
957 $fmt_class = '_RecentChanges_RssFormatter';
958 elseif ($format == 'rss2')
959 $fmt_class = '_RecentChanges_Rss2Formatter';
960 elseif ($format == 'rss091') {
961 include_once "lib/RSSWriter091.php";
962 $fmt_class = '_RecentChanges_RssFormatter091';
964 elseif ($format == 'sidebar')
965 $fmt_class = '_RecentChanges_SideBarFormatter';
966 elseif ($format == 'box')
967 $fmt_class = '_RecentChanges_BoxFormatter';
969 $fmt_class = '_RecentChanges_HtmlFormatter';
972 $fmt = new $fmt_class($args);
973 return $fmt->format($changes);
976 function run($dbi, $argstr, &$request, $basepage) {
977 $args = $this->getArgs($argstr, $request);
979 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
980 // to be enough for anyone.)
981 $args['days'] = min($args['days'], 365000);
983 // Hack alert: format() is a NORETURN for rss formatters.
984 return $this->format($this->getChanges($dbi, $args), $args);
987 // box is used to display a fixed-width, narrow version with common header.
988 // just a numbered list of limit pagenames, without date.
989 function box($args = false, $request = false, $basepage = false) {
990 if (!$request) $request =& $GLOBALS['request'];
991 if (!isset($args['limit'])) $args['limit'] = 15;
992 $args['format'] = 'box';
993 $args['show_minor'] = false;
994 $args['show_major'] = true;
995 $args['show_deleted'] = 'sometimes';
996 $args['show_all'] = false;
998 return $this->makeBox(WikiLink($this->getName(),'',
999 SplitPagename($this->getName())),
1001 ($this->getChanges($request->_dbi, $args), $args));
1007 class DayButtonBar extends HtmlElement {
1009 function DayButtonBar ($plugin_args) {
1010 $this->__construct('p', array('class' => 'wiki-rc-action'));
1012 // Display days selection buttons
1013 extract($plugin_args);
1018 $caption = _("Show minor edits for:");
1020 $caption = _("Show all changes for:");
1022 $caption = _("Show changes for:");
1024 $caption = _("All new pages since:");
1027 $this->pushContent($caption, ' ');
1030 $sep = $WikiTheme->getButtonSeparator();
1033 foreach (explode(",", $daylist) as $days) {
1035 $this->pushContent($sep);
1036 $this->pushContent($this->_makeDayButton($days));
1040 function _makeDayButton ($days) {
1041 global $WikiTheme, $request;
1044 $label = _("1 day");
1046 $label = "..."; //alldays
1048 $label = sprintf(_("%s days"), abs($days));
1050 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1052 return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
1056 // $Log: not supported by cvs2svn $
1057 // Revision 1.114 2007/02/17 22:39:44 rurban
1058 // format=rss overhaul
1060 // Revision 1.113 2007/02/17 14:15:52 rurban
1061 // new argument owner=[] for RecentChangesMyPages
1063 // Revision 1.112 2007/01/28 20:32:07 rurban
1064 // silence empty warning
1066 // Revision 1.111 2007/01/25 21:48:52 rurban
1067 // new argument author=[]
1069 // Revision 1.110 2007/01/22 23:51:36 rurban
1070 // new arg: only_new
1072 // Revision 1.109 2006/03/19 14:26:29 rurban
1073 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
1075 // Revision 1.108 2005/04/01 16:09:35 rurban
1076 // fix defaults in RecentChanges plugins: e.g. invalid pagenames for PageHistory
1078 // Revision 1.107 2005/02/04 13:45:28 rurban
1079 // improve box layout a bit
1081 // Revision 1.106 2005/02/02 19:39:10 rurban
1082 // honor show_all=false
1084 // Revision 1.105 2005/01/25 03:50:54 uckelman
1085 // pre_description is a member function, so call with $this->.
1087 // Revision 1.104 2005/01/24 23:15:16 uckelman
1088 // The extra description for RelatedChanges was appearing in RecentChanges
1089 // and PageHistory due to a bad test in _RecentChanges_HtmlFormatter. Fixed.
1091 // Revision 1.103 2004/12/15 17:45:09 rurban
1094 // Revision 1.102 2004/12/06 19:29:24 rurban
1095 // simplify RSS: add RSS2 link (rss tag only, new content-type)
1097 // Revision 1.101 2004/11/10 19:32:24 rurban
1098 // * optimize increaseHitCount, esp. for mysql.
1099 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1100 // * Pear_DB version logic (awful but needed)
1101 // * fix broken ADODB quote
1102 // * _extract_page_data simplification
1104 // Revision 1.100 2004/06/28 16:35:12 rurban
1105 // prevent from shell commands
1107 // Revision 1.99 2004/06/20 14:42:54 rurban
1108 // various php5 fixes (still broken at blockparser)
1110 // Revision 1.98 2004/06/14 11:31:39 rurban
1111 // renamed global $Theme to $WikiTheme (gforge nameclash)
1112 // inherit PageList default options from PageList
1113 // default sortby=pagename
1114 // use options in PageList_Selectable (limit, sortby, ...)
1115 // added action revert, with button at action=diff
1116 // added option regex to WikiAdminSearchReplace
1118 // Revision 1.97 2004/06/03 18:58:27 rurban
1119 // days links requires action=RelatedChanges arg
1121 // Revision 1.96 2004/05/18 16:23:40 rurban
1122 // rename split_pagename to SplitPagename
1124 // Revision 1.95 2004/05/16 22:07:35 rurban
1125 // check more config-default and predefined constants
1126 // various PagePerm fixes:
1127 // fix default PagePerms, esp. edit and view for Bogo and Password users
1128 // implemented Creator and Owner
1129 // BOGOUSERS renamed to BOGOUSER
1130 // fixed syntax errors in signin.tmpl
1132 // Revision 1.94 2004/05/14 20:55:03 rurban
1133 // simplified RecentComments
1135 // Revision 1.93 2004/05/14 17:33:07 rurban
1136 // new plugin RecentChanges
1138 // Revision 1.92 2004/04/21 04:29:10 rurban
1139 // Two convenient RecentChanges extensions
1140 // RelatedChanges (only links from current page)
1141 // RecentEdits (just change the default args)
1143 // Revision 1.91 2004/04/19 18:27:46 rurban
1144 // Prevent from some PHP5 warnings (ref args, no :: object init)
1145 // php5 runs now through, just one wrong XmlElement object init missing
1146 // Removed unneccesary UpgradeUser lines
1147 // Changed WikiLink to omit version if current (RecentChanges)
1149 // Revision 1.90 2004/04/18 01:11:52 rurban
1150 // more numeric pagename fixes.
1151 // fixed action=upload with merge conflict warnings.
1152 // charset changed from constant to global (dynamic utf-8 switching)
1154 // Revision 1.89 2004/04/10 02:30:49 rurban
1155 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1156 // Fixed "cannot setlocale..." (sf.net problem)
1158 // Revision 1.88 2004/04/01 15:57:10 rurban
1159 // simplified Sidebar theme: table, not absolute css positioning
1160 // added the new box methods.
1161 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1163 // Revision 1.87 2004/03/30 02:14:03 rurban
1164 // fixed yet another Prefs bug
1165 // added generic PearDb_iter
1166 // $request->appendValidators no so strict as before
1167 // added some box plugin methods
1168 // PageList commalist for condensed output
1170 // Revision 1.86 2004/03/12 13:31:43 rurban
1171 // enforce PagePermissions, errormsg if not Admin
1173 // Revision 1.85 2004/02/17 12:11:36 rurban
1174 // 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, ...)
1176 // Revision 1.84 2004/02/15 22:29:42 rurban
1177 // revert premature performance fix
1179 // Revision 1.83 2004/02/15 21:34:37 rurban
1180 // PageList enhanced and improved.
1181 // fixed new WikiAdmin... plugins
1182 // editpage, Theme with exp. htmlarea framework
1183 // (htmlarea yet committed, this is really questionable)
1184 // WikiUser... code with better session handling for prefs
1185 // enhanced UserPreferences (again)
1186 // RecentChanges for show_deleted: how should pages be deleted then?
1188 // Revision 1.82 2004/01/25 03:58:43 rurban
1189 // use stdlib:isWikiWord()
1191 // Revision 1.81 2003/11/28 21:06:31 carstenklapp
1192 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
1193 // instead of 1. Make diff buttons smaller with css. Added description
1194 // line back in at the top.
1196 // Revision 1.80 2003/11/27 15:17:01 carstenklapp
1197 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
1198 // button, to allow an image button for it to be added to Themes. Output
1199 // RSS button in small text size when theme has no button image.
1201 // Revision 1.79 2003/04/29 14:34:20 dairiki
1202 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
1204 // Revision 1.78 2003/03/04 01:55:05 dairiki
1205 // Fix to ensure absolute URL for logo in RSS recent changes.
1207 // Revision 1.77 2003/02/27 23:23:38 dairiki
1208 // Fix my breakage of CSS and sidebar RecentChanges output.
1210 // Revision 1.76 2003/02/27 22:48:44 dairiki
1211 // Fixes invalid HTML generated by PageHistory plugin.
1213 // (<noscript> is block-level and not allowed within <p>.)
1215 // Revision 1.75 2003/02/22 21:39:05 dairiki
1216 // Hackish fix for SF bug #622784.
1218 // (The root of the problem is clearly a PHP bug.)
1220 // Revision 1.74 2003/02/21 22:52:21 dairiki
1221 // Make sure to interpret relative links (like [/Subpage]) in summary
1222 // relative to correct basepage.
1224 // Revision 1.73 2003/02/21 04:12:06 dairiki
1225 // Minor fixes for new cached markup.
1227 // Revision 1.72 2003/02/17 02:19:01 dairiki
1228 // Fix so that PageHistory will work when the current revision
1229 // of a page has been "deleted".
1231 // Revision 1.71 2003/02/16 20:04:48 dairiki
1232 // Refactor the HTTP validator generation/checking code.
1234 // This also fixes a number of bugs with yesterdays validator mods.
1236 // Revision 1.70 2003/02/16 05:09:43 dairiki
1237 // Starting to fix handling of the HTTP validator headers, Last-Modified,
1240 // Last-Modified was being set incorrectly (but only when DEBUG was not
1241 // defined!) Setting a Last-Modified without setting an appropriate
1242 // Expires: and/or Cache-Control: header results in browsers caching
1243 // the page unconditionally (for a certain period of time).
1244 // This is generally bad, since it means people don't see updated
1245 // page contents right away --- this is particularly confusing to
1246 // the people who are editing pages since their edits don't show up
1247 // next time they browse the page.
1249 // Now, we don't allow caching of pages without revalidation
1250 // (via the If-Modified-Since and/or If-None-Match request headers.)
1251 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
1252 // appropriate value in index.php, but I advise against it.)
1256 // o Even when request is aborted due to the content not being
1257 // modified, we currently still do almost all the work involved
1258 // in producing the page. So the only real savings from all
1259 // this logic is in network bandwidth.
1261 // o Plugins which produce "dynamic" output need to be inspected
1262 // and made to call $request->addToETag() and
1263 // $request->setModificationTime() appropriately, otherwise the
1264 // page can change without the change being detected.
1265 // This leads to stale pages in cache again...
1267 // Revision 1.69 2003/01/18 22:01:43 carstenklapp
1269 // Reformatting & tabs to spaces;
1270 // Added copyleft, getVersion, getDescription, rcs_id.
1273 // (c-file-style: "gnu")
1277 // c-basic-offset: 4
1278 // c-hanging-comment-ender-p: nil
1279 // indent-tabs-mode: nil