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 if ($this->_args['daylist'])
449 $html->pushContent // force display of OptionsButtonBars
451 ("document.getElementById('rc-action-body').style.display='block';"));
452 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
453 $this->empty_message()));
459 function format_revision ($rev) {
461 $args = &$this->_args;
463 $class = 'rc-' . $this->importance($rev);
465 $time = $this->time($rev);
466 if ($rev->get('is_minor_edit')) {
467 $minor_flag = HTML(" ",
468 HTML::span(array('class' => 'pageinfo-minoredit'),
469 "(" . _("minor edit") . ")"));
471 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
475 $line = HTML::li(array('class' => $class));
477 if ($args['difflinks'])
478 $line->pushContent($this->diffLink($rev), ' ');
480 if ($args['historylinks'])
481 $line->pushContent($this->historyLink($rev), ' ');
483 // Do not display a link for a deleted page, just the page name
484 if ($rev->hasDefaultContents()) {
485 $linkorname = $rev->_pagename;
487 $linkorname = $this->pageLink($rev);
490 if ((isa($WikiTheme, 'WikiTheme_MonoBook')) or (isa($WikiTheme, 'WikiTheme_gforge'))) {
492 $args['historylinks'] ? '' : $this->historyLink($rev),
493 ' . . ', $linkorname, '; ',
495 $this->authorLink($rev),' ',
496 $this->authorContribs($rev),' ',
497 $this->summaryAsHTML($rev),' ',
500 $line->pushContent($linkorname, ' ',
502 $this->summaryAsHTML($rev),
504 $this->authorLink($rev));
511 /* format=contribs: no seperation into extra dates
512 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
514 class _RecentChanges_UserContribsFormatter
515 extends _RecentChanges_HtmlFormatter
517 function headline () {
519 extract($this->_args);
520 if ($author == '[]') $author = $request->_user->getID();
521 if ($owner == '[]') $owner = $request->_user->getID();
522 $author_args = $owner
523 ? array('owner' => $owner)
524 : array('author' => $author);
525 return array(_("UserContribs"),":",$owner ? $owner : $author,
527 $this->rss_icon($author_args),
528 $this->rss2_icon($author_args),
529 $this->atom_icon($author_args),
530 $this->rdf_icon($author_args),
531 $this->grazr_icon($author_args));
534 function format ($changes) {
535 include_once('lib/InlineParser.php');
537 $html = HTML(HTML::h2(false, $this->headline()));
539 $first = true; $count = 0;
540 while ($rev = $changes->next()) {
541 if (mayAccessPage('view', $rev->_pagename)) {
542 $lines->pushContent($this->format_revision($rev));
544 $this->setValidators($rev);
549 $this->_args['limit'] = $count;
550 if (($desc = $this->description()))
551 $html->pushContent($desc);
552 if ($this->_args['daylist']) {
553 $html->pushContent(new OptionsButtonBars($this->_args));
556 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
557 $this->empty_message()));
559 $html->pushContent($lines);
564 function format_revision ($rev) {
565 $args = &$this->_args;
566 $class = 'rc-' . $this->importance($rev);
567 $time = $this->time($rev);
568 if (! $rev->get('is_minor_edit'))
569 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
571 $line = HTML::li(array('class' => $class));
573 $line->pushContent($this->time($rev),", ");
574 $line->pushContent($this->date($rev)," ");
575 $line->pushContent($this->diffLink($rev), ' ');
576 $line->pushContent($this->historyLink($rev), ' ');
577 $line->pushContent($this->pageLink($rev), ' ',
578 $this->summaryAsHTML($rev));
583 class _RecentChanges_SideBarFormatter
584 extends _RecentChanges_HtmlFormatter
586 function rss_icon () {
589 function rss2_icon () { }
590 function headline () {
591 //title click opens the normal RC or RE page in the main browser frame
592 extract($this->_args);
593 $titlelink = WikiLink($this->title());
594 $titlelink->setAttr('target', '_content');
595 return HTML($this->logo(), $titlelink);
598 //logo click opens the HomePage in the main browser frame
600 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
603 'style' => 'height:2.5ex'
605 $linkurl = WikiLink(HOME_PAGE, false, $img);
606 $linkurl->setAttr('target', '_content');
610 function authorLink ($rev) {
611 $author = $rev->get('author');
612 if ( $this->authorHasPage($author) ) {
613 $linkurl = WikiLink($author);
614 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
620 function diffLink ($rev) {
621 $linkurl = parent::diffLink($rev);
622 $linkurl->setAttr('target', '_content');
623 $linkurl->setAttr('rel', 'nofollow');
624 // FIXME: Smelly hack to get smaller diff buttons in sidebar
625 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
628 function historyLink ($rev) {
629 $linkurl = parent::historyLink($rev);
630 $linkurl->setAttr('target', '_content');
631 // FIXME: Smelly hack to get smaller history buttons in sidebar
632 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
635 function pageLink ($rev) {
636 $linkurl = parent::pageLink($rev);
637 $linkurl->setAttr('target', '_content');
640 // Overriding summaryAsHTML, because there is no way yet to
641 // return summary as transformed text with
642 // links setAttr('target', '_content') in Mozilla sidebar.
643 // So for now don't create clickable links inside summary
644 // in the sidebar, or else they target the sidebar and not the
645 // main content window.
646 function summaryAsHTML ($rev) {
647 if ( !($summary = $this->summary($rev)) )
649 return HTML::span(array('class' => 'wiki-summary'),
651 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
656 function format ($changes) {
657 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
658 $html = _RecentChanges_HtmlFormatter::format ($changes);
659 $html = HTML::div(array('class' => 'wikitext'), $html);
661 $request->discardOutput();
663 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
664 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
665 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
666 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
669 extract($this->_args);
670 if (!empty($category))
672 elseif (!empty($pagematch))
675 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
676 printf("<title>" . $title . "</title>\n");
678 $css = $WikiTheme->getCSS();
682 printf("<body class=\"sidebar\">\n");
684 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>';
685 printf("\n</body>\n");
688 $request->finish(); // cut rest of page processing short
692 class _RecentChanges_BoxFormatter
693 extends _RecentChanges_HtmlFormatter
695 function rss_icon () {
697 function rss2_icon () {
699 function headline () {
701 function authorLink ($rev) {
703 function diffLink ($rev) {
705 function historyLink ($rev) {
707 function summaryAsHTML ($rev) {
709 function description () {
711 function format ($changes) {
712 include_once('lib/InlineParser.php');
717 $sp = HTML::Raw("\n · ");
718 while ($rev = $changes->next()) {
719 // enforce view permission
720 if (mayAccessPage('view',$rev->_pagename)) {
721 if ($link = $this->pageLink($rev)) // some entries may be empty
722 // (/Blog/.. interim pages)
723 $html->pushContent($sp, $link, HTML::br());
725 $this->setValidators($rev);
730 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
731 $this->empty_message()));
736 class _RecentChanges_RssFormatter
737 extends _RecentChanges_Formatter
739 var $_absurls = true;
741 function time ($rev) {
742 return Iso8601DateTime($rev->get('mtime'));
745 function pageURI ($rev) {
746 return WikiURL($rev, '', 'absurl');
749 function format ($changes) {
751 include_once('lib/RssWriter.php');
752 $rss = new RssWriter;
753 $rss->channel($this->channel_properties());
755 if (($props = $this->image_properties()))
757 if (($props = $this->textinput_properties()))
758 $rss->textinput($props);
761 while ($rev = $changes->next()) {
762 // enforce view permission
763 if (mayAccessPage('view', $rev->_pagename)) {
764 $rss->addItem($this->item_properties($rev),
765 $this->pageURI($rev));
767 $this->setValidators($rev);
773 $request->discardOutput();
775 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
776 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
778 // Flush errors in comment, otherwise it's invalid XML.
779 global $ErrorManager;
780 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
781 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
783 $request->finish(); // NORETURN!!!!
786 function image_properties () {
789 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
793 return array('title' => WIKI_NAME,
794 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
798 function textinput_properties () {
799 return array('title' => _("Search"),
800 'description' => _("Title Search"),
802 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
805 function channel_properties () {
808 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
809 extract($this->_args);
811 $description = $this->title();
816 return array('title' => $title,
818 'description' => $description,
819 'dc:date' => Iso8601DateTime(time()),
820 'dc:language' => $GLOBALS['LANG']);
822 /* FIXME: other things one might like in <channel>:
831 * rss091:managingEditor
833 * rss091:lastBuildDate
838 function item_properties ($rev) {
839 $page = $rev->getPage();
840 $pagename = $page->getName();
842 return array( 'title' => SplitPagename($pagename),
843 'description' => $this->summary($rev),
844 'link' => $this->pageURL($rev),
845 'dc:date' => $this->time($rev),
846 'dc:contributor' => $rev->get('author'),
847 'wiki:version' => $rev->getVersion(),
848 'wiki:importance' => $this->importance($rev),
849 'wiki:status' => $this->status($rev),
850 'wiki:diff' => $this->diffURL($rev),
851 'wiki:history' => $this->historyURL($rev)
856 /** explicit application/rss+xml Content-Type,
857 * simplified xml structure (no namespace),
858 * support for xml-rpc cloud registerProcedure (not yet)
860 class _RecentChanges_Rss2Formatter
861 extends _RecentChanges_RssFormatter {
863 function format ($changes) {
864 include_once('lib/RssWriter2.php');
865 $rss = new RssWriter2;
867 $rss->channel($this->channel_properties());
868 if (($props = $this->cloud_properties()))
870 if (($props = $this->image_properties()))
872 if (($props = $this->textinput_properties()))
873 $rss->textinput($props);
875 while ($rev = $changes->next()) {
876 // enforce view permission
877 if (mayAccessPage('view', $rev->_pagename)) {
878 $rss->addItem($this->item_properties($rev),
879 $this->pageURI($rev));
881 $this->setValidators($rev);
887 $request->discardOutput();
889 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
890 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
891 // Flush errors in comment, otherwise it's invalid XML.
892 global $ErrorManager;
893 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
894 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
896 $request->finish(); // NORETURN!!!!
899 function channel_properties () {
900 $chann_10 = parent::channel_properties();
901 return array_merge($chann_10,
902 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
903 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
904 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
905 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
906 'copyright' => COPYRIGHTPAGE_URL
910 // xml-rpc registerProcedure not yet implemented
911 function cloud_properties () { return false; }
912 function cloud_properties_test () {
913 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
914 'registerProcedure' => 'wiki.rssPleaseNotify',
915 'path' => DATA_PATH.'/RPC2.php',
916 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
917 'domain' => SERVER_NAME);
921 /** Explicit application/atom+xml Content-Type
922 * A weird, questionable format
924 class _RecentChanges_AtomFormatter
925 extends _RecentChanges_RssFormatter {
927 function format ($changes) {
929 include_once('lib/RssWriter.php');
932 // "channel" is called "feed" in atom
933 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
934 extract($this->_args);
936 $description = $this->title();
941 $feed_props = array('title' => $description,
942 'link' => array('rel'=>"alternate",
945 'id' => md5($rc_url),
946 'modified' => Iso8601DateTime(time()),
947 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
949 $rss->feed($feed_props);
951 while ($rev = $changes->next()) {
952 // enforce view permission
953 if (mayAccessPage('view', $rev->_pagename)) {
954 $props = $this->item_properties($rev);
955 $rss->addItem($props,
957 $this->pageURI($rev));
959 $this->setValidators($rev);
964 $request->discardOutput();
966 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
967 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
968 // Flush errors in comment, otherwise it's invalid XML.
969 global $ErrorManager;
970 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
971 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
973 $request->finish(); // NORETURN!!!!
976 function item_properties ($rev) {
977 $page = $rev->getPage();
978 $pagename = $page->getName();
979 return array( 'title' => $pagename,
980 'link' => array('rel' => 'alternate',
981 'type' => 'text/html',
982 'href' => $this->pageURL($rev)),
983 'summary' => $this->summary($rev),
984 'modified' => $this->time($rev)."Z",
985 'issued' => $this->time($rev),
986 'created' => $this->time($rev)."Z",
987 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
993 * Filter by non-empty
995 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
999 * @param $revisions object a WikiDB_PageRevisionIterator.
1001 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
1002 $this->_revisions = $revisions;
1003 $this->_check_current_revision = $check_current_revision;
1007 while (($rev = $this->_revisions->next())) {
1008 if ($this->_check_current_revision) {
1009 $page = $rev->getPage();
1010 $check_rev = $page->getCurrentRevision();
1015 if (! $check_rev->hasDefaultContents())
1025 * Filter by only_new.
1026 * Only new created pages
1028 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1032 * @param $revisions object a WikiDB_PageRevisionIterator.
1034 function NewPageRevisionIterator ($revisions) {
1035 $this->_revisions = $revisions;
1039 while (($rev = $this->_revisions->next())) {
1040 if ($rev->getVersion() == 1)
1049 * Only pages with links to a certain category
1051 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1053 function LinkRevisionIterator ($revisions, $category) {
1054 $this->_revisions = $revisions;
1055 if (preg_match("/[\?\.\*]/", $category)) {
1056 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1057 (new TextSearchQuery("*", true),
1058 new TextSearchQuery($category, true),
1061 $basepage = $GLOBALS['request']->getPage($category);
1062 $backlinkiter = $basepage->getBackLinks(true);
1064 $this->links = array();
1065 foreach ($backlinkiter->asArray() as $p) {
1066 if (is_object($p)) $this->links[] = $p->getName();
1067 elseif (is_array($p)) $this->links[] = $p['pagename'];
1068 else $this->links[] = $p;
1070 $backlinkiter->free();
1075 while (($rev = $this->_revisions->next())) {
1076 if (binary_search($rev->getName(), $this->links) != false)
1084 unset ($this->links);
1088 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1090 function PageMatchRevisionIterator ($revisions, $match) {
1091 $this->_revisions = $revisions;
1092 $this->search = new TextSearchQuery($match, true);
1096 while (($rev = $this->_revisions->next())) {
1097 if ($this->search->match($rev->getName()))
1105 unset ($this->search);
1112 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1114 function AuthorPageRevisionIterator ($revisions, $author) {
1115 $this->_revisions = $revisions;
1116 $this->_author = $author;
1120 while (($rev = $this->_revisions->next())) {
1121 if ($rev->get('author_id') == $this->_author)
1132 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1134 function OwnerPageRevisionIterator ($revisions, $owner) {
1135 $this->_revisions = $revisions;
1136 $this->_owner = $owner;
1140 while (($rev = $this->_revisions->next())) {
1141 $page = $rev->getPage();
1142 if ($page->getOwner() == $this->_owner)
1150 class WikiPlugin_RecentChanges
1153 function getName () {
1154 return _("RecentChanges");
1157 function getDescription () {
1158 return _("List all recent changes in this wiki.");
1161 function getVersion() {
1162 return preg_replace("/[Revision: $]/", '',
1166 function managesValidators() {
1167 // Note that this is a bit of a fig.
1168 // We set validators based on the most recently changed page,
1169 // but this fails when the most-recent page is deleted.
1170 // (Consider that the Last-Modified time will decrease
1171 // when this happens.)
1173 // We might be better off, leaving this as false (and junking
1174 // the validator logic above) and just falling back to the
1175 // default behavior (handled by WikiPlugin) of just using
1176 // the WikiDB global timestamp as the mtime.
1178 // Nevertheless, for now, I leave this here, mostly as an
1179 // example for how to use appendValidators() and managesValidators().
1184 function getDefaultArguments() {
1185 return array('days' => 2,
1186 'show_minor' => false,
1187 'show_major' => true,
1188 'show_all' => false,
1189 'show_deleted' => 'sometimes',
1190 'only_new' => false,
1196 'difflinks' => true,
1197 'historylinks' => false,
1204 function getArgs ($argstr, $request, $defaults = false) {
1205 if (!$defaults) $defaults = $this->getDefaultArguments();
1206 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1208 $action = $request->getArg('action');
1209 if ($action != 'browse' && ! $request->isActionPage($action))
1210 $args['format'] = false; // default -> HTML
1212 if ($args['format'] == 'rss' && empty($args['limit']))
1213 $args['limit'] = 15; // Fix default value for RSS.
1214 if ($args['format'] == 'rss2' && empty($args['limit']))
1215 $args['limit'] = 15; // Fix default value for RSS2.
1217 if ($args['format'] == 'sidebar' && empty($args['limit']))
1218 $args['limit'] = 10; // Fix default value for sidebar.
1223 function getMostRecentParams (&$args) {
1224 $show_all = false; $show_minor = false; $show_major = false;
1228 $params = array('include_minor_revisions' => $show_minor,
1229 'exclude_major_revisions' => !$show_major,
1230 'include_all_revisions' => !empty($show_all));
1232 $params['limit'] = $limit;
1233 if (!empty($args['author'])) {
1235 if ($args['author'] == '[]')
1236 $args['author'] = $request->_user->getID();
1237 $params['author'] = $args['author'];
1239 if (!empty($args['owner'])) {
1241 if ($args['owner'] == '[]')
1242 $args['owner'] = $request->_user->getID();
1243 $params['owner'] = $args['owner'];
1245 if (!empty($days)) {
1247 $params['since'] = time() - 24 * 3600 * $days;
1248 elseif ($days < 0.0)
1249 $params['since'] = 24 * 3600 * $days - time();
1255 function getChanges ($dbi, $args) {
1256 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1258 $show_deleted = @$args['show_deleted'];
1259 $show_all = @$args['show_all'];
1260 if ($show_deleted == 'sometimes')
1261 $show_deleted = @$args['show_minor'];
1263 // only pages (e.g. PageHistory of subpages)
1264 if (!empty($args['pagematch'])) {
1265 require_once("lib/TextSearchQuery.php");
1266 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1268 if (!empty($args['category'])) {
1269 require_once("lib/TextSearchQuery.php");
1270 $changes = new LinkRevisionIterator($changes, $args['category']);
1272 if (!empty($args['only_new']))
1273 $changes = new NewPageRevisionIterator($changes);
1274 if (!empty($args['author']))
1275 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1276 if (!empty($args['owner']))
1277 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1279 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1284 function format ($changes, $args) {
1286 $format = $args['format'];
1288 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1290 if ($format == 'rss')
1291 $fmt_class = '_RecentChanges_RssFormatter';
1292 elseif ($format == 'rss2')
1293 $fmt_class = '_RecentChanges_Rss2Formatter';
1294 elseif ($format == 'atom')
1295 $fmt_class = '_RecentChanges_AtomFormatter';
1296 elseif ($format == 'rss091') {
1297 include_once "lib/RSSWriter091.php";
1298 $fmt_class = '_RecentChanges_RssFormatter091';
1300 elseif ($format == 'sidebar')
1301 $fmt_class = '_RecentChanges_SideBarFormatter';
1302 elseif ($format == 'box')
1303 $fmt_class = '_RecentChanges_BoxFormatter';
1304 elseif ($format == 'contribs')
1305 $fmt_class = '_RecentChanges_UserContribsFormatter';
1307 $fmt_class = '_RecentChanges_HtmlFormatter';
1310 $fmt = new $fmt_class($args);
1311 return $fmt->format($changes);
1314 function run($dbi, $argstr, &$request, $basepage) {
1315 $args = $this->getArgs($argstr, $request);
1317 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1318 // to be enough for anyone.)
1319 $args['days'] = min($args['days'], 365000);
1321 // Within Categories just display Category Backlinks
1322 if (empty($args['category']) and empty($args['pagematch'])
1323 and preg_match("/^Category/", $request->getArg('pagename')))
1325 $args['category'] = $request->getArg('pagename');
1328 // Hack alert: format() is a NORETURN for rss formatters.
1329 return $this->format($this->getChanges($dbi, $args), $args);
1332 // box is used to display a fixed-width, narrow version with common header.
1333 // just a numbered list of limit pagenames, without date.
1334 function box($args = false, $request = false, $basepage = false) {
1335 if (!$request) $request =& $GLOBALS['request'];
1336 if (!isset($args['limit'])) $args['limit'] = 15;
1337 $args['format'] = 'box';
1338 $args['show_minor'] = false;
1339 $args['show_major'] = true;
1340 $args['show_deleted'] = 'sometimes';
1341 $args['show_all'] = false;
1343 return $this->makeBox(WikiLink($this->getName(),'',
1344 SplitPagename($this->getName())),
1346 ($this->getChanges($request->_dbi, $args), $args));
1351 class OptionsButtonBars extends HtmlElement {
1353 function OptionsButtonBars ($plugin_args) {
1354 $this->__construct('fieldset', array('class' => 'wiki-rc-action'));
1356 // Add ShowHideFolder button
1357 $icon = $GLOBALS['WikiTheme']->_findData('images/folderArrowOpen.png');
1358 $img = HTML::img(array('id' => 'rc-action-img',
1360 'onclick' => "showHideFolder('rc-action')",
1361 'alt' => _("Click to hide/show"),
1362 'title' => _("Click to hide/show")));
1364 // Display selection buttons
1365 extract($plugin_args);
1369 $caption = _("Show changes for:");
1372 $this->pushContent(HTML::legend($caption,' ',$img));
1373 $table = HTML::table(array('id' => 'rc-action-body',
1374 'style' => 'display:block'));
1377 foreach (explode(",", $daylist) as $days_button) {
1378 $tr->pushContent($this->_makeDayButton($days_button, $days));
1380 $table->pushContent($tr);
1383 $tr->pushContent($this->_makeUsersButton(0));
1384 $tr->pushContent($this->_makeUsersButton(1));
1385 $table->pushContent($tr);
1388 $tr->pushContent($this->_makePagesButton(0));
1389 $tr->pushContent($this->_makePagesButton(1));
1390 $table->pushContent($tr);
1393 $tr->pushContent($this->_makeMinorButton(1, $show_minor));
1394 $tr->pushContent($this->_makeMinorButton(0, $show_minor));
1395 $table->pushContent($tr);
1398 $tr->pushContent($this->_makeShowAllButton(1, $show_all));
1399 $tr->pushContent($this->_makeShowAllButton(0, $show_all));
1400 $table->pushContent($tr);
1403 $tr->pushContent($this->_makeNewPagesButton(0, $only_new));
1404 $tr->pushContent($this->_makeNewPagesButton(1, $only_new));
1405 $table->pushContent($tr);
1407 $this->pushContent($table);
1410 function _makeDayButton ($days_button, $days) {
1413 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days_button));
1414 if ($days_button == 1) {
1415 $label = _("1 day");
1416 } elseif ($days_button < 1) {
1417 $label = _("All time");
1419 $label = sprintf(_("%s days"), abs($days_button));
1421 $selected = HTML::td(array('class'=>'tdselected'), $label);
1422 $unselected = HTML::td(array('class'=>'tdunselected'),
1423 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1424 return ($days_button == $days) ? $selected : $unselected;
1427 function _makeUsersButton ($users) {
1431 $label = _("All users");
1434 $label = _("My modifications only");
1438 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1439 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
1440 if ($url == $selfurl) {
1441 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1443 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1444 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1447 function _makePagesButton ($pages) {
1451 $label = _("All pages");
1454 $label = _("My pages only");
1458 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1459 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1460 if ($url == $selfurl) {
1461 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1463 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1464 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1467 function _makeMinorButton ($minor_button, $show_minor) {
1470 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor_button));
1471 $label = ($minor_button == 0) ? _("Major modifications only") : _("All modifications");
1472 $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1473 $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1474 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1475 return ($minor_button == $show_minor) ? $selected : $unselected;
1478 function _makeShowAllButton ($showall_button, $show_all) {
1481 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall_button));
1482 $label = ($showall_button == 0) ? _("Page once only") : _("Full changes");
1483 $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1484 $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1485 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1486 return ($showall_button == $show_all) ? $selected : $unselected;
1489 function _makeNewPagesButton ($newpages_button, $only_new) {
1492 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages_button));
1493 $label = ($newpages_button == 0) ? _("Old and new pages") : _("New pages only");
1494 $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1495 $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1496 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1497 return ($newpages_button == $only_new) ? $selected : $unselected;
1501 // (c-file-style: "gnu")
1505 // c-basic-offset: 4
1506 // c-hanging-comment-ender-p: nil
1507 // indent-tabs-mode: nil