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)
114 global $WikiNameRegexp, $request;
115 $dbi = $request->getDbh();
116 return isWikiWord($author) && $dbi->isWikiPage($author);
119 function authorURL($author)
121 return $this->authorHasPage() ? WikiURL($author) : false;
125 function status($rev)
127 if ($rev->hasDefaultContents())
129 $page = $rev->getPage();
130 $prev = $page->getRevisionBefore($rev->getVersion());
131 if ($prev->hasDefaultContents())
136 function importance($rev)
138 return $rev->get('is_minor_edit') ? 'minor' : 'major';
141 function summary($rev)
143 if (($summary = $rev->get('summary')))
146 switch ($this->status($rev)) {
150 return _("New page");
156 function setValidators($most_recent_rev)
158 $rev = $most_recent_rev;
159 $validators = array('RecentChanges-top' =>
160 array($rev->getPageName(), $rev->getVersion()),
161 '%mtime' => $rev->get('mtime'));
163 $request->appendValidators($validators);
167 class _RecentChanges_HtmlFormatter
168 extends _RecentChanges_Formatter
170 function diffLink($rev)
173 $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
174 $button->setAttr('rel', 'nofollow');
175 return HTML("(", $button, ")");
178 /* deletions: red, additions: green */
179 function diffSummary($rev)
181 $html = $this->diffURL($rev);
185 function historyLink($rev)
188 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
189 $button->setAttr('rel', 'nofollow');
190 return HTML("(", $button, ")");
193 function pageLink($rev, $link_text = false)
196 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
199 $page = $rev->getPage();
201 if ($this->include_versions_in_URLs()) {
202 $version = $rev->getVersion();
203 if ($rev->isCurrent())
205 $exists = !$rev->hasDefaultContents();
209 $cur = $page->getCurrentRevision();
210 $exists = !$cur->hasDefaultContents();
213 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
215 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
219 function authorLink($rev)
221 return WikiLink($rev->get('author'), 'if_known');
224 /* Link to all users contributions (contribs and owns) */
225 function authorContribs($rev)
227 $author = $rev->get('author');
228 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
230 Button(array('action' => _("RecentChanges"),
231 'format' => 'contribs',
237 Button(array('action' => _("RecentChanges"),
238 'format' => 'contribs',
246 function summaryAsHTML($rev)
248 if (!($summary = $this->summary($rev)))
250 return HTML::span(array('class' => 'wiki-summary'),
252 // TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
253 // We do parse the summary:
254 // 1) if the summary contains {{foo}}, the template must no be
256 // 2) if the summary contains camel case, and DISABLE_MARKUP_WIKIWORD
257 // is true, the camel case must not be linked.
258 // Side-effect: brackets are not linked. TBD.
263 function format_icon($format, $filter = array())
265 global $request, $WikiTheme;
266 $args = $this->_args;
267 // remove links not used for those formats
268 unset($args['daylist']);
269 unset($args['difflinks']);
270 unset($args['historylinks']);
271 $rss_url = $request->getURLtoSelf
273 array('action' => $this->action, 'format' => $format),
275 return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
278 function rss_icon($args = array())
280 return $this->format_icon("rss", $args);
283 function rss2_icon($args = array())
285 return $this->format_icon("rss2", $args);
288 function atom_icon($args = array())
290 return $this->format_icon("atom", $args);
293 function rdf_icon($args = array())
295 return DEBUG ? $this->format_icon("rdf", $args) : '';
298 function rdfs_icon($args = array())
300 return DEBUG ? $this->format_icon("rdfs", $args) : '';
303 function owl_icon($args = array())
305 return DEBUG ? $this->format_icon("owl", $args) : '';
308 function grazr_icon($args = array())
310 global $request, $WikiTheme;
311 if (is_localhost()) return '';
312 if (SERVER_PROTOCOL == "https") return '';
313 $our_url = WikiURL($request->getArg('pagename'),
314 array_merge(array('action' => $this->action, 'format' => 'rss2'), $args),
316 $rss_url = 'http://grazr.com/gzpanel.html?' . $our_url;
317 return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
320 function pre_description()
322 extract($this->_args);
323 // FIXME: say something about show_all.
324 if ($show_major && $show_minor)
327 $edits = _("major edits"); else
328 $edits = _("minor edits");
329 if (isset($caption) and $caption == _("Recent Comments"))
330 $edits = _("comments");
331 if (!empty($only_new)) {
332 $edits = _("created new pages");
334 if (!empty($author)) {
337 $author = $request->_user->getID();
338 $edits .= sprintf(_(" for pages changed by %s"), $author);
340 if (!empty($owner)) {
343 $owner = $request->_user->getID();
344 $edits .= sprintf(_(" for pages owned by %s"), $owner);
346 if (!empty($category)) {
347 $edits .= sprintf(_(" for all pages linking to %s"), $category);
349 if (!empty($pagematch)) {
350 $edits .= sprintf(_(" for all pages matching '%s'"), $pagematch);
352 if ($timespan = $days > 0) {
353 if (intval($days) != $days)
354 $days = sprintf("%.1f", $days);
358 * Depending how this text is split up it can be tricky or
359 * impossible to translate with good grammar. So the seperate
360 * strings for 1 day and %s days are necessary in this case
361 * for translating to multiple languages, due to differing
362 * overlapping ideal word cutting points.
364 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
365 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
366 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
368 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
369 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
370 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
374 if (intval($days) == 1)
375 $desc = fmt("The %d most recent %s during the past day are listed below.",
378 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
379 $limit, $edits, $days);
381 $desc = fmt("The %d most recent %s are listed below.",
383 } elseif ($limit < 0) { //$limit < 0 means we want oldest pages
385 if (intval($days) == 1)
386 $desc = fmt("The %d oldest %s during the past day are listed below.",
389 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
390 $lmt, $edits, $days);
392 $desc = fmt("The %d oldest %s are listed below.",
396 if (intval($days) == 1)
397 $desc = fmt("The most recent %s during the past day are listed below.",
400 $desc = fmt("The most recent %s during the past %s days are listed below.",
403 $desc = fmt("All %s are listed below.", $edits);
408 function description()
410 return HTML::p(false, $this->pre_description());
416 extract($this->_args);
417 return array($this->title(),
423 /*$this->rdfs_icon(),
426 $this->sidebar_link());
429 function empty_message()
431 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
432 return _("No comments found");
434 return _("No changes found");
437 function sidebar_link()
439 extract($this->_args);
440 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
443 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
446 "function addPanel() {\n"
447 . " window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
448 . " \"$sidebarurl\",\"\");\n"
450 $jsf = JavaScript($addsidebarjsfunc);
453 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
454 array('title' => _("Click to add this feed to your sidebar"),
455 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
456 $addsidebarjsclick = asXML($sidebar_button);
457 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
458 . " (typeof window.sidebar.addPanel == 'function'))\n"
460 . " document.write('$addsidebarjsclick');\n"
463 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
466 function format($changes)
468 include_once 'lib/InlineParser.php';
470 $html = HTML(HTML::h2(false, $this->headline()));
471 if (($desc = $this->description()))
472 $html->pushContent($desc);
474 if ($this->_args['daylist']) {
475 $html->pushContent(new OptionsButtonBars($this->_args));
482 while ($rev = $changes->next()) {
483 if (($date = $this->date($rev)) != $last_date) {
485 $html->pushContent($lines);
486 // for user contributions no extra date line
487 $html->pushContent(HTML::h3($date));
492 // enforce view permission
493 if (mayAccessPage('view', $rev->_pagename)) {
494 $lines->pushContent($this->format_revision($rev));
496 $this->setValidators($rev);
501 $html->pushContent($lines);
503 if ($this->_args['daylist'])
504 $html->pushContent // force display of OptionsButtonBars
506 ("document.getElementById('rc-action-body').style.display='block';"));
507 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
508 $this->empty_message()));
514 function format_revision($rev)
517 $args = &$this->_args;
519 $class = 'rc-' . $this->importance($rev);
521 $time = $this->time($rev);
522 if ($rev->get('is_minor_edit')) {
523 $minor_flag = HTML(" ",
524 HTML::span(array('class' => 'pageinfo-minoredit'),
525 "(" . _("minor edit") . ")"));
527 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
531 $line = HTML::li(array('class' => $class));
533 if ($args['difflinks'])
534 $line->pushContent($this->diffLink($rev), ' ');
536 if ($args['historylinks'])
537 $line->pushContent($this->historyLink($rev), ' ');
539 // Do not display a link for a deleted page, just the page name
540 if ($rev->hasDefaultContents()) {
541 $linkorname = $rev->_pagename;
543 $linkorname = $this->pageLink($rev);
546 if ((isa($WikiTheme, 'WikiTheme_MonoBook')) or (isa($WikiTheme, 'WikiTheme_fusionforge'))) {
548 $args['historylinks'] ? '' : $this->historyLink($rev),
549 ' . . ', $linkorname, '; ',
551 $this->authorLink($rev), ' ',
552 $this->authorContribs($rev), ' ',
553 $this->summaryAsHTML($rev), ' ',
556 $line->pushContent($linkorname, ' ',
558 $this->summaryAsHTML($rev),
560 $this->authorLink($rev));
567 /* format=contribs: no seperation into extra dates
568 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
570 class _RecentChanges_UserContribsFormatter
571 extends _RecentChanges_HtmlFormatter
576 extract($this->_args);
577 if ($author == '[]') $author = $request->_user->getID();
578 if ($owner == '[]') $owner = $request->_user->getID();
579 $author_args = $owner
580 ? array('owner' => $owner)
581 : array('author' => $author);
582 return array(_("UserContribs"), ":", $owner ? $owner : $author,
584 $this->rss_icon($author_args),
585 $this->rss2_icon($author_args),
586 $this->atom_icon($author_args),
587 $this->rdf_icon($author_args),
588 $this->grazr_icon($author_args));
591 function format($changes)
593 include_once 'lib/InlineParser.php';
595 $html = HTML(HTML::h2(false, $this->headline()));
599 while ($rev = $changes->next()) {
600 if (mayAccessPage('view', $rev->_pagename)) {
601 $lines->pushContent($this->format_revision($rev));
603 $this->setValidators($rev);
608 $this->_args['limit'] = $count;
609 if (($desc = $this->description()))
610 $html->pushContent($desc);
611 if ($this->_args['daylist']) {
612 $html->pushContent(new OptionsButtonBars($this->_args));
615 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
616 $this->empty_message()));
618 $html->pushContent($lines);
623 function format_revision($rev)
625 $args = &$this->_args;
626 $class = 'rc-' . $this->importance($rev);
627 $time = $this->time($rev);
628 if (!$rev->get('is_minor_edit'))
629 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
631 $line = HTML::li(array('class' => $class));
633 $line->pushContent($this->time($rev), ", ");
634 $line->pushContent($this->date($rev), " ");
635 $line->pushContent($this->diffLink($rev), ' ');
636 $line->pushContent($this->historyLink($rev), ' ');
637 $line->pushContent($this->pageLink($rev), ' ',
638 $this->summaryAsHTML($rev));
643 class _RecentChanges_SideBarFormatter
644 extends _RecentChanges_HtmlFormatter
657 //title click opens the normal RC or RE page in the main browser frame
658 extract($this->_args);
659 $titlelink = WikiLink($this->title());
660 $titlelink->setAttr('target', '_content');
661 return HTML($this->logo(), $titlelink);
666 //logo click opens the HomePage in the main browser frame
668 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
670 'style' => 'height:2.5ex'
672 $linkurl = WikiLink(HOME_PAGE, false, $img);
673 $linkurl->setAttr('target', '_content');
677 function authorLink($rev)
679 $author = $rev->get('author');
680 if ($this->authorHasPage($author)) {
681 $linkurl = WikiLink($author);
682 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
688 function diffLink($rev)
690 $linkurl = parent::diffLink($rev);
691 $linkurl->setAttr('target', '_content');
692 $linkurl->setAttr('rel', 'nofollow');
693 // FIXME: Smelly hack to get smaller diff buttons in sidebar
694 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
698 function historyLink($rev)
700 $linkurl = parent::historyLink($rev);
701 $linkurl->setAttr('target', '_content');
702 // FIXME: Smelly hack to get smaller history buttons in sidebar
703 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
707 function pageLink($rev)
709 $linkurl = parent::pageLink($rev);
710 $linkurl->setAttr('target', '_content');
714 // Overriding summaryAsHTML, because there is no way yet to
715 // return summary as transformed text with
716 // links setAttr('target', '_content') in Mozilla sidebar.
717 // So for now don't create clickable links inside summary
718 // in the sidebar, or else they target the sidebar and not the
719 // main content window.
720 function summaryAsHTML($rev)
722 if (!($summary = $this->summary($rev)))
724 return HTML::span(array('class' => 'wiki-summary'),
727 $summary, /* $rev->get('markup')),*/
732 function format($changes)
734 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
735 $html = _RecentChanges_HtmlFormatter::format($changes);
736 $html = HTML::div(array('class' => 'wikitext'), $html);
738 $request->discardOutput();
740 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
741 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
742 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
743 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
746 extract($this->_args);
747 if (!empty($category))
749 elseif (!empty($pagematch))
750 $title = $pagematch; else
751 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
752 printf("<title>" . $title . "</title>\n");
754 $css = $WikiTheme->getCSS();
758 printf("<body class=\"sidebar\">\n");
760 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>';
761 printf("\n</body>\n");
764 $request->finish(); // cut rest of page processing short
768 class _RecentChanges_BoxFormatter
769 extends _RecentChanges_HtmlFormatter
783 function authorLink($rev)
787 function diffLink($rev)
791 function historyLink($rev)
795 function summaryAsHTML($rev)
799 function description()
803 function format($changes)
805 include_once 'lib/InlineParser.php';
810 $sp = HTML::Raw("\n · ");
811 while ($rev = $changes->next()) {
812 // enforce view permission
813 if (mayAccessPage('view', $rev->_pagename)) {
814 if ($link = $this->pageLink($rev)) // some entries may be empty
815 // (/Blog/.. interim pages)
816 $html->pushContent($sp, $link, HTML::br());
818 $this->setValidators($rev);
823 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
824 $this->empty_message()));
829 class _RecentChanges_RssFormatter
830 extends _RecentChanges_Formatter
832 var $_absurls = true;
836 return Iso8601DateTime($rev->get('mtime'));
839 function pageURI($rev)
841 return WikiURL($rev, '', 'absurl');
844 function format($changes)
847 include_once 'lib/RssWriter.php';
848 $rss = new RssWriter;
849 $rss->channel($this->channel_properties());
851 if (($props = $this->image_properties()))
853 if (($props = $this->textinput_properties()))
854 $rss->textinput($props);
857 while ($rev = $changes->next()) {
858 // enforce view permission
859 if (mayAccessPage('view', $rev->_pagename)) {
860 $rss->addItem($this->item_properties($rev),
861 $this->pageURI($rev));
863 $this->setValidators($rev);
869 $request->discardOutput();
871 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
872 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
874 // Flush errors in comment, otherwise it's invalid XML.
875 global $ErrorManager;
876 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
877 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
879 $request->finish(); // NORETURN!!!!
882 function image_properties()
886 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
890 return array('title' => WIKI_NAME,
891 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
895 function textinput_properties()
897 return array('title' => _("Search"),
898 'description' => _("Title Search"),
900 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
903 function channel_properties()
907 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
908 extract($this->_args);
910 $description = $this->title();
915 return array('title' => $title,
917 'description' => $description,
918 'dc:date' => Iso8601DateTime(time()),
919 'dc:language' => $GLOBALS['LANG']);
921 /* FIXME: other things one might like in <channel>:
930 * rss091:managingEditor
932 * rss091:lastBuildDate
937 function item_properties($rev)
939 $page = $rev->getPage();
940 $pagename = $page->getName();
942 return array('title' => SplitPagename($pagename),
943 'description' => $this->summary($rev),
944 'link' => $this->pageURL($rev),
945 'dc:date' => $this->time($rev),
946 'dc:contributor' => $rev->get('author'),
947 'wiki:version' => $rev->getVersion(),
948 'wiki:importance' => $this->importance($rev),
949 'wiki:status' => $this->status($rev),
950 'wiki:diff' => $this->diffURL($rev),
951 'wiki:history' => $this->historyURL($rev)
956 /** explicit application/rss+xml Content-Type,
957 * simplified xml structure (no namespace),
958 * support for xml-rpc cloud registerProcedure (not yet)
960 class _RecentChanges_Rss2Formatter
961 extends _RecentChanges_RssFormatter
964 function format($changes)
966 include_once 'lib/RssWriter2.php';
967 $rss = new RssWriter2;
969 $rss->channel($this->channel_properties());
970 if (($props = $this->cloud_properties()))
972 if (($props = $this->image_properties()))
974 if (($props = $this->textinput_properties()))
975 $rss->textinput($props);
977 while ($rev = $changes->next()) {
978 // enforce view permission
979 if (mayAccessPage('view', $rev->_pagename)) {
980 $rss->addItem($this->item_properties($rev),
981 $this->pageURI($rev));
983 $this->setValidators($rev);
989 $request->discardOutput();
991 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
992 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
993 // Flush errors in comment, otherwise it's invalid XML.
994 global $ErrorManager;
995 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
996 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
998 $request->finish(); // NORETURN!!!!
1001 function channel_properties()
1003 $chann_10 = parent::channel_properties();
1004 return array_merge($chann_10,
1005 array('generator' => 'PhpWiki-' . PHPWIKI_VERSION,
1006 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
1007 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
1008 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
1009 'copyright' => COPYRIGHTPAGE_URL
1013 // xml-rpc registerProcedure not yet implemented
1014 function cloud_properties()
1019 function cloud_properties_test()
1021 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
1022 'registerProcedure' => 'wiki.rssPleaseNotify',
1023 'path' => DATA_PATH . '/RPC2.php',
1024 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
1025 'domain' => SERVER_NAME);
1029 /** Explicit application/atom+xml Content-Type
1030 * A weird, questionable format
1032 class _RecentChanges_AtomFormatter
1033 extends _RecentChanges_RssFormatter
1036 function format($changes)
1039 include_once 'lib/RssWriter.php';
1040 $rss = new AtomFeed;
1042 // "channel" is called "feed" in atom
1043 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
1044 extract($this->_args);
1046 $description = $this->title();
1050 $title = $pagematch;
1051 $feed_props = array('title' => $description,
1052 'link' => array('rel' => "alternate",
1053 'type' => "text/html",
1055 'id' => md5($rc_url),
1056 'modified' => Iso8601DateTime(time()),
1057 'generator' => 'PhpWiki-' . PHPWIKI_VERSION,
1059 $rss->feed($feed_props);
1061 while ($rev = $changes->next()) {
1062 // enforce view permission
1063 if (mayAccessPage('view', $rev->_pagename)) {
1064 $props = $this->item_properties($rev);
1065 $rss->addItem($props,
1067 $this->pageURI($rev));
1069 $this->setValidators($rev);
1074 $request->discardOutput();
1076 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
1077 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
1078 // Flush errors in comment, otherwise it's invalid XML.
1079 global $ErrorManager;
1080 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
1081 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
1083 $request->finish(); // NORETURN!!!!
1086 function item_properties($rev)
1088 $page = $rev->getPage();
1089 $pagename = $page->getName();
1090 return array('title' => $pagename,
1091 'link' => array('rel' => 'alternate',
1092 'type' => 'text/html',
1093 'href' => $this->pageURL($rev)),
1094 'summary' => $this->summary($rev),
1095 'modified' => $this->time($rev) . "Z",
1096 'issued' => $this->time($rev),
1097 'created' => $this->time($rev) . "Z",
1098 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
1104 * Filter by non-empty
1106 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
1110 * @param $revisions object a WikiDB_PageRevisionIterator.
1111 * @param bool $check_current_revision
1114 function NonDeletedRevisionIterator($revisions, $check_current_revision = true)
1116 $this->_revisions = $revisions;
1117 $this->_check_current_revision = $check_current_revision;
1122 while (($rev = $this->_revisions->next())) {
1123 if ($this->_check_current_revision) {
1124 $page = $rev->getPage();
1125 $check_rev = $page->getCurrentRevision();
1129 if (!$check_rev->hasDefaultContents())
1139 * Filter by only_new.
1140 * Only new created pages
1142 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1146 * @param $revisions object a WikiDB_PageRevisionIterator.
1148 function NewPageRevisionIterator($revisions)
1150 $this->_revisions = $revisions;
1155 while (($rev = $this->_revisions->next())) {
1156 if ($rev->getVersion() == 1)
1165 * Only pages with links to a certain category
1167 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1169 function LinkRevisionIterator($revisions, $category)
1171 $this->_revisions = $revisions;
1172 if (preg_match("/[\?\.\*]/", $category)) {
1173 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1174 (new TextSearchQuery("*", true),
1175 new TextSearchQuery($category, true),
1178 $basepage = $GLOBALS['request']->getPage($category);
1179 $backlinkiter = $basepage->getBackLinks(true);
1181 $this->links = array();
1182 foreach ($backlinkiter->asArray() as $p) {
1183 if (is_object($p)) $this->links[] = $p->getName();
1184 elseif (is_array($p)) $this->links[] = $p['pagename']; else $this->links[] = $p;
1186 $backlinkiter->free();
1192 while (($rev = $this->_revisions->next())) {
1193 if (binary_search($rev->getName(), $this->links) != false)
1202 unset ($this->links);
1206 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1208 function PageMatchRevisionIterator($revisions, $match)
1210 $this->_revisions = $revisions;
1211 $this->search = new TextSearchQuery($match, true);
1216 while (($rev = $this->_revisions->next())) {
1217 if ($this->search->match($rev->getName()))
1226 unset ($this->search);
1233 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1235 function AuthorPageRevisionIterator($revisions, $author)
1237 $this->_revisions = $revisions;
1238 $this->_author = $author;
1243 while (($rev = $this->_revisions->next())) {
1244 if ($rev->get('author_id') == $this->_author)
1255 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1257 function OwnerPageRevisionIterator($revisions, $owner)
1259 $this->_revisions = $revisions;
1260 $this->_owner = $owner;
1265 while (($rev = $this->_revisions->next())) {
1266 $page = $rev->getPage();
1267 if ($page->getOwner() == $this->_owner)
1275 class WikiPlugin_RecentChanges
1280 return _("RecentChanges");
1283 function getDescription()
1285 return _("List all recent changes in this wiki.");
1288 function managesValidators()
1290 // Note that this is a bit of a fig.
1291 // We set validators based on the most recently changed page,
1292 // but this fails when the most-recent page is deleted.
1293 // (Consider that the Last-Modified time will decrease
1294 // when this happens.)
1296 // We might be better off, leaving this as false (and junking
1297 // the validator logic above) and just falling back to the
1298 // default behavior (handled by WikiPlugin) of just using
1299 // the WikiDB global timestamp as the mtime.
1301 // Nevertheless, for now, I leave this here, mostly as an
1302 // example for how to use appendValidators() and managesValidators().
1307 function getDefaultArguments()
1309 return array('days' => 2,
1310 'show_minor' => false,
1311 'show_major' => true,
1312 'show_all' => false,
1313 'show_deleted' => 'sometimes',
1314 'only_new' => false,
1320 'difflinks' => true,
1321 'historylinks' => false,
1328 function getArgs($argstr, $request, $defaults = false)
1330 if (!$defaults) $defaults = $this->getDefaultArguments();
1331 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1333 $action = $request->getArg('action');
1334 if ($action != 'browse' && !isActionPage($action))
1335 $args['format'] = false; // default -> HTML
1337 if ($args['format'] == 'rss' && empty($args['limit']))
1338 $args['limit'] = 15; // Fix default value for RSS.
1339 if ($args['format'] == 'rss2' && empty($args['limit']))
1340 $args['limit'] = 15; // Fix default value for RSS2.
1342 if ($args['format'] == 'sidebar' && empty($args['limit']))
1343 $args['limit'] = 10; // Fix default value for sidebar.
1348 function getMostRecentParams(&$args)
1351 $show_minor = false;
1352 $show_major = false;
1356 $params = array('include_minor_revisions' => $show_minor,
1357 'exclude_major_revisions' => !$show_major,
1358 'include_all_revisions' => !empty($show_all));
1360 $params['limit'] = $limit;
1361 if (!empty($args['author'])) {
1363 if ($args['author'] == '[]')
1364 $args['author'] = $request->_user->getID();
1365 $params['author'] = $args['author'];
1367 if (!empty($args['owner'])) {
1369 if ($args['owner'] == '[]')
1370 $args['owner'] = $request->_user->getID();
1371 $params['owner'] = $args['owner'];
1373 if (!empty($days)) {
1375 $params['since'] = time() - 24 * 3600 * $days;
1376 elseif ($days < 0.0)
1377 $params['since'] = 24 * 3600 * $days - time();
1383 function getChanges($dbi, $args)
1385 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1387 $show_deleted = @$args['show_deleted'];
1388 $show_all = @$args['show_all'];
1389 if ($show_deleted == 'sometimes')
1390 $show_deleted = @$args['show_minor'];
1392 // only pages (e.g. PageHistory of subpages)
1393 if (!empty($args['pagematch'])) {
1394 require_once 'lib/TextSearchQuery.php';
1395 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1397 if (!empty($args['category'])) {
1398 require_once 'lib/TextSearchQuery.php';
1399 $changes = new LinkRevisionIterator($changes, $args['category']);
1401 if (!empty($args['only_new']))
1402 $changes = new NewPageRevisionIterator($changes);
1403 if (!empty($args['author']))
1404 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1405 if (!empty($args['owner']))
1406 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1408 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1413 function format($changes, $args)
1416 $format = $args['format'];
1418 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1420 if ($format == 'rss')
1421 $fmt_class = '_RecentChanges_RssFormatter';
1422 elseif ($format == 'rss2')
1423 $fmt_class = '_RecentChanges_Rss2Formatter'; elseif ($format == 'atom')
1424 $fmt_class = '_RecentChanges_AtomFormatter'; elseif ($format == 'rss091') {
1425 include_once 'lib/RSSWriter091.php';
1426 $fmt_class = '_RecentChanges_RssFormatter091';
1427 } elseif ($format == 'sidebar')
1428 $fmt_class = '_RecentChanges_SideBarFormatter'; elseif ($format == 'box')
1429 $fmt_class = '_RecentChanges_BoxFormatter'; elseif ($format == 'contribs')
1430 $fmt_class = '_RecentChanges_UserContribsFormatter'; else
1431 $fmt_class = '_RecentChanges_HtmlFormatter';
1434 $fmt = new $fmt_class($args);
1435 return $fmt->format($changes);
1438 function run($dbi, $argstr, &$request, $basepage)
1440 $args = $this->getArgs($argstr, $request);
1442 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1443 // to be enough for anyone.)
1444 $args['days'] = min($args['days'], 365000);
1446 // Within Categories just display Category Backlinks
1447 if (empty($args['category']) and empty($args['pagematch'])
1448 and preg_match("/^Category/", $request->getArg('pagename'))
1450 $args['category'] = $request->getArg('pagename');
1453 // Hack alert: format() is a NORETURN for rss formatters.
1454 return $this->format($this->getChanges($dbi, $args), $args);
1457 // box is used to display a fixed-width, narrow version with common header.
1458 // just a numbered list of limit pagenames, without date.
1459 function box($args = false, $request = false, $basepage = false)
1461 if (!$request) $request =& $GLOBALS['request'];
1462 if (!isset($args['limit'])) $args['limit'] = 15;
1463 $args['format'] = 'box';
1464 $args['show_minor'] = false;
1465 $args['show_major'] = true;
1466 $args['show_deleted'] = 'sometimes';
1467 $args['show_all'] = false;
1469 return $this->makeBox(WikiLink($this->getName(), '',
1470 SplitPagename($this->getName())),
1472 ($this->getChanges($request->_dbi, $args), $args));
1479 class OptionsButtonBars extends HtmlElement
1482 function OptionsButtonBars($plugin_args)
1484 $this->__construct('fieldset', array('class' => 'wiki-rc-action'));
1486 // Add ShowHideFolder button
1487 $icon = $GLOBALS['WikiTheme']->_findData('images/folderArrowOpen.png');
1488 $img = HTML::img(array('id' => 'rc-action-img',
1490 'onclick' => "showHideFolder('rc-action')",
1491 'alt' => _("Click to hide/show"),
1492 'title' => _("Click to hide/show")));
1494 // Display selection buttons
1495 extract($plugin_args);
1499 $caption = _("Show changes for:");
1502 $this->pushContent(HTML::legend($caption, ' ', $img));
1503 $table = HTML::table(array('id' => 'rc-action-body',
1504 'style' => 'display:block'));
1507 foreach (explode(",", $daylist) as $days_button) {
1508 $tr->pushContent($this->_makeDayButton($days_button, $days));
1510 $table->pushContent($tr);
1513 $tr->pushContent($this->_makeUsersButton(0));
1514 $tr->pushContent($this->_makeUsersButton(1));
1515 $table->pushContent($tr);
1518 $tr->pushContent($this->_makePagesButton(0));
1519 $tr->pushContent($this->_makePagesButton(1));
1520 $table->pushContent($tr);
1523 $tr->pushContent($this->_makeMinorButton(1, $show_minor));
1524 $tr->pushContent($this->_makeMinorButton(0, $show_minor));
1525 $table->pushContent($tr);
1528 $tr->pushContent($this->_makeShowAllButton(1, $show_all));
1529 $tr->pushContent($this->_makeShowAllButton(0, $show_all));
1530 $table->pushContent($tr);
1533 $tr->pushContent($this->_makeNewPagesButton(0, $only_new));
1534 $tr->pushContent($this->_makeNewPagesButton(1, $only_new));
1535 $table->pushContent($tr);
1537 $this->pushContent($table);
1540 function _makeDayButton($days_button, $days)
1544 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days_button));
1545 if ($days_button == 1) {
1546 $label = _("1 day");
1547 } elseif ($days_button < 1) {
1548 $label = _("All time");
1550 $label = sprintf(_("%s days"), abs($days_button));
1552 $selected = HTML::td(array('class' => 'tdselected'), $label);
1553 $unselected = HTML::td(array('class' => 'tdunselected'),
1554 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1555 return ($days_button == $days) ? $selected : $unselected;
1558 function _makeUsersButton($users)
1563 $label = _("All users");
1566 $label = _("My modifications only");
1570 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1571 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
1572 if ($url == $selfurl) {
1573 return HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1575 return HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1576 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1579 function _makePagesButton($pages)
1584 $label = _("All pages");
1587 $label = _("My pages only");
1591 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1592 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1593 if ($url == $selfurl) {
1594 return HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1596 return HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1597 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1600 function _makeMinorButton($minor_button, $show_minor)
1604 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor_button));
1605 $label = ($minor_button == 0) ? _("Major modifications only") : _("All modifications");
1606 $selected = HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1607 $unselected = HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1608 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1609 return ($minor_button == $show_minor) ? $selected : $unselected;
1612 function _makeShowAllButton($showall_button, $show_all)
1616 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall_button));
1617 $label = ($showall_button == 0) ? _("Page once only") : _("Full changes");
1618 $selected = HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1619 $unselected = HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1620 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1621 return ($showall_button == $show_all) ? $selected : $unselected;
1624 function _makeNewPagesButton($newpages_button, $only_new)
1628 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages_button));
1629 $label = ($newpages_button == 0) ? _("Old and new pages") : _("New pages only");
1630 $selected = HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1631 $unselected = HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1632 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1633 return ($newpages_button == $only_new) ? $selected : $unselected;
1640 // c-basic-offset: 4
1641 // c-hanging-comment-ender-p: nil
1642 // indent-tabs-mode: nil