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 along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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)
33 $this->_args = $rc_args;
34 $this->_diffargs = array('action' => 'diff');
36 if ($rc_args['show_minor'] || !$rc_args['show_major'])
37 $this->_diffargs['previous'] = 'minor';
39 // PageHistoryPlugin doesn't have a 'daylist' arg.
40 if (!isset($this->_args['daylist']))
41 $this->_args['daylist'] = false;
47 extract($this->_args);
51 $title = $request->_user->getID();
53 $title = _("UserContribs") . ": $title";
57 $title = $request->_user->getID();
59 $title = _("UserContribs") . ": $title";
60 } elseif ($only_new) {
61 $title = _("RecentNewPages");
62 } elseif ($show_minor) {
63 $title = _("RecentEdits");
64 } else $title = _("RecentChanges");
66 if (!empty($category))
68 elseif (!empty($pagematch))
69 $title .= ":$pagematch";
73 function include_versions_in_URLs()
75 return (bool)$this->_args['show_all'];
81 return $WikiTheme->getDay($rev->get('mtime'));
87 return $WikiTheme->formatTime($rev->get('mtime'));
90 function diffURL($rev)
92 $args = $this->_diffargs;
93 if ($this->include_versions_in_URLs())
94 $args['version'] = $rev->getVersion();
95 $page = $rev->getPage();
96 return WikiURL($page->getName(), $args, $this->_absurls);
99 function historyURL($rev)
101 $page = $rev->getPage();
102 return WikiURL($page, array('action' => _("PageHistory")),
106 function pageURL($rev)
108 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
109 '', $this->_absurls);
112 function authorHasPage($author)
115 $dbi = $request->getDbh();
116 return isWikiWord($author) && $dbi->isWikiPage($author);
119 function authorURL($author)
121 return $this->authorHasPage() ? WikiURL($author) : false;
124 function status($rev)
126 if ($rev->hasDefaultContents())
128 $page = $rev->getPage();
129 $prev = $page->getRevisionBefore($rev->getVersion());
130 if ($prev->hasDefaultContents())
135 function importance($rev)
137 return $rev->get('is_minor_edit') ? 'minor' : 'major';
140 function summary($rev)
142 if (($summary = $rev->get('summary')))
145 switch ($this->status($rev)) {
149 return _("New page");
155 function setValidators($most_recent_rev)
157 $rev = $most_recent_rev;
158 $validators = array('RecentChanges-top' =>
159 array($rev->getPageName(), $rev->getVersion()),
160 '%mtime' => $rev->get('mtime'));
162 $request->appendValidators($validators);
166 class _RecentChanges_HtmlFormatter
167 extends _RecentChanges_Formatter
169 function diffLink($rev)
172 $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
173 $button->setAttr('rel', 'nofollow');
174 return HTML("(", $button, ")");
177 /* deletions: red, additions: green */
178 function diffSummary($rev)
180 $html = $this->diffURL($rev);
184 function historyLink($rev)
187 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
188 $button->setAttr('rel', 'nofollow');
189 return HTML("(", $button, ")");
192 function pageLink($rev, $link_text = false)
195 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
198 $page = $rev->getPage();
200 if ($this->include_versions_in_URLs()) {
201 $version = $rev->getVersion();
202 if ($rev->isCurrent())
204 $exists = !$rev->hasDefaultContents();
208 $cur = $page->getCurrentRevision();
209 $exists = !$cur->hasDefaultContents();
212 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
214 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
218 function authorLink($rev)
220 return WikiLink($rev->get('author'), 'if_known');
223 /* Link to all users contributions (contribs and owns) */
224 function authorContribs($rev)
226 $author = $rev->get('author');
227 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
229 Button(array('action' => _("RecentChanges"),
230 'format' => 'contribs',
236 Button(array('action' => _("RecentChanges"),
237 'format' => 'contribs',
245 function summaryAsHTML($rev)
247 if (!($summary = $this->summary($rev)))
249 return HTML::span(array('class' => 'wiki-summary'),
251 // TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
252 // We do parse the summary:
253 // 1) if the summary contains {{foo}}, the template must no be
255 // 2) if the summary contains camel case, and DISABLE_MARKUP_WIKIWORD
256 // is true, the camel case must not be linked.
257 // Side-effect: brackets are not linked. TBD.
262 function format_icon($format, $filter = array())
264 global $request, $WikiTheme;
265 $args = $this->_args;
266 // remove links not used for those formats
267 unset($args['daylist']);
268 unset($args['difflinks']);
269 unset($args['historylinks']);
270 $rss_url = $request->getURLtoSelf
272 array('action' => $this->action, 'format' => $format),
274 return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
277 function rss_icon($args = array())
279 return $this->format_icon("rss", $args);
282 function rss2_icon($args = array())
284 return $this->format_icon("rss2", $args);
287 function atom_icon($args = array())
289 return $this->format_icon("atom", $args);
292 function rdf_icon($args = array())
294 return DEBUG ? $this->format_icon("rdf", $args) : '';
297 function rdfs_icon($args = array())
299 return DEBUG ? $this->format_icon("rdfs", $args) : '';
302 function owl_icon($args = array())
304 return DEBUG ? $this->format_icon("owl", $args) : '';
307 function grazr_icon($args = array())
309 global $request, $WikiTheme;
310 if (is_localhost()) return '';
311 if (SERVER_PROTOCOL == "https") return '';
312 $our_url = WikiURL($request->getArg('pagename'),
313 array_merge(array('action' => $this->action, 'format' => 'rss2'), $args),
315 $rss_url = 'http://grazr.com/gzpanel.html?' . $our_url;
316 return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
319 function pre_description()
321 extract($this->_args);
322 // FIXME: say something about show_all.
323 if ($show_major && $show_minor)
326 $edits = _("major edits"); else
327 $edits = _("minor edits");
328 if (isset($caption) and $caption == _("Recent Comments"))
329 $edits = _("comments");
330 if (!empty($only_new)) {
331 $edits = _("created new pages");
333 if (!empty($author)) {
336 $author = $request->_user->getID();
337 $edits .= sprintf(_(" for pages changed by %s"), $author);
339 if (!empty($owner)) {
342 $owner = $request->_user->getID();
343 $edits .= sprintf(_(" for pages owned by %s"), $owner);
345 if (!empty($category)) {
346 $edits .= sprintf(_(" for all pages linking to %s"), $category);
348 if (!empty($pagematch)) {
349 $edits .= sprintf(_(" for all pages matching “%s”"), $pagematch);
351 if ($timespan = $days > 0) {
352 if (intval($days) != $days)
353 $days = sprintf("%.1f", $days);
357 * Depending how this text is split up it can be tricky or
358 * impossible to translate with good grammar. So the separate
359 * strings for 1 day and %s days are necessary in this case
360 * for translating to multiple languages, due to differing
361 * overlapping ideal word cutting points.
363 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
364 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
365 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
367 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
368 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
369 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
373 if (intval($days) == 1)
374 $desc = fmt("The %d most recent %s during the past day are listed below.",
377 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
378 $limit, $edits, $days);
380 $desc = fmt("The %d most recent %s are listed below.",
382 } elseif ($limit < 0) { //$limit < 0 means we want oldest pages
384 if (intval($days) == 1)
385 $desc = fmt("The %d oldest %s during the past day are listed below.",
388 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
389 $lmt, $edits, $days);
391 $desc = fmt("The %d oldest %s are listed below.",
395 if (intval($days) == 1)
396 $desc = fmt("The most recent %s during the past day are listed below.",
399 $desc = fmt("The most recent %s during the past %s days are listed below.",
402 $desc = fmt("All %s are listed below.", $edits);
407 function description()
409 return HTML::p(false, $this->pre_description());
415 extract($this->_args);
416 return array($this->title(),
422 /*$this->rdfs_icon(),
425 $this->sidebar_link());
428 function empty_message()
430 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
431 return _("No comments found");
433 return _("No changes found");
436 function sidebar_link()
438 extract($this->_args);
439 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
441 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
444 "function addPanel() {\n"
445 . " window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
446 . " \"$sidebarurl\",\"\");\n"
448 $jsf = JavaScript($addsidebarjsfunc);
451 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
452 array('title' => _("Click to add this feed to your sidebar"),
453 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
454 $addsidebarjsclick = asXML($sidebar_button);
455 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
456 . " (typeof window.sidebar.addPanel == 'function'))\n"
458 . " document.write('$addsidebarjsclick');\n"
461 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
464 function format($changes)
466 include_once 'lib/InlineParser.php';
468 $html = HTML(HTML::h2(false, $this->headline()));
469 if (($desc = $this->description()))
470 $html->pushContent($desc);
472 if ($this->_args['daylist']) {
473 $html->pushContent(new OptionsButtonBars($this->_args));
480 while ($rev = $changes->next()) {
481 if (($date = $this->date($rev)) != $last_date) {
483 $html->pushContent($lines);
484 // for user contributions no extra date line
485 $html->pushContent(HTML::h3($date));
490 // enforce view permission
491 if (mayAccessPage('view', $rev->_pagename)) {
492 $lines->pushContent($this->format_revision($rev));
494 $this->setValidators($rev);
499 $html->pushContent($lines);
501 if ($this->_args['daylist'])
502 $html->pushContent // force display of OptionsButtonBars
504 ("document.getElementById('rc-action-body').style.display='block';"));
505 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
506 $this->empty_message()));
512 function format_revision($rev)
515 $args = &$this->_args;
517 $class = 'rc-' . $this->importance($rev);
519 $time = $this->time($rev);
520 if ($rev->get('is_minor_edit')) {
521 $minor_flag = HTML(" ",
522 HTML::span(array('class' => 'pageinfo-minoredit'),
523 "(" . _("minor edit") . ")"));
525 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
529 $line = HTML::li(array('class' => $class));
531 if ($args['difflinks'])
532 $line->pushContent($this->diffLink($rev), ' ');
534 if ($args['historylinks'])
535 $line->pushContent($this->historyLink($rev), ' ');
537 // Do not display a link for a deleted page, just the page name
538 if ($rev->hasDefaultContents()) {
539 $linkorname = $rev->_pagename;
541 $linkorname = $this->pageLink($rev);
544 if ((isa($WikiTheme, 'WikiTheme_MonoBook')) or (isa($WikiTheme, 'WikiTheme_fusionforge'))) {
546 $args['historylinks'] ? '' : $this->historyLink($rev),
547 ' . . ', $linkorname, '; ',
549 $this->authorLink($rev), ' ',
550 $this->authorContribs($rev), ' ',
551 $this->summaryAsHTML($rev), ' ',
554 $line->pushContent($linkorname, ' ',
556 $this->summaryAsHTML($rev),
558 $this->authorLink($rev));
565 /* format=contribs: no seperation into extra dates
566 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
568 class _RecentChanges_UserContribsFormatter
569 extends _RecentChanges_HtmlFormatter
574 extract($this->_args);
575 if ($author == '[]') $author = $request->_user->getID();
576 if ($owner == '[]') $owner = $request->_user->getID();
577 $author_args = $owner
578 ? array('owner' => $owner)
579 : array('author' => $author);
580 return array(_("UserContribs"), ":", $owner ? $owner : $author,
582 $this->rss_icon($author_args),
583 $this->rss2_icon($author_args),
584 $this->atom_icon($author_args),
585 $this->rdf_icon($author_args),
586 $this->grazr_icon($author_args));
589 function format($changes)
591 include_once 'lib/InlineParser.php';
593 $html = HTML(HTML::h2(false, $this->headline()));
597 while ($rev = $changes->next()) {
598 if (mayAccessPage('view', $rev->_pagename)) {
599 $lines->pushContent($this->format_revision($rev));
601 $this->setValidators($rev);
606 $this->_args['limit'] = $count;
607 if (($desc = $this->description()))
608 $html->pushContent($desc);
609 if ($this->_args['daylist']) {
610 $html->pushContent(new OptionsButtonBars($this->_args));
613 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
614 $this->empty_message()));
616 $html->pushContent($lines);
621 function format_revision($rev)
623 $args = &$this->_args;
624 $class = 'rc-' . $this->importance($rev);
625 $time = $this->time($rev);
626 if (!$rev->get('is_minor_edit'))
627 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
629 $line = HTML::li(array('class' => $class));
631 $line->pushContent($this->time($rev), ", ");
632 $line->pushContent($this->date($rev), " ");
633 $line->pushContent($this->diffLink($rev), ' ');
634 $line->pushContent($this->historyLink($rev), ' ');
635 $line->pushContent($this->pageLink($rev), ' ',
636 $this->summaryAsHTML($rev));
641 class _RecentChanges_SideBarFormatter
642 extends _RecentChanges_HtmlFormatter
644 function rss_icon($args = array())
649 function rss2_icon($args = array())
655 //title click opens the normal RC or RE page in the main browser frame
656 extract($this->_args);
657 $titlelink = WikiLink($this->title());
658 $titlelink->setAttr('target', '_content');
659 return HTML($this->logo(), $titlelink);
664 //logo click opens the HomePage in the main browser frame
666 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
668 'style' => 'height:2.5ex'
670 $linkurl = WikiLink(HOME_PAGE, false, $img);
671 $linkurl->setAttr('target', '_content');
675 function authorLink($rev)
677 $author = $rev->get('author');
678 if ($this->authorHasPage($author)) {
679 $linkurl = WikiLink($author);
680 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
686 function diffLink($rev)
688 $linkurl = parent::diffLink($rev);
689 $linkurl->setAttr('target', '_content');
690 $linkurl->setAttr('rel', 'nofollow');
691 // FIXME: Smelly hack to get smaller diff buttons in sidebar
692 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
696 function historyLink($rev)
698 $linkurl = parent::historyLink($rev);
699 $linkurl->setAttr('target', '_content');
700 // FIXME: Smelly hack to get smaller history buttons in sidebar
701 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
705 function pageLink($rev, $link_text = false)
707 $linkurl = parent::pageLink($rev);
708 $linkurl->setAttr('target', '_content');
712 // Overriding summaryAsHTML, because there is no way yet to
713 // return summary as transformed text with
714 // links setAttr('target', '_content') in Mozilla sidebar.
715 // So for now don't create clickable links inside summary
716 // in the sidebar, or else they target the sidebar and not the
717 // main content window.
718 function summaryAsHTML($rev)
720 if (!($summary = $this->summary($rev)))
722 return HTML::span(array('class' => 'wiki-summary'),
725 $summary, /* $rev->get('markup')),*/
729 function format($changes)
731 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
732 $html = _RecentChanges_HtmlFormatter::format($changes);
733 $html = HTML::div(array('class' => 'wikitext'), $html);
735 $request->discardOutput();
737 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
738 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
739 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
740 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
743 extract($this->_args);
744 if (!empty($category))
746 elseif (!empty($pagematch))
747 $title = $pagematch; else
748 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
749 printf("<title>" . $title . "</title>\n");
751 $css = $WikiTheme->getCSS();
755 printf("<body class=\"sidebar\">\n");
757 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>';
758 printf("\n</body>\n");
761 $request->finish(); // cut rest of page processing short
765 class _RecentChanges_BoxFormatter
766 extends _RecentChanges_HtmlFormatter
768 function rss_icon($args = array())
772 function rss2_icon($args = array())
780 function authorLink($rev)
784 function diffLink($rev)
788 function historyLink($rev)
792 function summaryAsHTML($rev)
796 function description()
800 function format($changes)
802 include_once 'lib/InlineParser.php';
804 while ($rev = $changes->next()) {
805 // enforce view permission
806 if (mayAccessPage('view', $rev->_pagename)) {
807 if ($link = $this->pageLink($rev)) // some entries may be empty
808 // (/Blog/.. interim pages)
809 $html->pushContent(HTML::li($link));
811 $this->setValidators($rev);
816 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
817 $this->empty_message()));
822 class _RecentChanges_RssFormatter
823 extends _RecentChanges_Formatter
825 var $_absurls = true;
829 return Iso8601DateTime($rev->get('mtime'));
832 function pageURI($rev)
834 return WikiURL($rev, '', 'absurl');
837 function format($changes)
840 include_once 'lib/RssWriter.php';
841 $rss = new RssWriter;
842 $rss->channel($this->channel_properties());
844 if (($props = $this->image_properties()))
846 if (($props = $this->textinput_properties()))
847 $rss->textinput($props);
850 while ($rev = $changes->next()) {
851 // enforce view permission
852 if (mayAccessPage('view', $rev->_pagename)) {
853 $rss->addItem($this->item_properties($rev),
854 $this->pageURI($rev));
856 $this->setValidators($rev);
862 $request->discardOutput();
864 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
865 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
867 // Flush errors in comment, otherwise it's invalid XML.
868 global $ErrorManager;
869 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
870 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
872 $request->finish(); // NORETURN!!!!
875 function image_properties()
879 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
883 return array('title' => WIKI_NAME,
884 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
888 function textinput_properties()
890 return array('title' => _("Search"),
891 'description' => _("Title Search"),
893 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
896 function channel_properties()
900 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
901 extract($this->_args);
903 $description = $this->title();
908 return array('title' => $title,
910 'description' => $description,
911 'dc:date' => Iso8601DateTime(time()),
912 'dc:language' => $GLOBALS['LANG']);
914 /* FIXME: other things one might like in <channel>:
923 * rss091:managingEditor
925 * rss091:lastBuildDate
930 function item_properties($rev)
932 $page = $rev->getPage();
933 $pagename = $page->getName();
935 return array('title' => SplitPagename($pagename),
936 'description' => $this->summary($rev),
937 'link' => $this->pageURL($rev),
938 'dc:date' => $this->time($rev),
939 'dc:contributor' => $rev->get('author'),
940 'wiki:version' => $rev->getVersion(),
941 'wiki:importance' => $this->importance($rev),
942 'wiki:status' => $this->status($rev),
943 'wiki:diff' => $this->diffURL($rev),
944 'wiki:history' => $this->historyURL($rev)
949 /** explicit application/rss+xml Content-Type,
950 * simplified xml structure (no namespace),
951 * support for xml-rpc cloud registerProcedure (not yet)
953 class _RecentChanges_Rss2Formatter
954 extends _RecentChanges_RssFormatter
957 function format($changes)
959 include_once 'lib/RssWriter2.php';
960 $rss = new RssWriter2;
962 $rss->channel($this->channel_properties());
963 if (($props = $this->cloud_properties()))
965 if (($props = $this->image_properties()))
967 if (($props = $this->textinput_properties()))
968 $rss->textinput($props);
970 while ($rev = $changes->next()) {
971 // enforce view permission
972 if (mayAccessPage('view', $rev->_pagename)) {
973 $rss->addItem($this->item_properties($rev),
974 $this->pageURI($rev));
976 $this->setValidators($rev);
982 $request->discardOutput();
984 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
985 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
986 // Flush errors in comment, otherwise it's invalid XML.
987 global $ErrorManager;
988 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
989 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
991 $request->finish(); // NORETURN!!!!
994 function channel_properties()
996 $chann_10 = parent::channel_properties();
997 return array_merge($chann_10,
998 array('generator' => 'PhpWiki-' . PHPWIKI_VERSION,
999 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
1000 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
1001 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
1002 'copyright' => COPYRIGHTPAGE_URL
1006 // xml-rpc registerProcedure not yet implemented
1007 function cloud_properties()
1012 function cloud_properties_test()
1014 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
1015 'registerProcedure' => 'wiki.rssPleaseNotify',
1016 'path' => DATA_PATH . '/RPC2.php',
1017 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
1018 'domain' => SERVER_NAME);
1022 /** Explicit application/atom+xml Content-Type
1023 * A weird, questionable format
1025 class _RecentChanges_AtomFormatter
1026 extends _RecentChanges_RssFormatter
1029 function format($changes)
1032 include_once 'lib/RssWriter.php';
1033 $rss = new AtomFeed;
1035 // "channel" is called "feed" in atom
1036 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
1037 extract($this->_args);
1038 $description = $this->title();
1039 $feed_props = array('title' => $description,
1040 'link' => array('rel' => "alternate",
1041 'type' => "text/html",
1043 'id' => md5($rc_url),
1044 'modified' => Iso8601DateTime(time()),
1045 'generator' => 'PhpWiki-' . PHPWIKI_VERSION,
1047 $rss->feed($feed_props);
1049 while ($rev = $changes->next()) {
1050 // enforce view permission
1051 if (mayAccessPage('view', $rev->_pagename)) {
1052 $props = $this->item_properties($rev);
1053 $rss->addItem($props,
1055 $this->pageURI($rev));
1057 $this->setValidators($rev);
1062 $request->discardOutput();
1064 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
1065 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
1066 // Flush errors in comment, otherwise it's invalid XML.
1067 global $ErrorManager;
1068 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
1069 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
1071 $request->finish(); // NORETURN!!!!
1074 function item_properties($rev)
1076 $page = $rev->getPage();
1077 $pagename = $page->getName();
1078 return array('title' => $pagename,
1079 'link' => array('rel' => 'alternate',
1080 'type' => 'text/html',
1081 'href' => $this->pageURL($rev)),
1082 'summary' => $this->summary($rev),
1083 'modified' => $this->time($rev) . "Z",
1084 'issued' => $this->time($rev),
1085 'created' => $this->time($rev) . "Z",
1086 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
1092 * Filter by non-empty
1094 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
1098 * @param $revisions object a WikiDB_PageRevisionIterator.
1099 * @param bool $check_current_revision
1102 function NonDeletedRevisionIterator($revisions, $check_current_revision = true)
1104 $this->_revisions = $revisions;
1105 $this->_check_current_revision = $check_current_revision;
1110 while (($rev = $this->_revisions->next())) {
1111 if ($this->_check_current_revision) {
1112 $page = $rev->getPage();
1113 $check_rev = $page->getCurrentRevision();
1117 if (!$check_rev->hasDefaultContents())
1127 * Filter by only_new.
1128 * Only new created pages
1130 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1134 * @param $revisions object a WikiDB_PageRevisionIterator.
1136 function NewPageRevisionIterator($revisions)
1138 $this->_revisions = $revisions;
1143 while (($rev = $this->_revisions->next())) {
1144 if ($rev->getVersion() == 1)
1153 * Only pages with links to a certain category
1155 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1157 function LinkRevisionIterator($revisions, $category)
1159 $this->_revisions = $revisions;
1160 if (preg_match("/[\?\.\*]/", $category)) {
1161 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1162 (new TextSearchQuery("*", true),
1163 new TextSearchQuery($category, true),
1166 $basepage = $GLOBALS['request']->getPage($category);
1167 $backlinkiter = $basepage->getBackLinks(true);
1169 $this->links = array();
1170 foreach ($backlinkiter->asArray() as $p) {
1171 if (is_object($p)) $this->links[] = $p->getName();
1172 elseif (is_array($p)) $this->links[] = $p['pagename']; else $this->links[] = $p;
1174 $backlinkiter->free();
1180 while (($rev = $this->_revisions->next())) {
1181 if (binary_search($rev->getName(), $this->links) != false)
1190 unset ($this->links);
1194 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1196 function PageMatchRevisionIterator($revisions, $match)
1198 $this->_revisions = $revisions;
1199 $this->search = new TextSearchQuery($match, true);
1204 while (($rev = $this->_revisions->next())) {
1205 if ($this->search->match($rev->getName()))
1214 unset ($this->search);
1221 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1223 function AuthorPageRevisionIterator($revisions, $author)
1225 $this->_revisions = $revisions;
1226 $this->_author = $author;
1231 while (($rev = $this->_revisions->next())) {
1232 if ($rev->get('author_id') == $this->_author)
1243 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1245 function OwnerPageRevisionIterator($revisions, $owner)
1247 $this->_revisions = $revisions;
1248 $this->_owner = $owner;
1253 while (($rev = $this->_revisions->next())) {
1254 $page = $rev->getPage();
1255 if ($page->getOwner() == $this->_owner)
1263 class WikiPlugin_RecentChanges
1268 return _("RecentChanges");
1271 function getDescription()
1273 return _("List all recent changes in this wiki.");
1276 function managesValidators()
1278 // Note that this is a bit of a fig.
1279 // We set validators based on the most recently changed page,
1280 // but this fails when the most-recent page is deleted.
1281 // (Consider that the Last-Modified time will decrease
1282 // when this happens.)
1284 // We might be better off, leaving this as false (and junking
1285 // the validator logic above) and just falling back to the
1286 // default behavior (handled by WikiPlugin) of just using
1287 // the WikiDB global timestamp as the mtime.
1289 // Nevertheless, for now, I leave this here, mostly as an
1290 // example for how to use appendValidators() and managesValidators().
1295 function getDefaultArguments()
1297 return array('days' => 2,
1298 'show_minor' => false,
1299 'show_major' => true,
1300 'show_all' => false,
1301 'show_deleted' => 'sometimes',
1302 'only_new' => false,
1308 'difflinks' => true,
1309 'historylinks' => false,
1316 function getArgs($argstr, $request, $defaults = false)
1318 if (!$defaults) $defaults = $this->getDefaultArguments();
1319 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1321 $action = $request->getArg('action');
1322 if ($action != 'browse' && !isActionPage($action))
1323 $args['format'] = false; // default -> HTML
1325 if ($args['format'] == 'rss' && empty($args['limit']))
1326 $args['limit'] = 15; // Fix default value for RSS.
1327 if ($args['format'] == 'rss2' && empty($args['limit']))
1328 $args['limit'] = 15; // Fix default value for RSS2.
1330 if ($args['format'] == 'sidebar' && empty($args['limit']))
1331 $args['limit'] = 10; // Fix default value for sidebar.
1336 function getMostRecentParams(&$args)
1339 $show_minor = false;
1340 $show_major = false;
1344 $params = array('include_minor_revisions' => $show_minor,
1345 'exclude_major_revisions' => !$show_major,
1346 'include_all_revisions' => !empty($show_all));
1348 $params['limit'] = $limit;
1349 if (!empty($args['author'])) {
1351 if ($args['author'] == '[]')
1352 $args['author'] = $request->_user->getID();
1353 $params['author'] = $args['author'];
1355 if (!empty($args['owner'])) {
1357 if ($args['owner'] == '[]')
1358 $args['owner'] = $request->_user->getID();
1359 $params['owner'] = $args['owner'];
1361 if (!empty($days)) {
1363 $params['since'] = time() - 24 * 3600 * $days;
1364 elseif ($days < 0.0)
1365 $params['since'] = 24 * 3600 * $days - time();
1371 function getChanges($dbi, $args)
1373 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1375 $show_deleted = @$args['show_deleted'];
1376 $show_all = @$args['show_all'];
1377 if ($show_deleted == 'sometimes')
1378 $show_deleted = @$args['show_minor'];
1380 // only pages (e.g. PageHistory of subpages)
1381 if (!empty($args['pagematch'])) {
1382 require_once 'lib/TextSearchQuery.php';
1383 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1385 if (!empty($args['category'])) {
1386 require_once 'lib/TextSearchQuery.php';
1387 $changes = new LinkRevisionIterator($changes, $args['category']);
1389 if (!empty($args['only_new']))
1390 $changes = new NewPageRevisionIterator($changes);
1391 if (!empty($args['author']))
1392 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1393 if (!empty($args['owner']))
1394 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1396 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1401 function format($changes, $args)
1404 $format = $args['format'];
1406 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1408 if ($format == 'rss')
1409 $fmt_class = '_RecentChanges_RssFormatter';
1410 elseif ($format == 'rss2')
1411 $fmt_class = '_RecentChanges_Rss2Formatter'; elseif ($format == 'atom')
1412 $fmt_class = '_RecentChanges_AtomFormatter'; elseif ($format == 'rss091') {
1413 include_once 'lib/RSSWriter091.php';
1414 $fmt_class = '_RecentChanges_RssFormatter091';
1415 } elseif ($format == 'sidebar')
1416 $fmt_class = '_RecentChanges_SideBarFormatter'; elseif ($format == 'box')
1417 $fmt_class = '_RecentChanges_BoxFormatter'; elseif ($format == 'contribs')
1418 $fmt_class = '_RecentChanges_UserContribsFormatter'; else
1419 $fmt_class = '_RecentChanges_HtmlFormatter';
1422 $fmt = new $fmt_class($args);
1423 return $fmt->format($changes);
1426 function run($dbi, $argstr, &$request, $basepage)
1428 $args = $this->getArgs($argstr, $request);
1430 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1431 // to be enough for anyone.)
1432 $args['days'] = min($args['days'], 365000);
1434 // Within Categories just display Category Backlinks
1435 if (empty($args['category']) and empty($args['pagematch'])
1436 and preg_match("/^Category/", $request->getArg('pagename'))
1438 $args['category'] = $request->getArg('pagename');
1441 // Hack alert: format() is a NORETURN for rss formatters.
1442 return $this->format($this->getChanges($dbi, $args), $args);
1445 // box is used to display a fixed-width, narrow version with common header.
1446 // just a numbered list of limit pagenames, without date.
1447 function box($args = false, $request = false, $basepage = false)
1449 if (!$request) $request =& $GLOBALS['request'];
1450 if (!isset($args['limit'])) $args['limit'] = 15;
1451 $args['format'] = 'box';
1452 $args['show_minor'] = false;
1453 $args['show_major'] = true;
1454 $args['show_deleted'] = 'sometimes';
1455 $args['show_all'] = false;
1457 return $this->makeBox(WikiLink($this->getName(), '',
1458 SplitPagename($this->getName())),
1460 ($this->getChanges($request->_dbi, $args), $args));
1465 class OptionsButtonBars extends HtmlElement
1468 function OptionsButtonBars($plugin_args)
1470 $this->__construct('fieldset', array('class' => 'wiki-rc-action'));
1472 // Add ShowHideFolder button
1473 $icon = $GLOBALS['WikiTheme']->_findData('images/folderArrowOpen.png');
1474 $img = HTML::img(array('id' => 'rc-action-img',
1476 'onclick' => "showHideFolder('rc-action')",
1477 'alt' => _("Click to hide/show"),
1478 'title' => _("Click to hide/show")));
1480 // Display selection buttons
1481 extract($plugin_args);
1485 $caption = _("Show changes for:");
1488 $this->pushContent(HTML::legend($caption, ' ', $img));
1489 $table = HTML::table(array('id' => 'rc-action-body',
1490 'style' => 'display:block'));
1493 foreach (explode(",", $daylist) as $days_button) {
1494 $tr->pushContent($this->_makeDayButton($days_button, $days));
1496 $table->pushContent($tr);
1499 $tr->pushContent($this->_makeUsersButton(0));
1500 $tr->pushContent($this->_makeUsersButton(1));
1501 $table->pushContent($tr);
1504 $tr->pushContent($this->_makePagesButton(0));
1505 $tr->pushContent($this->_makePagesButton(1));
1506 $table->pushContent($tr);
1509 $tr->pushContent($this->_makeMinorButton(1, $show_minor));
1510 $tr->pushContent($this->_makeMinorButton(0, $show_minor));
1511 $table->pushContent($tr);
1514 $tr->pushContent($this->_makeShowAllButton(1, $show_all));
1515 $tr->pushContent($this->_makeShowAllButton(0, $show_all));
1516 $table->pushContent($tr);
1519 $tr->pushContent($this->_makeNewPagesButton(0, $only_new));
1520 $tr->pushContent($this->_makeNewPagesButton(1, $only_new));
1521 $table->pushContent($tr);
1523 $this->pushContent($table);
1526 function _makeDayButton($days_button, $days)
1530 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days_button));
1531 if ($days_button == 1) {
1532 $label = _("1 day");
1533 } elseif ($days_button < 1) {
1534 $label = _("All time");
1536 $label = sprintf(_("%s days"), abs($days_button));
1538 $selected = HTML::td(array('class' => 'tdselected'), $label);
1539 $unselected = HTML::td(array('class' => 'tdunselected'),
1540 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1541 return ($days_button == $days) ? $selected : $unselected;
1544 function _makeUsersButton($users)
1549 $label = _("All users");
1552 $label = _("My modifications only");
1556 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1557 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
1558 if ($url == $selfurl) {
1559 return HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1561 return HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1562 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1565 function _makePagesButton($pages)
1570 $label = _("All pages");
1573 $label = _("My pages only");
1577 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1578 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1579 if ($url == $selfurl) {
1580 return HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1582 return HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1583 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1586 function _makeMinorButton($minor_button, $show_minor)
1590 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor_button));
1591 $label = ($minor_button == 0) ? _("Major modifications only") : _("All modifications");
1592 $selected = HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1593 $unselected = HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1594 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1595 return ($minor_button == $show_minor) ? $selected : $unselected;
1598 function _makeShowAllButton($showall_button, $show_all)
1602 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall_button));
1603 $label = ($showall_button == 0) ? _("Page once only") : _("Full changes");
1604 $selected = HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1605 $unselected = HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1606 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1607 return ($showall_button == $show_all) ? $selected : $unselected;
1610 function _makeNewPagesButton($newpages_button, $only_new)
1614 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages_button));
1615 $label = ($newpages_button == 0) ? _("Old and new pages") : _("New pages only");
1616 $selected = HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1617 $unselected = HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1618 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1619 return ($newpages_button == $only_new) ? $selected : $unselected;
1626 // c-basic-offset: 4
1627 // c-hanging-comment-ender-p: nil
1628 // indent-tabs-mode: nil