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()),
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_gforge'))) {
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'),
610 'style' => 'height:2.5ex'
612 $linkurl = WikiLink(HOME_PAGE, false, $img);
613 $linkurl->setAttr('target', '_content');
617 function authorLink ($rev) {
618 $author = $rev->get('author');
619 if ( $this->authorHasPage($author) ) {
620 $linkurl = WikiLink($author);
621 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
627 function diffLink ($rev) {
628 $linkurl = parent::diffLink($rev);
629 $linkurl->setAttr('target', '_content');
630 $linkurl->setAttr('rel', 'nofollow');
631 // FIXME: Smelly hack to get smaller diff buttons in sidebar
632 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
635 function historyLink ($rev) {
636 $linkurl = parent::historyLink($rev);
637 $linkurl->setAttr('target', '_content');
638 // FIXME: Smelly hack to get smaller history buttons in sidebar
639 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
642 function pageLink ($rev) {
643 $linkurl = parent::pageLink($rev);
644 $linkurl->setAttr('target', '_content');
647 // Overriding summaryAsHTML, because there is no way yet to
648 // return summary as transformed text with
649 // links setAttr('target', '_content') in Mozilla sidebar.
650 // So for now don't create clickable links inside summary
651 // in the sidebar, or else they target the sidebar and not the
652 // main content window.
653 function summaryAsHTML ($rev) {
654 if ( !($summary = $this->summary($rev)) )
656 return HTML::span(array('class' => 'wiki-summary'),
658 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
663 function format ($changes) {
664 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
665 $html = _RecentChanges_HtmlFormatter::format ($changes);
666 $html = HTML::div(array('class' => 'wikitext'), $html);
668 $request->discardOutput();
670 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
671 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
672 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
673 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
676 extract($this->_args);
677 if (!empty($category))
679 elseif (!empty($pagematch))
682 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
683 printf("<title>" . $title . "</title>\n");
685 $css = $WikiTheme->getCSS();
689 printf("<body class=\"sidebar\">\n");
691 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>';
692 printf("\n</body>\n");
695 $request->finish(); // cut rest of page processing short
699 class _RecentChanges_BoxFormatter
700 extends _RecentChanges_HtmlFormatter
702 function rss_icon () {
704 function rss2_icon () {
706 function headline () {
708 function authorLink ($rev) {
710 function diffLink ($rev) {
712 function historyLink ($rev) {
714 function summaryAsHTML ($rev) {
716 function description () {
718 function format ($changes) {
719 include_once('lib/InlineParser.php');
724 $sp = HTML::Raw("\n · ");
725 while ($rev = $changes->next()) {
726 // enforce view permission
727 if (mayAccessPage('view',$rev->_pagename)) {
728 if ($link = $this->pageLink($rev)) // some entries may be empty
729 // (/Blog/.. interim pages)
730 $html->pushContent($sp, $link, HTML::br());
732 $this->setValidators($rev);
737 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
738 $this->empty_message()));
743 class _RecentChanges_RssFormatter
744 extends _RecentChanges_Formatter
746 var $_absurls = true;
748 function time ($rev) {
749 return Iso8601DateTime($rev->get('mtime'));
752 function pageURI ($rev) {
753 return WikiURL($rev, '', 'absurl');
756 function format ($changes) {
758 include_once('lib/RssWriter.php');
759 $rss = new RssWriter;
760 $rss->channel($this->channel_properties());
762 if (($props = $this->image_properties()))
764 if (($props = $this->textinput_properties()))
765 $rss->textinput($props);
768 while ($rev = $changes->next()) {
769 // enforce view permission
770 if (mayAccessPage('view', $rev->_pagename)) {
771 $rss->addItem($this->item_properties($rev),
772 $this->pageURI($rev));
774 $this->setValidators($rev);
780 $request->discardOutput();
782 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
783 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
785 // Flush errors in comment, otherwise it's invalid XML.
786 global $ErrorManager;
787 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
788 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
790 $request->finish(); // NORETURN!!!!
793 function image_properties () {
796 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
800 return array('title' => WIKI_NAME,
801 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
805 function textinput_properties () {
806 return array('title' => _("Search"),
807 'description' => _("Title Search"),
809 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
812 function channel_properties () {
815 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
816 extract($this->_args);
818 $description = $this->title();
823 return array('title' => $title,
825 'description' => $description,
826 'dc:date' => Iso8601DateTime(time()),
827 'dc:language' => $GLOBALS['LANG']);
829 /* FIXME: other things one might like in <channel>:
838 * rss091:managingEditor
840 * rss091:lastBuildDate
845 function item_properties ($rev) {
846 $page = $rev->getPage();
847 $pagename = $page->getName();
849 return array( 'title' => SplitPagename($pagename),
850 'description' => $this->summary($rev),
851 'link' => $this->pageURL($rev),
852 'dc:date' => $this->time($rev),
853 'dc:contributor' => $rev->get('author'),
854 'wiki:version' => $rev->getVersion(),
855 'wiki:importance' => $this->importance($rev),
856 'wiki:status' => $this->status($rev),
857 'wiki:diff' => $this->diffURL($rev),
858 'wiki:history' => $this->historyURL($rev)
863 /** explicit application/rss+xml Content-Type,
864 * simplified xml structure (no namespace),
865 * support for xml-rpc cloud registerProcedure (not yet)
867 class _RecentChanges_Rss2Formatter
868 extends _RecentChanges_RssFormatter {
870 function format ($changes) {
871 include_once('lib/RssWriter2.php');
872 $rss = new RssWriter2;
874 $rss->channel($this->channel_properties());
875 if (($props = $this->cloud_properties()))
877 if (($props = $this->image_properties()))
879 if (($props = $this->textinput_properties()))
880 $rss->textinput($props);
882 while ($rev = $changes->next()) {
883 // enforce view permission
884 if (mayAccessPage('view', $rev->_pagename)) {
885 $rss->addItem($this->item_properties($rev),
886 $this->pageURI($rev));
888 $this->setValidators($rev);
894 $request->discardOutput();
896 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
897 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
898 // Flush errors in comment, otherwise it's invalid XML.
899 global $ErrorManager;
900 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
901 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
903 $request->finish(); // NORETURN!!!!
906 function channel_properties () {
907 $chann_10 = parent::channel_properties();
908 return array_merge($chann_10,
909 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
910 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
911 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
912 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
913 'copyright' => COPYRIGHTPAGE_URL
917 // xml-rpc registerProcedure not yet implemented
918 function cloud_properties () { return false; }
919 function cloud_properties_test () {
920 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
921 'registerProcedure' => 'wiki.rssPleaseNotify',
922 'path' => DATA_PATH.'/RPC2.php',
923 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
924 'domain' => SERVER_NAME);
928 /** Explicit application/atom+xml Content-Type
929 * A weird, questionable format
931 class _RecentChanges_AtomFormatter
932 extends _RecentChanges_RssFormatter {
934 function format ($changes) {
936 include_once('lib/RssWriter.php');
939 // "channel" is called "feed" in atom
940 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
941 extract($this->_args);
943 $description = $this->title();
948 $feed_props = array('title' => $description,
949 'link' => array('rel'=>"alternate",
952 'id' => md5($rc_url),
953 'modified' => Iso8601DateTime(time()),
954 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
956 $rss->feed($feed_props);
958 while ($rev = $changes->next()) {
959 // enforce view permission
960 if (mayAccessPage('view', $rev->_pagename)) {
961 $props = $this->item_properties($rev);
962 $rss->addItem($props,
964 $this->pageURI($rev));
966 $this->setValidators($rev);
971 $request->discardOutput();
973 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
974 printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
975 // Flush errors in comment, otherwise it's invalid XML.
976 global $ErrorManager;
977 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
978 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
980 $request->finish(); // NORETURN!!!!
983 function item_properties ($rev) {
984 $page = $rev->getPage();
985 $pagename = $page->getName();
986 return array( 'title' => $pagename,
987 'link' => array('rel' => 'alternate',
988 'type' => 'text/html',
989 'href' => $this->pageURL($rev)),
990 'summary' => $this->summary($rev),
991 'modified' => $this->time($rev)."Z",
992 'issued' => $this->time($rev),
993 'created' => $this->time($rev)."Z",
994 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
1000 * Filter by non-empty
1002 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
1006 * @param $revisions object a WikiDB_PageRevisionIterator.
1008 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
1009 $this->_revisions = $revisions;
1010 $this->_check_current_revision = $check_current_revision;
1014 while (($rev = $this->_revisions->next())) {
1015 if ($this->_check_current_revision) {
1016 $page = $rev->getPage();
1017 $check_rev = $page->getCurrentRevision();
1022 if (! $check_rev->hasDefaultContents())
1032 * Filter by only_new.
1033 * Only new created pages
1035 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1039 * @param $revisions object a WikiDB_PageRevisionIterator.
1041 function NewPageRevisionIterator ($revisions) {
1042 $this->_revisions = $revisions;
1046 while (($rev = $this->_revisions->next())) {
1047 if ($rev->getVersion() == 1)
1056 * Only pages with links to a certain category
1058 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1060 function LinkRevisionIterator ($revisions, $category) {
1061 $this->_revisions = $revisions;
1062 if (preg_match("/[\?\.\*]/", $category)) {
1063 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1064 (new TextSearchQuery("*", true),
1065 new TextSearchQuery($category, true),
1068 $basepage = $GLOBALS['request']->getPage($category);
1069 $backlinkiter = $basepage->getBackLinks(true);
1071 $this->links = array();
1072 foreach ($backlinkiter->asArray() as $p) {
1073 if (is_object($p)) $this->links[] = $p->getName();
1074 elseif (is_array($p)) $this->links[] = $p['pagename'];
1075 else $this->links[] = $p;
1077 $backlinkiter->free();
1082 while (($rev = $this->_revisions->next())) {
1083 if (binary_search($rev->getName(), $this->links) != false)
1091 unset ($this->links);
1095 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1097 function PageMatchRevisionIterator ($revisions, $match) {
1098 $this->_revisions = $revisions;
1099 $this->search = new TextSearchQuery($match, true);
1103 while (($rev = $this->_revisions->next())) {
1104 if ($this->search->match($rev->getName()))
1112 unset ($this->search);
1119 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1121 function AuthorPageRevisionIterator ($revisions, $author) {
1122 $this->_revisions = $revisions;
1123 $this->_author = $author;
1127 while (($rev = $this->_revisions->next())) {
1128 if ($rev->get('author_id') == $this->_author)
1139 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1141 function OwnerPageRevisionIterator ($revisions, $owner) {
1142 $this->_revisions = $revisions;
1143 $this->_owner = $owner;
1147 while (($rev = $this->_revisions->next())) {
1148 $page = $rev->getPage();
1149 if ($page->getOwner() == $this->_owner)
1157 class WikiPlugin_RecentChanges
1160 function getName () {
1161 return _("RecentChanges");
1164 function getDescription () {
1165 return _("List all recent changes in this wiki.");
1168 function managesValidators() {
1169 // Note that this is a bit of a fig.
1170 // We set validators based on the most recently changed page,
1171 // but this fails when the most-recent page is deleted.
1172 // (Consider that the Last-Modified time will decrease
1173 // when this happens.)
1175 // We might be better off, leaving this as false (and junking
1176 // the validator logic above) and just falling back to the
1177 // default behavior (handled by WikiPlugin) of just using
1178 // the WikiDB global timestamp as the mtime.
1180 // Nevertheless, for now, I leave this here, mostly as an
1181 // example for how to use appendValidators() and managesValidators().
1186 function getDefaultArguments() {
1187 return array('days' => 2,
1188 'show_minor' => false,
1189 'show_major' => true,
1190 'show_all' => false,
1191 'show_deleted' => 'sometimes',
1192 'only_new' => false,
1198 'difflinks' => true,
1199 'historylinks' => false,
1206 function getArgs ($argstr, $request, $defaults = false) {
1207 if (!$defaults) $defaults = $this->getDefaultArguments();
1208 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1210 $action = $request->getArg('action');
1211 if ($action != 'browse' && !isActionPage($action))
1212 $args['format'] = false; // default -> HTML
1214 if ($args['format'] == 'rss' && empty($args['limit']))
1215 $args['limit'] = 15; // Fix default value for RSS.
1216 if ($args['format'] == 'rss2' && empty($args['limit']))
1217 $args['limit'] = 15; // Fix default value for RSS2.
1219 if ($args['format'] == 'sidebar' && empty($args['limit']))
1220 $args['limit'] = 10; // Fix default value for sidebar.
1225 function getMostRecentParams (&$args) {
1226 $show_all = false; $show_minor = false; $show_major = false;
1230 $params = array('include_minor_revisions' => $show_minor,
1231 'exclude_major_revisions' => !$show_major,
1232 'include_all_revisions' => !empty($show_all));
1234 $params['limit'] = $limit;
1235 if (!empty($args['author'])) {
1237 if ($args['author'] == '[]')
1238 $args['author'] = $request->_user->getID();
1239 $params['author'] = $args['author'];
1241 if (!empty($args['owner'])) {
1243 if ($args['owner'] == '[]')
1244 $args['owner'] = $request->_user->getID();
1245 $params['owner'] = $args['owner'];
1247 if (!empty($days)) {
1249 $params['since'] = time() - 24 * 3600 * $days;
1250 elseif ($days < 0.0)
1251 $params['since'] = 24 * 3600 * $days - time();
1257 function getChanges ($dbi, $args) {
1258 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1260 $show_deleted = @$args['show_deleted'];
1261 $show_all = @$args['show_all'];
1262 if ($show_deleted == 'sometimes')
1263 $show_deleted = @$args['show_minor'];
1265 // only pages (e.g. PageHistory of subpages)
1266 if (!empty($args['pagematch'])) {
1267 require_once("lib/TextSearchQuery.php");
1268 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1270 if (!empty($args['category'])) {
1271 require_once("lib/TextSearchQuery.php");
1272 $changes = new LinkRevisionIterator($changes, $args['category']);
1274 if (!empty($args['only_new']))
1275 $changes = new NewPageRevisionIterator($changes);
1276 if (!empty($args['author']))
1277 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1278 if (!empty($args['owner']))
1279 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1281 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1286 function format ($changes, $args) {
1288 $format = $args['format'];
1290 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1292 if ($format == 'rss')
1293 $fmt_class = '_RecentChanges_RssFormatter';
1294 elseif ($format == 'rss2')
1295 $fmt_class = '_RecentChanges_Rss2Formatter';
1296 elseif ($format == 'atom')
1297 $fmt_class = '_RecentChanges_AtomFormatter';
1298 elseif ($format == 'rss091') {
1299 include_once "lib/RSSWriter091.php";
1300 $fmt_class = '_RecentChanges_RssFormatter091';
1302 elseif ($format == 'sidebar')
1303 $fmt_class = '_RecentChanges_SideBarFormatter';
1304 elseif ($format == 'box')
1305 $fmt_class = '_RecentChanges_BoxFormatter';
1306 elseif ($format == 'contribs')
1307 $fmt_class = '_RecentChanges_UserContribsFormatter';
1309 $fmt_class = '_RecentChanges_HtmlFormatter';
1312 $fmt = new $fmt_class($args);
1313 return $fmt->format($changes);
1316 function run($dbi, $argstr, &$request, $basepage) {
1317 $args = $this->getArgs($argstr, $request);
1319 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1320 // to be enough for anyone.)
1321 $args['days'] = min($args['days'], 365000);
1323 // Within Categories just display Category Backlinks
1324 if (empty($args['category']) and empty($args['pagematch'])
1325 and preg_match("/^Category/", $request->getArg('pagename')))
1327 $args['category'] = $request->getArg('pagename');
1330 // Hack alert: format() is a NORETURN for rss formatters.
1331 return $this->format($this->getChanges($dbi, $args), $args);
1334 // box is used to display a fixed-width, narrow version with common header.
1335 // just a numbered list of limit pagenames, without date.
1336 function box($args = false, $request = false, $basepage = false) {
1337 if (!$request) $request =& $GLOBALS['request'];
1338 if (!isset($args['limit'])) $args['limit'] = 15;
1339 $args['format'] = 'box';
1340 $args['show_minor'] = false;
1341 $args['show_major'] = true;
1342 $args['show_deleted'] = 'sometimes';
1343 $args['show_all'] = false;
1345 return $this->makeBox(WikiLink($this->getName(),'',
1346 SplitPagename($this->getName())),
1348 ($this->getChanges($request->_dbi, $args), $args));
1353 class OptionsButtonBars extends HtmlElement {
1355 function OptionsButtonBars ($plugin_args) {
1356 $this->__construct('fieldset', array('class' => 'wiki-rc-action'));
1358 // Add ShowHideFolder button
1359 $icon = $GLOBALS['WikiTheme']->_findData('images/folderArrowOpen.png');
1360 $img = HTML::img(array('id' => 'rc-action-img',
1362 'onclick' => "showHideFolder('rc-action')",
1363 'alt' => _("Click to hide/show"),
1364 'title' => _("Click to hide/show")));
1366 // Display selection buttons
1367 extract($plugin_args);
1371 $caption = _("Show changes for:");
1374 $this->pushContent(HTML::legend($caption,' ',$img));
1375 $table = HTML::table(array('id' => 'rc-action-body',
1376 'style' => 'display:block'));
1379 foreach (explode(",", $daylist) as $days_button) {
1380 $tr->pushContent($this->_makeDayButton($days_button, $days));
1382 $table->pushContent($tr);
1385 $tr->pushContent($this->_makeUsersButton(0));
1386 $tr->pushContent($this->_makeUsersButton(1));
1387 $table->pushContent($tr);
1390 $tr->pushContent($this->_makePagesButton(0));
1391 $tr->pushContent($this->_makePagesButton(1));
1392 $table->pushContent($tr);
1395 $tr->pushContent($this->_makeMinorButton(1, $show_minor));
1396 $tr->pushContent($this->_makeMinorButton(0, $show_minor));
1397 $table->pushContent($tr);
1400 $tr->pushContent($this->_makeShowAllButton(1, $show_all));
1401 $tr->pushContent($this->_makeShowAllButton(0, $show_all));
1402 $table->pushContent($tr);
1405 $tr->pushContent($this->_makeNewPagesButton(0, $only_new));
1406 $tr->pushContent($this->_makeNewPagesButton(1, $only_new));
1407 $table->pushContent($tr);
1409 $this->pushContent($table);
1412 function _makeDayButton ($days_button, $days) {
1415 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days_button));
1416 if ($days_button == 1) {
1417 $label = _("1 day");
1418 } elseif ($days_button < 1) {
1419 $label = _("All time");
1421 $label = sprintf(_("%s days"), abs($days_button));
1423 $selected = HTML::td(array('class'=>'tdselected'), $label);
1424 $unselected = HTML::td(array('class'=>'tdunselected'),
1425 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1426 return ($days_button == $days) ? $selected : $unselected;
1429 function _makeUsersButton ($users) {
1433 $label = _("All users");
1436 $label = _("My modifications only");
1440 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1441 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
1442 if ($url == $selfurl) {
1443 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1445 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1446 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1449 function _makePagesButton ($pages) {
1453 $label = _("All pages");
1456 $label = _("My pages only");
1460 $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1461 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1462 if ($url == $selfurl) {
1463 return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1465 return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1466 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1469 function _makeMinorButton ($minor_button, $show_minor) {
1472 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor_button));
1473 $label = ($minor_button == 0) ? _("Major modifications only") : _("All modifications");
1474 $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1475 $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1476 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1477 return ($minor_button == $show_minor) ? $selected : $unselected;
1480 function _makeShowAllButton ($showall_button, $show_all) {
1483 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall_button));
1484 $label = ($showall_button == 0) ? _("Page once only") : _("Full changes");
1485 $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1486 $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1487 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1488 return ($showall_button == $show_all) ? $selected : $unselected;
1491 function _makeNewPagesButton ($newpages_button, $only_new) {
1494 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages_button));
1495 $label = ($newpages_button == 0) ? _("Old and new pages") : _("New pages only");
1496 $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1497 $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1498 HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1499 return ($newpages_button == $only_new) ? $selected : $unselected;
1503 // (c-file-style: "gnu")
1507 // c-basic-offset: 4
1508 // c-hanging-comment-ender-p: nil
1509 // indent-tabs-mode: nil