4 Copyright 1999,2000,2001,2002,2007 $ThePhpWikiProgrammingTeam
5 Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 This file is part of PhpWiki.
9 PhpWiki is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 PhpWiki is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with PhpWiki; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 include_once("lib/WikiPlugin.php");
26 class _RecentChanges_Formatter
28 var $_absurls = false;
29 var $action = "RecentChanges";
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;
45 extract($this->_args);
49 $title = $request->_user->getID();
51 $title = _("UserContribs").": $title";
55 $title = $request->_user->getID();
57 $title = _("UserContribs").": $title";
58 } elseif ($only_new) {
59 $title = _("RecentNewPages");
60 } elseif ($show_minor) {
61 $title = _("RecentEdits");
62 } else $title = _("RecentChanges");
64 if (!empty($category))
66 elseif (!empty($pagematch))
67 $title .= ":$pagematch";
71 function include_versions_in_URLs() {
72 return (bool) $this->_args['show_all'];
75 function date ($rev) {
77 return $WikiTheme->getDay($rev->get('mtime'));
80 function time ($rev) {
82 return $WikiTheme->formatTime($rev->get('mtime'));
85 function diffURL ($rev) {
86 $args = $this->_diffargs;
87 if ($this->include_versions_in_URLs())
88 $args['version'] = $rev->getVersion();
89 $page = $rev->getPage();
90 return WikiURL($page->getName(), $args, $this->_absurls);
93 function historyURL ($rev) {
94 $page = $rev->getPage();
95 return WikiURL($page, array('action' => _("PageHistory")),
99 function pageURL ($rev) {
100 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
101 '', $this->_absurls);
104 function authorHasPage ($author) {
105 global $WikiNameRegexp, $request;
106 $dbi = $request->getDbh();
107 return isWikiWord($author) && $dbi->isWikiPage($author);
110 function authorURL ($author) {
111 return $this->authorHasPage() ? WikiURL($author) : false;
115 function status ($rev) {
116 if ($rev->hasDefaultContents())
118 $page = $rev->getPage();
119 $prev = $page->getRevisionBefore($rev->getVersion());
120 if ($prev->hasDefaultContents())
125 function importance ($rev) {
126 return $rev->get('is_minor_edit') ? 'minor' : 'major';
129 function summary($rev) {
130 if ( ($summary = $rev->get('summary')) )
133 switch ($this->status($rev)) {
137 return _("New page");
143 function setValidators($most_recent_rev) {
144 $rev = $most_recent_rev;
145 $validators = array('RecentChanges-top' =>
146 array($rev->getPageName(), $rev->getVersion()),
147 '%mtime' => $rev->get('mtime'));
149 $request->appendValidators($validators);
153 class _RecentChanges_HtmlFormatter
154 extends _RecentChanges_Formatter
156 function diffLink ($rev) {
158 $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
159 $button->setAttr('rel', 'nofollow');
160 return HTML("(",$button,")");
163 /* deletions: red, additions: green */
164 function diffSummary ($rev) {
165 $html = $this->diffURL($rev);
169 function historyLink ($rev) {
171 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
172 $button->setAttr('rel', 'nofollow');
173 return HTML("(",$button,")");
176 function pageLink ($rev, $link_text=false) {
178 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
181 $page = $rev->getPage();
183 if ($this->include_versions_in_URLs()) {
184 $version = $rev->getVersion();
185 if ($rev->isCurrent())
187 $exists = !$rev->hasDefaultContents();
191 $cur = $page->getCurrentRevision();
192 $exists = !$cur->hasDefaultContents();
195 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
197 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
201 function authorLink ($rev) {
202 return WikiLink($rev->get('author'), 'if_known');
205 /* Link to all users contributions (contribs and owns) */
206 function authorContribs ($rev) {
207 $author = $rev->get('author');
208 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
210 Button(array('action' => _("RecentChanges"),
211 'format' => 'contribs',
217 Button(array('action' => _("RecentChanges"),
218 'format' => 'contribs',
226 function summaryAsHTML ($rev) {
227 if ( !($summary = $this->summary($rev)) )
229 return HTML::span( array('class' => 'wiki-summary'),
231 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
235 function format_icon ($format, $filter = array()) {
236 global $request, $WikiTheme;
237 $args = $this->_args;
238 // remove links not used for those formats
239 unset($args['daylist']);
240 unset($args['difflinks']);
241 unset($args['historylinks']);
242 $rss_url = $request->getURLtoSelf
244 array('action' => $this->action, 'format' => $format),
246 return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
249 function rss_icon ($args=array()) { return $this->format_icon("rss", $args); }
250 function rss2_icon ($args=array()) { return $this->format_icon("rss2", $args); }
251 function atom_icon ($args=array()) { return $this->format_icon("atom", $args); }
252 function rdf_icon ($args=array()) { return DEBUG ? $this->format_icon("rdf", $args) : ''; }
253 function rdfs_icon ($args=array()) { return DEBUG ? $this->format_icon("rdfs", $args) : ''; }
254 function owl_icon ($args=array()) { return DEBUG ? $this->format_icon("owl", $args) : ''; }
256 function grazr_icon ($args = array()) {
257 global $request, $WikiTheme;
258 if (is_localhost()) return '';
259 if (SERVER_PROTOCOL == "https") return '';
260 $our_url = WikiURL($request->getArg('pagename'),
261 array_merge(array('action' => $this->action, 'format' => 'rss2'), $args),
263 $rss_url = 'http://grazr.com/gzpanel.html?' . $our_url;
264 return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
267 function pre_description () {
268 extract($this->_args);
269 // FIXME: say something about show_all.
270 if ($show_major && $show_minor)
273 $edits = _("major edits");
275 $edits = _("minor edits");
276 if (isset($caption) and $caption == _("Recent Comments"))
277 $edits = _("comments");
278 if (!empty($only_new)) {
279 $edits = _("created new pages");
281 if (!empty($author)) {
284 $author = $request->_user->getID();
285 $edits .= sprintf(_(" for pages changed by %s"), $author);
287 if (!empty($owner)) {
290 $owner = $request->_user->getID();
291 $edits .= sprintf(_(" for pages owned by %s"), $owner);
293 if (!empty($category)) {
294 $edits .= sprintf(_(" for all pages linking to %s"), $category);
296 if (!empty($pagematch)) {
297 $edits .= sprintf(_(" for all pages matching '%s'"), $pagematch);
299 if ($timespan = $days > 0) {
300 if (intval($days) != $days)
301 $days = sprintf("%.1f", $days);
305 * Depending how this text is split up it can be tricky or
306 * impossible to translate with good grammar. So the seperate
307 * strings for 1 day and %s days are necessary in this case
308 * for translating to multiple languages, due to differing
309 * overlapping ideal word cutting points.
311 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
312 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
313 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
315 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
316 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
317 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
321 if (intval($days) == 1)
322 $desc = fmt("The %d most recent %s during the past day are listed below.",
325 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
326 $limit, $edits, $days);
328 $desc = fmt("The %d most recent %s are listed below.",
331 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
333 if (intval($days) == 1)
334 $desc = fmt("The %d oldest %s during the past day are listed below.",
337 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
338 $lmt, $edits, $days);
340 $desc = fmt("The %d oldest %s are listed below.",
346 if (intval($days) == 1)
347 $desc = fmt("The most recent %s during the past day are listed below.",
350 $desc = fmt("The most recent %s during the past %s days are listed below.",
353 $desc = fmt("All %s are listed below.", $edits);
358 function description() {
359 return HTML::p(false, $this->pre_description());
363 function headline () {
364 extract($this->_args);
365 return array($this->title(),
371 /*$this->rdfs_icon(),
374 $this->sidebar_link());
377 function empty_message() {
378 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
379 return _("No comments found");
381 return _("No changes found");
384 function sidebar_link() {
385 extract($this->_args);
386 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
389 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
392 "function addPanel() {\n"
393 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
394 ." \"$sidebarurl\",\"\");\n"
396 $jsf = JavaScript($addsidebarjsfunc);
399 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
400 array('title' => _("Click to add this feed to your sidebar"),
401 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
402 $addsidebarjsclick = asXML($sidebar_button);
403 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
404 ." (typeof window.sidebar.addPanel == 'function'))\n"
406 ." document.write('$addsidebarjsclick');\n"
409 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
412 function format ($changes) {
413 include_once('lib/InlineParser.php');
415 $html = HTML(HTML::h2(false, $this->headline()));
416 if (($desc = $this->description()))
417 $html->pushContent($desc);
419 if ($this->_args['daylist']) {
420 $html->pushContent(new OptionsButtonBars($this->_args));
427 while ($rev = $changes->next()) {
428 if (($date = $this->date($rev)) != $last_date) {
430 $html->pushContent($lines);
431 // for user contributions no extra date line
432 $html->pushContent(HTML::h3($date));
437 // enforce view permission
438 if (mayAccessPage('view', $rev->_pagename)) {
439 $lines->pushContent($this->format_revision($rev));
441 $this->setValidators($rev);
446 $html->pushContent($lines);
448 if ($this->_args['daylist'])
449 $html->pushContent // force display of OptionsButtonBars
451 ("document.getElementById('rc-action-body').style.display='block';"));
452 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
453 $this->empty_message()));
459 function format_revision ($rev) {
461 $args = &$this->_args;
463 $class = 'rc-' . $this->importance($rev);
465 $time = $this->time($rev);
466 if (! $rev->get('is_minor_edit'))
467 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
469 $line = HTML::li(array('class' => $class));
471 if ($args['difflinks'])
472 $line->pushContent($this->diffLink($rev), ' ');
474 if ($args['historylinks'])
475 $line->pushContent($this->historyLink($rev), ' ');
477 // Do not display a link for a deleted page, just the page name
478 if ($rev->hasDefaultContents()) {
479 $linkorname = $rev->_pagename;
481 $linkorname = $this->pageLink($rev);
484 if ((isa($WikiTheme, 'WikiTheme_MonoBook')) or (isa($WikiTheme, 'WikiTheme_gforge'))) {
486 $args['historylinks'] ? '' : $this->historyLink($rev),
487 ' . . ', $linkorname, '; ',
489 $this->authorLink($rev),' ',
490 $this->authorContribs($rev),' ',
491 $this->summaryAsHTML($rev));
493 $line->pushContent($linkorname, ' ',
495 $this->summaryAsHTML($rev),
497 $this->authorLink($rev));
504 /* format=contribs: no seperation into extra dates
505 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
507 class _RecentChanges_UserContribsFormatter
508 extends _RecentChanges_HtmlFormatter
510 function headline () {
512 extract($this->_args);
513 if ($author == '[]') $author = $request->_user->getID();
514 if ($owner == '[]') $owner = $request->_user->getID();
515 $author_args = $owner
516 ? array('owner' => $owner)
517 : array('author' => $author);
518 return array(_("UserContribs"),":",$owner ? $owner : $author,
520 $this->rss_icon($author_args),
521 $this->rss2_icon($author_args),
522 $this->atom_icon($author_args),
523 $this->rdf_icon($author_args),
524 $this->grazr_icon($author_args));
527 function format ($changes) {
528 include_once('lib/InlineParser.php');
530 $html = HTML(HTML::h2(false, $this->headline()));
532 $first = true; $count = 0;
533 while ($rev = $changes->next()) {
534 if (mayAccessPage('view', $rev->_pagename)) {
535 $lines->pushContent($this->format_revision($rev));
537 $this->setValidators($rev);
542 $this->_args['limit'] = $count;
543 if (($desc = $this->description()))
544 $html->pushContent($desc);
545 if ($this->_args['daylist']) {
546 $html->pushContent(new OptionsButtonBars($this->_args));
549 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
550 $this->empty_message()));
552 $html->pushContent($lines);
557 function format_revision ($rev) {
558 $args = &$this->_args;
559 $class = 'rc-' . $this->importance($rev);
560 $time = $this->time($rev);
561 if (! $rev->get('is_minor_edit'))
562 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
564 $line = HTML::li(array('class' => $class));
566 $line->pushContent($this->time($rev),", ");
567 $line->pushContent($this->date($rev)," ");
568 $line->pushContent($this->diffLink($rev), ' ');
569 $line->pushContent($this->historyLink($rev), ' ');
570 $line->pushContent($this->pageLink($rev), ' ',
571 $this->summaryAsHTML($rev));
576 class _RecentChanges_SideBarFormatter
577 extends _RecentChanges_HtmlFormatter
579 function rss_icon () {
582 function rss2_icon () { }
583 function headline () {
584 //title click opens the normal RC or RE page in the main browser frame
585 extract($this->_args);
586 $titlelink = WikiLink($this->title());
587 $titlelink->setAttr('target', '_content');
588 return HTML($this->logo(), $titlelink);
591 //logo click opens the HomePage in the main browser frame
593 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
596 'style' => 'height:2.5ex'
598 $linkurl = WikiLink(HOME_PAGE, false, $img);
599 $linkurl->setAttr('target', '_content');
603 function authorLink ($rev) {
604 $author = $rev->get('author');
605 if ( $this->authorHasPage($author) ) {
606 $linkurl = WikiLink($author);
607 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
613 function diffLink ($rev) {
614 $linkurl = parent::diffLink($rev);
615 $linkurl->setAttr('target', '_content');
616 $linkurl->setAttr('rel', 'nofollow');
617 // FIXME: Smelly hack to get smaller diff buttons in sidebar
618 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
621 function historyLink ($rev) {
622 $linkurl = parent::historyLink($rev);
623 $linkurl->setAttr('target', '_content');
624 // FIXME: Smelly hack to get smaller history buttons in sidebar
625 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
628 function pageLink ($rev) {
629 $linkurl = parent::pageLink($rev);
630 $linkurl->setAttr('target', '_content');
633 // Overriding summaryAsHTML, because there is no way yet to
634 // return summary as transformed text with
635 // links setAttr('target', '_content') in Mozilla sidebar.
636 // So for now don't create clickable links inside summary
637 // in the sidebar, or else they target the sidebar and not the
638 // main content window.
639 function summaryAsHTML ($rev) {
640 if ( !($summary = $this->summary($rev)) )
642 return HTML::span(array('class' => 'wiki-summary'),
644 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
649 function format ($changes) {
650 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
651 $html = _RecentChanges_HtmlFormatter::format ($changes);
652 $html = HTML::div(array('class' => 'wikitext'), $html);
654 $request->discardOutput();
656 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
657 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
658 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
659 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
662 extract($this->_args);
663 if (!empty($category))
665 elseif (!empty($pagematch))
668 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
669 printf("<title>" . $title . "</title>\n");
671 $css = $WikiTheme->getCSS();
675 printf("<body class=\"sidebar\">\n");
677 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>';
678 printf("\n</body>\n");
681 $request->finish(); // cut rest of page processing short
685 class _RecentChanges_BoxFormatter
686 extends _RecentChanges_HtmlFormatter
688 function rss_icon () {
690 function rss2_icon () {
692 function headline () {
694 function authorLink ($rev) {
696 function diffLink ($rev) {
698 function historyLink ($rev) {
700 function summaryAsHTML ($rev) {
702 function description () {
704 function format ($changes) {
705 include_once('lib/InlineParser.php');
710 $sp = HTML::Raw("\n · ");
711 while ($rev = $changes->next()) {
712 // enforce view permission
713 if (mayAccessPage('view',$rev->_pagename)) {
714 if ($link = $this->pageLink($rev)) // some entries may be empty
715 // (/Blog/.. interim pages)
716 $html->pushContent($sp, $link, HTML::br());
718 $this->setValidators($rev);
723 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
724 $this->empty_message()));
729 class _RecentChanges_RssFormatter
730 extends _RecentChanges_Formatter
732 var $_absurls = true;
734 function time ($rev) {
735 return Iso8601DateTime($rev->get('mtime'));
738 function pageURI ($rev) {
739 return WikiURL($rev, '', 'absurl');
742 function format ($changes) {
744 include_once('lib/RssWriter.php');
745 $rss = new RssWriter;
746 $rss->channel($this->channel_properties());
748 if (($props = $this->image_properties()))
750 if (($props = $this->textinput_properties()))
751 $rss->textinput($props);
754 while ($rev = $changes->next()) {
755 // enforce view permission
756 if (mayAccessPage('view', $rev->_pagename)) {
757 $rss->addItem($this->item_properties($rev),
758 $this->pageURI($rev));
760 $this->setValidators($rev);
766 $request->discardOutput();
768 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
769 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
771 // Flush errors in comment, otherwise it's invalid XML.
772 global $ErrorManager;
773 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
774 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
776 $request->finish(); // NORETURN!!!!
779 function image_properties () {
782 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
786 return array('title' => WIKI_NAME,
787 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
791 function textinput_properties () {
792 return array('title' => _("Search"),
793 'description' => _("Title Search"),
795 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
798 function channel_properties () {
801 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
802 extract($this->_args);
804 $description = $this->title();
809 return array('title' => $title,
811 'description' => $description,
812 'dc:date' => Iso8601DateTime(time()),
813 'dc:language' => $GLOBALS['LANG']);
815 /* FIXME: other things one might like in <channel>:
824 * rss091:managingEditor
826 * rss091:lastBuildDate
831 function item_properties ($rev) {
832 $page = $rev->getPage();
833 $pagename = $page->getName();
835 return array( 'title' => SplitPagename($pagename),
836 'description' => $this->summary($rev),
837 'link' => $this->pageURL($rev),
838 'dc:date' => $this->time($rev),
839 'dc:contributor' => $rev->get('author'),
840 'wiki:version' => $rev->getVersion(),
841 'wiki:importance' => $this->importance($rev),
842 'wiki:status' => $this->status($rev),
843 'wiki:diff' => $this->diffURL($rev),
844 'wiki:history' => $this->historyURL($rev)
849 /** explicit application/rss+xml Content-Type,
850 * simplified xml structure (no namespace),
851 * support for xml-rpc cloud registerProcedure (not yet)
853 class _RecentChanges_Rss2Formatter
854 extends _RecentChanges_RssFormatter {
856 function format ($changes) {
857 include_once('lib/RssWriter2.php');
858 $rss = new RssWriter2;
860 $rss->channel($this->channel_properties());
861 if (($props = $this->cloud_properties()))
863 if (($props = $this->image_properties()))
865 if (($props = $this->textinput_properties()))
866 $rss->textinput($props);
868 while ($rev = $changes->next()) {
869 // enforce view permission
870 if (mayAccessPage('view', $rev->_pagename)) {
871 $rss->addItem($this->item_properties($rev),
872 $this->pageURI($rev));
874 $this->setValidators($rev);
880 $request->discardOutput();
882 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
883 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
884 // Flush errors in comment, otherwise it's invalid XML.
885 global $ErrorManager;
886 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
887 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
889 $request->finish(); // NORETURN!!!!
892 function channel_properties () {
893 $chann_10 = parent::channel_properties();
894 return array_merge($chann_10,
895 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
896 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
897 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
898 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
899 'copyright' => COPYRIGHTPAGE_URL
903 // xml-rpc registerProcedure not yet implemented
904 function cloud_properties () { return false; }
905 function cloud_properties_test () {
906 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
907 'registerProcedure' => 'wiki.rssPleaseNotify',
908 'path' => DATA_PATH.'/RPC2.php',
909 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
910 'domain' => SERVER_NAME);
914 /** Explicit application/atom+xml Content-Type
915 * A weird, questionable format
917 class _RecentChanges_AtomFormatter
918 extends _RecentChanges_RssFormatter {
920 function format ($changes) {
922 include_once('lib/RssWriter.php');
925 // "channel" is called "feed" in atom
926 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
927 extract($this->_args);
929 $description = $this->title();
934 $feed_props = array('title' => $description,
935 'link' => array('rel'=>"alternate",
938 'id' => md5($rc_url),
939 'modified' => Iso8601DateTime(time()),
940 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
942 $rss->feed($feed_props);
944 while ($rev = $changes->next()) {
945 // enforce view permission
946 if (mayAccessPage('view', $rev->_pagename)) {
947 $props = $this->item_properties($rev);
948 $rss->addItem($props,
950 $this->pageURI($rev));
952 $this->setValidators($rev);
957 $request->discardOutput();
959 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
960 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
961 // Flush errors in comment, otherwise it's invalid XML.
962 global $ErrorManager;
963 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
964 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
966 $request->finish(); // NORETURN!!!!
969 function item_properties ($rev) {
970 $page = $rev->getPage();
971 $pagename = $page->getName();
972 return array( 'title' => $pagename,
973 'link' => array('rel' => 'alternate',
974 'type' => 'text/html',
975 'href' => $this->pageURL($rev)),
976 'summary' => $this->summary($rev),
977 'modified' => $this->time($rev)."Z",
978 'issued' => $this->time($rev),
979 'created' => $this->time($rev)."Z",
980 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
986 * Filter by non-empty
988 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
992 * @param $revisions object a WikiDB_PageRevisionIterator.
994 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
995 $this->_revisions = $revisions;
996 $this->_check_current_revision = $check_current_revision;
1000 while (($rev = $this->_revisions->next())) {
1001 if ($this->_check_current_revision) {
1002 $page = $rev->getPage();
1003 $check_rev = $page->getCurrentRevision();
1008 if (! $check_rev->hasDefaultContents())
1018 * Filter by only_new.
1019 * Only new created pages
1021 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1025 * @param $revisions object a WikiDB_PageRevisionIterator.
1027 function NewPageRevisionIterator ($revisions) {
1028 $this->_revisions = $revisions;
1032 while (($rev = $this->_revisions->next())) {
1033 if ($rev->getVersion() == 1)
1042 * Only pages with links to a certain category
1044 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1046 function LinkRevisionIterator ($revisions, $category) {
1047 $this->_revisions = $revisions;
1048 if (preg_match("/[\?\.\*]/", $category)) {
1049 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1050 (new TextSearchQuery("*", true),
1051 new TextSearchQuery($category, true),
1054 $basepage = $GLOBALS['request']->getPage($category);
1055 $backlinkiter = $basepage->getBackLinks(true);
1057 $this->links = array();
1058 foreach ($backlinkiter->asArray() as $p) {
1059 if (is_object($p)) $this->links[] = $p->getName();
1060 elseif (is_array($p)) $this->links[] = $p['pagename'];
1061 else $this->links[] = $p;
1063 $backlinkiter->free();
1068 while (($rev = $this->_revisions->next())) {
1069 if (binary_search($rev->getName(), $this->links) != false)
1077 unset ($this->links);
1081 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1083 function PageMatchRevisionIterator ($revisions, $match) {
1084 $this->_revisions = $revisions;
1085 $this->search = new TextSearchQuery($match, true);
1089 while (($rev = $this->_revisions->next())) {
1090 if ($this->search->match($rev->getName()))
1098 unset ($this->search);
1105 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1107 function AuthorPageRevisionIterator ($revisions, $author) {
1108 $this->_revisions = $revisions;
1109 $this->_author = $author;
1113 while (($rev = $this->_revisions->next())) {
1114 if ($rev->get('author_id') == $this->_author)
1125 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1127 function OwnerPageRevisionIterator ($revisions, $owner) {
1128 $this->_revisions = $revisions;
1129 $this->_owner = $owner;
1133 while (($rev = $this->_revisions->next())) {
1134 $page = $rev->getPage();
1135 if ($page->getOwner() == $this->_owner)
1143 class WikiPlugin_RecentChanges
1146 function getName () {
1147 return _("RecentChanges");
1150 function getDescription () {
1151 return _("List all recent changes in this wiki.");
1154 function getVersion() {
1155 return preg_replace("/[Revision: $]/", '',
1159 function managesValidators() {
1160 // Note that this is a bit of a fig.
1161 // We set validators based on the most recently changed page,
1162 // but this fails when the most-recent page is deleted.
1163 // (Consider that the Last-Modified time will decrease
1164 // when this happens.)
1166 // We might be better off, leaving this as false (and junking
1167 // the validator logic above) and just falling back to the
1168 // default behavior (handled by WikiPlugin) of just using
1169 // the WikiDB global timestamp as the mtime.
1171 // Nevertheless, for now, I leave this here, mostly as an
1172 // example for how to use appendValidators() and managesValidators().
1177 function getDefaultArguments() {
1178 return array('days' => 2,
1179 'show_minor' => false,
1180 'show_major' => true,
1181 'show_all' => false,
1182 'show_deleted' => 'sometimes',
1183 'only_new' => false,
1189 'difflinks' => true,
1190 'historylinks' => false,
1197 function getArgs ($argstr, $request, $defaults = false) {
1198 if (!$defaults) $defaults = $this->getDefaultArguments();
1199 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1201 $action = $request->getArg('action');
1202 if ($action != 'browse' && ! $request->isActionPage($action))
1203 $args['format'] = false; // default -> HTML
1205 if ($args['format'] == 'rss' && empty($args['limit']))
1206 $args['limit'] = 15; // Fix default value for RSS.
1207 if ($args['format'] == 'rss2' && empty($args['limit']))
1208 $args['limit'] = 15; // Fix default value for RSS2.
1210 if ($args['format'] == 'sidebar' && empty($args['limit']))
1211 $args['limit'] = 10; // Fix default value for sidebar.
1216 function getMostRecentParams (&$args) {
1217 $show_all = false; $show_minor = false; $show_major = false;
1221 $params = array('include_minor_revisions' => $show_minor,
1222 'exclude_major_revisions' => !$show_major,
1223 'include_all_revisions' => !empty($show_all));
1225 $params['limit'] = $limit;
1226 if (!empty($args['author'])) {
1228 if ($args['author'] == '[]')
1229 $args['author'] = $request->_user->getID();
1230 $params['author'] = $args['author'];
1232 if (!empty($args['owner'])) {
1234 if ($args['owner'] == '[]')
1235 $args['owner'] = $request->_user->getID();
1236 $params['owner'] = $args['owner'];
1238 if (!empty($days)) {
1240 $params['since'] = time() - 24 * 3600 * $days;
1241 elseif ($days < 0.0)
1242 $params['since'] = 24 * 3600 * $days - time();
1248 function getChanges ($dbi, $args) {
1249 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1251 $show_deleted = @$args['show_deleted'];
1252 $show_all = @$args['show_all'];
1253 if ($show_deleted == 'sometimes')
1254 $show_deleted = @$args['show_minor'];
1256 // only pages (e.g. PageHistory of subpages)
1257 if (!empty($args['pagematch'])) {
1258 require_once("lib/TextSearchQuery.php");
1259 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1261 if (!empty($args['category'])) {
1262 require_once("lib/TextSearchQuery.php");
1263 $changes = new LinkRevisionIterator($changes, $args['category']);
1265 if (!empty($args['only_new']))
1266 $changes = new NewPageRevisionIterator($changes);
1267 if (!empty($args['author']))
1268 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1269 if (!empty($args['owner']))
1270 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1272 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1277 function format ($changes, $args) {
1279 $format = $args['format'];
1281 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1283 if ($format == 'rss')
1284 $fmt_class = '_RecentChanges_RssFormatter';
1285 elseif ($format == 'rss2')
1286 $fmt_class = '_RecentChanges_Rss2Formatter';
1287 elseif ($format == 'atom')
1288 $fmt_class = '_RecentChanges_AtomFormatter';
1289 elseif ($format == 'rss091') {
1290 include_once "lib/RSSWriter091.php";
1291 $fmt_class = '_RecentChanges_RssFormatter091';
1293 elseif ($format == 'sidebar')
1294 $fmt_class = '_RecentChanges_SideBarFormatter';
1295 elseif ($format == 'box')
1296 $fmt_class = '_RecentChanges_BoxFormatter';
1297 elseif ($format == 'contribs')
1298 $fmt_class = '_RecentChanges_UserContribsFormatter';
1300 $fmt_class = '_RecentChanges_HtmlFormatter';
1303 $fmt = new $fmt_class($args);
1304 return $fmt->format($changes);
1307 function run($dbi, $argstr, &$request, $basepage) {
1308 $args = $this->getArgs($argstr, $request);
1310 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1311 // to be enough for anyone.)
1312 $args['days'] = min($args['days'], 365000);
1314 // Within Categories just display Category Backlinks
1315 if (empty($args['category']) and empty($args['pagematch'])
1316 and preg_match("/^Category/", $request->getArg('pagename')))
1318 $args['category'] = $request->getArg('pagename');
1321 // Hack alert: format() is a NORETURN for rss formatters.
1322 return $this->format($this->getChanges($dbi, $args), $args);
1325 // box is used to display a fixed-width, narrow version with common header.
1326 // just a numbered list of limit pagenames, without date.
1327 function box($args = false, $request = false, $basepage = false) {
1328 if (!$request) $request =& $GLOBALS['request'];
1329 if (!isset($args['limit'])) $args['limit'] = 15;
1330 $args['format'] = 'box';
1331 $args['show_minor'] = false;
1332 $args['show_major'] = true;
1333 $args['show_deleted'] = 'sometimes';
1334 $args['show_all'] = false;
1336 return $this->makeBox(WikiLink($this->getName(),'',
1337 SplitPagename($this->getName())),
1339 ($this->getChanges($request->_dbi, $args), $args));
1344 class OptionsButtonBars extends HtmlElement {
1346 function OptionsButtonBars ($plugin_args) {
1347 $this->__construct('fieldset', array('class' => 'wiki-rc-action'));
1349 // Add ShowHideFolder button
1350 $icon = $GLOBALS['WikiTheme']->_findData('images/folderArrowOpen.png');
1351 $img = HTML::img(array('id' => 'rc-action-img',
1353 'onclick' => "showHideFolder('rc-action')",
1354 'alt' => _("Click to hide/show"),
1355 'title' => _("Click to hide/show")));
1357 // Display selection buttons
1358 extract($plugin_args);
1362 $caption = _("Show changes for:");
1365 $this->pushContent(HTML::legend($caption,' ',$img));
1366 $table = HTML::table(array('id' => 'rc-action-body',
1367 'style' => 'display:block'));
1370 foreach (explode(",", $daylist) as $days) {
1371 $tr->pushContent($this->_makeDayButton($days));
1373 $table->pushContent($tr);
1376 $tr->pushContent($this->_makeUsersButton(0));
1377 $tr->pushContent($this->_makeUsersButton(1));
1378 $table->pushContent($tr);
1381 $tr->pushContent($this->_makePagesButton(0));
1382 $tr->pushContent($this->_makePagesButton(1));
1383 $table->pushContent($tr);
1386 $tr->pushContent($this->_makeMinorButton(1));
1387 $tr->pushContent($this->_makeMinorButton(0));
1388 $table->pushContent($tr);
1391 $tr->pushContent($this->_makeShowAllButton(1));
1392 $tr->pushContent($this->_makeShowAllButton(0));
1393 $table->pushContent($tr);
1396 $tr->pushContent($this->_makeNewPagesButton(0));
1397 $tr->pushContent($this->_makeNewPagesButton(1));
1398 $table->pushContent($tr);
1400 $this->pushContent($table);
1403 function _makeDayButton ($days) {
1407 $label = _("1 day");
1409 $label = _("All time");
1411 $label = sprintf(_("%s days"), abs($days));
1413 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1414 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1415 if ($url == $selfurl) {
1416 return HTML::td(array('class'=>'tdselected'), $label);
1418 return HTML::td(array('class'=>'tdunselected'),
1419 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1422 function _makeUsersButton ($users) {
1426 $label = _("All users");
1429 $label = _("My modifications only");
1433 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1434 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
1435 if ($url == $selfurl) {
1436 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1438 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1439 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1442 function _makePagesButton ($pages) {
1446 $label = _("All pages");
1449 $label = _("My pages only");
1453 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1454 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1455 if ($url == $selfurl) {
1456 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1458 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1459 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1462 function _makeMinorButton ($minor) {
1466 $label = _("Major modifications only");
1468 $label = _("All modifications");
1471 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1472 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor));
1473 if ($url == $selfurl) {
1474 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1476 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1477 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1480 function _makeShowAllButton ($showall) {
1483 if ($showall == 0) {
1484 $label = _("Page once only");
1486 $label = _("Full changes");
1489 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1490 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall));
1491 if ($url == $selfurl) {
1492 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1494 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1495 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1498 function _makeNewPagesButton ($newpages) {
1501 if ($newpages == 0) {
1502 $label = _("Old and new pages");
1504 $label = _("New pages only");
1507 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1508 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages));
1509 if ($url == $selfurl) {
1510 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1513 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1514 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1518 // (c-file-style: "gnu")
1522 // c-basic-offset: 4
1523 // c-hanging-comment-ender-p: nil
1524 // indent-tabs-mode: nil