2 rcs_id('$Id: RecentChanges.php,v 1.118 2007-06-02 18:24:59 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');
132 return HTML("(",$button,")");
135 /* deletions: red, additions: green */
136 function diffSummary ($rev) {
137 $html = $this->diffURL($rev);
141 function historyLink ($rev) {
143 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
144 $button->setAttr('rel', 'nofollow');
145 return HTML("(",$button,")");
148 function pageLink ($rev, $link_text=false) {
150 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),'auto',$link_text);
152 $page = $rev->getPage();
154 if ($this->include_versions_in_URLs()) {
155 $version = $rev->getVersion();
156 if ($rev->isCurrent())
158 $exists = !$rev->hasDefaultContents();
162 $cur = $page->getCurrentRevision();
163 $exists = !$cur->hasDefaultContents();
166 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
168 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
172 function authorLink ($rev) {
173 return WikiLink($rev->get('author'), 'if_known');
176 /* Link to all users contributions (contribs and owns) */
177 function authorContribs ($rev) {
178 $author = $rev->get('author');
179 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
181 Button(array('action' => _("RecentChanges"),
182 'format' => 'contribs',
188 Button(array('action' => _("RecentChanges"),
189 'format' => 'contribs',
197 function summaryAsHTML ($rev) {
198 if ( !($summary = $this->summary($rev)) )
200 return HTML::span( array('class' => 'wiki-summary'),
202 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
206 function rss_icon () {
207 global $request, $WikiTheme;
209 $rss_url = $request->getURLtoSelf(array('action' => 'RecentChanges', 'format' => 'rss'));
210 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
211 $WikiTheme->makeButton("RSS", $rss_url, 'rssicon'));
213 function rss2_icon () {
214 global $request, $WikiTheme;
216 $rss_url = $request->getURLtoSelf(array('action' => 'RecentChanges', 'format' => 'rss2'));
217 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
218 $WikiTheme->makeButton("xml", $rss_url, 'rssicon'));
220 function atom_icon () {
221 global $request, $WikiTheme;
223 $rss_url = $request->getURLtoSelf(array('action' => 'RecentChanges', 'format' => 'atom'));
224 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
225 $WikiTheme->makeButton("atom", $rss_url, 'rssicon'));
228 function grazr_icon () {
229 global $request, $WikiTheme;
230 $rss_url = 'http://grazr.com/gzpanel.html?' .
231 WikiURL($request->getArg('pagename'),array('action' => 'RecentChanges', 'format' => 'rss2'),true);
232 return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'),
233 $WikiTheme->makeButton("grazr-it", $rss_url, 'rssicon'));
236 function pre_description () {
237 extract($this->_args);
238 // FIXME: say something about show_all.
239 if ($show_major && $show_minor)
242 $edits = _("major edits");
244 $edits = _("minor edits");
245 if (isset($caption) and $caption == _("Recent Comments"))
246 $edits = _("comments");
247 if (!empty($only_new)) {
248 $edits = _("created new pages");
250 if (!empty($author)) {
253 $author = $request->_user->getID();
254 $edits .= sprintf(_(" for pages changed by %s"), $author);
256 if (!empty($owner)) {
259 $owner = $request->_user->getID();
260 $edits .= sprintf(_(" for pages owned by %s"), $owner);
262 if ($timespan = $days > 0) {
263 if (intval($days) != $days)
264 $days = sprintf("%.1f", $days);
268 * Depending how this text is split up it can be tricky or
269 * impossible to translate with good grammar. So the seperate
270 * strings for 1 day and %s days are necessary in this case
271 * for translating to multiple languages, due to differing
272 * overlapping ideal word cutting points.
274 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
275 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
276 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
278 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
279 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
280 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
284 if (intval($days) == 1)
285 $desc = fmt("The %d most recent %s during the past day are listed below.",
288 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
289 $limit, $edits, $days);
291 $desc = fmt("The %d most recent %s are listed below.",
294 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
296 if (intval($days) == 1)
297 $desc = fmt("The %d oldest %s during the past day are listed below.",
300 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
301 $lmt, $edits, $days);
303 $desc = fmt("The %d oldest %s are listed below.",
309 if (intval($days) == 1)
310 $desc = fmt("The most recent %s during the past day are listed below.",
313 $desc = fmt("The most recent %s during the past %s days are listed below.",
316 $desc = fmt("All %s are listed below.", $edits);
321 function description() {
322 return HTML::p(false, $this->pre_description());
327 extract($this->_args);
328 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
331 HTML::raw(' '), $this->rss2_icon(),
332 HTML::raw(' '), $this->grazr_icon(),
333 HTML::raw(' '), $this->atom_icon(),
334 $this->sidebar_link());
337 function empty_message() {
338 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
339 return _("No comments found");
341 return _("No changes found");
344 function sidebar_link() {
345 extract($this->_args);
346 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
349 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
352 "function addPanel() {\n"
353 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
354 ." \"$sidebarurl\",\"\");\n"
356 $jsf = JavaScript($addsidebarjsfunc);
359 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon');
360 $addsidebarjsclick = asXML(HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), $sidebar_button));
361 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
362 ." (typeof window.sidebar.addPanel == 'function'))\n"
364 ." document.write('$addsidebarjsclick');\n"
367 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
370 function format ($changes) {
371 include_once('lib/InlineParser.php');
373 $html = HTML(HTML::h2(false, $this->title()));
374 if (($desc = $this->description()))
375 $html->pushContent($desc);
377 if ($this->_args['daylist'])
378 $html->pushContent(new DayButtonBar($this->_args));
384 while ($rev = $changes->next()) {
385 if (($date = $this->date($rev)) != $last_date) {
387 $html->pushContent($lines);
388 // for user contributions no extra date line
389 $html->pushContent(HTML::h3($date));
394 // enforce view permission
395 if (mayAccessPage('view', $rev->_pagename)) {
396 $lines->pushContent($this->format_revision($rev));
398 $this->setValidators($rev);
403 $html->pushContent($lines);
405 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
406 $this->empty_message()));
411 function format_revision ($rev) {
413 $args = &$this->_args;
415 $class = 'rc-' . $this->importance($rev);
417 $time = $this->time($rev);
418 if (! $rev->get('is_minor_edit'))
419 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
421 $line = HTML::li(array('class' => $class));
423 if ($args['difflinks'])
424 $line->pushContent($this->diffLink($rev), ' ');
426 if ($args['historylinks'])
427 $line->pushContent($this->historyLink($rev), ' ');
429 if (isa($WikiTheme, 'Theme_MonoBook')) {
431 $args['historylinks'] ? '' : $this->historyLink($rev),
432 ' . . ', $this->pageLink($rev), '; ',
434 $this->authorLink($rev),' ',
435 $this->authorContribs($rev),' ',
436 $this->summaryAsHTML($rev));
438 $line->pushContent($this->pageLink($rev), ' ',
440 $this->summaryAsHTML($rev),
442 $this->authorLink($rev));
449 /* format=contribs: no seperation into extra dates
450 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
452 class _RecentChanges_UserContribsFormatter
453 extends _RecentChanges_HtmlFormatter
456 extract($this->_args);
457 return array(_("UserContribs"),":",$author ? $author : $owner,
460 HTML::raw(' '), $this->rss2_icon(),
461 //HTML::raw(' '), $this->grazr_icon(),
462 HTML::raw(' '), $this->atom_icon());
465 function format ($changes) {
466 include_once('lib/InlineParser.php');
468 $html = HTML(HTML::h2(false, $this->title()));
470 $first = true; $count = 0;
471 while ($rev = $changes->next()) {
472 if (mayAccessPage('view', $rev->_pagename)) {
473 $lines->pushContent($this->format_revision($rev));
475 $this->setValidators($rev);
480 $this->_args['limit'] = $count;
481 if (($desc = $this->description()))
482 $html->pushContent($desc);
483 if ($this->_args['daylist'])
484 $html->pushContent(new DayButtonBar($this->_args));
486 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
487 $this->empty_message()));
489 $html->pushContent($lines);
494 function format_revision ($rev) {
495 $args = &$this->_args;
496 $class = 'rc-' . $this->importance($rev);
497 $time = $this->time($rev);
498 if (! $rev->get('is_minor_edit'))
499 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
501 $line = HTML::li(array('class' => $class));
503 $line->pushContent($this->time($rev),", ");
504 $line->pushContent($this->date($rev)," ");
505 $line->pushContent($this->diffLink($rev), ' ');
506 $line->pushContent($this->historyLink($rev), ' ');
507 $line->pushContent($this->pageLink($rev), ' ',
508 $this->summaryAsHTML($rev));
513 class _RecentChanges_SideBarFormatter
514 extends _RecentChanges_HtmlFormatter
516 function rss_icon () {
519 function rss2_icon () { }
521 //title click opens the normal RC or RE page in the main browser frame
522 extract($this->_args);
523 $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
524 $titlelink->setAttr('target', '_content');
525 return HTML($this->logo(), $titlelink);
528 //logo click opens the HomePage in the main browser frame
530 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
533 'style' => 'height:2.5ex'
535 $linkurl = WikiLink(HOME_PAGE, false, $img);
536 $linkurl->setAttr('target', '_content');
540 function authorLink ($rev) {
541 $author = $rev->get('author');
542 if ( $this->authorHasPage($author) ) {
543 $linkurl = WikiLink($author);
544 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
550 function diffLink ($rev) {
551 $linkurl = parent::diffLink($rev);
552 $linkurl->setAttr('target', '_content');
553 $linkurl->setAttr('rel', 'nofollow');
554 // FIXME: Smelly hack to get smaller diff buttons in sidebar
555 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
558 function historyLink ($rev) {
559 $linkurl = parent::historyLink($rev);
560 $linkurl->setAttr('target', '_content');
561 // FIXME: Smelly hack to get smaller history buttons in sidebar
562 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
565 function pageLink ($rev) {
566 $linkurl = parent::pageLink($rev);
567 $linkurl->setAttr('target', '_content');
570 // Overriding summaryAsHTML, because there is no way yet to
571 // return summary as transformed text with
572 // links setAttr('target', '_content') in Mozilla sidebar.
573 // So for now don't create clickable links inside summary
574 // in the sidebar, or else they target the sidebar and not the
575 // main content window.
576 function summaryAsHTML ($rev) {
577 if ( !($summary = $this->summary($rev)) )
579 return HTML::span(array('class' => 'wiki-summary'),
581 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
586 function format ($changes) {
587 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
588 $html = _RecentChanges_HtmlFormatter::format ($changes);
589 $html = HTML::div(array('class' => 'wikitext'), $html);
591 $request->discardOutput();
593 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
594 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
595 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
596 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
599 extract($this->_args);
600 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
601 printf("<title>" . $title . "</title>\n");
603 $css = $WikiTheme->getCSS();
607 printf("<body class=\"sidebar\">\n");
609 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>';
610 printf("\n</body>\n");
613 $request->finish(); // cut rest of page processing short
617 class _RecentChanges_BoxFormatter
618 extends _RecentChanges_HtmlFormatter
620 function rss_icon () {
622 function rss2_icon () {
626 function authorLink ($rev) {
628 function diffLink ($rev) {
630 function historyLink ($rev) {
632 function summaryAsHTML ($rev) {
634 function description () {
636 function format ($changes) {
637 include_once('lib/InlineParser.php');
642 $sp = HTML::Raw("\n · ");
643 while ($rev = $changes->next()) {
644 // enforce view permission
645 if (mayAccessPage('view',$rev->_pagename)) {
646 if ($link = $this->pageLink($rev)) // some entries may be empty
647 // (/Blog/.. interim pages)
648 $html->pushContent($sp, $link, HTML::br());
650 $this->setValidators($rev);
655 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
656 $this->empty_message()));
661 class _RecentChanges_RssFormatter
662 extends _RecentChanges_Formatter
664 var $_absurls = true;
666 function time ($rev) {
667 return Iso8601DateTime($rev->get('mtime'));
670 function pageURI ($rev) {
671 return WikiURL($rev, '', 'absurl');
674 function format ($changes) {
676 include_once('lib/RssWriter.php');
677 $rss = new RssWriter;
679 $rss->channel($this->channel_properties());
681 if (($props = $this->image_properties()))
683 if (($props = $this->textinput_properties()))
684 $rss->textinput($props);
687 while ($rev = $changes->next()) {
688 // enforce view permission
689 if (mayAccessPage('view', $rev->_pagename)) {
690 $rss->addItem($this->item_properties($rev),
691 $this->pageURI($rev));
693 $this->setValidators($rev);
699 $request->discardOutput();
701 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
703 // Flush errors in comment, otherwise it's invalid XML.
704 global $ErrorManager;
705 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
706 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
708 $request->finish(); // NORETURN!!!!
711 function image_properties () {
714 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
718 return array('title' => WIKI_NAME,
719 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
723 function textinput_properties () {
724 return array('title' => _("Search"),
725 'description' => _("Title Search"),
727 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
730 function channel_properties () {
733 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
734 return array('title' => WIKI_NAME,
736 'description' => _("RecentChanges"),
737 'dc:date' => Iso8601DateTime(time()),
738 'dc:language' => $GLOBALS['LANG']);
740 /* FIXME: other things one might like in <channel>:
749 * rss091:managingEditor
751 * rss091:lastBuildDate
756 function item_properties ($rev) {
757 $page = $rev->getPage();
758 $pagename = $page->getName();
760 return array( 'title' => SplitPagename($pagename),
761 'description' => $this->summary($rev),
762 'link' => $this->pageURL($rev),
763 'dc:date' => $this->time($rev),
764 'dc:contributor' => $rev->get('author'),
765 'wiki:version' => $rev->getVersion(),
766 'wiki:importance' => $this->importance($rev),
767 'wiki:status' => $this->status($rev),
768 'wiki:diff' => $this->diffURL($rev),
769 'wiki:history' => $this->historyURL($rev)
774 /** explicit application/rss+xml Content-Type,
775 * simplified xml structure (no namespace),
776 * support for xml-rpc cloud registerProcedure (not yet)
778 class _RecentChanges_Rss2Formatter
779 extends _RecentChanges_RssFormatter {
781 function format ($changes) {
782 include_once('lib/RssWriter2.php');
783 $rss = new RssWriter2;
785 $rss->channel($this->channel_properties());
786 if (($props = $this->cloud_properties()))
788 if (($props = $this->image_properties()))
790 if (($props = $this->textinput_properties()))
791 $rss->textinput($props);
793 while ($rev = $changes->next()) {
794 // enforce view permission
795 if (mayAccessPage('view', $rev->_pagename)) {
796 $rss->addItem($this->item_properties($rev),
797 $this->pageURI($rev));
799 $this->setValidators($rev);
805 $request->discardOutput();
807 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
808 // Flush errors in comment, otherwise it's invalid XML.
809 global $ErrorManager;
810 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
811 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
813 $request->finish(); // NORETURN!!!!
816 function channel_properties () {
817 $chann_10 = parent::channel_properties();
818 return array_merge($chann_10,
819 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
820 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
821 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
822 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
823 'copyright' => COPYRIGHTPAGE_URL
827 // xml-rpc registerProcedure not yet implemented
828 function cloud_properties () { return false; }
829 function cloud_properties_test () {
830 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
831 'registerProcedure' => 'wiki.rssPleaseNotify',
832 'path' => DATA_PATH.'/RPC2.php',
833 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
834 'domain' => SERVER_NAME);
839 * Filter by non-empty
841 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
845 * @param $revisions object a WikiDB_PageRevisionIterator.
847 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
848 $this->_revisions = $revisions;
849 $this->_check_current_revision = $check_current_revision;
853 while (($rev = $this->_revisions->next())) {
854 if ($this->_check_current_revision) {
855 $page = $rev->getPage();
856 $check_rev = $page->getCurrentRevision();
861 if (! $check_rev->hasDefaultContents())
871 * Filter by only_new.
872 * Only new created pages
874 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
878 * @param $revisions object a WikiDB_PageRevisionIterator.
880 function NewPageRevisionIterator ($revisions) {
881 $this->_revisions = $revisions;
885 while (($rev = $this->_revisions->next())) {
886 if ($rev->getVersion() == 1)
897 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
899 function AuthorPageRevisionIterator ($revisions, $author) {
900 $this->_revisions = $revisions;
901 $this->_author = $author;
905 while (($rev = $this->_revisions->next())) {
906 if ($rev->get('author_id') == $this->_author)
917 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
919 function OwnerPageRevisionIterator ($revisions, $owner) {
920 $this->_revisions = $revisions;
921 $this->_owner = $owner;
925 while (($rev = $this->_revisions->next())) {
926 $page = $rev->getPage();
927 if ($page->getOwner() == $this->_owner)
935 class WikiPlugin_RecentChanges
938 function getName () {
939 return _("RecentChanges");
942 function getVersion() {
943 return preg_replace("/[Revision: $]/", '',
944 "\$Revision: 1.118 $");
947 function managesValidators() {
948 // Note that this is a bit of a fig.
949 // We set validators based on the most recently changed page,
950 // but this fails when the most-recent page is deleted.
951 // (Consider that the Last-Modified time will decrease
952 // when this happens.)
954 // We might be better off, leaving this as false (and junking
955 // the validator logic above) and just falling back to the
956 // default behavior (handled by WikiPlugin) of just using
957 // the WikiDB global timestamp as the mtime.
959 // Nevertheless, for now, I leave this here, mostly as an
960 // example for how to use appendValidators() and managesValidators().
965 function getDefaultArguments() {
966 return array('days' => 2,
967 'show_minor' => false,
968 'show_major' => true,
970 'show_deleted' => 'sometimes',
978 'historylinks' => false,
983 function getArgs ($argstr, $request, $defaults = false) {
984 if (!$defaults) $defaults = $this->getDefaultArguments();
985 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
987 $action = $request->getArg('action');
988 if ($action != 'browse' && ! $request->isActionPage($action))
989 $args['format'] = false; // default -> HTML
991 if ($args['format'] == 'rss' && empty($args['limit']))
992 $args['limit'] = 15; // Fix default value for RSS.
993 if ($args['format'] == 'rss2' && empty($args['limit']))
994 $args['limit'] = 15; // Fix default value for RSS2.
996 if ($args['format'] == 'sidebar' && empty($args['limit']))
997 $args['limit'] = 10; // Fix default value for sidebar.
1002 function getMostRecentParams (&$args) {
1003 $show_all = false; $show_minor = false; $show_major = false;
1007 $params = array('include_minor_revisions' => $show_minor,
1008 'exclude_major_revisions' => !$show_major,
1009 'include_all_revisions' => !empty($show_all));
1011 $params['limit'] = $limit;
1012 if (!empty($args['author'])) {
1014 if ($args['author'] == '[]')
1015 $args['author'] = $request->_user->getID();
1016 $params['author'] = $args['author'];
1018 if (!empty($args['owner'])) {
1020 if ($args['owner'] == '[]')
1021 $args['owner'] = $request->_user->getID();
1022 $params['owner'] = $args['owner'];
1024 if (!empty($days)) {
1026 $params['since'] = time() - 24 * 3600 * $days;
1027 elseif ($days < 0.0)
1028 $params['since'] = 24 * 3600 * $days - time();
1034 function getChanges ($dbi, $args) {
1035 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1037 $show_deleted = @$args['show_deleted'];
1038 $show_all = @$args['show_all'];
1039 if ($show_deleted == 'sometimes')
1040 $show_deleted = @$args['show_minor'];
1042 if (!empty($args['only_new']))
1043 $changes = new NewPageRevisionIterator($changes);
1044 if (!empty($args['author']))
1045 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1046 if (!empty($args['owner']))
1047 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1049 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1054 function format ($changes, $args) {
1056 $format = $args['format'];
1058 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1060 if ($format == 'rss')
1061 $fmt_class = '_RecentChanges_RssFormatter';
1062 elseif ($format == 'rss2')
1063 $fmt_class = '_RecentChanges_Rss2Formatter';
1064 elseif ($format == 'rss091') {
1065 include_once "lib/RSSWriter091.php";
1066 $fmt_class = '_RecentChanges_RssFormatter091';
1068 elseif ($format == 'sidebar')
1069 $fmt_class = '_RecentChanges_SideBarFormatter';
1070 elseif ($format == 'box')
1071 $fmt_class = '_RecentChanges_BoxFormatter';
1072 elseif ($format == 'contribs')
1073 $fmt_class = '_RecentChanges_UserContribsFormatter';
1075 $fmt_class = '_RecentChanges_HtmlFormatter';
1078 $fmt = new $fmt_class($args);
1079 return $fmt->format($changes);
1082 function run($dbi, $argstr, &$request, $basepage) {
1083 $args = $this->getArgs($argstr, $request);
1085 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1086 // to be enough for anyone.)
1087 $args['days'] = min($args['days'], 365000);
1089 // Hack alert: format() is a NORETURN for rss formatters.
1090 return $this->format($this->getChanges($dbi, $args), $args);
1093 // box is used to display a fixed-width, narrow version with common header.
1094 // just a numbered list of limit pagenames, without date.
1095 function box($args = false, $request = false, $basepage = false) {
1096 if (!$request) $request =& $GLOBALS['request'];
1097 if (!isset($args['limit'])) $args['limit'] = 15;
1098 $args['format'] = 'box';
1099 $args['show_minor'] = false;
1100 $args['show_major'] = true;
1101 $args['show_deleted'] = 'sometimes';
1102 $args['show_all'] = false;
1104 return $this->makeBox(WikiLink($this->getName(),'',
1105 SplitPagename($this->getName())),
1107 ($this->getChanges($request->_dbi, $args), $args));
1113 class DayButtonBar extends HtmlElement {
1115 function DayButtonBar ($plugin_args) {
1116 $this->__construct('p', array('class' => 'wiki-rc-action'));
1118 // Display days selection buttons
1119 extract($plugin_args);
1124 $caption = _("Show minor edits for:");
1126 $caption = _("Show all changes for:");
1128 $caption = _("Show changes for:");
1130 $caption = _("All new pages since:");
1133 $this->pushContent($caption, ' ');
1136 $sep = $WikiTheme->getButtonSeparator();
1139 foreach (explode(",", $daylist) as $days) {
1141 $this->pushContent($sep);
1142 $this->pushContent($this->_makeDayButton($days));
1146 function _makeDayButton ($days) {
1147 global $WikiTheme, $request;
1150 $label = _("1 day");
1152 $label = "..."; //alldays
1154 $label = sprintf(_("%s days"), abs($days));
1156 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1158 return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
1162 // $Log: not supported by cvs2svn $
1163 // Revision 1.117 2007/05/30 20:43:31 rurban
1164 // added MonoBook UserContribs
1166 // Revision 1.116 2007/05/13 18:13:41 rurban
1167 // use all filters, not just the first, ignoring the others. improve wording a bit
1169 // Revision 1.115 2007/04/08 16:24:10 rurban
1170 // Remove redundant code in ->authorLink(): 'if_known' does the same
1172 // Revision 1.114 2007/02/17 22:39:44 rurban
1173 // format=rss overhaul
1175 // Revision 1.113 2007/02/17 14:15:52 rurban
1176 // new argument owner=[] for RecentChangesMyPages
1178 // Revision 1.112 2007/01/28 20:32:07 rurban
1179 // silence empty warning
1181 // Revision 1.111 2007/01/25 21:48:52 rurban
1182 // new argument author=[]
1184 // Revision 1.110 2007/01/22 23:51:36 rurban
1185 // new arg: only_new
1187 // Revision 1.109 2006/03/19 14:26:29 rurban
1188 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
1190 // Revision 1.108 2005/04/01 16:09:35 rurban
1191 // fix defaults in RecentChanges plugins: e.g. invalid pagenames for PageHistory
1193 // Revision 1.107 2005/02/04 13:45:28 rurban
1194 // improve box layout a bit
1196 // Revision 1.106 2005/02/02 19:39:10 rurban
1197 // honor show_all=false
1199 // Revision 1.105 2005/01/25 03:50:54 uckelman
1200 // pre_description is a member function, so call with $this->.
1202 // Revision 1.104 2005/01/24 23:15:16 uckelman
1203 // The extra description for RelatedChanges was appearing in RecentChanges
1204 // and PageHistory due to a bad test in _RecentChanges_HtmlFormatter. Fixed.
1206 // Revision 1.103 2004/12/15 17:45:09 rurban
1209 // Revision 1.102 2004/12/06 19:29:24 rurban
1210 // simplify RSS: add RSS2 link (rss tag only, new content-type)
1212 // Revision 1.101 2004/11/10 19:32:24 rurban
1213 // * optimize increaseHitCount, esp. for mysql.
1214 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1215 // * Pear_DB version logic (awful but needed)
1216 // * fix broken ADODB quote
1217 // * _extract_page_data simplification
1219 // Revision 1.100 2004/06/28 16:35:12 rurban
1220 // prevent from shell commands
1222 // Revision 1.99 2004/06/20 14:42:54 rurban
1223 // various php5 fixes (still broken at blockparser)
1225 // Revision 1.98 2004/06/14 11:31:39 rurban
1226 // renamed global $Theme to $WikiTheme (gforge nameclash)
1227 // inherit PageList default options from PageList
1228 // default sortby=pagename
1229 // use options in PageList_Selectable (limit, sortby, ...)
1230 // added action revert, with button at action=diff
1231 // added option regex to WikiAdminSearchReplace
1233 // Revision 1.97 2004/06/03 18:58:27 rurban
1234 // days links requires action=RelatedChanges arg
1236 // Revision 1.96 2004/05/18 16:23:40 rurban
1237 // rename split_pagename to SplitPagename
1239 // Revision 1.95 2004/05/16 22:07:35 rurban
1240 // check more config-default and predefined constants
1241 // various PagePerm fixes:
1242 // fix default PagePerms, esp. edit and view for Bogo and Password users
1243 // implemented Creator and Owner
1244 // BOGOUSERS renamed to BOGOUSER
1245 // fixed syntax errors in signin.tmpl
1247 // Revision 1.94 2004/05/14 20:55:03 rurban
1248 // simplified RecentComments
1250 // Revision 1.93 2004/05/14 17:33:07 rurban
1251 // new plugin RecentChanges
1253 // Revision 1.92 2004/04/21 04:29:10 rurban
1254 // Two convenient RecentChanges extensions
1255 // RelatedChanges (only links from current page)
1256 // RecentEdits (just change the default args)
1258 // Revision 1.91 2004/04/19 18:27:46 rurban
1259 // Prevent from some PHP5 warnings (ref args, no :: object init)
1260 // php5 runs now through, just one wrong XmlElement object init missing
1261 // Removed unneccesary UpgradeUser lines
1262 // Changed WikiLink to omit version if current (RecentChanges)
1264 // Revision 1.90 2004/04/18 01:11:52 rurban
1265 // more numeric pagename fixes.
1266 // fixed action=upload with merge conflict warnings.
1267 // charset changed from constant to global (dynamic utf-8 switching)
1269 // Revision 1.89 2004/04/10 02:30:49 rurban
1270 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1271 // Fixed "cannot setlocale..." (sf.net problem)
1273 // Revision 1.88 2004/04/01 15:57:10 rurban
1274 // simplified Sidebar theme: table, not absolute css positioning
1275 // added the new box methods.
1276 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1278 // Revision 1.87 2004/03/30 02:14:03 rurban
1279 // fixed yet another Prefs bug
1280 // added generic PearDb_iter
1281 // $request->appendValidators no so strict as before
1282 // added some box plugin methods
1283 // PageList commalist for condensed output
1285 // Revision 1.86 2004/03/12 13:31:43 rurban
1286 // enforce PagePermissions, errormsg if not Admin
1288 // Revision 1.85 2004/02/17 12:11:36 rurban
1289 // 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, ...)
1291 // Revision 1.84 2004/02/15 22:29:42 rurban
1292 // revert premature performance fix
1294 // Revision 1.83 2004/02/15 21:34:37 rurban
1295 // PageList enhanced and improved.
1296 // fixed new WikiAdmin... plugins
1297 // editpage, Theme with exp. htmlarea framework
1298 // (htmlarea yet committed, this is really questionable)
1299 // WikiUser... code with better session handling for prefs
1300 // enhanced UserPreferences (again)
1301 // RecentChanges for show_deleted: how should pages be deleted then?
1303 // Revision 1.82 2004/01/25 03:58:43 rurban
1304 // use stdlib:isWikiWord()
1306 // Revision 1.81 2003/11/28 21:06:31 carstenklapp
1307 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
1308 // instead of 1. Make diff buttons smaller with css. Added description
1309 // line back in at the top.
1311 // Revision 1.80 2003/11/27 15:17:01 carstenklapp
1312 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
1313 // button, to allow an image button for it to be added to Themes. Output
1314 // RSS button in small text size when theme has no button image.
1316 // Revision 1.79 2003/04/29 14:34:20 dairiki
1317 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
1319 // Revision 1.78 2003/03/04 01:55:05 dairiki
1320 // Fix to ensure absolute URL for logo in RSS recent changes.
1322 // Revision 1.77 2003/02/27 23:23:38 dairiki
1323 // Fix my breakage of CSS and sidebar RecentChanges output.
1325 // Revision 1.76 2003/02/27 22:48:44 dairiki
1326 // Fixes invalid HTML generated by PageHistory plugin.
1328 // (<noscript> is block-level and not allowed within <p>.)
1330 // Revision 1.75 2003/02/22 21:39:05 dairiki
1331 // Hackish fix for SF bug #622784.
1333 // (The root of the problem is clearly a PHP bug.)
1335 // Revision 1.74 2003/02/21 22:52:21 dairiki
1336 // Make sure to interpret relative links (like [/Subpage]) in summary
1337 // relative to correct basepage.
1339 // Revision 1.73 2003/02/21 04:12:06 dairiki
1340 // Minor fixes for new cached markup.
1342 // Revision 1.72 2003/02/17 02:19:01 dairiki
1343 // Fix so that PageHistory will work when the current revision
1344 // of a page has been "deleted".
1346 // Revision 1.71 2003/02/16 20:04:48 dairiki
1347 // Refactor the HTTP validator generation/checking code.
1349 // This also fixes a number of bugs with yesterdays validator mods.
1351 // Revision 1.70 2003/02/16 05:09:43 dairiki
1352 // Starting to fix handling of the HTTP validator headers, Last-Modified,
1355 // Last-Modified was being set incorrectly (but only when DEBUG was not
1356 // defined!) Setting a Last-Modified without setting an appropriate
1357 // Expires: and/or Cache-Control: header results in browsers caching
1358 // the page unconditionally (for a certain period of time).
1359 // This is generally bad, since it means people don't see updated
1360 // page contents right away --- this is particularly confusing to
1361 // the people who are editing pages since their edits don't show up
1362 // next time they browse the page.
1364 // Now, we don't allow caching of pages without revalidation
1365 // (via the If-Modified-Since and/or If-None-Match request headers.)
1366 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
1367 // appropriate value in index.php, but I advise against it.)
1371 // o Even when request is aborted due to the content not being
1372 // modified, we currently still do almost all the work involved
1373 // in producing the page. So the only real savings from all
1374 // this logic is in network bandwidth.
1376 // o Plugins which produce "dynamic" output need to be inspected
1377 // and made to call $request->addToETag() and
1378 // $request->setModificationTime() appropriately, otherwise the
1379 // page can change without the change being detected.
1380 // This leads to stale pages in cache again...
1382 // Revision 1.69 2003/01/18 22:01:43 carstenklapp
1384 // Reformatting & tabs to spaces;
1385 // Added copyleft, getVersion, getDescription, rcs_id.
1388 // (c-file-style: "gnu")
1392 // c-basic-offset: 4
1393 // c-hanging-comment-ender-p: nil
1394 // indent-tabs-mode: nil