4 Copyright 1999,2000,2001,2002,2007 $ThePhpWikiProgrammingTeam
5 Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 This file is part of PhpWiki.
9 PhpWiki is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 PhpWiki is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with PhpWiki; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 include_once("lib/WikiPlugin.php");
28 class _RecentChanges_Formatter
30 var $_absurls = false;
31 var $action = "RecentChanges";
33 function _RecentChanges_Formatter ($rc_args) {
34 $this->_args = $rc_args;
35 $this->_diffargs = array('action' => 'diff');
37 if ($rc_args['show_minor'] || !$rc_args['show_major'])
38 $this->_diffargs['previous'] = 'minor';
40 // PageHistoryPlugin doesn't have a 'daylist' arg.
41 if (!isset($this->_args['daylist']))
42 $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() {
74 return (bool) $this->_args['show_all'];
77 function date ($rev) {
79 return $WikiTheme->getDay($rev->get('mtime'));
82 function time ($rev) {
84 return $WikiTheme->formatTime($rev->get('mtime'));
87 function diffURL ($rev) {
88 $args = $this->_diffargs;
89 if ($this->include_versions_in_URLs())
90 $args['version'] = $rev->getVersion();
91 $page = $rev->getPage();
92 return WikiURL($page->getName(), $args, $this->_absurls);
95 function historyURL ($rev) {
96 $page = $rev->getPage();
97 return WikiURL($page, array('action' => _("PageHistory")),
101 function pageURL ($rev) {
102 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
103 '', $this->_absurls);
106 function authorHasPage ($author) {
107 global $WikiNameRegexp, $request;
108 $dbi = $request->getDbh();
109 return isWikiWord($author) && $dbi->isWikiPage($author);
112 function authorURL ($author) {
113 return $this->authorHasPage() ? WikiURL($author) : false;
117 function status ($rev) {
118 if ($rev->hasDefaultContents())
120 $page = $rev->getPage();
121 $prev = $page->getRevisionBefore($rev->getVersion());
122 if ($prev->hasDefaultContents())
127 function importance ($rev) {
128 return $rev->get('is_minor_edit') ? 'minor' : 'major';
131 function summary($rev) {
132 if ( ($summary = $rev->get('summary')) )
135 switch ($this->status($rev)) {
139 return _("New page");
145 function setValidators($most_recent_rev) {
146 $rev = $most_recent_rev;
147 $validators = array('RecentChanges-top' =>
148 array($rev->getPageName(), $rev->getVersion()),
149 '%mtime' => $rev->get('mtime'));
151 $request->appendValidators($validators);
155 class _RecentChanges_HtmlFormatter
156 extends _RecentChanges_Formatter
158 function diffLink ($rev) {
160 $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
161 $button->setAttr('rel', 'nofollow');
162 return HTML("(",$button,")");
165 /* deletions: red, additions: green */
166 function diffSummary ($rev) {
167 $html = $this->diffURL($rev);
171 function historyLink ($rev) {
173 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
174 $button->setAttr('rel', 'nofollow');
175 return HTML("(",$button,")");
178 function pageLink ($rev, $link_text=false) {
180 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
183 $page = $rev->getPage();
185 if ($this->include_versions_in_URLs()) {
186 $version = $rev->getVersion();
187 if ($rev->isCurrent())
189 $exists = !$rev->hasDefaultContents();
193 $cur = $page->getCurrentRevision();
194 $exists = !$cur->hasDefaultContents();
197 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
199 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
203 function authorLink ($rev) {
204 return WikiLink($rev->get('author'), 'if_known');
207 /* Link to all users contributions (contribs and owns) */
208 function authorContribs ($rev) {
209 $author = $rev->get('author');
210 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
212 Button(array('action' => _("RecentChanges"),
213 'format' => 'contribs',
219 Button(array('action' => _("RecentChanges"),
220 'format' => 'contribs',
228 function summaryAsHTML ($rev) {
229 if ( !($summary = $this->summary($rev)) )
231 return HTML::span( array('class' => 'wiki-summary'),
233 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
237 function format_icon ($format, $filter = array()) {
238 global $request, $WikiTheme;
239 $args = $this->_args;
240 // remove links not used for those formats
241 unset($args['daylist']);
242 unset($args['difflinks']);
243 unset($args['historylinks']);
244 $rss_url = $request->getURLtoSelf
246 array('action' => $this->action, 'format' => $format),
248 return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
251 function rss_icon ($args=array()) { return $this->format_icon("rss", $args); }
252 function rss2_icon ($args=array()) { return $this->format_icon("rss2", $args); }
253 function atom_icon ($args=array()) { return $this->format_icon("atom", $args); }
254 function rdf_icon ($args=array()) { return DEBUG ? $this->format_icon("rdf", $args) : ''; }
255 function rdfs_icon ($args=array()) { return DEBUG ? $this->format_icon("rdfs", $args) : ''; }
256 function owl_icon ($args=array()) { return DEBUG ? $this->format_icon("owl", $args) : ''; }
258 function grazr_icon ($args = array()) {
259 global $request, $WikiTheme;
260 if (is_localhost()) return '';
261 if (SERVER_PROTOCOL == "https") return '';
262 $our_url = WikiURL($request->getArg('pagename'),
263 array_merge(array('action' => $this->action, 'format' => 'rss2'), $args),
265 $rss_url = 'http://grazr.com/gzpanel.html?' . $our_url;
266 return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
269 function pre_description () {
270 extract($this->_args);
271 // FIXME: say something about show_all.
272 if ($show_major && $show_minor)
275 $edits = _("major edits");
277 $edits = _("minor edits");
278 if (isset($caption) and $caption == _("Recent Comments"))
279 $edits = _("comments");
280 if (!empty($only_new)) {
281 $edits = _("created new pages");
283 if (!empty($author)) {
286 $author = $request->_user->getID();
287 $edits .= sprintf(_(" for pages changed by %s"), $author);
289 if (!empty($owner)) {
292 $owner = $request->_user->getID();
293 $edits .= sprintf(_(" for pages owned by %s"), $owner);
295 if (!empty($category)) {
296 $edits .= sprintf(_(" for all pages linking to %s"), $category);
298 if (!empty($pagematch)) {
299 $edits .= sprintf(_(" for all pages matching '%s'"), $pagematch);
301 if ($timespan = $days > 0) {
302 if (intval($days) != $days)
303 $days = sprintf("%.1f", $days);
307 * Depending how this text is split up it can be tricky or
308 * impossible to translate with good grammar. So the seperate
309 * strings for 1 day and %s days are necessary in this case
310 * for translating to multiple languages, due to differing
311 * overlapping ideal word cutting points.
313 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
314 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
315 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
317 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
318 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
319 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
323 if (intval($days) == 1)
324 $desc = fmt("The %d most recent %s during the past day are listed below.",
327 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
328 $limit, $edits, $days);
330 $desc = fmt("The %d most recent %s are listed below.",
333 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
335 if (intval($days) == 1)
336 $desc = fmt("The %d oldest %s during the past day are listed below.",
339 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
340 $lmt, $edits, $days);
342 $desc = fmt("The %d oldest %s are listed below.",
348 if (intval($days) == 1)
349 $desc = fmt("The most recent %s during the past day are listed below.",
352 $desc = fmt("The most recent %s during the past %s days are listed below.",
355 $desc = fmt("All %s are listed below.", $edits);
360 function description() {
361 return HTML::p(false, $this->pre_description());
365 function headline () {
366 extract($this->_args);
367 return array($this->title(),
373 /*$this->rdfs_icon(),
376 $this->sidebar_link());
379 function empty_message() {
380 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
381 return _("No comments found");
383 return _("No changes found");
386 function sidebar_link() {
387 extract($this->_args);
388 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
391 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
394 "function addPanel() {\n"
395 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
396 ." \"$sidebarurl\",\"\");\n"
398 $jsf = JavaScript($addsidebarjsfunc);
401 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
402 array('title' => _("Click to add this feed to your sidebar"),
403 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
404 $addsidebarjsclick = asXML($sidebar_button);
405 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
406 ." (typeof window.sidebar.addPanel == 'function'))\n"
408 ." document.write('$addsidebarjsclick');\n"
411 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
414 function format ($changes) {
415 include_once('lib/InlineParser.php');
417 $html = HTML(HTML::h2(false, $this->headline()));
418 if (($desc = $this->description()))
419 $html->pushContent($desc);
421 if ($this->_args['daylist']) {
422 $html->pushContent(new OptionsButtonBars($this->_args));
429 while ($rev = $changes->next()) {
430 if (($date = $this->date($rev)) != $last_date) {
432 $html->pushContent($lines);
433 // for user contributions no extra date line
434 $html->pushContent(HTML::h3($date));
439 // enforce view permission
440 if (mayAccessPage('view', $rev->_pagename)) {
441 $lines->pushContent($this->format_revision($rev));
443 $this->setValidators($rev);
448 $html->pushContent($lines);
450 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
451 $this->empty_message()));
456 function format_revision ($rev) {
458 $args = &$this->_args;
460 $class = 'rc-' . $this->importance($rev);
462 $time = $this->time($rev);
463 if (! $rev->get('is_minor_edit'))
464 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
466 $line = HTML::li(array('class' => $class));
468 if ($args['difflinks'])
469 $line->pushContent($this->diffLink($rev), ' ');
471 if ($args['historylinks'])
472 $line->pushContent($this->historyLink($rev), ' ');
474 // Do not display a link for a deleted page, just the page name
475 if ($rev->hasDefaultContents()) {
476 $linkorname = $rev->_pagename;
478 $linkorname = $this->pageLink($rev);
481 if ((isa($WikiTheme, 'WikiTheme_MonoBook')) or (isa($WikiTheme, 'WikiTheme_gforge'))) {
483 $args['historylinks'] ? '' : $this->historyLink($rev),
484 ' . . ', $linkorname, '; ',
486 $this->authorLink($rev),' ',
487 $this->authorContribs($rev),' ',
488 $this->summaryAsHTML($rev));
490 $line->pushContent($linkorname, ' ',
492 $this->summaryAsHTML($rev),
494 $this->authorLink($rev));
501 /* format=contribs: no seperation into extra dates
502 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
504 class _RecentChanges_UserContribsFormatter
505 extends _RecentChanges_HtmlFormatter
507 function headline () {
509 extract($this->_args);
510 if ($author == '[]') $author = $request->_user->getID();
511 if ($owner == '[]') $owner = $request->_user->getID();
512 $author_args = $owner
513 ? array('owner' => $owner)
514 : array('author' => $author);
515 return array(_("UserContribs"),":",$owner ? $owner : $author,
517 $this->rss_icon($author_args),
518 $this->rss2_icon($author_args),
519 $this->atom_icon($author_args),
520 $this->rdf_icon($author_args),
521 $this->grazr_icon($author_args));
524 function format ($changes) {
525 include_once('lib/InlineParser.php');
527 $html = HTML(HTML::h2(false, $this->headline()));
529 $first = true; $count = 0;
530 while ($rev = $changes->next()) {
531 if (mayAccessPage('view', $rev->_pagename)) {
532 $lines->pushContent($this->format_revision($rev));
534 $this->setValidators($rev);
539 $this->_args['limit'] = $count;
540 if (($desc = $this->description()))
541 $html->pushContent($desc);
542 if ($this->_args['daylist']) {
543 $html->pushContent(new OptionsButtonBars($this->_args));
546 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
547 $this->empty_message()));
549 $html->pushContent($lines);
554 function format_revision ($rev) {
555 $args = &$this->_args;
556 $class = 'rc-' . $this->importance($rev);
557 $time = $this->time($rev);
558 if (! $rev->get('is_minor_edit'))
559 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
561 $line = HTML::li(array('class' => $class));
563 $line->pushContent($this->time($rev),", ");
564 $line->pushContent($this->date($rev)," ");
565 $line->pushContent($this->diffLink($rev), ' ');
566 $line->pushContent($this->historyLink($rev), ' ');
567 $line->pushContent($this->pageLink($rev), ' ',
568 $this->summaryAsHTML($rev));
573 class _RecentChanges_SideBarFormatter
574 extends _RecentChanges_HtmlFormatter
576 function rss_icon () {
579 function rss2_icon () { }
580 function headline () {
581 //title click opens the normal RC or RE page in the main browser frame
582 extract($this->_args);
583 $titlelink = WikiLink($this->title());
584 $titlelink->setAttr('target', '_content');
585 return HTML($this->logo(), $titlelink);
588 //logo click opens the HomePage in the main browser frame
590 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
593 'style' => 'height:2.5ex'
595 $linkurl = WikiLink(HOME_PAGE, false, $img);
596 $linkurl->setAttr('target', '_content');
600 function authorLink ($rev) {
601 $author = $rev->get('author');
602 if ( $this->authorHasPage($author) ) {
603 $linkurl = WikiLink($author);
604 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
610 function diffLink ($rev) {
611 $linkurl = parent::diffLink($rev);
612 $linkurl->setAttr('target', '_content');
613 $linkurl->setAttr('rel', 'nofollow');
614 // FIXME: Smelly hack to get smaller diff buttons in sidebar
615 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
618 function historyLink ($rev) {
619 $linkurl = parent::historyLink($rev);
620 $linkurl->setAttr('target', '_content');
621 // FIXME: Smelly hack to get smaller history buttons in sidebar
622 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
625 function pageLink ($rev) {
626 $linkurl = parent::pageLink($rev);
627 $linkurl->setAttr('target', '_content');
630 // Overriding summaryAsHTML, because there is no way yet to
631 // return summary as transformed text with
632 // links setAttr('target', '_content') in Mozilla sidebar.
633 // So for now don't create clickable links inside summary
634 // in the sidebar, or else they target the sidebar and not the
635 // main content window.
636 function summaryAsHTML ($rev) {
637 if ( !($summary = $this->summary($rev)) )
639 return HTML::span(array('class' => 'wiki-summary'),
641 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
646 function format ($changes) {
647 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
648 $html = _RecentChanges_HtmlFormatter::format ($changes);
649 $html = HTML::div(array('class' => 'wikitext'), $html);
651 $request->discardOutput();
653 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
654 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
655 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
656 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
659 extract($this->_args);
660 if (!empty($category))
662 elseif (!empty($pagematch))
665 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
666 printf("<title>" . $title . "</title>\n");
668 $css = $WikiTheme->getCSS();
672 printf("<body class=\"sidebar\">\n");
674 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>';
675 printf("\n</body>\n");
678 $request->finish(); // cut rest of page processing short
682 class _RecentChanges_BoxFormatter
683 extends _RecentChanges_HtmlFormatter
685 function rss_icon () {
687 function rss2_icon () {
689 function headline () {
691 function authorLink ($rev) {
693 function diffLink ($rev) {
695 function historyLink ($rev) {
697 function summaryAsHTML ($rev) {
699 function description () {
701 function format ($changes) {
702 include_once('lib/InlineParser.php');
707 $sp = HTML::Raw("\n · ");
708 while ($rev = $changes->next()) {
709 // enforce view permission
710 if (mayAccessPage('view',$rev->_pagename)) {
711 if ($link = $this->pageLink($rev)) // some entries may be empty
712 // (/Blog/.. interim pages)
713 $html->pushContent($sp, $link, HTML::br());
715 $this->setValidators($rev);
720 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
721 $this->empty_message()));
726 class _RecentChanges_RssFormatter
727 extends _RecentChanges_Formatter
729 var $_absurls = true;
731 function time ($rev) {
732 return Iso8601DateTime($rev->get('mtime'));
735 function pageURI ($rev) {
736 return WikiURL($rev, '', 'absurl');
739 function format ($changes) {
741 include_once('lib/RssWriter.php');
742 $rss = new RssWriter;
743 $rss->channel($this->channel_properties());
745 if (($props = $this->image_properties()))
747 if (($props = $this->textinput_properties()))
748 $rss->textinput($props);
751 while ($rev = $changes->next()) {
752 // enforce view permission
753 if (mayAccessPage('view', $rev->_pagename)) {
754 $rss->addItem($this->item_properties($rev),
755 $this->pageURI($rev));
757 $this->setValidators($rev);
763 $request->discardOutput();
765 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
766 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
768 // Flush errors in comment, otherwise it's invalid XML.
769 global $ErrorManager;
770 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
771 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
773 $request->finish(); // NORETURN!!!!
776 function image_properties () {
779 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
783 return array('title' => WIKI_NAME,
784 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
788 function textinput_properties () {
789 return array('title' => _("Search"),
790 'description' => _("Title Search"),
792 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
795 function channel_properties () {
798 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
799 extract($this->_args);
801 $description = $this->title();
806 return array('title' => $title,
808 'description' => $description,
809 'dc:date' => Iso8601DateTime(time()),
810 'dc:language' => $GLOBALS['LANG']);
812 /* FIXME: other things one might like in <channel>:
821 * rss091:managingEditor
823 * rss091:lastBuildDate
828 function item_properties ($rev) {
829 $page = $rev->getPage();
830 $pagename = $page->getName();
832 return array( 'title' => SplitPagename($pagename),
833 'description' => $this->summary($rev),
834 'link' => $this->pageURL($rev),
835 'dc:date' => $this->time($rev),
836 'dc:contributor' => $rev->get('author'),
837 'wiki:version' => $rev->getVersion(),
838 'wiki:importance' => $this->importance($rev),
839 'wiki:status' => $this->status($rev),
840 'wiki:diff' => $this->diffURL($rev),
841 'wiki:history' => $this->historyURL($rev)
846 /** explicit application/rss+xml Content-Type,
847 * simplified xml structure (no namespace),
848 * support for xml-rpc cloud registerProcedure (not yet)
850 class _RecentChanges_Rss2Formatter
851 extends _RecentChanges_RssFormatter {
853 function format ($changes) {
854 include_once('lib/RssWriter2.php');
855 $rss = new RssWriter2;
857 $rss->channel($this->channel_properties());
858 if (($props = $this->cloud_properties()))
860 if (($props = $this->image_properties()))
862 if (($props = $this->textinput_properties()))
863 $rss->textinput($props);
865 while ($rev = $changes->next()) {
866 // enforce view permission
867 if (mayAccessPage('view', $rev->_pagename)) {
868 $rss->addItem($this->item_properties($rev),
869 $this->pageURI($rev));
871 $this->setValidators($rev);
877 $request->discardOutput();
879 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
880 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
881 // Flush errors in comment, otherwise it's invalid XML.
882 global $ErrorManager;
883 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
884 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
886 $request->finish(); // NORETURN!!!!
889 function channel_properties () {
890 $chann_10 = parent::channel_properties();
891 return array_merge($chann_10,
892 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
893 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
894 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
895 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
896 'copyright' => COPYRIGHTPAGE_URL
900 // xml-rpc registerProcedure not yet implemented
901 function cloud_properties () { return false; }
902 function cloud_properties_test () {
903 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
904 'registerProcedure' => 'wiki.rssPleaseNotify',
905 'path' => DATA_PATH.'/RPC2.php',
906 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
907 'domain' => SERVER_NAME);
911 /** Explicit application/atom+xml Content-Type
912 * A weird, questionable format
914 class _RecentChanges_AtomFormatter
915 extends _RecentChanges_RssFormatter {
917 function format ($changes) {
919 include_once('lib/RssWriter.php');
922 // "channel" is called "feed" in atom
923 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
924 extract($this->_args);
926 $description = $this->title();
931 $feed_props = array('title' => $description,
932 'link' => array('rel'=>"alternate",
935 'id' => md5($rc_url),
936 'modified' => Iso8601DateTime(time()),
937 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
939 $rss->feed($feed_props);
941 while ($rev = $changes->next()) {
942 // enforce view permission
943 if (mayAccessPage('view', $rev->_pagename)) {
944 $props = $this->item_properties($rev);
945 $rss->addItem($props,
947 $this->pageURI($rev));
949 $this->setValidators($rev);
954 $request->discardOutput();
956 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
957 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
958 // Flush errors in comment, otherwise it's invalid XML.
959 global $ErrorManager;
960 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
961 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
963 $request->finish(); // NORETURN!!!!
966 function item_properties ($rev) {
967 $page = $rev->getPage();
968 $pagename = $page->getName();
969 return array( 'title' => $pagename,
970 'link' => array('rel' => 'alternate',
971 'type' => 'text/html',
972 'href' => $this->pageURL($rev)),
973 'summary' => $this->summary($rev),
974 'modified' => $this->time($rev)."Z",
975 'issued' => $this->time($rev),
976 'created' => $this->time($rev)."Z",
977 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
983 * Filter by non-empty
985 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
989 * @param $revisions object a WikiDB_PageRevisionIterator.
991 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
992 $this->_revisions = $revisions;
993 $this->_check_current_revision = $check_current_revision;
997 while (($rev = $this->_revisions->next())) {
998 if ($this->_check_current_revision) {
999 $page = $rev->getPage();
1000 $check_rev = $page->getCurrentRevision();
1005 if (! $check_rev->hasDefaultContents())
1015 * Filter by only_new.
1016 * Only new created pages
1018 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1022 * @param $revisions object a WikiDB_PageRevisionIterator.
1024 function NewPageRevisionIterator ($revisions) {
1025 $this->_revisions = $revisions;
1029 while (($rev = $this->_revisions->next())) {
1030 if ($rev->getVersion() == 1)
1039 * Only pages with links to a certain category
1041 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1043 function LinkRevisionIterator ($revisions, $category) {
1044 $this->_revisions = $revisions;
1045 if (preg_match("/[\?\.\*]/", $category)) {
1046 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1047 (new TextSearchQuery("*", true),
1048 new TextSearchQuery($category, true),
1051 $basepage = $GLOBALS['request']->getPage($category);
1052 $backlinkiter = $basepage->getBackLinks(true);
1054 $this->links = array();
1055 foreach ($backlinkiter->asArray() as $p) {
1056 if (is_object($p)) $this->links[] = $p->getName();
1057 elseif (is_array($p)) $this->links[] = $p['pagename'];
1058 else $this->links[] = $p;
1060 $backlinkiter->free();
1065 while (($rev = $this->_revisions->next())) {
1066 if (binary_search($rev->getName(), $this->links) != false)
1074 unset ($this->links);
1078 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1080 function PageMatchRevisionIterator ($revisions, $match) {
1081 $this->_revisions = $revisions;
1082 $this->search = new TextSearchQuery($match, true);
1086 while (($rev = $this->_revisions->next())) {
1087 if ($this->search->match($rev->getName()))
1095 unset ($this->search);
1102 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1104 function AuthorPageRevisionIterator ($revisions, $author) {
1105 $this->_revisions = $revisions;
1106 $this->_author = $author;
1110 while (($rev = $this->_revisions->next())) {
1111 if ($rev->get('author_id') == $this->_author)
1122 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1124 function OwnerPageRevisionIterator ($revisions, $owner) {
1125 $this->_revisions = $revisions;
1126 $this->_owner = $owner;
1130 while (($rev = $this->_revisions->next())) {
1131 $page = $rev->getPage();
1132 if ($page->getOwner() == $this->_owner)
1140 class WikiPlugin_RecentChanges
1143 function getName () {
1144 return _("RecentChanges");
1147 function getVersion() {
1148 return preg_replace("/[Revision: $]/", '',
1152 function managesValidators() {
1153 // Note that this is a bit of a fig.
1154 // We set validators based on the most recently changed page,
1155 // but this fails when the most-recent page is deleted.
1156 // (Consider that the Last-Modified time will decrease
1157 // when this happens.)
1159 // We might be better off, leaving this as false (and junking
1160 // the validator logic above) and just falling back to the
1161 // default behavior (handled by WikiPlugin) of just using
1162 // the WikiDB global timestamp as the mtime.
1164 // Nevertheless, for now, I leave this here, mostly as an
1165 // example for how to use appendValidators() and managesValidators().
1170 function getDefaultArguments() {
1171 return array('days' => 2,
1172 'show_minor' => false,
1173 'show_major' => true,
1174 'show_all' => false,
1175 'show_deleted' => 'sometimes',
1176 'only_new' => false,
1182 'difflinks' => true,
1183 'historylinks' => false,
1190 function getArgs ($argstr, $request, $defaults = false) {
1191 if (!$defaults) $defaults = $this->getDefaultArguments();
1192 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1194 $action = $request->getArg('action');
1195 if ($action != 'browse' && ! $request->isActionPage($action))
1196 $args['format'] = false; // default -> HTML
1198 if ($args['format'] == 'rss' && empty($args['limit']))
1199 $args['limit'] = 15; // Fix default value for RSS.
1200 if ($args['format'] == 'rss2' && empty($args['limit']))
1201 $args['limit'] = 15; // Fix default value for RSS2.
1203 if ($args['format'] == 'sidebar' && empty($args['limit']))
1204 $args['limit'] = 10; // Fix default value for sidebar.
1209 function getMostRecentParams (&$args) {
1210 $show_all = false; $show_minor = false; $show_major = false;
1214 $params = array('include_minor_revisions' => $show_minor,
1215 'exclude_major_revisions' => !$show_major,
1216 'include_all_revisions' => !empty($show_all));
1218 $params['limit'] = $limit;
1219 if (!empty($args['author'])) {
1221 if ($args['author'] == '[]')
1222 $args['author'] = $request->_user->getID();
1223 $params['author'] = $args['author'];
1225 if (!empty($args['owner'])) {
1227 if ($args['owner'] == '[]')
1228 $args['owner'] = $request->_user->getID();
1229 $params['owner'] = $args['owner'];
1231 if (!empty($days)) {
1233 $params['since'] = time() - 24 * 3600 * $days;
1234 elseif ($days < 0.0)
1235 $params['since'] = 24 * 3600 * $days - time();
1241 function getChanges ($dbi, $args) {
1242 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1244 $show_deleted = @$args['show_deleted'];
1245 $show_all = @$args['show_all'];
1246 if ($show_deleted == 'sometimes')
1247 $show_deleted = @$args['show_minor'];
1249 // only pages (e.g. PageHistory of subpages)
1250 if (!empty($args['pagematch'])) {
1251 require_once("lib/TextSearchQuery.php");
1252 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1254 if (!empty($args['category'])) {
1255 require_once("lib/TextSearchQuery.php");
1256 $changes = new LinkRevisionIterator($changes, $args['category']);
1258 if (!empty($args['only_new']))
1259 $changes = new NewPageRevisionIterator($changes);
1260 if (!empty($args['author']))
1261 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1262 if (!empty($args['owner']))
1263 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1265 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1270 function format ($changes, $args) {
1272 $format = $args['format'];
1274 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1276 if ($format == 'rss')
1277 $fmt_class = '_RecentChanges_RssFormatter';
1278 elseif ($format == 'rss2')
1279 $fmt_class = '_RecentChanges_Rss2Formatter';
1280 elseif ($format == 'atom')
1281 $fmt_class = '_RecentChanges_AtomFormatter';
1282 elseif ($format == 'rss091') {
1283 include_once "lib/RSSWriter091.php";
1284 $fmt_class = '_RecentChanges_RssFormatter091';
1286 elseif ($format == 'sidebar')
1287 $fmt_class = '_RecentChanges_SideBarFormatter';
1288 elseif ($format == 'box')
1289 $fmt_class = '_RecentChanges_BoxFormatter';
1290 elseif ($format == 'contribs')
1291 $fmt_class = '_RecentChanges_UserContribsFormatter';
1293 $fmt_class = '_RecentChanges_HtmlFormatter';
1296 $fmt = new $fmt_class($args);
1297 return $fmt->format($changes);
1300 function run($dbi, $argstr, &$request, $basepage) {
1301 $args = $this->getArgs($argstr, $request);
1303 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1304 // to be enough for anyone.)
1305 $args['days'] = min($args['days'], 365000);
1307 // Within Categories just display Category Backlinks
1308 if (empty($args['category']) and empty($args['pagematch'])
1309 and preg_match("/^Category/", $request->getArg('pagename')))
1311 $args['category'] = $request->getArg('pagename');
1314 // Hack alert: format() is a NORETURN for rss formatters.
1315 return $this->format($this->getChanges($dbi, $args), $args);
1318 // box is used to display a fixed-width, narrow version with common header.
1319 // just a numbered list of limit pagenames, without date.
1320 function box($args = false, $request = false, $basepage = false) {
1321 if (!$request) $request =& $GLOBALS['request'];
1322 if (!isset($args['limit'])) $args['limit'] = 15;
1323 $args['format'] = 'box';
1324 $args['show_minor'] = false;
1325 $args['show_major'] = true;
1326 $args['show_deleted'] = 'sometimes';
1327 $args['show_all'] = false;
1329 return $this->makeBox(WikiLink($this->getName(),'',
1330 SplitPagename($this->getName())),
1332 ($this->getChanges($request->_dbi, $args), $args));
1337 class OptionsButtonBars extends HtmlElement {
1339 function OptionsButtonBars ($plugin_args) {
1340 $this->__construct('fieldset', array('class' => 'wiki-rc-action'));
1342 // Display selection buttons
1343 extract($plugin_args);
1347 $caption = _("Show changes for:");
1350 $this->pushContent(HTML::legend($caption));
1351 $table = HTML::table();
1354 foreach (explode(",", $daylist) as $days) {
1355 $tr->pushContent($this->_makeDayButton($days));
1357 $table->pushContent($tr);
1360 $tr->pushContent($this->_makeUsersButton(0));
1361 $tr->pushContent($this->_makeUsersButton(1));
1362 $table->pushContent($tr);
1365 $tr->pushContent($this->_makePagesButton(0));
1366 $tr->pushContent($this->_makePagesButton(1));
1367 $table->pushContent($tr);
1370 $tr->pushContent($this->_makeMinorButton(1));
1371 $tr->pushContent($this->_makeMinorButton(0));
1372 $table->pushContent($tr);
1375 $tr->pushContent($this->_makeShowAllButton(1));
1376 $tr->pushContent($this->_makeShowAllButton(0));
1377 $table->pushContent($tr);
1380 $tr->pushContent($this->_makeNewPagesButton(0));
1381 $tr->pushContent($this->_makeNewPagesButton(1));
1382 $table->pushContent($tr);
1384 $this->pushContent($table);
1387 function _makeDayButton ($days) {
1391 $label = _("1 day");
1393 $label = _("All time");
1395 $label = sprintf(_("%s days"), abs($days));
1397 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1398 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1399 if ($url == $selfurl) {
1400 return HTML::td(array('class'=>'tdselected'), $label);
1402 return HTML::td(array('class'=>'tdunselected'),
1403 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1406 function _makeUsersButton ($users) {
1410 $label = _("All users");
1413 $label = _("My modifications only");
1417 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1418 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
1419 if ($url == $selfurl) {
1420 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1422 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1423 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1426 function _makePagesButton ($pages) {
1430 $label = _("All pages");
1433 $label = _("My pages only");
1437 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1438 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1439 if ($url == $selfurl) {
1440 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1442 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1443 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1446 function _makeMinorButton ($minor) {
1450 $label = _("Major modifications only");
1452 $label = _("All modifications");
1455 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1456 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor));
1457 if ($url == $selfurl) {
1458 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1460 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1461 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1464 function _makeShowAllButton ($showall) {
1467 if ($showall == 0) {
1468 $label = _("Page once only");
1470 $label = _("Full changes");
1473 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1474 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall));
1475 if ($url == $selfurl) {
1476 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1478 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1479 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1482 function _makeNewPagesButton ($newpages) {
1485 if ($newpages == 0) {
1486 $label = _("Old and new pages");
1488 $label = _("New pages only");
1491 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1492 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages));
1493 if ($url == $selfurl) {
1494 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1497 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1498 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1502 // (c-file-style: "gnu")
1506 // c-basic-offset: 4
1507 // c-hanging-comment-ender-p: nil
1508 // indent-tabs-mode: nil