2 rcs_id('$Id: RecentChanges.php,v 1.117 2007-05-30 20:43:31 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) {
412 $args = &$this->_args;
414 $class = 'rc-' . $this->importance($rev);
416 $time = $this->time($rev);
417 if (! $rev->get('is_minor_edit'))
418 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
420 $line = HTML::li(array('class' => $class));
422 if ($args['difflinks'])
423 $line->pushContent($this->diffLink($rev), ' ');
425 if ($args['historylinks'])
426 $line->pushContent($this->historyLink($rev), ' ');
428 if (isa($GLOBALS['WikiTheme'],'Theme_MonoBook')) {
430 $args['historylinks'] ? '' : $this->historyLink($rev),
431 ' . . ', $this->pageLink($rev), '; ',
433 $this->authorLink($rev),' ',
434 $this->authorContribs($rev),' ',
435 $this->summaryAsHTML($rev));
437 $line->pushContent($this->pageLink($rev), ' ',
439 $this->summaryAsHTML($rev),
441 $this->authorLink($rev));
448 /* format=contribs: no seperation into extra dates
449 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
451 class _RecentChanges_UserContribsFormatter
452 extends _RecentChanges_HtmlFormatter
455 extract($this->_args);
456 return array(_("UserContribs"),":",$author ? $author : $owner,
459 HTML::raw(' '), $this->rss2_icon(),
460 //HTML::raw(' '), $this->grazr_icon(),
461 HTML::raw(' '), $this->atom_icon());
464 function format ($changes) {
465 include_once('lib/InlineParser.php');
467 $html = HTML(HTML::h2(false, $this->title()));
469 $first = true; $count = 0;
470 while ($rev = $changes->next()) {
471 if (mayAccessPage('view', $rev->_pagename)) {
472 $lines->pushContent($this->format_revision($rev));
474 $this->setValidators($rev);
479 $this->_args['limit'] = $count;
480 if (($desc = $this->description()))
481 $html->pushContent($desc);
482 if ($this->_args['daylist'])
483 $html->pushContent(new DayButtonBar($this->_args));
485 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
486 $this->empty_message()));
488 $html->pushContent($lines);
493 function format_revision ($rev) {
494 $args = &$this->_args;
495 $class = 'rc-' . $this->importance($rev);
496 $time = $this->time($rev);
497 if (! $rev->get('is_minor_edit'))
498 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
500 $line = HTML::li(array('class' => $class));
502 $line->pushContent($this->time($rev),", ");
503 $line->pushContent($this->date($rev)," ");
504 $line->pushContent($this->diffLink($rev), ' ');
505 $line->pushContent($this->historyLink($rev), ' ');
506 $line->pushContent($this->pageLink($rev), ' ',
507 $this->summaryAsHTML($rev));
512 class _RecentChanges_SideBarFormatter
513 extends _RecentChanges_HtmlFormatter
515 function rss_icon () {
518 function rss2_icon () { }
520 //title click opens the normal RC or RE page in the main browser frame
521 extract($this->_args);
522 $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
523 $titlelink->setAttr('target', '_content');
524 return HTML($this->logo(), $titlelink);
527 //logo click opens the HomePage in the main browser frame
529 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
532 'style' => 'height:2.5ex'
534 $linkurl = WikiLink(HOME_PAGE, false, $img);
535 $linkurl->setAttr('target', '_content');
539 function authorLink ($rev) {
540 $author = $rev->get('author');
541 if ( $this->authorHasPage($author) ) {
542 $linkurl = WikiLink($author);
543 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
549 function diffLink ($rev) {
550 $linkurl = parent::diffLink($rev);
551 $linkurl->setAttr('target', '_content');
552 $linkurl->setAttr('rel', 'nofollow');
553 // FIXME: Smelly hack to get smaller diff buttons in sidebar
554 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
557 function historyLink ($rev) {
558 $linkurl = parent::historyLink($rev);
559 $linkurl->setAttr('target', '_content');
560 // FIXME: Smelly hack to get smaller history buttons in sidebar
561 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
564 function pageLink ($rev) {
565 $linkurl = parent::pageLink($rev);
566 $linkurl->setAttr('target', '_content');
569 // Overriding summaryAsHTML, because there is no way yet to
570 // return summary as transformed text with
571 // links setAttr('target', '_content') in Mozilla sidebar.
572 // So for now don't create clickable links inside summary
573 // in the sidebar, or else they target the sidebar and not the
574 // main content window.
575 function summaryAsHTML ($rev) {
576 if ( !($summary = $this->summary($rev)) )
578 return HTML::span(array('class' => 'wiki-summary'),
580 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
585 function format ($changes) {
586 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
587 $html = _RecentChanges_HtmlFormatter::format ($changes);
588 $html = HTML::div(array('class' => 'wikitext'), $html);
590 $request->discardOutput();
592 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
593 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
594 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
595 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
598 extract($this->_args);
599 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
600 printf("<title>" . $title . "</title>\n");
602 $css = $WikiTheme->getCSS();
606 printf("<body class=\"sidebar\">\n");
608 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>';
609 printf("\n</body>\n");
612 $request->finish(); // cut rest of page processing short
616 class _RecentChanges_BoxFormatter
617 extends _RecentChanges_HtmlFormatter
619 function rss_icon () {
621 function rss2_icon () {
625 function authorLink ($rev) {
627 function diffLink ($rev) {
629 function historyLink ($rev) {
631 function summaryAsHTML ($rev) {
633 function description () {
635 function format ($changes) {
636 include_once('lib/InlineParser.php');
641 $sp = HTML::Raw("\n · ");
642 while ($rev = $changes->next()) {
643 // enforce view permission
644 if (mayAccessPage('view',$rev->_pagename)) {
645 if ($link = $this->pageLink($rev)) // some entries may be empty
646 // (/Blog/.. interim pages)
647 $html->pushContent($sp, $link, HTML::br());
649 $this->setValidators($rev);
654 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
655 $this->empty_message()));
660 class _RecentChanges_RssFormatter
661 extends _RecentChanges_Formatter
663 var $_absurls = true;
665 function time ($rev) {
666 return Iso8601DateTime($rev->get('mtime'));
669 function pageURI ($rev) {
670 return WikiURL($rev, '', 'absurl');
673 function format ($changes) {
675 include_once('lib/RssWriter.php');
676 $rss = new RssWriter;
678 $rss->channel($this->channel_properties());
680 if (($props = $this->image_properties()))
682 if (($props = $this->textinput_properties()))
683 $rss->textinput($props);
686 while ($rev = $changes->next()) {
687 // enforce view permission
688 if (mayAccessPage('view', $rev->_pagename)) {
689 $rss->addItem($this->item_properties($rev),
690 $this->pageURI($rev));
692 $this->setValidators($rev);
698 $request->discardOutput();
700 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
702 // Flush errors in comment, otherwise it's invalid XML.
703 global $ErrorManager;
704 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
705 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
707 $request->finish(); // NORETURN!!!!
710 function image_properties () {
713 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
717 return array('title' => WIKI_NAME,
718 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
722 function textinput_properties () {
723 return array('title' => _("Search"),
724 'description' => _("Title Search"),
726 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
729 function channel_properties () {
732 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
733 return array('title' => WIKI_NAME,
735 'description' => _("RecentChanges"),
736 'dc:date' => Iso8601DateTime(time()),
737 'dc:language' => $GLOBALS['LANG']);
739 /* FIXME: other things one might like in <channel>:
748 * rss091:managingEditor
750 * rss091:lastBuildDate
755 function item_properties ($rev) {
756 $page = $rev->getPage();
757 $pagename = $page->getName();
759 return array( 'title' => SplitPagename($pagename),
760 'description' => $this->summary($rev),
761 'link' => $this->pageURL($rev),
762 'dc:date' => $this->time($rev),
763 'dc:contributor' => $rev->get('author'),
764 'wiki:version' => $rev->getVersion(),
765 'wiki:importance' => $this->importance($rev),
766 'wiki:status' => $this->status($rev),
767 'wiki:diff' => $this->diffURL($rev),
768 'wiki:history' => $this->historyURL($rev)
773 /** explicit application/rss+xml Content-Type,
774 * simplified xml structure (no namespace),
775 * support for xml-rpc cloud registerProcedure (not yet)
777 class _RecentChanges_Rss2Formatter
778 extends _RecentChanges_RssFormatter {
780 function format ($changes) {
781 include_once('lib/RssWriter2.php');
782 $rss = new RssWriter2;
784 $rss->channel($this->channel_properties());
785 if (($props = $this->cloud_properties()))
787 if (($props = $this->image_properties()))
789 if (($props = $this->textinput_properties()))
790 $rss->textinput($props);
792 while ($rev = $changes->next()) {
793 // enforce view permission
794 if (mayAccessPage('view', $rev->_pagename)) {
795 $rss->addItem($this->item_properties($rev),
796 $this->pageURI($rev));
798 $this->setValidators($rev);
804 $request->discardOutput();
806 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
807 // Flush errors in comment, otherwise it's invalid XML.
808 global $ErrorManager;
809 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
810 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
812 $request->finish(); // NORETURN!!!!
815 function channel_properties () {
816 $chann_10 = parent::channel_properties();
817 return array_merge($chann_10,
818 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
819 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
820 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
821 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
822 'copyright' => COPYRIGHTPAGE_URL
826 // xml-rpc registerProcedure not yet implemented
827 function cloud_properties () { return false; }
828 function cloud_properties_test () {
829 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
830 'registerProcedure' => 'wiki.rssPleaseNotify',
831 'path' => DATA_PATH.'/RPC2.php',
832 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
833 'domain' => SERVER_NAME);
838 * Filter by non-empty
840 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
844 * @param $revisions object a WikiDB_PageRevisionIterator.
846 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
847 $this->_revisions = $revisions;
848 $this->_check_current_revision = $check_current_revision;
852 while (($rev = $this->_revisions->next())) {
853 if ($this->_check_current_revision) {
854 $page = $rev->getPage();
855 $check_rev = $page->getCurrentRevision();
860 if (! $check_rev->hasDefaultContents())
870 * Filter by only_new.
871 * Only new created pages
873 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
877 * @param $revisions object a WikiDB_PageRevisionIterator.
879 function NewPageRevisionIterator ($revisions) {
880 $this->_revisions = $revisions;
884 while (($rev = $this->_revisions->next())) {
885 if ($rev->getVersion() == 1)
896 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
898 function AuthorPageRevisionIterator ($revisions, $author) {
899 $this->_revisions = $revisions;
900 $this->_author = $author;
904 while (($rev = $this->_revisions->next())) {
905 if ($rev->get('author_id') == $this->_author)
916 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
918 function OwnerPageRevisionIterator ($revisions, $owner) {
919 $this->_revisions = $revisions;
920 $this->_owner = $owner;
924 while (($rev = $this->_revisions->next())) {
925 $page = $rev->getPage();
926 if ($page->getOwner() == $this->_owner)
934 class WikiPlugin_RecentChanges
937 function getName () {
938 return _("RecentChanges");
941 function getVersion() {
942 return preg_replace("/[Revision: $]/", '',
943 "\$Revision: 1.117 $");
946 function managesValidators() {
947 // Note that this is a bit of a fig.
948 // We set validators based on the most recently changed page,
949 // but this fails when the most-recent page is deleted.
950 // (Consider that the Last-Modified time will decrease
951 // when this happens.)
953 // We might be better off, leaving this as false (and junking
954 // the validator logic above) and just falling back to the
955 // default behavior (handled by WikiPlugin) of just using
956 // the WikiDB global timestamp as the mtime.
958 // Nevertheless, for now, I leave this here, mostly as an
959 // example for how to use appendValidators() and managesValidators().
964 function getDefaultArguments() {
965 return array('days' => 2,
966 'show_minor' => false,
967 'show_major' => true,
969 'show_deleted' => 'sometimes',
977 'historylinks' => false,
982 function getArgs ($argstr, $request, $defaults = false) {
983 if (!$defaults) $defaults = $this->getDefaultArguments();
984 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
986 $action = $request->getArg('action');
987 if ($action != 'browse' && ! $request->isActionPage($action))
988 $args['format'] = false; // default -> HTML
990 if ($args['format'] == 'rss' && empty($args['limit']))
991 $args['limit'] = 15; // Fix default value for RSS.
992 if ($args['format'] == 'rss2' && empty($args['limit']))
993 $args['limit'] = 15; // Fix default value for RSS2.
995 if ($args['format'] == 'sidebar' && empty($args['limit']))
996 $args['limit'] = 10; // Fix default value for sidebar.
1001 function getMostRecentParams (&$args) {
1002 $show_all = false; $show_minor = false; $show_major = false;
1006 $params = array('include_minor_revisions' => $show_minor,
1007 'exclude_major_revisions' => !$show_major,
1008 'include_all_revisions' => !empty($show_all));
1010 $params['limit'] = $limit;
1011 if (!empty($args['author'])) {
1013 if ($args['author'] == '[]')
1014 $args['author'] = $request->_user->getID();
1015 $params['author'] = $args['author'];
1017 if (!empty($args['owner'])) {
1019 if ($args['owner'] == '[]')
1020 $args['owner'] = $request->_user->getID();
1021 $params['owner'] = $args['owner'];
1023 if (!empty($days)) {
1025 $params['since'] = time() - 24 * 3600 * $days;
1026 elseif ($days < 0.0)
1027 $params['since'] = 24 * 3600 * $days - time();
1033 function getChanges ($dbi, $args) {
1034 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1036 $show_deleted = @$args['show_deleted'];
1037 $show_all = @$args['show_all'];
1038 if ($show_deleted == 'sometimes')
1039 $show_deleted = @$args['show_minor'];
1041 if (!empty($args['only_new']))
1042 $changes = new NewPageRevisionIterator($changes);
1043 if (!empty($args['author']))
1044 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1045 if (!empty($args['owner']))
1046 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1048 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1053 function format ($changes, $args) {
1055 $format = $args['format'];
1057 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1059 if ($format == 'rss')
1060 $fmt_class = '_RecentChanges_RssFormatter';
1061 elseif ($format == 'rss2')
1062 $fmt_class = '_RecentChanges_Rss2Formatter';
1063 elseif ($format == 'rss091') {
1064 include_once "lib/RSSWriter091.php";
1065 $fmt_class = '_RecentChanges_RssFormatter091';
1067 elseif ($format == 'sidebar')
1068 $fmt_class = '_RecentChanges_SideBarFormatter';
1069 elseif ($format == 'box')
1070 $fmt_class = '_RecentChanges_BoxFormatter';
1071 elseif ($format == 'contribs')
1072 $fmt_class = '_RecentChanges_UserContribsFormatter';
1074 $fmt_class = '_RecentChanges_HtmlFormatter';
1077 $fmt = new $fmt_class($args);
1078 return $fmt->format($changes);
1081 function run($dbi, $argstr, &$request, $basepage) {
1082 $args = $this->getArgs($argstr, $request);
1084 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1085 // to be enough for anyone.)
1086 $args['days'] = min($args['days'], 365000);
1088 // Hack alert: format() is a NORETURN for rss formatters.
1089 return $this->format($this->getChanges($dbi, $args), $args);
1092 // box is used to display a fixed-width, narrow version with common header.
1093 // just a numbered list of limit pagenames, without date.
1094 function box($args = false, $request = false, $basepage = false) {
1095 if (!$request) $request =& $GLOBALS['request'];
1096 if (!isset($args['limit'])) $args['limit'] = 15;
1097 $args['format'] = 'box';
1098 $args['show_minor'] = false;
1099 $args['show_major'] = true;
1100 $args['show_deleted'] = 'sometimes';
1101 $args['show_all'] = false;
1103 return $this->makeBox(WikiLink($this->getName(),'',
1104 SplitPagename($this->getName())),
1106 ($this->getChanges($request->_dbi, $args), $args));
1112 class DayButtonBar extends HtmlElement {
1114 function DayButtonBar ($plugin_args) {
1115 $this->__construct('p', array('class' => 'wiki-rc-action'));
1117 // Display days selection buttons
1118 extract($plugin_args);
1123 $caption = _("Show minor edits for:");
1125 $caption = _("Show all changes for:");
1127 $caption = _("Show changes for:");
1129 $caption = _("All new pages since:");
1132 $this->pushContent($caption, ' ');
1135 $sep = $WikiTheme->getButtonSeparator();
1138 foreach (explode(",", $daylist) as $days) {
1140 $this->pushContent($sep);
1141 $this->pushContent($this->_makeDayButton($days));
1145 function _makeDayButton ($days) {
1146 global $WikiTheme, $request;
1149 $label = _("1 day");
1151 $label = "..."; //alldays
1153 $label = sprintf(_("%s days"), abs($days));
1155 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1157 return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
1161 // $Log: not supported by cvs2svn $
1162 // Revision 1.116 2007/05/13 18:13:41 rurban
1163 // use all filters, not just the first, ignoring the others. improve wording a bit
1165 // Revision 1.115 2007/04/08 16:24:10 rurban
1166 // Remove redundant code in ->authorLink(): 'if_known' does the same
1168 // Revision 1.114 2007/02/17 22:39:44 rurban
1169 // format=rss overhaul
1171 // Revision 1.113 2007/02/17 14:15:52 rurban
1172 // new argument owner=[] for RecentChangesMyPages
1174 // Revision 1.112 2007/01/28 20:32:07 rurban
1175 // silence empty warning
1177 // Revision 1.111 2007/01/25 21:48:52 rurban
1178 // new argument author=[]
1180 // Revision 1.110 2007/01/22 23:51:36 rurban
1181 // new arg: only_new
1183 // Revision 1.109 2006/03/19 14:26:29 rurban
1184 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
1186 // Revision 1.108 2005/04/01 16:09:35 rurban
1187 // fix defaults in RecentChanges plugins: e.g. invalid pagenames for PageHistory
1189 // Revision 1.107 2005/02/04 13:45:28 rurban
1190 // improve box layout a bit
1192 // Revision 1.106 2005/02/02 19:39:10 rurban
1193 // honor show_all=false
1195 // Revision 1.105 2005/01/25 03:50:54 uckelman
1196 // pre_description is a member function, so call with $this->.
1198 // Revision 1.104 2005/01/24 23:15:16 uckelman
1199 // The extra description for RelatedChanges was appearing in RecentChanges
1200 // and PageHistory due to a bad test in _RecentChanges_HtmlFormatter. Fixed.
1202 // Revision 1.103 2004/12/15 17:45:09 rurban
1205 // Revision 1.102 2004/12/06 19:29:24 rurban
1206 // simplify RSS: add RSS2 link (rss tag only, new content-type)
1208 // Revision 1.101 2004/11/10 19:32:24 rurban
1209 // * optimize increaseHitCount, esp. for mysql.
1210 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1211 // * Pear_DB version logic (awful but needed)
1212 // * fix broken ADODB quote
1213 // * _extract_page_data simplification
1215 // Revision 1.100 2004/06/28 16:35:12 rurban
1216 // prevent from shell commands
1218 // Revision 1.99 2004/06/20 14:42:54 rurban
1219 // various php5 fixes (still broken at blockparser)
1221 // Revision 1.98 2004/06/14 11:31:39 rurban
1222 // renamed global $Theme to $WikiTheme (gforge nameclash)
1223 // inherit PageList default options from PageList
1224 // default sortby=pagename
1225 // use options in PageList_Selectable (limit, sortby, ...)
1226 // added action revert, with button at action=diff
1227 // added option regex to WikiAdminSearchReplace
1229 // Revision 1.97 2004/06/03 18:58:27 rurban
1230 // days links requires action=RelatedChanges arg
1232 // Revision 1.96 2004/05/18 16:23:40 rurban
1233 // rename split_pagename to SplitPagename
1235 // Revision 1.95 2004/05/16 22:07:35 rurban
1236 // check more config-default and predefined constants
1237 // various PagePerm fixes:
1238 // fix default PagePerms, esp. edit and view for Bogo and Password users
1239 // implemented Creator and Owner
1240 // BOGOUSERS renamed to BOGOUSER
1241 // fixed syntax errors in signin.tmpl
1243 // Revision 1.94 2004/05/14 20:55:03 rurban
1244 // simplified RecentComments
1246 // Revision 1.93 2004/05/14 17:33:07 rurban
1247 // new plugin RecentChanges
1249 // Revision 1.92 2004/04/21 04:29:10 rurban
1250 // Two convenient RecentChanges extensions
1251 // RelatedChanges (only links from current page)
1252 // RecentEdits (just change the default args)
1254 // Revision 1.91 2004/04/19 18:27:46 rurban
1255 // Prevent from some PHP5 warnings (ref args, no :: object init)
1256 // php5 runs now through, just one wrong XmlElement object init missing
1257 // Removed unneccesary UpgradeUser lines
1258 // Changed WikiLink to omit version if current (RecentChanges)
1260 // Revision 1.90 2004/04/18 01:11:52 rurban
1261 // more numeric pagename fixes.
1262 // fixed action=upload with merge conflict warnings.
1263 // charset changed from constant to global (dynamic utf-8 switching)
1265 // Revision 1.89 2004/04/10 02:30:49 rurban
1266 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1267 // Fixed "cannot setlocale..." (sf.net problem)
1269 // Revision 1.88 2004/04/01 15:57:10 rurban
1270 // simplified Sidebar theme: table, not absolute css positioning
1271 // added the new box methods.
1272 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1274 // Revision 1.87 2004/03/30 02:14:03 rurban
1275 // fixed yet another Prefs bug
1276 // added generic PearDb_iter
1277 // $request->appendValidators no so strict as before
1278 // added some box plugin methods
1279 // PageList commalist for condensed output
1281 // Revision 1.86 2004/03/12 13:31:43 rurban
1282 // enforce PagePermissions, errormsg if not Admin
1284 // Revision 1.85 2004/02/17 12:11:36 rurban
1285 // 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, ...)
1287 // Revision 1.84 2004/02/15 22:29:42 rurban
1288 // revert premature performance fix
1290 // Revision 1.83 2004/02/15 21:34:37 rurban
1291 // PageList enhanced and improved.
1292 // fixed new WikiAdmin... plugins
1293 // editpage, Theme with exp. htmlarea framework
1294 // (htmlarea yet committed, this is really questionable)
1295 // WikiUser... code with better session handling for prefs
1296 // enhanced UserPreferences (again)
1297 // RecentChanges for show_deleted: how should pages be deleted then?
1299 // Revision 1.82 2004/01/25 03:58:43 rurban
1300 // use stdlib:isWikiWord()
1302 // Revision 1.81 2003/11/28 21:06:31 carstenklapp
1303 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
1304 // instead of 1. Make diff buttons smaller with css. Added description
1305 // line back in at the top.
1307 // Revision 1.80 2003/11/27 15:17:01 carstenklapp
1308 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
1309 // button, to allow an image button for it to be added to Themes. Output
1310 // RSS button in small text size when theme has no button image.
1312 // Revision 1.79 2003/04/29 14:34:20 dairiki
1313 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
1315 // Revision 1.78 2003/03/04 01:55:05 dairiki
1316 // Fix to ensure absolute URL for logo in RSS recent changes.
1318 // Revision 1.77 2003/02/27 23:23:38 dairiki
1319 // Fix my breakage of CSS and sidebar RecentChanges output.
1321 // Revision 1.76 2003/02/27 22:48:44 dairiki
1322 // Fixes invalid HTML generated by PageHistory plugin.
1324 // (<noscript> is block-level and not allowed within <p>.)
1326 // Revision 1.75 2003/02/22 21:39:05 dairiki
1327 // Hackish fix for SF bug #622784.
1329 // (The root of the problem is clearly a PHP bug.)
1331 // Revision 1.74 2003/02/21 22:52:21 dairiki
1332 // Make sure to interpret relative links (like [/Subpage]) in summary
1333 // relative to correct basepage.
1335 // Revision 1.73 2003/02/21 04:12:06 dairiki
1336 // Minor fixes for new cached markup.
1338 // Revision 1.72 2003/02/17 02:19:01 dairiki
1339 // Fix so that PageHistory will work when the current revision
1340 // of a page has been "deleted".
1342 // Revision 1.71 2003/02/16 20:04:48 dairiki
1343 // Refactor the HTTP validator generation/checking code.
1345 // This also fixes a number of bugs with yesterdays validator mods.
1347 // Revision 1.70 2003/02/16 05:09:43 dairiki
1348 // Starting to fix handling of the HTTP validator headers, Last-Modified,
1351 // Last-Modified was being set incorrectly (but only when DEBUG was not
1352 // defined!) Setting a Last-Modified without setting an appropriate
1353 // Expires: and/or Cache-Control: header results in browsers caching
1354 // the page unconditionally (for a certain period of time).
1355 // This is generally bad, since it means people don't see updated
1356 // page contents right away --- this is particularly confusing to
1357 // the people who are editing pages since their edits don't show up
1358 // next time they browse the page.
1360 // Now, we don't allow caching of pages without revalidation
1361 // (via the If-Modified-Since and/or If-None-Match request headers.)
1362 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
1363 // appropriate value in index.php, but I advise against it.)
1367 // o Even when request is aborted due to the content not being
1368 // modified, we currently still do almost all the work involved
1369 // in producing the page. So the only real savings from all
1370 // this logic is in network bandwidth.
1372 // o Plugins which produce "dynamic" output need to be inspected
1373 // and made to call $request->addToETag() and
1374 // $request->setModificationTime() appropriately, otherwise the
1375 // page can change without the change being detected.
1376 // This leads to stale pages in cache again...
1378 // Revision 1.69 2003/01/18 22:01:43 carstenklapp
1380 // Reformatting & tabs to spaces;
1381 // Added copyleft, getVersion, getDescription, rcs_id.
1384 // (c-file-style: "gnu")
1388 // c-basic-offset: 4
1389 // c-hanging-comment-ender-p: nil
1390 // indent-tabs-mode: nil