4 Copyright 1999,2000,2001,2002,2007 $ThePhpWikiProgrammingTeam
5 Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 This file is part of PhpWiki.
9 PhpWiki is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 PhpWiki is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with PhpWiki; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 include_once("lib/WikiPlugin.php");
26 class _RecentChanges_Formatter
28 var $_absurls = false;
29 var $action = "RecentChanges";
31 function _RecentChanges_Formatter ($rc_args) {
32 $this->_args = $rc_args;
33 $this->_diffargs = array('action' => 'diff');
35 if ($rc_args['show_minor'] || !$rc_args['show_major'])
36 $this->_diffargs['previous'] = 'minor';
38 // PageHistoryPlugin doesn't have a 'daylist' arg.
39 if (!isset($this->_args['daylist']))
40 $this->_args['daylist'] = false;
45 extract($this->_args);
49 $title = $request->_user->getID();
51 $title = _("UserContribs").": $title";
55 $title = $request->_user->getID();
57 $title = _("UserContribs").": $title";
58 } elseif ($only_new) {
59 $title = _("RecentNewPages");
60 } elseif ($show_minor) {
61 $title = _("RecentEdits");
62 } else $title = _("RecentChanges");
64 if (!empty($category))
66 elseif (!empty($pagematch))
67 $title .= ":$pagematch";
71 function include_versions_in_URLs() {
72 return (bool) $this->_args['show_all'];
75 function date ($rev) {
77 return $WikiTheme->getDay($rev->get('mtime'));
80 function time ($rev) {
82 return $WikiTheme->formatTime($rev->get('mtime'));
85 function diffURL ($rev) {
86 $args = $this->_diffargs;
87 if ($this->include_versions_in_URLs())
88 $args['version'] = $rev->getVersion();
89 $page = $rev->getPage();
90 return WikiURL($page->getName(), $args, $this->_absurls);
93 function historyURL ($rev) {
94 $page = $rev->getPage();
95 return WikiURL($page, array('action' => _("PageHistory")),
99 function pageURL ($rev) {
100 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
101 '', $this->_absurls);
104 function authorHasPage ($author) {
105 global $WikiNameRegexp, $request;
106 $dbi = $request->getDbh();
107 return isWikiWord($author) && $dbi->isWikiPage($author);
110 function authorURL ($author) {
111 return $this->authorHasPage() ? WikiURL($author) : false;
115 function status ($rev) {
116 if ($rev->hasDefaultContents())
118 $page = $rev->getPage();
119 $prev = $page->getRevisionBefore($rev->getVersion());
120 if ($prev->hasDefaultContents())
125 function importance ($rev) {
126 return $rev->get('is_minor_edit') ? 'minor' : 'major';
129 function summary($rev) {
130 if ( ($summary = $rev->get('summary')) )
133 switch ($this->status($rev)) {
137 return _("New page");
143 function setValidators($most_recent_rev) {
144 $rev = $most_recent_rev;
145 $validators = array('RecentChanges-top' =>
146 array($rev->getPageName(), $rev->getVersion()),
147 '%mtime' => $rev->get('mtime'));
149 $request->appendValidators($validators);
153 class _RecentChanges_HtmlFormatter
154 extends _RecentChanges_Formatter
156 function diffLink ($rev) {
158 $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
159 $button->setAttr('rel', 'nofollow');
160 return HTML("(",$button,")");
163 /* deletions: red, additions: green */
164 function diffSummary ($rev) {
165 $html = $this->diffURL($rev);
169 function historyLink ($rev) {
171 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
172 $button->setAttr('rel', 'nofollow');
173 return HTML("(",$button,")");
176 function pageLink ($rev, $link_text=false) {
178 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
181 $page = $rev->getPage();
183 if ($this->include_versions_in_URLs()) {
184 $version = $rev->getVersion();
185 if ($rev->isCurrent())
187 $exists = !$rev->hasDefaultContents();
191 $cur = $page->getCurrentRevision();
192 $exists = !$cur->hasDefaultContents();
195 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
197 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
201 function authorLink ($rev) {
202 return WikiLink($rev->get('author'), 'if_known');
205 /* Link to all users contributions (contribs and owns) */
206 function authorContribs ($rev) {
207 $author = $rev->get('author');
208 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
210 Button(array('action' => _("RecentChanges"),
211 'format' => 'contribs',
217 Button(array('action' => _("RecentChanges"),
218 'format' => 'contribs',
226 function summaryAsHTML ($rev) {
227 if ( !($summary = $this->summary($rev)) )
229 return HTML::span( array('class' => 'wiki-summary'),
231 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
235 function format_icon ($format, $filter = array()) {
236 global $request, $WikiTheme;
237 $args = $this->_args;
238 // remove links not used for those formats
239 unset($args['daylist']);
240 unset($args['difflinks']);
241 unset($args['historylinks']);
242 $rss_url = $request->getURLtoSelf
244 array('action' => $this->action, 'format' => $format),
246 return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
249 function rss_icon ($args=array()) { return $this->format_icon("rss", $args); }
250 function rss2_icon ($args=array()) { return $this->format_icon("rss2", $args); }
251 function atom_icon ($args=array()) { return $this->format_icon("atom", $args); }
252 function rdf_icon ($args=array()) { return DEBUG ? $this->format_icon("rdf", $args) : ''; }
253 function rdfs_icon ($args=array()) { return DEBUG ? $this->format_icon("rdfs", $args) : ''; }
254 function owl_icon ($args=array()) { return DEBUG ? $this->format_icon("owl", $args) : ''; }
256 function grazr_icon ($args = array()) {
257 global $request, $WikiTheme;
258 if (is_localhost()) return '';
259 if (SERVER_PROTOCOL == "https") return '';
260 $our_url = WikiURL($request->getArg('pagename'),
261 array_merge(array('action' => $this->action, 'format' => 'rss2'), $args),
263 $rss_url = 'http://grazr.com/gzpanel.html?' . $our_url;
264 return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
267 function pre_description () {
268 extract($this->_args);
269 // FIXME: say something about show_all.
270 if ($show_major && $show_minor)
273 $edits = _("major edits");
275 $edits = _("minor edits");
276 if (isset($caption) and $caption == _("Recent Comments"))
277 $edits = _("comments");
278 if (!empty($only_new)) {
279 $edits = _("created new pages");
281 if (!empty($author)) {
284 $author = $request->_user->getID();
285 $edits .= sprintf(_(" for pages changed by %s"), $author);
287 if (!empty($owner)) {
290 $owner = $request->_user->getID();
291 $edits .= sprintf(_(" for pages owned by %s"), $owner);
293 if (!empty($category)) {
294 $edits .= sprintf(_(" for all pages linking to %s"), $category);
296 if (!empty($pagematch)) {
297 $edits .= sprintf(_(" for all pages matching '%s'"), $pagematch);
299 if ($timespan = $days > 0) {
300 if (intval($days) != $days)
301 $days = sprintf("%.1f", $days);
305 * Depending how this text is split up it can be tricky or
306 * impossible to translate with good grammar. So the seperate
307 * strings for 1 day and %s days are necessary in this case
308 * for translating to multiple languages, due to differing
309 * overlapping ideal word cutting points.
311 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
312 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
313 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
315 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
316 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
317 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
321 if (intval($days) == 1)
322 $desc = fmt("The %d most recent %s during the past day are listed below.",
325 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
326 $limit, $edits, $days);
328 $desc = fmt("The %d most recent %s are listed below.",
331 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
333 if (intval($days) == 1)
334 $desc = fmt("The %d oldest %s during the past day are listed below.",
337 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
338 $lmt, $edits, $days);
340 $desc = fmt("The %d oldest %s are listed below.",
346 if (intval($days) == 1)
347 $desc = fmt("The most recent %s during the past day are listed below.",
350 $desc = fmt("The most recent %s during the past %s days are listed below.",
353 $desc = fmt("All %s are listed below.", $edits);
358 function description() {
359 return HTML::p(false, $this->pre_description());
363 function headline () {
364 extract($this->_args);
365 return array($this->title(),
371 /*$this->rdfs_icon(),
374 $this->sidebar_link());
377 function empty_message() {
378 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
379 return _("No comments found");
381 return _("No changes found");
384 function sidebar_link() {
385 extract($this->_args);
386 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
389 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
392 "function addPanel() {\n"
393 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
394 ." \"$sidebarurl\",\"\");\n"
396 $jsf = JavaScript($addsidebarjsfunc);
399 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
400 array('title' => _("Click to add this feed to your sidebar"),
401 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
402 $addsidebarjsclick = asXML($sidebar_button);
403 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
404 ." (typeof window.sidebar.addPanel == 'function'))\n"
406 ." document.write('$addsidebarjsclick');\n"
409 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
412 function format ($changes) {
413 include_once('lib/InlineParser.php');
415 $html = HTML(HTML::h2(false, $this->headline()));
416 if (($desc = $this->description()))
417 $html->pushContent($desc);
419 if ($this->_args['daylist']) {
420 $html->pushContent(new OptionsButtonBars($this->_args));
427 while ($rev = $changes->next()) {
428 if (($date = $this->date($rev)) != $last_date) {
430 $html->pushContent($lines);
431 // for user contributions no extra date line
432 $html->pushContent(HTML::h3($date));
437 // enforce view permission
438 if (mayAccessPage('view', $rev->_pagename)) {
439 $lines->pushContent($this->format_revision($rev));
441 $this->setValidators($rev);
446 $html->pushContent($lines);
448 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
449 $this->empty_message()));
454 function format_revision ($rev) {
456 $args = &$this->_args;
458 $class = 'rc-' . $this->importance($rev);
460 $time = $this->time($rev);
461 if (! $rev->get('is_minor_edit'))
462 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
464 $line = HTML::li(array('class' => $class));
466 if ($args['difflinks'])
467 $line->pushContent($this->diffLink($rev), ' ');
469 if ($args['historylinks'])
470 $line->pushContent($this->historyLink($rev), ' ');
472 // Do not display a link for a deleted page, just the page name
473 if ($rev->hasDefaultContents()) {
474 $linkorname = $rev->_pagename;
476 $linkorname = $this->pageLink($rev);
479 if ((isa($WikiTheme, 'WikiTheme_MonoBook')) or (isa($WikiTheme, 'WikiTheme_gforge'))) {
481 $args['historylinks'] ? '' : $this->historyLink($rev),
482 ' . . ', $linkorname, '; ',
484 $this->authorLink($rev),' ',
485 $this->authorContribs($rev),' ',
486 $this->summaryAsHTML($rev));
488 $line->pushContent($linkorname, ' ',
490 $this->summaryAsHTML($rev),
492 $this->authorLink($rev));
499 /* format=contribs: no seperation into extra dates
500 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
502 class _RecentChanges_UserContribsFormatter
503 extends _RecentChanges_HtmlFormatter
505 function headline () {
507 extract($this->_args);
508 if ($author == '[]') $author = $request->_user->getID();
509 if ($owner == '[]') $owner = $request->_user->getID();
510 $author_args = $owner
511 ? array('owner' => $owner)
512 : array('author' => $author);
513 return array(_("UserContribs"),":",$owner ? $owner : $author,
515 $this->rss_icon($author_args),
516 $this->rss2_icon($author_args),
517 $this->atom_icon($author_args),
518 $this->rdf_icon($author_args),
519 $this->grazr_icon($author_args));
522 function format ($changes) {
523 include_once('lib/InlineParser.php');
525 $html = HTML(HTML::h2(false, $this->headline()));
527 $first = true; $count = 0;
528 while ($rev = $changes->next()) {
529 if (mayAccessPage('view', $rev->_pagename)) {
530 $lines->pushContent($this->format_revision($rev));
532 $this->setValidators($rev);
537 $this->_args['limit'] = $count;
538 if (($desc = $this->description()))
539 $html->pushContent($desc);
540 if ($this->_args['daylist']) {
541 $html->pushContent(new OptionsButtonBars($this->_args));
544 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
545 $this->empty_message()));
547 $html->pushContent($lines);
552 function format_revision ($rev) {
553 $args = &$this->_args;
554 $class = 'rc-' . $this->importance($rev);
555 $time = $this->time($rev);
556 if (! $rev->get('is_minor_edit'))
557 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
559 $line = HTML::li(array('class' => $class));
561 $line->pushContent($this->time($rev),", ");
562 $line->pushContent($this->date($rev)," ");
563 $line->pushContent($this->diffLink($rev), ' ');
564 $line->pushContent($this->historyLink($rev), ' ');
565 $line->pushContent($this->pageLink($rev), ' ',
566 $this->summaryAsHTML($rev));
571 class _RecentChanges_SideBarFormatter
572 extends _RecentChanges_HtmlFormatter
574 function rss_icon () {
577 function rss2_icon () { }
578 function headline () {
579 //title click opens the normal RC or RE page in the main browser frame
580 extract($this->_args);
581 $titlelink = WikiLink($this->title());
582 $titlelink->setAttr('target', '_content');
583 return HTML($this->logo(), $titlelink);
586 //logo click opens the HomePage in the main browser frame
588 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
591 'style' => 'height:2.5ex'
593 $linkurl = WikiLink(HOME_PAGE, false, $img);
594 $linkurl->setAttr('target', '_content');
598 function authorLink ($rev) {
599 $author = $rev->get('author');
600 if ( $this->authorHasPage($author) ) {
601 $linkurl = WikiLink($author);
602 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
608 function diffLink ($rev) {
609 $linkurl = parent::diffLink($rev);
610 $linkurl->setAttr('target', '_content');
611 $linkurl->setAttr('rel', 'nofollow');
612 // FIXME: Smelly hack to get smaller diff buttons in sidebar
613 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
616 function historyLink ($rev) {
617 $linkurl = parent::historyLink($rev);
618 $linkurl->setAttr('target', '_content');
619 // FIXME: Smelly hack to get smaller history buttons in sidebar
620 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
623 function pageLink ($rev) {
624 $linkurl = parent::pageLink($rev);
625 $linkurl->setAttr('target', '_content');
628 // Overriding summaryAsHTML, because there is no way yet to
629 // return summary as transformed text with
630 // links setAttr('target', '_content') in Mozilla sidebar.
631 // So for now don't create clickable links inside summary
632 // in the sidebar, or else they target the sidebar and not the
633 // main content window.
634 function summaryAsHTML ($rev) {
635 if ( !($summary = $this->summary($rev)) )
637 return HTML::span(array('class' => 'wiki-summary'),
639 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
644 function format ($changes) {
645 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
646 $html = _RecentChanges_HtmlFormatter::format ($changes);
647 $html = HTML::div(array('class' => 'wikitext'), $html);
649 $request->discardOutput();
651 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
652 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
653 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
654 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
657 extract($this->_args);
658 if (!empty($category))
660 elseif (!empty($pagematch))
663 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
664 printf("<title>" . $title . "</title>\n");
666 $css = $WikiTheme->getCSS();
670 printf("<body class=\"sidebar\">\n");
672 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>';
673 printf("\n</body>\n");
676 $request->finish(); // cut rest of page processing short
680 class _RecentChanges_BoxFormatter
681 extends _RecentChanges_HtmlFormatter
683 function rss_icon () {
685 function rss2_icon () {
687 function headline () {
689 function authorLink ($rev) {
691 function diffLink ($rev) {
693 function historyLink ($rev) {
695 function summaryAsHTML ($rev) {
697 function description () {
699 function format ($changes) {
700 include_once('lib/InlineParser.php');
705 $sp = HTML::Raw("\n · ");
706 while ($rev = $changes->next()) {
707 // enforce view permission
708 if (mayAccessPage('view',$rev->_pagename)) {
709 if ($link = $this->pageLink($rev)) // some entries may be empty
710 // (/Blog/.. interim pages)
711 $html->pushContent($sp, $link, HTML::br());
713 $this->setValidators($rev);
718 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
719 $this->empty_message()));
724 class _RecentChanges_RssFormatter
725 extends _RecentChanges_Formatter
727 var $_absurls = true;
729 function time ($rev) {
730 return Iso8601DateTime($rev->get('mtime'));
733 function pageURI ($rev) {
734 return WikiURL($rev, '', 'absurl');
737 function format ($changes) {
739 include_once('lib/RssWriter.php');
740 $rss = new RssWriter;
741 $rss->channel($this->channel_properties());
743 if (($props = $this->image_properties()))
745 if (($props = $this->textinput_properties()))
746 $rss->textinput($props);
749 while ($rev = $changes->next()) {
750 // enforce view permission
751 if (mayAccessPage('view', $rev->_pagename)) {
752 $rss->addItem($this->item_properties($rev),
753 $this->pageURI($rev));
755 $this->setValidators($rev);
761 $request->discardOutput();
763 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
764 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
766 // Flush errors in comment, otherwise it's invalid XML.
767 global $ErrorManager;
768 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
769 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
771 $request->finish(); // NORETURN!!!!
774 function image_properties () {
777 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
781 return array('title' => WIKI_NAME,
782 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
786 function textinput_properties () {
787 return array('title' => _("Search"),
788 'description' => _("Title Search"),
790 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
793 function channel_properties () {
796 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
797 extract($this->_args);
799 $description = $this->title();
804 return array('title' => $title,
806 'description' => $description,
807 'dc:date' => Iso8601DateTime(time()),
808 'dc:language' => $GLOBALS['LANG']);
810 /* FIXME: other things one might like in <channel>:
819 * rss091:managingEditor
821 * rss091:lastBuildDate
826 function item_properties ($rev) {
827 $page = $rev->getPage();
828 $pagename = $page->getName();
830 return array( 'title' => SplitPagename($pagename),
831 'description' => $this->summary($rev),
832 'link' => $this->pageURL($rev),
833 'dc:date' => $this->time($rev),
834 'dc:contributor' => $rev->get('author'),
835 'wiki:version' => $rev->getVersion(),
836 'wiki:importance' => $this->importance($rev),
837 'wiki:status' => $this->status($rev),
838 'wiki:diff' => $this->diffURL($rev),
839 'wiki:history' => $this->historyURL($rev)
844 /** explicit application/rss+xml Content-Type,
845 * simplified xml structure (no namespace),
846 * support for xml-rpc cloud registerProcedure (not yet)
848 class _RecentChanges_Rss2Formatter
849 extends _RecentChanges_RssFormatter {
851 function format ($changes) {
852 include_once('lib/RssWriter2.php');
853 $rss = new RssWriter2;
855 $rss->channel($this->channel_properties());
856 if (($props = $this->cloud_properties()))
858 if (($props = $this->image_properties()))
860 if (($props = $this->textinput_properties()))
861 $rss->textinput($props);
863 while ($rev = $changes->next()) {
864 // enforce view permission
865 if (mayAccessPage('view', $rev->_pagename)) {
866 $rss->addItem($this->item_properties($rev),
867 $this->pageURI($rev));
869 $this->setValidators($rev);
875 $request->discardOutput();
877 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
878 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
879 // Flush errors in comment, otherwise it's invalid XML.
880 global $ErrorManager;
881 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
882 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
884 $request->finish(); // NORETURN!!!!
887 function channel_properties () {
888 $chann_10 = parent::channel_properties();
889 return array_merge($chann_10,
890 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
891 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
892 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
893 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
894 'copyright' => COPYRIGHTPAGE_URL
898 // xml-rpc registerProcedure not yet implemented
899 function cloud_properties () { return false; }
900 function cloud_properties_test () {
901 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
902 'registerProcedure' => 'wiki.rssPleaseNotify',
903 'path' => DATA_PATH.'/RPC2.php',
904 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
905 'domain' => SERVER_NAME);
909 /** Explicit application/atom+xml Content-Type
910 * A weird, questionable format
912 class _RecentChanges_AtomFormatter
913 extends _RecentChanges_RssFormatter {
915 function format ($changes) {
917 include_once('lib/RssWriter.php');
920 // "channel" is called "feed" in atom
921 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
922 extract($this->_args);
924 $description = $this->title();
929 $feed_props = array('title' => $description,
930 'link' => array('rel'=>"alternate",
933 'id' => md5($rc_url),
934 'modified' => Iso8601DateTime(time()),
935 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
937 $rss->feed($feed_props);
939 while ($rev = $changes->next()) {
940 // enforce view permission
941 if (mayAccessPage('view', $rev->_pagename)) {
942 $props = $this->item_properties($rev);
943 $rss->addItem($props,
945 $this->pageURI($rev));
947 $this->setValidators($rev);
952 $request->discardOutput();
954 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
955 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
956 // Flush errors in comment, otherwise it's invalid XML.
957 global $ErrorManager;
958 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
959 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
961 $request->finish(); // NORETURN!!!!
964 function item_properties ($rev) {
965 $page = $rev->getPage();
966 $pagename = $page->getName();
967 return array( 'title' => $pagename,
968 'link' => array('rel' => 'alternate',
969 'type' => 'text/html',
970 'href' => $this->pageURL($rev)),
971 'summary' => $this->summary($rev),
972 'modified' => $this->time($rev)."Z",
973 'issued' => $this->time($rev),
974 'created' => $this->time($rev)."Z",
975 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
981 * Filter by non-empty
983 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
987 * @param $revisions object a WikiDB_PageRevisionIterator.
989 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
990 $this->_revisions = $revisions;
991 $this->_check_current_revision = $check_current_revision;
995 while (($rev = $this->_revisions->next())) {
996 if ($this->_check_current_revision) {
997 $page = $rev->getPage();
998 $check_rev = $page->getCurrentRevision();
1003 if (! $check_rev->hasDefaultContents())
1013 * Filter by only_new.
1014 * Only new created pages
1016 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1020 * @param $revisions object a WikiDB_PageRevisionIterator.
1022 function NewPageRevisionIterator ($revisions) {
1023 $this->_revisions = $revisions;
1027 while (($rev = $this->_revisions->next())) {
1028 if ($rev->getVersion() == 1)
1037 * Only pages with links to a certain category
1039 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1041 function LinkRevisionIterator ($revisions, $category) {
1042 $this->_revisions = $revisions;
1043 if (preg_match("/[\?\.\*]/", $category)) {
1044 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1045 (new TextSearchQuery("*", true),
1046 new TextSearchQuery($category, true),
1049 $basepage = $GLOBALS['request']->getPage($category);
1050 $backlinkiter = $basepage->getBackLinks(true);
1052 $this->links = array();
1053 foreach ($backlinkiter->asArray() as $p) {
1054 if (is_object($p)) $this->links[] = $p->getName();
1055 elseif (is_array($p)) $this->links[] = $p['pagename'];
1056 else $this->links[] = $p;
1058 $backlinkiter->free();
1063 while (($rev = $this->_revisions->next())) {
1064 if (binary_search($rev->getName(), $this->links) != false)
1072 unset ($this->links);
1076 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1078 function PageMatchRevisionIterator ($revisions, $match) {
1079 $this->_revisions = $revisions;
1080 $this->search = new TextSearchQuery($match, true);
1084 while (($rev = $this->_revisions->next())) {
1085 if ($this->search->match($rev->getName()))
1093 unset ($this->search);
1100 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1102 function AuthorPageRevisionIterator ($revisions, $author) {
1103 $this->_revisions = $revisions;
1104 $this->_author = $author;
1108 while (($rev = $this->_revisions->next())) {
1109 if ($rev->get('author_id') == $this->_author)
1120 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1122 function OwnerPageRevisionIterator ($revisions, $owner) {
1123 $this->_revisions = $revisions;
1124 $this->_owner = $owner;
1128 while (($rev = $this->_revisions->next())) {
1129 $page = $rev->getPage();
1130 if ($page->getOwner() == $this->_owner)
1138 class WikiPlugin_RecentChanges
1141 function getName () {
1142 return _("RecentChanges");
1145 function getDescription () {
1146 return _("List all recent changes in this wiki.");
1149 function getVersion() {
1150 return preg_replace("/[Revision: $]/", '',
1154 function managesValidators() {
1155 // Note that this is a bit of a fig.
1156 // We set validators based on the most recently changed page,
1157 // but this fails when the most-recent page is deleted.
1158 // (Consider that the Last-Modified time will decrease
1159 // when this happens.)
1161 // We might be better off, leaving this as false (and junking
1162 // the validator logic above) and just falling back to the
1163 // default behavior (handled by WikiPlugin) of just using
1164 // the WikiDB global timestamp as the mtime.
1166 // Nevertheless, for now, I leave this here, mostly as an
1167 // example for how to use appendValidators() and managesValidators().
1172 function getDefaultArguments() {
1173 return array('days' => 2,
1174 'show_minor' => false,
1175 'show_major' => true,
1176 'show_all' => false,
1177 'show_deleted' => 'sometimes',
1178 'only_new' => false,
1184 'difflinks' => true,
1185 'historylinks' => false,
1192 function getArgs ($argstr, $request, $defaults = false) {
1193 if (!$defaults) $defaults = $this->getDefaultArguments();
1194 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1196 $action = $request->getArg('action');
1197 if ($action != 'browse' && ! $request->isActionPage($action))
1198 $args['format'] = false; // default -> HTML
1200 if ($args['format'] == 'rss' && empty($args['limit']))
1201 $args['limit'] = 15; // Fix default value for RSS.
1202 if ($args['format'] == 'rss2' && empty($args['limit']))
1203 $args['limit'] = 15; // Fix default value for RSS2.
1205 if ($args['format'] == 'sidebar' && empty($args['limit']))
1206 $args['limit'] = 10; // Fix default value for sidebar.
1211 function getMostRecentParams (&$args) {
1212 $show_all = false; $show_minor = false; $show_major = false;
1216 $params = array('include_minor_revisions' => $show_minor,
1217 'exclude_major_revisions' => !$show_major,
1218 'include_all_revisions' => !empty($show_all));
1220 $params['limit'] = $limit;
1221 if (!empty($args['author'])) {
1223 if ($args['author'] == '[]')
1224 $args['author'] = $request->_user->getID();
1225 $params['author'] = $args['author'];
1227 if (!empty($args['owner'])) {
1229 if ($args['owner'] == '[]')
1230 $args['owner'] = $request->_user->getID();
1231 $params['owner'] = $args['owner'];
1233 if (!empty($days)) {
1235 $params['since'] = time() - 24 * 3600 * $days;
1236 elseif ($days < 0.0)
1237 $params['since'] = 24 * 3600 * $days - time();
1243 function getChanges ($dbi, $args) {
1244 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1246 $show_deleted = @$args['show_deleted'];
1247 $show_all = @$args['show_all'];
1248 if ($show_deleted == 'sometimes')
1249 $show_deleted = @$args['show_minor'];
1251 // only pages (e.g. PageHistory of subpages)
1252 if (!empty($args['pagematch'])) {
1253 require_once("lib/TextSearchQuery.php");
1254 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1256 if (!empty($args['category'])) {
1257 require_once("lib/TextSearchQuery.php");
1258 $changes = new LinkRevisionIterator($changes, $args['category']);
1260 if (!empty($args['only_new']))
1261 $changes = new NewPageRevisionIterator($changes);
1262 if (!empty($args['author']))
1263 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1264 if (!empty($args['owner']))
1265 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1267 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1272 function format ($changes, $args) {
1274 $format = $args['format'];
1276 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1278 if ($format == 'rss')
1279 $fmt_class = '_RecentChanges_RssFormatter';
1280 elseif ($format == 'rss2')
1281 $fmt_class = '_RecentChanges_Rss2Formatter';
1282 elseif ($format == 'atom')
1283 $fmt_class = '_RecentChanges_AtomFormatter';
1284 elseif ($format == 'rss091') {
1285 include_once "lib/RSSWriter091.php";
1286 $fmt_class = '_RecentChanges_RssFormatter091';
1288 elseif ($format == 'sidebar')
1289 $fmt_class = '_RecentChanges_SideBarFormatter';
1290 elseif ($format == 'box')
1291 $fmt_class = '_RecentChanges_BoxFormatter';
1292 elseif ($format == 'contribs')
1293 $fmt_class = '_RecentChanges_UserContribsFormatter';
1295 $fmt_class = '_RecentChanges_HtmlFormatter';
1298 $fmt = new $fmt_class($args);
1299 return $fmt->format($changes);
1302 function run($dbi, $argstr, &$request, $basepage) {
1303 $args = $this->getArgs($argstr, $request);
1305 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1306 // to be enough for anyone.)
1307 $args['days'] = min($args['days'], 365000);
1309 // Within Categories just display Category Backlinks
1310 if (empty($args['category']) and empty($args['pagematch'])
1311 and preg_match("/^Category/", $request->getArg('pagename')))
1313 $args['category'] = $request->getArg('pagename');
1316 // Hack alert: format() is a NORETURN for rss formatters.
1317 return $this->format($this->getChanges($dbi, $args), $args);
1320 // box is used to display a fixed-width, narrow version with common header.
1321 // just a numbered list of limit pagenames, without date.
1322 function box($args = false, $request = false, $basepage = false) {
1323 if (!$request) $request =& $GLOBALS['request'];
1324 if (!isset($args['limit'])) $args['limit'] = 15;
1325 $args['format'] = 'box';
1326 $args['show_minor'] = false;
1327 $args['show_major'] = true;
1328 $args['show_deleted'] = 'sometimes';
1329 $args['show_all'] = false;
1331 return $this->makeBox(WikiLink($this->getName(),'',
1332 SplitPagename($this->getName())),
1334 ($this->getChanges($request->_dbi, $args), $args));
1339 class OptionsButtonBars extends HtmlElement {
1341 function OptionsButtonBars ($plugin_args) {
1342 $this->__construct('fieldset', array('class' => 'wiki-rc-action'));
1344 // Display selection buttons
1345 extract($plugin_args);
1349 $caption = _("Show changes for:");
1352 $this->pushContent(HTML::legend($caption));
1353 $table = HTML::table();
1356 foreach (explode(",", $daylist) as $days) {
1357 $tr->pushContent($this->_makeDayButton($days));
1359 $table->pushContent($tr);
1362 $tr->pushContent($this->_makeUsersButton(0));
1363 $tr->pushContent($this->_makeUsersButton(1));
1364 $table->pushContent($tr);
1367 $tr->pushContent($this->_makePagesButton(0));
1368 $tr->pushContent($this->_makePagesButton(1));
1369 $table->pushContent($tr);
1372 $tr->pushContent($this->_makeMinorButton(1));
1373 $tr->pushContent($this->_makeMinorButton(0));
1374 $table->pushContent($tr);
1377 $tr->pushContent($this->_makeShowAllButton(1));
1378 $tr->pushContent($this->_makeShowAllButton(0));
1379 $table->pushContent($tr);
1382 $tr->pushContent($this->_makeNewPagesButton(0));
1383 $tr->pushContent($this->_makeNewPagesButton(1));
1384 $table->pushContent($tr);
1386 $this->pushContent($table);
1389 function _makeDayButton ($days) {
1393 $label = _("1 day");
1395 $label = _("All time");
1397 $label = sprintf(_("%s days"), abs($days));
1399 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1400 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1401 if ($url == $selfurl) {
1402 return HTML::td(array('class'=>'tdselected'), $label);
1404 return HTML::td(array('class'=>'tdunselected'),
1405 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1408 function _makeUsersButton ($users) {
1412 $label = _("All users");
1415 $label = _("My modifications only");
1419 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1420 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
1421 if ($url == $selfurl) {
1422 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1424 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1425 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1428 function _makePagesButton ($pages) {
1432 $label = _("All pages");
1435 $label = _("My pages only");
1439 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1440 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1441 if ($url == $selfurl) {
1442 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1444 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1445 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1448 function _makeMinorButton ($minor) {
1452 $label = _("Major modifications only");
1454 $label = _("All modifications");
1457 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1458 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor));
1459 if ($url == $selfurl) {
1460 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1462 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1463 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1466 function _makeShowAllButton ($showall) {
1469 if ($showall == 0) {
1470 $label = _("Page once only");
1472 $label = _("Full changes");
1475 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1476 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall));
1477 if ($url == $selfurl) {
1478 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1480 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1481 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1484 function _makeNewPagesButton ($newpages) {
1487 if ($newpages == 0) {
1488 $label = _("Old and new pages");
1490 $label = _("New pages only");
1493 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1494 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages));
1495 if ($url == $selfurl) {
1496 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1499 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1500 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1504 // (c-file-style: "gnu")
1508 // c-basic-offset: 4
1509 // c-hanging-comment-ender-p: nil
1510 // indent-tabs-mode: nil