4 * Copyright 1999,2000,2001,2002,2007 $ThePhpWikiProgrammingTeam
5 * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 include_once 'lib/WikiPlugin.php';
26 class _RecentChanges_Formatter
28 var $_absurls = false;
29 var $action = "RecentChanges";
31 function _RecentChanges_Formatter ($rc_args) {
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()),
232 // We do parse the summary:
233 // 1) if the summary contains {{foo}}, the template must no be
235 // 2) if the summary contains camel case, and DISABLE_MARKUP_WIKIWORD
236 // is true, the camel case must not be linked.
237 // Side-effect: brackets are not linked. TBD.
242 function format_icon ($format, $filter = array()) {
243 global $request, $WikiTheme;
244 $args = $this->_args;
245 // remove links not used for those formats
246 unset($args['daylist']);
247 unset($args['difflinks']);
248 unset($args['historylinks']);
249 $rss_url = $request->getURLtoSelf
251 array('action' => $this->action, 'format' => $format),
253 return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
256 function rss_icon ($args=array()) { return $this->format_icon("rss", $args); }
257 function rss2_icon ($args=array()) { return $this->format_icon("rss2", $args); }
258 function atom_icon ($args=array()) { return $this->format_icon("atom", $args); }
259 function rdf_icon ($args=array()) { return DEBUG ? $this->format_icon("rdf", $args) : ''; }
260 function rdfs_icon ($args=array()) { return DEBUG ? $this->format_icon("rdfs", $args) : ''; }
261 function owl_icon ($args=array()) { return DEBUG ? $this->format_icon("owl", $args) : ''; }
263 function grazr_icon ($args = array()) {
264 global $request, $WikiTheme;
265 if (is_localhost()) return '';
266 if (SERVER_PROTOCOL == "https") return '';
267 $our_url = WikiURL($request->getArg('pagename'),
268 array_merge(array('action' => $this->action, 'format' => 'rss2'), $args),
270 $rss_url = 'http://grazr.com/gzpanel.html?' . $our_url;
271 return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
274 function pre_description () {
275 extract($this->_args);
276 // FIXME: say something about show_all.
277 if ($show_major && $show_minor)
280 $edits = _("major edits");
282 $edits = _("minor edits");
283 if (isset($caption) and $caption == _("Recent Comments"))
284 $edits = _("comments");
285 if (!empty($only_new)) {
286 $edits = _("created new pages");
288 if (!empty($author)) {
291 $author = $request->_user->getID();
292 $edits .= sprintf(_(" for pages changed by %s"), $author);
294 if (!empty($owner)) {
297 $owner = $request->_user->getID();
298 $edits .= sprintf(_(" for pages owned by %s"), $owner);
300 if (!empty($category)) {
301 $edits .= sprintf(_(" for all pages linking to %s"), $category);
303 if (!empty($pagematch)) {
304 $edits .= sprintf(_(" for all pages matching '%s'"), $pagematch);
306 if ($timespan = $days > 0) {
307 if (intval($days) != $days)
308 $days = sprintf("%.1f", $days);
312 * Depending how this text is split up it can be tricky or
313 * impossible to translate with good grammar. So the seperate
314 * strings for 1 day and %s days are necessary in this case
315 * for translating to multiple languages, due to differing
316 * overlapping ideal word cutting points.
318 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
319 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
320 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
322 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
323 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
324 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
328 if (intval($days) == 1)
329 $desc = fmt("The %d most recent %s during the past day are listed below.",
332 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
333 $limit, $edits, $days);
335 $desc = fmt("The %d most recent %s are listed below.",
338 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
340 if (intval($days) == 1)
341 $desc = fmt("The %d oldest %s during the past day are listed below.",
344 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
345 $lmt, $edits, $days);
347 $desc = fmt("The %d oldest %s are listed below.",
353 if (intval($days) == 1)
354 $desc = fmt("The most recent %s during the past day are listed below.",
357 $desc = fmt("The most recent %s during the past %s days are listed below.",
360 $desc = fmt("All %s are listed below.", $edits);
365 function description() {
366 return HTML::p(false, $this->pre_description());
370 function headline () {
371 extract($this->_args);
372 return array($this->title(),
378 /*$this->rdfs_icon(),
381 $this->sidebar_link());
384 function empty_message() {
385 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
386 return _("No comments found");
388 return _("No changes found");
391 function sidebar_link() {
392 extract($this->_args);
393 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
396 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
399 "function addPanel() {\n"
400 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
401 ." \"$sidebarurl\",\"\");\n"
403 $jsf = JavaScript($addsidebarjsfunc);
406 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
407 array('title' => _("Click to add this feed to your sidebar"),
408 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
409 $addsidebarjsclick = asXML($sidebar_button);
410 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
411 ." (typeof window.sidebar.addPanel == 'function'))\n"
413 ." document.write('$addsidebarjsclick');\n"
416 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
419 function format ($changes) {
420 include_once 'lib/InlineParser.php';
422 $html = HTML(HTML::h2(false, $this->headline()));
423 if (($desc = $this->description()))
424 $html->pushContent($desc);
426 if ($this->_args['daylist']) {
427 $html->pushContent(new OptionsButtonBars($this->_args));
434 while ($rev = $changes->next()) {
435 if (($date = $this->date($rev)) != $last_date) {
437 $html->pushContent($lines);
438 // for user contributions no extra date line
439 $html->pushContent(HTML::h3($date));
444 // enforce view permission
445 if (mayAccessPage('view', $rev->_pagename)) {
446 $lines->pushContent($this->format_revision($rev));
448 $this->setValidators($rev);
453 $html->pushContent($lines);
455 if ($this->_args['daylist'])
456 $html->pushContent // force display of OptionsButtonBars
458 ("document.getElementById('rc-action-body').style.display='block';"));
459 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
460 $this->empty_message()));
466 function format_revision ($rev) {
468 $args = &$this->_args;
470 $class = 'rc-' . $this->importance($rev);
472 $time = $this->time($rev);
473 if ($rev->get('is_minor_edit')) {
474 $minor_flag = HTML(" ",
475 HTML::span(array('class' => 'pageinfo-minoredit'),
476 "(" . _("minor edit") . ")"));
478 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
482 $line = HTML::li(array('class' => $class));
484 if ($args['difflinks'])
485 $line->pushContent($this->diffLink($rev), ' ');
487 if ($args['historylinks'])
488 $line->pushContent($this->historyLink($rev), ' ');
490 // Do not display a link for a deleted page, just the page name
491 if ($rev->hasDefaultContents()) {
492 $linkorname = $rev->_pagename;
494 $linkorname = $this->pageLink($rev);
497 if ((isa($WikiTheme, 'WikiTheme_MonoBook')) or (isa($WikiTheme, 'WikiTheme_fusionforge'))) {
499 $args['historylinks'] ? '' : $this->historyLink($rev),
500 ' . . ', $linkorname, '; ',
502 $this->authorLink($rev),' ',
503 $this->authorContribs($rev),' ',
504 $this->summaryAsHTML($rev),' ',
507 $line->pushContent($linkorname, ' ',
509 $this->summaryAsHTML($rev),
511 $this->authorLink($rev));
518 /* format=contribs: no seperation into extra dates
519 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
521 class _RecentChanges_UserContribsFormatter
522 extends _RecentChanges_HtmlFormatter
524 function headline () {
526 extract($this->_args);
527 if ($author == '[]') $author = $request->_user->getID();
528 if ($owner == '[]') $owner = $request->_user->getID();
529 $author_args = $owner
530 ? array('owner' => $owner)
531 : array('author' => $author);
532 return array(_("UserContribs"),":",$owner ? $owner : $author,
534 $this->rss_icon($author_args),
535 $this->rss2_icon($author_args),
536 $this->atom_icon($author_args),
537 $this->rdf_icon($author_args),
538 $this->grazr_icon($author_args));
541 function format ($changes) {
542 include_once 'lib/InlineParser.php';
544 $html = HTML(HTML::h2(false, $this->headline()));
546 $first = true; $count = 0;
547 while ($rev = $changes->next()) {
548 if (mayAccessPage('view', $rev->_pagename)) {
549 $lines->pushContent($this->format_revision($rev));
551 $this->setValidators($rev);
556 $this->_args['limit'] = $count;
557 if (($desc = $this->description()))
558 $html->pushContent($desc);
559 if ($this->_args['daylist']) {
560 $html->pushContent(new OptionsButtonBars($this->_args));
563 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
564 $this->empty_message()));
566 $html->pushContent($lines);
571 function format_revision ($rev) {
572 $args = &$this->_args;
573 $class = 'rc-' . $this->importance($rev);
574 $time = $this->time($rev);
575 if (! $rev->get('is_minor_edit'))
576 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
578 $line = HTML::li(array('class' => $class));
580 $line->pushContent($this->time($rev),", ");
581 $line->pushContent($this->date($rev)," ");
582 $line->pushContent($this->diffLink($rev), ' ');
583 $line->pushContent($this->historyLink($rev), ' ');
584 $line->pushContent($this->pageLink($rev), ' ',
585 $this->summaryAsHTML($rev));
590 class _RecentChanges_SideBarFormatter
591 extends _RecentChanges_HtmlFormatter
593 function rss_icon () {
596 function rss2_icon () { }
597 function headline () {
598 //title click opens the normal RC or RE page in the main browser frame
599 extract($this->_args);
600 $titlelink = WikiLink($this->title());
601 $titlelink->setAttr('target', '_content');
602 return HTML($this->logo(), $titlelink);
605 //logo click opens the HomePage in the main browser frame
607 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
609 'style' => 'height:2.5ex'
611 $linkurl = WikiLink(HOME_PAGE, false, $img);
612 $linkurl->setAttr('target', '_content');
616 function authorLink ($rev) {
617 $author = $rev->get('author');
618 if ( $this->authorHasPage($author) ) {
619 $linkurl = WikiLink($author);
620 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
626 function diffLink ($rev) {
627 $linkurl = parent::diffLink($rev);
628 $linkurl->setAttr('target', '_content');
629 $linkurl->setAttr('rel', 'nofollow');
630 // FIXME: Smelly hack to get smaller diff buttons in sidebar
631 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
634 function historyLink ($rev) {
635 $linkurl = parent::historyLink($rev);
636 $linkurl->setAttr('target', '_content');
637 // FIXME: Smelly hack to get smaller history buttons in sidebar
638 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
641 function pageLink ($rev) {
642 $linkurl = parent::pageLink($rev);
643 $linkurl->setAttr('target', '_content');
646 // Overriding summaryAsHTML, because there is no way yet to
647 // return summary as transformed text with
648 // links setAttr('target', '_content') in Mozilla sidebar.
649 // So for now don't create clickable links inside summary
650 // in the sidebar, or else they target the sidebar and not the
651 // main content window.
652 function summaryAsHTML ($rev) {
653 if ( !($summary = $this->summary($rev)) )
655 return HTML::span(array('class' => 'wiki-summary'),
657 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
662 function format ($changes) {
663 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
664 $html = _RecentChanges_HtmlFormatter::format ($changes);
665 $html = HTML::div(array('class' => 'wikitext'), $html);
667 $request->discardOutput();
669 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
670 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
671 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
672 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
675 extract($this->_args);
676 if (!empty($category))
678 elseif (!empty($pagematch))
681 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
682 printf("<title>" . $title . "</title>\n");
684 $css = $WikiTheme->getCSS();
688 printf("<body class=\"sidebar\">\n");
690 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>';
691 printf("\n</body>\n");
694 $request->finish(); // cut rest of page processing short
698 class _RecentChanges_BoxFormatter
699 extends _RecentChanges_HtmlFormatter
701 function rss_icon () {
703 function rss2_icon () {
705 function headline () {
707 function authorLink ($rev) {
709 function diffLink ($rev) {
711 function historyLink ($rev) {
713 function summaryAsHTML ($rev) {
715 function description () {
717 function format ($changes) {
718 include_once 'lib/InlineParser.php';
723 $sp = HTML::Raw("\n · ");
724 while ($rev = $changes->next()) {
725 // enforce view permission
726 if (mayAccessPage('view',$rev->_pagename)) {
727 if ($link = $this->pageLink($rev)) // some entries may be empty
728 // (/Blog/.. interim pages)
729 $html->pushContent($sp, $link, HTML::br());
731 $this->setValidators($rev);
736 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
737 $this->empty_message()));
742 class _RecentChanges_RssFormatter
743 extends _RecentChanges_Formatter
745 var $_absurls = true;
747 function time ($rev) {
748 return Iso8601DateTime($rev->get('mtime'));
751 function pageURI ($rev) {
752 return WikiURL($rev, '', 'absurl');
755 function format ($changes) {
757 include_once 'lib/RssWriter.php';
758 $rss = new RssWriter;
759 $rss->channel($this->channel_properties());
761 if (($props = $this->image_properties()))
763 if (($props = $this->textinput_properties()))
764 $rss->textinput($props);
767 while ($rev = $changes->next()) {
768 // enforce view permission
769 if (mayAccessPage('view', $rev->_pagename)) {
770 $rss->addItem($this->item_properties($rev),
771 $this->pageURI($rev));
773 $this->setValidators($rev);
779 $request->discardOutput();
781 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
782 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
784 // Flush errors in comment, otherwise it's invalid XML.
785 global $ErrorManager;
786 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
787 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
789 $request->finish(); // NORETURN!!!!
792 function image_properties () {
795 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
799 return array('title' => WIKI_NAME,
800 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
804 function textinput_properties () {
805 return array('title' => _("Search"),
806 'description' => _("Title Search"),
808 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
811 function channel_properties () {
814 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
815 extract($this->_args);
817 $description = $this->title();
822 return array('title' => $title,
824 'description' => $description,
825 'dc:date' => Iso8601DateTime(time()),
826 'dc:language' => $GLOBALS['LANG']);
828 /* FIXME: other things one might like in <channel>:
837 * rss091:managingEditor
839 * rss091:lastBuildDate
844 function item_properties ($rev) {
845 $page = $rev->getPage();
846 $pagename = $page->getName();
848 return array( 'title' => SplitPagename($pagename),
849 'description' => $this->summary($rev),
850 'link' => $this->pageURL($rev),
851 'dc:date' => $this->time($rev),
852 'dc:contributor' => $rev->get('author'),
853 'wiki:version' => $rev->getVersion(),
854 'wiki:importance' => $this->importance($rev),
855 'wiki:status' => $this->status($rev),
856 'wiki:diff' => $this->diffURL($rev),
857 'wiki:history' => $this->historyURL($rev)
862 /** explicit application/rss+xml Content-Type,
863 * simplified xml structure (no namespace),
864 * support for xml-rpc cloud registerProcedure (not yet)
866 class _RecentChanges_Rss2Formatter
867 extends _RecentChanges_RssFormatter {
869 function format ($changes) {
870 include_once 'lib/RssWriter2.php';
871 $rss = new RssWriter2;
873 $rss->channel($this->channel_properties());
874 if (($props = $this->cloud_properties()))
876 if (($props = $this->image_properties()))
878 if (($props = $this->textinput_properties()))
879 $rss->textinput($props);
881 while ($rev = $changes->next()) {
882 // enforce view permission
883 if (mayAccessPage('view', $rev->_pagename)) {
884 $rss->addItem($this->item_properties($rev),
885 $this->pageURI($rev));
887 $this->setValidators($rev);
893 $request->discardOutput();
895 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
896 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
897 // Flush errors in comment, otherwise it's invalid XML.
898 global $ErrorManager;
899 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
900 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
902 $request->finish(); // NORETURN!!!!
905 function channel_properties () {
906 $chann_10 = parent::channel_properties();
907 return array_merge($chann_10,
908 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
909 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
910 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
911 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
912 'copyright' => COPYRIGHTPAGE_URL
916 // xml-rpc registerProcedure not yet implemented
917 function cloud_properties () { return false; }
918 function cloud_properties_test () {
919 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
920 'registerProcedure' => 'wiki.rssPleaseNotify',
921 'path' => DATA_PATH.'/RPC2.php',
922 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
923 'domain' => SERVER_NAME);
927 /** Explicit application/atom+xml Content-Type
928 * A weird, questionable format
930 class _RecentChanges_AtomFormatter
931 extends _RecentChanges_RssFormatter {
933 function format ($changes) {
935 include_once 'lib/RssWriter.php';
938 // "channel" is called "feed" in atom
939 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
940 extract($this->_args);
942 $description = $this->title();
947 $feed_props = array('title' => $description,
948 'link' => array('rel'=>"alternate",
951 'id' => md5($rc_url),
952 'modified' => Iso8601DateTime(time()),
953 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
955 $rss->feed($feed_props);
957 while ($rev = $changes->next()) {
958 // enforce view permission
959 if (mayAccessPage('view', $rev->_pagename)) {
960 $props = $this->item_properties($rev);
961 $rss->addItem($props,
963 $this->pageURI($rev));
965 $this->setValidators($rev);
970 $request->discardOutput();
972 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
973 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
974 // Flush errors in comment, otherwise it's invalid XML.
975 global $ErrorManager;
976 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
977 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
979 $request->finish(); // NORETURN!!!!
982 function item_properties ($rev) {
983 $page = $rev->getPage();
984 $pagename = $page->getName();
985 return array( 'title' => $pagename,
986 'link' => array('rel' => 'alternate',
987 'type' => 'text/html',
988 'href' => $this->pageURL($rev)),
989 'summary' => $this->summary($rev),
990 'modified' => $this->time($rev)."Z",
991 'issued' => $this->time($rev),
992 'created' => $this->time($rev)."Z",
993 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
999 * Filter by non-empty
1001 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
1005 * @param $revisions object a WikiDB_PageRevisionIterator.
1007 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
1008 $this->_revisions = $revisions;
1009 $this->_check_current_revision = $check_current_revision;
1013 while (($rev = $this->_revisions->next())) {
1014 if ($this->_check_current_revision) {
1015 $page = $rev->getPage();
1016 $check_rev = $page->getCurrentRevision();
1021 if (! $check_rev->hasDefaultContents())
1031 * Filter by only_new.
1032 * Only new created pages
1034 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1038 * @param $revisions object a WikiDB_PageRevisionIterator.
1040 function NewPageRevisionIterator ($revisions) {
1041 $this->_revisions = $revisions;
1045 while (($rev = $this->_revisions->next())) {
1046 if ($rev->getVersion() == 1)
1055 * Only pages with links to a certain category
1057 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1059 function LinkRevisionIterator ($revisions, $category) {
1060 $this->_revisions = $revisions;
1061 if (preg_match("/[\?\.\*]/", $category)) {
1062 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1063 (new TextSearchQuery("*", true),
1064 new TextSearchQuery($category, true),
1067 $basepage = $GLOBALS['request']->getPage($category);
1068 $backlinkiter = $basepage->getBackLinks(true);
1070 $this->links = array();
1071 foreach ($backlinkiter->asArray() as $p) {
1072 if (is_object($p)) $this->links[] = $p->getName();
1073 elseif (is_array($p)) $this->links[] = $p['pagename'];
1074 else $this->links[] = $p;
1076 $backlinkiter->free();
1081 while (($rev = $this->_revisions->next())) {
1082 if (binary_search($rev->getName(), $this->links) != false)
1090 unset ($this->links);
1094 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1096 function PageMatchRevisionIterator ($revisions, $match) {
1097 $this->_revisions = $revisions;
1098 $this->search = new TextSearchQuery($match, true);
1102 while (($rev = $this->_revisions->next())) {
1103 if ($this->search->match($rev->getName()))
1111 unset ($this->search);
1118 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1120 function AuthorPageRevisionIterator ($revisions, $author) {
1121 $this->_revisions = $revisions;
1122 $this->_author = $author;
1126 while (($rev = $this->_revisions->next())) {
1127 if ($rev->get('author_id') == $this->_author)
1138 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1140 function OwnerPageRevisionIterator ($revisions, $owner) {
1141 $this->_revisions = $revisions;
1142 $this->_owner = $owner;
1146 while (($rev = $this->_revisions->next())) {
1147 $page = $rev->getPage();
1148 if ($page->getOwner() == $this->_owner)
1156 class WikiPlugin_RecentChanges
1159 function getName () {
1160 return _("RecentChanges");
1163 function getDescription () {
1164 return _("List all recent changes in this wiki.");
1167 function managesValidators() {
1168 // Note that this is a bit of a fig.
1169 // We set validators based on the most recently changed page,
1170 // but this fails when the most-recent page is deleted.
1171 // (Consider that the Last-Modified time will decrease
1172 // when this happens.)
1174 // We might be better off, leaving this as false (and junking
1175 // the validator logic above) and just falling back to the
1176 // default behavior (handled by WikiPlugin) of just using
1177 // the WikiDB global timestamp as the mtime.
1179 // Nevertheless, for now, I leave this here, mostly as an
1180 // example for how to use appendValidators() and managesValidators().
1185 function getDefaultArguments() {
1186 return array('days' => 2,
1187 'show_minor' => false,
1188 'show_major' => true,
1189 'show_all' => false,
1190 'show_deleted' => 'sometimes',
1191 'only_new' => false,
1197 'difflinks' => true,
1198 'historylinks' => false,
1205 function getArgs ($argstr, $request, $defaults = false) {
1206 if (!$defaults) $defaults = $this->getDefaultArguments();
1207 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1209 $action = $request->getArg('action');
1210 if ($action != 'browse' && !isActionPage($action))
1211 $args['format'] = false; // default -> HTML
1213 if ($args['format'] == 'rss' && empty($args['limit']))
1214 $args['limit'] = 15; // Fix default value for RSS.
1215 if ($args['format'] == 'rss2' && empty($args['limit']))
1216 $args['limit'] = 15; // Fix default value for RSS2.
1218 if ($args['format'] == 'sidebar' && empty($args['limit']))
1219 $args['limit'] = 10; // Fix default value for sidebar.
1224 function getMostRecentParams (&$args) {
1225 $show_all = false; $show_minor = false; $show_major = false;
1229 $params = array('include_minor_revisions' => $show_minor,
1230 'exclude_major_revisions' => !$show_major,
1231 'include_all_revisions' => !empty($show_all));
1233 $params['limit'] = $limit;
1234 if (!empty($args['author'])) {
1236 if ($args['author'] == '[]')
1237 $args['author'] = $request->_user->getID();
1238 $params['author'] = $args['author'];
1240 if (!empty($args['owner'])) {
1242 if ($args['owner'] == '[]')
1243 $args['owner'] = $request->_user->getID();
1244 $params['owner'] = $args['owner'];
1246 if (!empty($days)) {
1248 $params['since'] = time() - 24 * 3600 * $days;
1249 elseif ($days < 0.0)
1250 $params['since'] = 24 * 3600 * $days - time();
1256 function getChanges ($dbi, $args) {
1257 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1259 $show_deleted = @$args['show_deleted'];
1260 $show_all = @$args['show_all'];
1261 if ($show_deleted == 'sometimes')
1262 $show_deleted = @$args['show_minor'];
1264 // only pages (e.g. PageHistory of subpages)
1265 if (!empty($args['pagematch'])) {
1266 require_once 'lib/TextSearchQuery.php';
1267 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1269 if (!empty($args['category'])) {
1270 require_once 'lib/TextSearchQuery.php';
1271 $changes = new LinkRevisionIterator($changes, $args['category']);
1273 if (!empty($args['only_new']))
1274 $changes = new NewPageRevisionIterator($changes);
1275 if (!empty($args['author']))
1276 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1277 if (!empty($args['owner']))
1278 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1280 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1285 function format ($changes, $args) {
1287 $format = $args['format'];
1289 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1291 if ($format == 'rss')
1292 $fmt_class = '_RecentChanges_RssFormatter';
1293 elseif ($format == 'rss2')
1294 $fmt_class = '_RecentChanges_Rss2Formatter';
1295 elseif ($format == 'atom')
1296 $fmt_class = '_RecentChanges_AtomFormatter';
1297 elseif ($format == 'rss091') {
1298 include_once 'lib/RSSWriter091.php';
1299 $fmt_class = '_RecentChanges_RssFormatter091';
1301 elseif ($format == 'sidebar')
1302 $fmt_class = '_RecentChanges_SideBarFormatter';
1303 elseif ($format == 'box')
1304 $fmt_class = '_RecentChanges_BoxFormatter';
1305 elseif ($format == 'contribs')
1306 $fmt_class = '_RecentChanges_UserContribsFormatter';
1308 $fmt_class = '_RecentChanges_HtmlFormatter';
1311 $fmt = new $fmt_class($args);
1312 return $fmt->format($changes);
1315 function run($dbi, $argstr, &$request, $basepage) {
1316 $args = $this->getArgs($argstr, $request);
1318 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1319 // to be enough for anyone.)
1320 $args['days'] = min($args['days'], 365000);
1322 // Within Categories just display Category Backlinks
1323 if (empty($args['category']) and empty($args['pagematch'])
1324 and preg_match("/^Category/", $request->getArg('pagename')))
1326 $args['category'] = $request->getArg('pagename');
1329 // Hack alert: format() is a NORETURN for rss formatters.
1330 return $this->format($this->getChanges($dbi, $args), $args);
1333 // box is used to display a fixed-width, narrow version with common header.
1334 // just a numbered list of limit pagenames, without date.
1335 function box($args = false, $request = false, $basepage = false) {
1336 if (!$request) $request =& $GLOBALS['request'];
1337 if (!isset($args['limit'])) $args['limit'] = 15;
1338 $args['format'] = 'box';
1339 $args['show_minor'] = false;
1340 $args['show_major'] = true;
1341 $args['show_deleted'] = 'sometimes';
1342 $args['show_all'] = false;
1344 return $this->makeBox(WikiLink($this->getName(),'',
1345 SplitPagename($this->getName())),
1347 ($this->getChanges($request->_dbi, $args), $args));
1352 class OptionsButtonBars extends HtmlElement {
1354 function OptionsButtonBars ($plugin_args) {
1355 $this->__construct('fieldset', array('class' => 'wiki-rc-action'));
1357 // Add ShowHideFolder button
1358 $icon = $GLOBALS['WikiTheme']->_findData('images/folderArrowOpen.png');
1359 $img = HTML::img(array('id' => 'rc-action-img',
1361 'onclick' => "showHideFolder('rc-action')",
1362 'alt' => _("Click to hide/show"),
1363 'title' => _("Click to hide/show")));
1365 // Display selection buttons
1366 extract($plugin_args);
1370 $caption = _("Show changes for:");
1373 $this->pushContent(HTML::legend($caption,' ',$img));
1374 $table = HTML::table(array('id' => 'rc-action-body',
1375 'style' => 'display:block'));
1378 foreach (explode(",", $daylist) as $days_button) {
1379 $tr->pushContent($this->_makeDayButton($days_button, $days));
1381 $table->pushContent($tr);
1384 $tr->pushContent($this->_makeUsersButton(0));
1385 $tr->pushContent($this->_makeUsersButton(1));
1386 $table->pushContent($tr);
1389 $tr->pushContent($this->_makePagesButton(0));
1390 $tr->pushContent($this->_makePagesButton(1));
1391 $table->pushContent($tr);
1394 $tr->pushContent($this->_makeMinorButton(1, $show_minor));
1395 $tr->pushContent($this->_makeMinorButton(0, $show_minor));
1396 $table->pushContent($tr);
1399 $tr->pushContent($this->_makeShowAllButton(1, $show_all));
1400 $tr->pushContent($this->_makeShowAllButton(0, $show_all));
1401 $table->pushContent($tr);
1404 $tr->pushContent($this->_makeNewPagesButton(0, $only_new));
1405 $tr->pushContent($this->_makeNewPagesButton(1, $only_new));
1406 $table->pushContent($tr);
1408 $this->pushContent($table);
1411 function _makeDayButton ($days_button, $days) {
1414 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days_button));
1415 if ($days_button == 1) {
1416 $label = _("1 day");
1417 } elseif ($days_button < 1) {
1418 $label = _("All time");
1420 $label = sprintf(_("%s days"), abs($days_button));
1422 $selected = HTML::td(array('class'=>'tdselected'), $label);
1423 $unselected = HTML::td(array('class'=>'tdunselected'),
1424 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1425 return ($days_button == $days) ? $selected : $unselected;
1428 function _makeUsersButton ($users) {
1432 $label = _("All users");
1435 $label = _("My modifications only");
1439 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1440 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
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 _makePagesButton ($pages) {
1452 $label = _("All pages");
1455 $label = _("My pages only");
1459 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1460 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1461 if ($url == $selfurl) {
1462 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1464 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1465 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1468 function _makeMinorButton ($minor_button, $show_minor) {
1471 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor_button));
1472 $label = ($minor_button == 0) ? _("Major modifications only") : _("All modifications");
1473 $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1474 $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1475 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1476 return ($minor_button == $show_minor) ? $selected : $unselected;
1479 function _makeShowAllButton ($showall_button, $show_all) {
1482 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall_button));
1483 $label = ($showall_button == 0) ? _("Page once only") : _("Full changes");
1484 $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1485 $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1486 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1487 return ($showall_button == $show_all) ? $selected : $unselected;
1490 function _makeNewPagesButton ($newpages_button, $only_new) {
1493 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages_button));
1494 $label = ($newpages_button == 0) ? _("Old and new pages") : _("New pages only");
1495 $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1496 $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1497 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1498 return ($newpages_button == $only_new) ? $selected : $unselected;
1505 // c-basic-offset: 4
1506 // c-hanging-comment-ender-p: nil
1507 // indent-tabs-mode: nil