4 Copyright 1999,2000,2001,2002,2007 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 include_once("lib/WikiPlugin.php");
27 class _RecentChanges_Formatter
29 var $_absurls = false;
30 var $action = "RecentChanges";
32 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;
46 extract($this->_args);
47 if ($author == '[]') $author = $request->_user->getID();
48 if ($owner == '[]') $owner = $request->_user->getID();
49 if ($author) $title = _("UserContribs").":$author";
50 elseif ($owner) $title = _("UserContribs").":$owner";
51 elseif ($only_new) $title = _("RecentNewPages");
52 elseif ($show_minor) $title = _("RecentEdits");
53 else $title = _("RecentChanges");
55 if (!empty($category))
57 elseif (!empty($pagematch))
58 $title .= ":$pagematch";
62 function include_versions_in_URLs() {
63 return (bool) $this->_args['show_all'];
66 function date ($rev) {
68 return $WikiTheme->getDay($rev->get('mtime'));
71 function time ($rev) {
73 return $WikiTheme->formatTime($rev->get('mtime'));
76 function diffURL ($rev) {
77 $args = $this->_diffargs;
78 if ($this->include_versions_in_URLs())
79 $args['version'] = $rev->getVersion();
80 $page = $rev->getPage();
81 return WikiURL($page->getName(), $args, $this->_absurls);
84 function historyURL ($rev) {
85 $page = $rev->getPage();
86 return WikiURL($page, array('action' => _("PageHistory")),
90 function pageURL ($rev) {
91 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
95 function authorHasPage ($author) {
96 global $WikiNameRegexp, $request;
97 $dbi = $request->getDbh();
98 return isWikiWord($author) && $dbi->isWikiPage($author);
101 function authorURL ($author) {
102 return $this->authorHasPage() ? WikiURL($author) : false;
106 function status ($rev) {
107 if ($rev->hasDefaultContents())
109 $page = $rev->getPage();
110 $prev = $page->getRevisionBefore($rev->getVersion());
111 if ($prev->hasDefaultContents())
116 function importance ($rev) {
117 return $rev->get('is_minor_edit') ? 'minor' : 'major';
120 function summary($rev) {
121 if ( ($summary = $rev->get('summary')) )
124 switch ($this->status($rev)) {
128 return _("New page");
134 function setValidators($most_recent_rev) {
135 $rev = $most_recent_rev;
136 $validators = array('RecentChanges-top' =>
137 array($rev->getPageName(), $rev->getVersion()),
138 '%mtime' => $rev->get('mtime'));
140 $request->appendValidators($validators);
144 class _RecentChanges_HtmlFormatter
145 extends _RecentChanges_Formatter
147 function diffLink ($rev) {
149 $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
150 $button->setAttr('rel', 'nofollow');
151 return HTML("(",$button,")");
154 /* deletions: red, additions: green */
155 function diffSummary ($rev) {
156 $html = $this->diffURL($rev);
160 function historyLink ($rev) {
162 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
163 $button->setAttr('rel', 'nofollow');
164 return HTML("(",$button,")");
167 function pageLink ($rev, $link_text=false) {
169 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
172 $page = $rev->getPage();
174 if ($this->include_versions_in_URLs()) {
175 $version = $rev->getVersion();
176 if ($rev->isCurrent())
178 $exists = !$rev->hasDefaultContents();
182 $cur = $page->getCurrentRevision();
183 $exists = !$cur->hasDefaultContents();
186 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
188 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
192 function authorLink ($rev) {
193 return WikiLink($rev->get('author'), 'if_known');
196 /* Link to all users contributions (contribs and owns) */
197 function authorContribs ($rev) {
198 $author = $rev->get('author');
199 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
201 Button(array('action' => _("RecentChanges"),
202 'format' => 'contribs',
208 Button(array('action' => _("RecentChanges"),
209 'format' => 'contribs',
217 function summaryAsHTML ($rev) {
218 if ( !($summary = $this->summary($rev)) )
220 return HTML::span( array('class' => 'wiki-summary'),
222 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
226 function format_icon ($format, $filter = array()) {
227 global $request, $WikiTheme;
228 $args = $this->_args;
229 // remove links not used for those formats
230 unset($args['daylist']);
231 unset($args['difflinks']);
232 unset($args['historylinks']);
233 $rss_url = $request->getURLtoSelf
235 array('action' => $this->action, 'format' => $format),
237 return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
240 function rss_icon ($args=array()) { return $this->format_icon("rss", $args); }
241 function rss2_icon ($args=array()) { return $this->format_icon("rss2", $args); }
242 function atom_icon ($args=array()) { return $this->format_icon("atom", $args); }
243 function rdf_icon ($args=array()) { return DEBUG ? $this->format_icon("rdf", $args) : ''; }
244 function rdfs_icon ($args=array()) { return DEBUG ? $this->format_icon("rdfs", $args) : ''; }
245 function owl_icon ($args=array()) { return DEBUG ? $this->format_icon("owl", $args) : ''; }
247 function grazr_icon ($args = array()) {
248 global $request, $WikiTheme;
249 if (is_localhost()) return '';
250 if (SERVER_PROTOCOL == "https") return '';
251 $our_url = WikiURL($request->getArg('pagename'),
252 array_merge(array('action' => $this->action, 'format' => 'rss2'), $args),
254 $rss_url = 'http://grazr.com/gzpanel.html?' . $our_url;
255 return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
258 function pre_description () {
259 extract($this->_args);
260 // FIXME: say something about show_all.
261 if ($show_major && $show_minor)
264 $edits = _("major edits");
266 $edits = _("minor edits");
267 if (isset($caption) and $caption == _("Recent Comments"))
268 $edits = _("comments");
269 if (!empty($only_new)) {
270 $edits = _("created new pages");
272 if (!empty($author)) {
275 $author = $request->_user->getID();
276 $edits .= sprintf(_(" for pages changed by %s"), $author);
278 if (!empty($owner)) {
281 $owner = $request->_user->getID();
282 $edits .= sprintf(_(" for pages owned by %s"), $owner);
284 if (!empty($category)) {
285 $edits .= sprintf(_(" for all pages linking to %s"), $category);
287 if (!empty($pagematch)) {
288 $edits .= sprintf(_(" for all pages matching '%s'"), $pagematch);
290 if ($timespan = $days > 0) {
291 if (intval($days) != $days)
292 $days = sprintf("%.1f", $days);
296 * Depending how this text is split up it can be tricky or
297 * impossible to translate with good grammar. So the seperate
298 * strings for 1 day and %s days are necessary in this case
299 * for translating to multiple languages, due to differing
300 * overlapping ideal word cutting points.
302 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
303 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
304 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
306 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
307 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
308 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
312 if (intval($days) == 1)
313 $desc = fmt("The %d most recent %s during the past day are listed below.",
316 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
317 $limit, $edits, $days);
319 $desc = fmt("The %d most recent %s are listed below.",
322 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
324 if (intval($days) == 1)
325 $desc = fmt("The %d oldest %s during the past day are listed below.",
328 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
329 $lmt, $edits, $days);
331 $desc = fmt("The %d oldest %s are listed below.",
337 if (intval($days) == 1)
338 $desc = fmt("The most recent %s during the past day are listed below.",
341 $desc = fmt("The most recent %s during the past %s days are listed below.",
344 $desc = fmt("All %s are listed below.", $edits);
349 function description() {
350 return HTML::p(false, $this->pre_description());
354 function headline () {
355 extract($this->_args);
356 return array($this->title(),
362 /*$this->rdfs_icon(),
365 $this->sidebar_link());
368 function empty_message() {
369 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
370 return _("No comments found");
372 return _("No changes found");
375 function sidebar_link() {
376 extract($this->_args);
377 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
380 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
383 "function addPanel() {\n"
384 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
385 ." \"$sidebarurl\",\"\");\n"
387 $jsf = JavaScript($addsidebarjsfunc);
390 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
391 array('title' => _("Click to add this feed to your sidebar"),
392 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
393 $addsidebarjsclick = asXML($sidebar_button);
394 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
395 ." (typeof window.sidebar.addPanel == 'function'))\n"
397 ." document.write('$addsidebarjsclick');\n"
400 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
403 function format ($changes) {
404 include_once('lib/InlineParser.php');
406 $html = HTML(HTML::h2(false, $this->headline()));
407 if (($desc = $this->description()))
408 $html->pushContent($desc);
410 if ($this->_args['daylist'])
411 $html->pushContent(new DayButtonBar($this->_args));
417 while ($rev = $changes->next()) {
418 if (($date = $this->date($rev)) != $last_date) {
420 $html->pushContent($lines);
421 // for user contributions no extra date line
422 $html->pushContent(HTML::h3($date));
427 // enforce view permission
428 if (mayAccessPage('view', $rev->_pagename)) {
429 $lines->pushContent($this->format_revision($rev));
431 $this->setValidators($rev);
436 $html->pushContent($lines);
438 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
439 $this->empty_message()));
444 function format_revision ($rev) {
446 $args = &$this->_args;
448 $class = 'rc-' . $this->importance($rev);
450 $time = $this->time($rev);
451 if (! $rev->get('is_minor_edit'))
452 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
454 $line = HTML::li(array('class' => $class));
456 if ($args['difflinks'])
457 $line->pushContent($this->diffLink($rev), ' ');
459 if ($args['historylinks'])
460 $line->pushContent($this->historyLink($rev), ' ');
462 // Do not display a link for a deleted page, just the page name
463 if ($rev->hasDefaultContents()) {
464 $linkorname = $rev->_pagename;
466 $linkorname = $this->pageLink($rev);
469 if (isa($WikiTheme, 'WikiTheme_MonoBook')) {
471 $args['historylinks'] ? '' : $this->historyLink($rev),
472 ' . . ', $linkorname, '; ',
474 $this->authorLink($rev),' ',
475 $this->authorContribs($rev),' ',
476 $this->summaryAsHTML($rev));
478 $line->pushContent($linkorname, ' ',
480 $this->summaryAsHTML($rev),
482 $this->authorLink($rev));
489 /* format=contribs: no seperation into extra dates
490 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
492 class _RecentChanges_UserContribsFormatter
493 extends _RecentChanges_HtmlFormatter
495 function headline () {
497 extract($this->_args);
498 if ($author == '[]') $author = $request->_user->getID();
499 if ($owner == '[]') $owner = $request->_user->getID();
500 $author_args = $owner
501 ? array('owner' => $owner)
502 : array('author' => $author);
503 return array(_("UserContribs"),":",$owner ? $owner : $author,
505 $this->rss_icon($author_args),
506 $this->rss2_icon($author_args),
507 $this->atom_icon($author_args),
508 $this->rdf_icon($author_args),
509 $this->grazr_icon($author_args));
512 function format ($changes) {
513 include_once('lib/InlineParser.php');
515 $html = HTML(HTML::h2(false, $this->headline()));
517 $first = true; $count = 0;
518 while ($rev = $changes->next()) {
519 if (mayAccessPage('view', $rev->_pagename)) {
520 $lines->pushContent($this->format_revision($rev));
522 $this->setValidators($rev);
527 $this->_args['limit'] = $count;
528 if (($desc = $this->description()))
529 $html->pushContent($desc);
530 if ($this->_args['daylist'])
531 $html->pushContent(new DayButtonBar($this->_args));
533 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
534 $this->empty_message()));
536 $html->pushContent($lines);
541 function format_revision ($rev) {
542 $args = &$this->_args;
543 $class = 'rc-' . $this->importance($rev);
544 $time = $this->time($rev);
545 if (! $rev->get('is_minor_edit'))
546 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
548 $line = HTML::li(array('class' => $class));
550 $line->pushContent($this->time($rev),", ");
551 $line->pushContent($this->date($rev)," ");
552 $line->pushContent($this->diffLink($rev), ' ');
553 $line->pushContent($this->historyLink($rev), ' ');
554 $line->pushContent($this->pageLink($rev), ' ',
555 $this->summaryAsHTML($rev));
560 class _RecentChanges_SideBarFormatter
561 extends _RecentChanges_HtmlFormatter
563 function rss_icon () {
566 function rss2_icon () { }
567 function headline () {
568 //title click opens the normal RC or RE page in the main browser frame
569 extract($this->_args);
570 $titlelink = WikiLink($this->title());
571 $titlelink->setAttr('target', '_content');
572 return HTML($this->logo(), $titlelink);
575 //logo click opens the HomePage in the main browser frame
577 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
580 'style' => 'height:2.5ex'
582 $linkurl = WikiLink(HOME_PAGE, false, $img);
583 $linkurl->setAttr('target', '_content');
587 function authorLink ($rev) {
588 $author = $rev->get('author');
589 if ( $this->authorHasPage($author) ) {
590 $linkurl = WikiLink($author);
591 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
597 function diffLink ($rev) {
598 $linkurl = parent::diffLink($rev);
599 $linkurl->setAttr('target', '_content');
600 $linkurl->setAttr('rel', 'nofollow');
601 // FIXME: Smelly hack to get smaller diff buttons in sidebar
602 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
605 function historyLink ($rev) {
606 $linkurl = parent::historyLink($rev);
607 $linkurl->setAttr('target', '_content');
608 // FIXME: Smelly hack to get smaller history buttons in sidebar
609 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
612 function pageLink ($rev) {
613 $linkurl = parent::pageLink($rev);
614 $linkurl->setAttr('target', '_content');
617 // Overriding summaryAsHTML, because there is no way yet to
618 // return summary as transformed text with
619 // links setAttr('target', '_content') in Mozilla sidebar.
620 // So for now don't create clickable links inside summary
621 // in the sidebar, or else they target the sidebar and not the
622 // main content window.
623 function summaryAsHTML ($rev) {
624 if ( !($summary = $this->summary($rev)) )
626 return HTML::span(array('class' => 'wiki-summary'),
628 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
633 function format ($changes) {
634 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
635 $html = _RecentChanges_HtmlFormatter::format ($changes);
636 $html = HTML::div(array('class' => 'wikitext'), $html);
638 $request->discardOutput();
640 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
641 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
642 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
643 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
646 extract($this->_args);
647 if (!empty($category))
649 elseif (!empty($pagematch))
652 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
653 printf("<title>" . $title . "</title>\n");
655 $css = $WikiTheme->getCSS();
659 printf("<body class=\"sidebar\">\n");
661 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>';
662 printf("\n</body>\n");
665 $request->finish(); // cut rest of page processing short
669 class _RecentChanges_BoxFormatter
670 extends _RecentChanges_HtmlFormatter
672 function rss_icon () {
674 function rss2_icon () {
676 function headline () {
678 function authorLink ($rev) {
680 function diffLink ($rev) {
682 function historyLink ($rev) {
684 function summaryAsHTML ($rev) {
686 function description () {
688 function format ($changes) {
689 include_once('lib/InlineParser.php');
694 $sp = HTML::Raw("\n · ");
695 while ($rev = $changes->next()) {
696 // enforce view permission
697 if (mayAccessPage('view',$rev->_pagename)) {
698 if ($link = $this->pageLink($rev)) // some entries may be empty
699 // (/Blog/.. interim pages)
700 $html->pushContent($sp, $link, HTML::br());
702 $this->setValidators($rev);
707 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
708 $this->empty_message()));
713 class _RecentChanges_RssFormatter
714 extends _RecentChanges_Formatter
716 var $_absurls = true;
718 function time ($rev) {
719 return Iso8601DateTime($rev->get('mtime'));
722 function pageURI ($rev) {
723 return WikiURL($rev, '', 'absurl');
726 function format ($changes) {
728 include_once('lib/RssWriter.php');
729 $rss = new RssWriter;
730 $rss->channel($this->channel_properties());
732 if (($props = $this->image_properties()))
734 if (($props = $this->textinput_properties()))
735 $rss->textinput($props);
738 while ($rev = $changes->next()) {
739 // enforce view permission
740 if (mayAccessPage('view', $rev->_pagename)) {
741 $rss->addItem($this->item_properties($rev),
742 $this->pageURI($rev));
744 $this->setValidators($rev);
750 $request->discardOutput();
752 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
753 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
755 // Flush errors in comment, otherwise it's invalid XML.
756 global $ErrorManager;
757 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
758 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
760 $request->finish(); // NORETURN!!!!
763 function image_properties () {
766 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
770 return array('title' => WIKI_NAME,
771 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
775 function textinput_properties () {
776 return array('title' => _("Search"),
777 'description' => _("Title Search"),
779 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
782 function channel_properties () {
785 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
786 extract($this->_args);
788 $description = $this->title();
793 return array('title' => $title,
795 'description' => $description,
796 'dc:date' => Iso8601DateTime(time()),
797 'dc:language' => $GLOBALS['LANG']);
799 /* FIXME: other things one might like in <channel>:
808 * rss091:managingEditor
810 * rss091:lastBuildDate
815 function item_properties ($rev) {
816 $page = $rev->getPage();
817 $pagename = $page->getName();
819 return array( 'title' => SplitPagename($pagename),
820 'description' => $this->summary($rev),
821 'link' => $this->pageURL($rev),
822 'dc:date' => $this->time($rev),
823 'dc:contributor' => $rev->get('author'),
824 'wiki:version' => $rev->getVersion(),
825 'wiki:importance' => $this->importance($rev),
826 'wiki:status' => $this->status($rev),
827 'wiki:diff' => $this->diffURL($rev),
828 'wiki:history' => $this->historyURL($rev)
833 /** explicit application/rss+xml Content-Type,
834 * simplified xml structure (no namespace),
835 * support for xml-rpc cloud registerProcedure (not yet)
837 class _RecentChanges_Rss2Formatter
838 extends _RecentChanges_RssFormatter {
840 function format ($changes) {
841 include_once('lib/RssWriter2.php');
842 $rss = new RssWriter2;
844 $rss->channel($this->channel_properties());
845 if (($props = $this->cloud_properties()))
847 if (($props = $this->image_properties()))
849 if (($props = $this->textinput_properties()))
850 $rss->textinput($props);
852 while ($rev = $changes->next()) {
853 // enforce view permission
854 if (mayAccessPage('view', $rev->_pagename)) {
855 $rss->addItem($this->item_properties($rev),
856 $this->pageURI($rev));
858 $this->setValidators($rev);
865 $request->discardOutput();
867 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
868 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
869 // Flush errors in comment, otherwise it's invalid XML.
870 global $ErrorManager;
871 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
872 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
874 $request->finish(); // NORETURN!!!!
877 function channel_properties () {
878 $chann_10 = parent::channel_properties();
879 return array_merge($chann_10,
880 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
881 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
882 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
883 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
884 'copyright' => COPYRIGHTPAGE_URL
888 // xml-rpc registerProcedure not yet implemented
889 function cloud_properties () { return false; }
890 function cloud_properties_test () {
891 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
892 'registerProcedure' => 'wiki.rssPleaseNotify',
893 'path' => DATA_PATH.'/RPC2.php',
894 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
895 'domain' => SERVER_NAME);
899 /** Explicit application/atom+xml Content-Type
900 * A weird, questionable format
902 class _RecentChanges_AtomFormatter
903 extends _RecentChanges_RssFormatter {
905 function format ($changes) {
907 include_once('lib/RssWriter.php');
910 // "channel" is called "feed" in atom
911 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
912 extract($this->_args);
914 $description = $this->title();
919 $feed_props = array('title' => $description,
920 'link' => array('rel'=>"alternate",
923 'id' => md5($rc_url),
924 'modified' => Iso8601DateTime(time()),
925 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
927 $rss->feed($feed_props);
929 while ($rev = $changes->next()) {
930 // enforce view permission
931 if (mayAccessPage('view', $rev->_pagename)) {
932 $props = $this->item_properties($rev);
933 $rss->addItem($props,
935 $this->pageURI($rev));
937 $this->setValidators($rev);
942 $request->discardOutput();
944 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
945 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
946 // Flush errors in comment, otherwise it's invalid XML.
947 global $ErrorManager;
948 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
949 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
951 $request->finish(); // NORETURN!!!!
954 function item_properties ($rev) {
955 $page = $rev->getPage();
956 $pagename = $page->getName();
957 return array( 'title' => $pagename,
958 'link' => array('rel' => 'alternate',
959 'type' => 'text/html',
960 'href' => $this->pageURL($rev)),
961 'summary' => $this->summary($rev),
962 'modified' => $this->time($rev)."Z",
963 'issued' => $this->time($rev),
964 'created' => $this->time($rev)."Z",
965 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
971 * Filter by non-empty
973 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
977 * @param $revisions object a WikiDB_PageRevisionIterator.
979 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
980 $this->_revisions = $revisions;
981 $this->_check_current_revision = $check_current_revision;
985 while (($rev = $this->_revisions->next())) {
986 if ($this->_check_current_revision) {
987 $page = $rev->getPage();
988 $check_rev = $page->getCurrentRevision();
993 if (! $check_rev->hasDefaultContents())
1003 * Filter by only_new.
1004 * Only new created pages
1006 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1010 * @param $revisions object a WikiDB_PageRevisionIterator.
1012 function NewPageRevisionIterator ($revisions) {
1013 $this->_revisions = $revisions;
1017 while (($rev = $this->_revisions->next())) {
1018 if ($rev->getVersion() == 1)
1027 * Only pages with links to a certain category
1029 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1031 function LinkRevisionIterator ($revisions, $category) {
1032 $this->_revisions = $revisions;
1033 if (preg_match("/[\?\.\*]/", $category)) {
1034 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1035 (new TextSearchQuery("*", true),
1036 new TextSearchQuery($category, true),
1039 $basepage = $GLOBALS['request']->getPage($category);
1040 $backlinkiter = $basepage->getBackLinks(true);
1042 $this->links = array();
1043 foreach ($backlinkiter->asArray() as $p) {
1044 if (is_object($p)) $this->links[] = $p->getName();
1045 elseif (is_array($p)) $this->links[] = $p['pagename'];
1046 else $this->links[] = $p;
1048 $backlinkiter->free();
1053 while (($rev = $this->_revisions->next())) {
1054 if (binary_search($rev->getName(), $this->links) != false)
1062 unset ($this->links);
1066 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1068 function PageMatchRevisionIterator ($revisions, $match) {
1069 $this->_revisions = $revisions;
1070 $this->search = new TextSearchQuery($match, true);
1074 while (($rev = $this->_revisions->next())) {
1075 if ($this->search->match($rev->getName()))
1083 unset ($this->search);
1090 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1092 function AuthorPageRevisionIterator ($revisions, $author) {
1093 $this->_revisions = $revisions;
1094 $this->_author = $author;
1098 while (($rev = $this->_revisions->next())) {
1099 if ($rev->get('author_id') == $this->_author)
1110 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1112 function OwnerPageRevisionIterator ($revisions, $owner) {
1113 $this->_revisions = $revisions;
1114 $this->_owner = $owner;
1118 while (($rev = $this->_revisions->next())) {
1119 $page = $rev->getPage();
1120 if ($page->getOwner() == $this->_owner)
1128 class WikiPlugin_RecentChanges
1131 function getName () {
1132 return _("RecentChanges");
1135 function getVersion() {
1136 return preg_replace("/[Revision: $]/", '',
1140 function managesValidators() {
1141 // Note that this is a bit of a fig.
1142 // We set validators based on the most recently changed page,
1143 // but this fails when the most-recent page is deleted.
1144 // (Consider that the Last-Modified time will decrease
1145 // when this happens.)
1147 // We might be better off, leaving this as false (and junking
1148 // the validator logic above) and just falling back to the
1149 // default behavior (handled by WikiPlugin) of just using
1150 // the WikiDB global timestamp as the mtime.
1152 // Nevertheless, for now, I leave this here, mostly as an
1153 // example for how to use appendValidators() and managesValidators().
1158 function getDefaultArguments() {
1159 return array('days' => 2,
1160 'show_minor' => false,
1161 'show_major' => true,
1162 'show_all' => false,
1163 'show_deleted' => 'sometimes',
1164 'only_new' => false,
1170 'difflinks' => true,
1171 'historylinks' => false,
1178 function getArgs ($argstr, $request, $defaults = false) {
1179 if (!$defaults) $defaults = $this->getDefaultArguments();
1180 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1182 $action = $request->getArg('action');
1183 if ($action != 'browse' && ! $request->isActionPage($action))
1184 $args['format'] = false; // default -> HTML
1186 if ($args['format'] == 'rss' && empty($args['limit']))
1187 $args['limit'] = 15; // Fix default value for RSS.
1188 if ($args['format'] == 'rss2' && empty($args['limit']))
1189 $args['limit'] = 15; // Fix default value for RSS2.
1191 if ($args['format'] == 'sidebar' && empty($args['limit']))
1192 $args['limit'] = 10; // Fix default value for sidebar.
1197 function getMostRecentParams (&$args) {
1198 $show_all = false; $show_minor = false; $show_major = false;
1202 $params = array('include_minor_revisions' => $show_minor,
1203 'exclude_major_revisions' => !$show_major,
1204 'include_all_revisions' => !empty($show_all));
1206 $params['limit'] = $limit;
1207 if (!empty($args['author'])) {
1209 if ($args['author'] == '[]')
1210 $args['author'] = $request->_user->getID();
1211 $params['author'] = $args['author'];
1213 if (!empty($args['owner'])) {
1215 if ($args['owner'] == '[]')
1216 $args['owner'] = $request->_user->getID();
1217 $params['owner'] = $args['owner'];
1219 if (!empty($days)) {
1221 $params['since'] = time() - 24 * 3600 * $days;
1222 elseif ($days < 0.0)
1223 $params['since'] = 24 * 3600 * $days - time();
1229 function getChanges ($dbi, $args) {
1230 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1232 $show_deleted = @$args['show_deleted'];
1233 $show_all = @$args['show_all'];
1234 if ($show_deleted == 'sometimes')
1235 $show_deleted = @$args['show_minor'];
1237 // only pages (e.g. PageHistory of subpages)
1238 if (!empty($args['pagematch'])) {
1239 require_once("lib/TextSearchQuery.php");
1240 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1242 if (!empty($args['category'])) {
1243 require_once("lib/TextSearchQuery.php");
1244 $changes = new LinkRevisionIterator($changes, $args['category']);
1246 if (!empty($args['only_new']))
1247 $changes = new NewPageRevisionIterator($changes);
1248 if (!empty($args['author']))
1249 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1250 if (!empty($args['owner']))
1251 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1253 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1258 function format ($changes, $args) {
1260 $format = $args['format'];
1262 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1264 if ($format == 'rss')
1265 $fmt_class = '_RecentChanges_RssFormatter';
1266 elseif ($format == 'rss2')
1267 $fmt_class = '_RecentChanges_Rss2Formatter';
1268 elseif ($format == 'atom')
1269 $fmt_class = '_RecentChanges_AtomFormatter';
1270 elseif ($format == 'rss091') {
1271 include_once "lib/RSSWriter091.php";
1272 $fmt_class = '_RecentChanges_RssFormatter091';
1274 elseif ($format == 'sidebar')
1275 $fmt_class = '_RecentChanges_SideBarFormatter';
1276 elseif ($format == 'box')
1277 $fmt_class = '_RecentChanges_BoxFormatter';
1278 elseif ($format == 'contribs')
1279 $fmt_class = '_RecentChanges_UserContribsFormatter';
1281 $fmt_class = '_RecentChanges_HtmlFormatter';
1284 $fmt = new $fmt_class($args);
1285 return $fmt->format($changes);
1288 function run($dbi, $argstr, &$request, $basepage) {
1289 $args = $this->getArgs($argstr, $request);
1291 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1292 // to be enough for anyone.)
1293 $args['days'] = min($args['days'], 365000);
1295 // Within Categories just display Category Backlinks
1296 if (empty($args['category']) and empty($args['pagematch'])
1297 and preg_match("/^Category/", $request->getArg('pagename')))
1299 $args['category'] = $request->getArg('pagename');
1302 // Hack alert: format() is a NORETURN for rss formatters.
1303 return $this->format($this->getChanges($dbi, $args), $args);
1306 // box is used to display a fixed-width, narrow version with common header.
1307 // just a numbered list of limit pagenames, without date.
1308 function box($args = false, $request = false, $basepage = false) {
1309 if (!$request) $request =& $GLOBALS['request'];
1310 if (!isset($args['limit'])) $args['limit'] = 15;
1311 $args['format'] = 'box';
1312 $args['show_minor'] = false;
1313 $args['show_major'] = true;
1314 $args['show_deleted'] = 'sometimes';
1315 $args['show_all'] = false;
1317 return $this->makeBox(WikiLink($this->getName(),'',
1318 SplitPagename($this->getName())),
1320 ($this->getChanges($request->_dbi, $args), $args));
1326 class DayButtonBar extends HtmlElement {
1328 function DayButtonBar ($plugin_args) {
1329 $this->__construct('p', array('class' => 'wiki-rc-action'));
1331 // Display days selection buttons
1332 extract($plugin_args);
1337 $caption = _("Show minor edits for:");
1339 $caption = _("Show all changes for:");
1341 $caption = _("Show changes for:");
1343 $caption = _("All new pages since:");
1346 $this->pushContent($caption, ' ');
1349 $sep = $WikiTheme->getButtonSeparator();
1352 foreach (explode(",", $daylist) as $days) {
1354 $this->pushContent($sep);
1355 $this->pushContent($this->_makeDayButton($days));
1359 function _makeDayButton ($days) {
1360 global $WikiTheme, $request;
1363 $label = _("1 day");
1365 $label = "..."; //alldays
1367 $label = sprintf(_("%s days"), abs($days));
1369 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1371 return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
1375 // (c-file-style: "gnu")
1379 // c-basic-offset: 4
1380 // c-hanging-comment-ender-p: nil
1381 // indent-tabs-mode: nil