4 Copyright 1999,2000,2001,2002,2007 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 include_once("lib/WikiPlugin.php");
27 class _RecentChanges_Formatter
29 var $_absurls = false;
30 var $action = "RecentChanges";
32 function _RecentChanges_Formatter ($rc_args) {
33 $this->_args = $rc_args;
34 $this->_diffargs = array('action' => 'diff');
36 if ($rc_args['show_minor'] || !$rc_args['show_major'])
37 $this->_diffargs['previous'] = 'minor';
39 // PageHistoryPlugin doesn't have a 'daylist' arg.
40 if (!isset($this->_args['daylist']))
41 $this->_args['daylist'] = false;
46 extract($this->_args);
47 if ($author == '[]') $author = $request->_user->getID();
48 if ($owner == '[]') $owner = $request->_user->getID();
49 if ($author) $title = _("UserContribs").":$author";
50 elseif ($owner) $title = _("UserContribs").":$owner";
51 elseif ($only_new) $title = _("RecentNewPages");
52 elseif ($show_minor) $title = _("RecentEdits");
53 else $title = _("RecentChanges");
55 if (!empty($category))
57 elseif (!empty($pagematch))
58 $title .= ":$pagematch";
62 function include_versions_in_URLs() {
63 return (bool) $this->_args['show_all'];
66 function date ($rev) {
68 return $WikiTheme->getDay($rev->get('mtime'));
71 function time ($rev) {
73 return $WikiTheme->formatTime($rev->get('mtime'));
76 function diffURL ($rev) {
77 $args = $this->_diffargs;
78 if ($this->include_versions_in_URLs())
79 $args['version'] = $rev->getVersion();
80 $page = $rev->getPage();
81 return WikiURL($page->getName(), $args, $this->_absurls);
84 function historyURL ($rev) {
85 $page = $rev->getPage();
86 return WikiURL($page, array('action' => _("PageHistory")),
90 function pageURL ($rev) {
91 return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
95 function authorHasPage ($author) {
96 global $WikiNameRegexp, $request;
97 $dbi = $request->getDbh();
98 return isWikiWord($author) && $dbi->isWikiPage($author);
101 function authorURL ($author) {
102 return $this->authorHasPage() ? WikiURL($author) : false;
106 function status ($rev) {
107 if ($rev->hasDefaultContents())
109 $page = $rev->getPage();
110 $prev = $page->getRevisionBefore($rev->getVersion());
111 if ($prev->hasDefaultContents())
116 function importance ($rev) {
117 return $rev->get('is_minor_edit') ? 'minor' : 'major';
120 function summary($rev) {
121 if ( ($summary = $rev->get('summary')) )
124 switch ($this->status($rev)) {
128 return _("New page");
134 function setValidators($most_recent_rev) {
135 $rev = $most_recent_rev;
136 $validators = array('RecentChanges-top' =>
137 array($rev->getPageName(), $rev->getVersion()),
138 '%mtime' => $rev->get('mtime'));
140 $request->appendValidators($validators);
144 class _RecentChanges_HtmlFormatter
145 extends _RecentChanges_Formatter
147 function diffLink ($rev) {
149 $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
150 $button->setAttr('rel', 'nofollow');
151 return HTML("(",$button,")");
154 /* deletions: red, additions: green */
155 function diffSummary ($rev) {
156 $html = $this->diffURL($rev);
160 function historyLink ($rev) {
162 $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
163 $button->setAttr('rel', 'nofollow');
164 return HTML("(",$button,")");
167 function pageLink ($rev, $link_text=false) {
169 return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
172 $page = $rev->getPage();
174 if ($this->include_versions_in_URLs()) {
175 $version = $rev->getVersion();
176 if ($rev->isCurrent())
178 $exists = !$rev->hasDefaultContents();
182 $cur = $page->getCurrentRevision();
183 $exists = !$cur->hasDefaultContents();
186 return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
188 return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
192 function authorLink ($rev) {
193 return WikiLink($rev->get('author'), 'if_known');
196 /* Link to all users contributions (contribs and owns) */
197 function authorContribs ($rev) {
198 $author = $rev->get('author');
199 if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
201 Button(array('action' => _("RecentChanges"),
202 'format' => 'contribs',
208 Button(array('action' => _("RecentChanges"),
209 'format' => 'contribs',
217 function summaryAsHTML ($rev) {
218 if ( !($summary = $this->summary($rev)) )
220 return HTML::span( array('class' => 'wiki-summary'),
222 TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
226 function format_icon ($format, $filter = array()) {
227 global $request, $WikiTheme;
228 $args = $this->_args;
229 // remove links not used for those formats
230 unset($args['daylist']);
231 unset($args['difflinks']);
232 unset($args['historylinks']);
233 $rss_url = $request->getURLtoSelf
235 array('action' => $this->action, 'format' => $format),
237 return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
240 function rss_icon ($args=array()) { return $this->format_icon("rss", $args); }
241 function rss2_icon ($args=array()) { return $this->format_icon("rss2", $args); }
242 function atom_icon ($args=array()) { return $this->format_icon("atom", $args); }
243 function rdf_icon ($args=array()) { return DEBUG ? $this->format_icon("rdf", $args) : ''; }
244 function rdfs_icon ($args=array()) { return DEBUG ? $this->format_icon("rdfs", $args) : ''; }
245 function owl_icon ($args=array()) { return DEBUG ? $this->format_icon("owl", $args) : ''; }
247 function grazr_icon ($args = array()) {
248 global $request, $WikiTheme;
249 if (is_localhost()) return '';
250 if (SERVER_PROTOCOL == "https") return '';
251 $our_url = WikiURL($request->getArg('pagename'),
252 array_merge(array('action' => $this->action, 'format' => 'rss2'), $args),
254 $rss_url = 'http://grazr.com/gzpanel.html?' . $our_url;
255 return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
258 function pre_description () {
259 extract($this->_args);
260 // FIXME: say something about show_all.
261 if ($show_major && $show_minor)
264 $edits = _("major edits");
266 $edits = _("minor edits");
267 if (isset($caption) and $caption == _("Recent Comments"))
268 $edits = _("comments");
269 if (!empty($only_new)) {
270 $edits = _("created new pages");
272 if (!empty($author)) {
275 $author = $request->_user->getID();
276 $edits .= sprintf(_(" for pages changed by %s"), $author);
278 if (!empty($owner)) {
281 $owner = $request->_user->getID();
282 $edits .= sprintf(_(" for pages owned by %s"), $owner);
284 if (!empty($category)) {
285 $edits .= sprintf(_(" for all pages linking to %s"), $category);
287 if (!empty($pagematch)) {
288 $edits .= sprintf(_(" for all pages matching '%s'"), $pagematch);
290 if ($timespan = $days > 0) {
291 if (intval($days) != $days)
292 $days = sprintf("%.1f", $days);
296 * Depending how this text is split up it can be tricky or
297 * impossible to translate with good grammar. So the seperate
298 * strings for 1 day and %s days are necessary in this case
299 * for translating to multiple languages, due to differing
300 * overlapping ideal word cutting points.
302 * en: day/days "The %d most recent %s [during (the past] day) are listed below."
303 * de: 1 Tag "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
304 * de: %s days "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
306 * en: day/days "The %d most recent %s during [the past] (day) are listed below."
307 * fr: 1 jour "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
308 * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
312 if (intval($days) == 1)
313 $desc = fmt("The %d most recent %s during the past day are listed below.",
316 $desc = fmt("The %d most recent %s during the past %s days are listed below.",
317 $limit, $edits, $days);
319 $desc = fmt("The %d most recent %s are listed below.",
322 elseif ($limit < 0) { //$limit < 0 means we want oldest pages
324 if (intval($days) == 1)
325 $desc = fmt("The %d oldest %s during the past day are listed below.",
328 $desc = fmt("The %d oldest %s during the past %s days are listed below.",
329 $lmt, $edits, $days);
331 $desc = fmt("The %d oldest %s are listed below.",
337 if (intval($days) == 1)
338 $desc = fmt("The most recent %s during the past day are listed below.",
341 $desc = fmt("The most recent %s during the past %s days are listed below.",
344 $desc = fmt("All %s are listed below.", $edits);
349 function description() {
350 return HTML::p(false, $this->pre_description());
354 function headline () {
355 extract($this->_args);
356 return array($this->title(),
362 /*$this->rdfs_icon(),
365 $this->sidebar_link());
368 function empty_message() {
369 if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
370 return _("No comments found");
372 return _("No changes found");
375 function sidebar_link() {
376 extract($this->_args);
377 $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
380 $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
383 "function addPanel() {\n"
384 ." window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
385 ." \"$sidebarurl\",\"\");\n"
387 $jsf = JavaScript($addsidebarjsfunc);
390 $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
391 array('title' => _("Click to add this feed to your sidebar"),
392 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
393 $addsidebarjsclick = asXML($sidebar_button);
394 $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
395 ." (typeof window.sidebar.addPanel == 'function'))\n"
397 ." document.write('$addsidebarjsclick');\n"
400 return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
403 function format ($changes) {
404 include_once('lib/InlineParser.php');
406 $html = HTML(HTML::h2(false, $this->headline()));
407 if (($desc = $this->description()))
408 $html->pushContent($desc);
410 if ($this->_args['daylist'])
411 $html->pushContent(new DayButtonBar($this->_args));
417 while ($rev = $changes->next()) {
418 if (($date = $this->date($rev)) != $last_date) {
420 $html->pushContent($lines);
421 // for user contributions no extra date line
422 $html->pushContent(HTML::h3($date));
427 // enforce view permission
428 if (mayAccessPage('view', $rev->_pagename)) {
429 $lines->pushContent($this->format_revision($rev));
431 $this->setValidators($rev);
436 $html->pushContent($lines);
438 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
439 $this->empty_message()));
444 function format_revision ($rev) {
446 $args = &$this->_args;
448 $class = 'rc-' . $this->importance($rev);
450 $time = $this->time($rev);
451 if (! $rev->get('is_minor_edit'))
452 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
454 $line = HTML::li(array('class' => $class));
456 if ($args['difflinks'])
457 $line->pushContent($this->diffLink($rev), ' ');
459 if ($args['historylinks'])
460 $line->pushContent($this->historyLink($rev), ' ');
462 if (isa($WikiTheme, 'WikiTheme_MonoBook')) {
464 $args['historylinks'] ? '' : $this->historyLink($rev),
465 ' . . ', $this->pageLink($rev), '; ',
467 $this->authorLink($rev),' ',
468 $this->authorContribs($rev),' ',
469 $this->summaryAsHTML($rev));
471 $line->pushContent($this->pageLink($rev), ' ',
473 $this->summaryAsHTML($rev),
475 $this->authorLink($rev));
482 /* format=contribs: no seperation into extra dates
483 * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link) (top)
485 class _RecentChanges_UserContribsFormatter
486 extends _RecentChanges_HtmlFormatter
488 function headline () {
490 extract($this->_args);
491 if ($author == '[]') $author = $request->_user->getID();
492 if ($owner == '[]') $owner = $request->_user->getID();
493 $author_args = $owner
494 ? array('owner' => $owner)
495 : array('author' => $author);
496 return array(_("UserContribs"),":",$owner ? $owner : $author,
498 $this->rss_icon($author_args),
499 $this->rss2_icon($author_args),
500 $this->atom_icon($author_args),
501 $this->rdf_icon($author_args),
502 $this->grazr_icon($author_args));
505 function format ($changes) {
506 include_once('lib/InlineParser.php');
508 $html = HTML(HTML::h2(false, $this->headline()));
510 $first = true; $count = 0;
511 while ($rev = $changes->next()) {
512 if (mayAccessPage('view', $rev->_pagename)) {
513 $lines->pushContent($this->format_revision($rev));
515 $this->setValidators($rev);
520 $this->_args['limit'] = $count;
521 if (($desc = $this->description()))
522 $html->pushContent($desc);
523 if ($this->_args['daylist'])
524 $html->pushContent(new DayButtonBar($this->_args));
526 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
527 $this->empty_message()));
529 $html->pushContent($lines);
534 function format_revision ($rev) {
535 $args = &$this->_args;
536 $class = 'rc-' . $this->importance($rev);
537 $time = $this->time($rev);
538 if (! $rev->get('is_minor_edit'))
539 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
541 $line = HTML::li(array('class' => $class));
543 $line->pushContent($this->time($rev),", ");
544 $line->pushContent($this->date($rev)," ");
545 $line->pushContent($this->diffLink($rev), ' ');
546 $line->pushContent($this->historyLink($rev), ' ');
547 $line->pushContent($this->pageLink($rev), ' ',
548 $this->summaryAsHTML($rev));
553 class _RecentChanges_SideBarFormatter
554 extends _RecentChanges_HtmlFormatter
556 function rss_icon () {
559 function rss2_icon () { }
560 function headline () {
561 //title click opens the normal RC or RE page in the main browser frame
562 extract($this->_args);
563 $titlelink = WikiLink($this->title());
564 $titlelink->setAttr('target', '_content');
565 return HTML($this->logo(), $titlelink);
568 //logo click opens the HomePage in the main browser frame
570 $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
573 'style' => 'height:2.5ex'
575 $linkurl = WikiLink(HOME_PAGE, false, $img);
576 $linkurl->setAttr('target', '_content');
580 function authorLink ($rev) {
581 $author = $rev->get('author');
582 if ( $this->authorHasPage($author) ) {
583 $linkurl = WikiLink($author);
584 $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
590 function diffLink ($rev) {
591 $linkurl = parent::diffLink($rev);
592 $linkurl->setAttr('target', '_content');
593 $linkurl->setAttr('rel', 'nofollow');
594 // FIXME: Smelly hack to get smaller diff buttons in sidebar
595 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
598 function historyLink ($rev) {
599 $linkurl = parent::historyLink($rev);
600 $linkurl->setAttr('target', '_content');
601 // FIXME: Smelly hack to get smaller history buttons in sidebar
602 $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
605 function pageLink ($rev) {
606 $linkurl = parent::pageLink($rev);
607 $linkurl->setAttr('target', '_content');
610 // Overriding summaryAsHTML, because there is no way yet to
611 // return summary as transformed text with
612 // links setAttr('target', '_content') in Mozilla sidebar.
613 // So for now don't create clickable links inside summary
614 // in the sidebar, or else they target the sidebar and not the
615 // main content window.
616 function summaryAsHTML ($rev) {
617 if ( !($summary = $this->summary($rev)) )
619 return HTML::span(array('class' => 'wiki-summary'),
621 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
626 function format ($changes) {
627 $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
628 $html = _RecentChanges_HtmlFormatter::format ($changes);
629 $html = HTML::div(array('class' => 'wikitext'), $html);
631 $request->discardOutput();
633 printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
634 printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
635 printf(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
636 printf('<html xmlns="http://www.w3.org/1999/xhtml">');
639 extract($this->_args);
640 if (!empty($category))
642 elseif (!empty($pagematch))
645 $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
646 printf("<title>" . $title . "</title>\n");
648 $css = $WikiTheme->getCSS();
652 printf("<body class=\"sidebar\">\n");
654 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>';
655 printf("\n</body>\n");
658 $request->finish(); // cut rest of page processing short
662 class _RecentChanges_BoxFormatter
663 extends _RecentChanges_HtmlFormatter
665 function rss_icon () {
667 function rss2_icon () {
669 function headline () {
671 function authorLink ($rev) {
673 function diffLink ($rev) {
675 function historyLink ($rev) {
677 function summaryAsHTML ($rev) {
679 function description () {
681 function format ($changes) {
682 include_once('lib/InlineParser.php');
687 $sp = HTML::Raw("\n · ");
688 while ($rev = $changes->next()) {
689 // enforce view permission
690 if (mayAccessPage('view',$rev->_pagename)) {
691 if ($link = $this->pageLink($rev)) // some entries may be empty
692 // (/Blog/.. interim pages)
693 $html->pushContent($sp, $link, HTML::br());
695 $this->setValidators($rev);
700 $html->pushContent(HTML::p(array('class' => 'rc-empty'),
701 $this->empty_message()));
706 class _RecentChanges_RssFormatter
707 extends _RecentChanges_Formatter
709 var $_absurls = true;
711 function time ($rev) {
712 return Iso8601DateTime($rev->get('mtime'));
715 function pageURI ($rev) {
716 return WikiURL($rev, '', 'absurl');
719 function format ($changes) {
721 include_once('lib/RssWriter.php');
722 $rss = new RssWriter;
723 $rss->channel($this->channel_properties());
725 if (($props = $this->image_properties()))
727 if (($props = $this->textinput_properties()))
728 $rss->textinput($props);
731 while ($rev = $changes->next()) {
732 // enforce view permission
733 if (mayAccessPage('view', $rev->_pagename)) {
734 $rss->addItem($this->item_properties($rev),
735 $this->pageURI($rev));
737 $this->setValidators($rev);
743 $request->discardOutput();
745 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
746 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
748 // Flush errors in comment, otherwise it's invalid XML.
749 global $ErrorManager;
750 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
751 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
753 $request->finish(); // NORETURN!!!!
756 function image_properties () {
759 $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
763 return array('title' => WIKI_NAME,
764 'link' => WikiURL(HOME_PAGE, false, 'absurl'),
768 function textinput_properties () {
769 return array('title' => _("Search"),
770 'description' => _("Title Search"),
772 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
775 function channel_properties () {
778 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
779 extract($this->_args);
781 $description = $this->title();
786 return array('title' => $title,
788 'description' => $description,
789 'dc:date' => Iso8601DateTime(time()),
790 'dc:language' => $GLOBALS['LANG']);
792 /* FIXME: other things one might like in <channel>:
801 * rss091:managingEditor
803 * rss091:lastBuildDate
808 function item_properties ($rev) {
809 $page = $rev->getPage();
810 $pagename = $page->getName();
812 return array( 'title' => SplitPagename($pagename),
813 'description' => $this->summary($rev),
814 'link' => $this->pageURL($rev),
815 'dc:date' => $this->time($rev),
816 'dc:contributor' => $rev->get('author'),
817 'wiki:version' => $rev->getVersion(),
818 'wiki:importance' => $this->importance($rev),
819 'wiki:status' => $this->status($rev),
820 'wiki:diff' => $this->diffURL($rev),
821 'wiki:history' => $this->historyURL($rev)
826 /** explicit application/rss+xml Content-Type,
827 * simplified xml structure (no namespace),
828 * support for xml-rpc cloud registerProcedure (not yet)
830 class _RecentChanges_Rss2Formatter
831 extends _RecentChanges_RssFormatter {
833 function format ($changes) {
834 include_once('lib/RssWriter2.php');
835 $rss = new RssWriter2;
837 $rss->channel($this->channel_properties());
838 if (($props = $this->cloud_properties()))
840 if (($props = $this->image_properties()))
842 if (($props = $this->textinput_properties()))
843 $rss->textinput($props);
845 while ($rev = $changes->next()) {
846 // enforce view permission
847 if (mayAccessPage('view', $rev->_pagename)) {
848 $rss->addItem($this->item_properties($rev),
849 $this->pageURI($rev));
851 $this->setValidators($rev);
858 $request->discardOutput();
860 //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
861 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
862 // Flush errors in comment, otherwise it's invalid XML.
863 global $ErrorManager;
864 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
865 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
867 $request->finish(); // NORETURN!!!!
870 function channel_properties () {
871 $chann_10 = parent::channel_properties();
872 return array_merge($chann_10,
873 array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
874 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
875 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
876 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
877 'copyright' => COPYRIGHTPAGE_URL
881 // xml-rpc registerProcedure not yet implemented
882 function cloud_properties () { return false; }
883 function cloud_properties_test () {
884 return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
885 'registerProcedure' => 'wiki.rssPleaseNotify',
886 'path' => DATA_PATH.'/RPC2.php',
887 'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
888 'domain' => SERVER_NAME);
892 /** Explicit application/atom+xml Content-Type
893 * A weird, questionable format
895 class _RecentChanges_AtomFormatter
896 extends _RecentChanges_RssFormatter {
898 function format ($changes) {
900 include_once('lib/RssWriter.php');
903 // "channel" is called "feed" in atom
904 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
905 extract($this->_args);
907 $description = $this->title();
912 $feed_props = array('title' => $description,
913 'link' => array('rel'=>"alternate",
916 'id' => md5($rc_url),
917 'modified' => Iso8601DateTime(time()),
918 'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
920 $rss->feed($feed_props);
922 while ($rev = $changes->next()) {
923 // enforce view permission
924 if (mayAccessPage('view', $rev->_pagename)) {
925 $props = $this->item_properties($rev);
926 $rss->addItem($props,
928 $this->pageURI($rev));
930 $this->setValidators($rev);
935 $request->discardOutput();
937 //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
938 printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
939 // Flush errors in comment, otherwise it's invalid XML.
940 global $ErrorManager;
941 if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
942 printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
944 $request->finish(); // NORETURN!!!!
947 function item_properties ($rev) {
948 $page = $rev->getPage();
949 $pagename = $page->getName();
950 return array( 'title' => $pagename,
951 'link' => array('rel' => 'alternate',
952 'type' => 'text/html',
953 'href' => $this->pageURL($rev)),
954 'summary' => $this->summary($rev),
955 'modified' => $this->time($rev)."Z",
956 'issued' => $this->time($rev),
957 'created' => $this->time($rev)."Z",
958 'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
964 * Filter by non-empty
966 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
970 * @param $revisions object a WikiDB_PageRevisionIterator.
972 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
973 $this->_revisions = $revisions;
974 $this->_check_current_revision = $check_current_revision;
978 while (($rev = $this->_revisions->next())) {
979 if ($this->_check_current_revision) {
980 $page = $rev->getPage();
981 $check_rev = $page->getCurrentRevision();
986 if (! $check_rev->hasDefaultContents())
996 * Filter by only_new.
997 * Only new created pages
999 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1003 * @param $revisions object a WikiDB_PageRevisionIterator.
1005 function NewPageRevisionIterator ($revisions) {
1006 $this->_revisions = $revisions;
1010 while (($rev = $this->_revisions->next())) {
1011 if ($rev->getVersion() == 1)
1020 * Only pages with links to a certain category
1022 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1024 function LinkRevisionIterator ($revisions, $category) {
1025 $this->_revisions = $revisions;
1026 if (preg_match("/[\?\.\*]/", $category)) {
1027 $backlinkiter = $this->_revisions->_wikidb->linkSearch
1028 (new TextSearchQuery("*", true),
1029 new TextSearchQuery($category, true),
1032 $basepage = $GLOBALS['request']->getPage($category);
1033 $backlinkiter = $basepage->getBackLinks(true);
1035 $this->links = array();
1036 foreach ($backlinkiter->asArray() as $p) {
1037 if (is_object($p)) $this->links[] = $p->getName();
1038 elseif (is_array($p)) $this->links[] = $p['pagename'];
1039 else $this->links[] = $p;
1041 $backlinkiter->free();
1046 while (($rev = $this->_revisions->next())) {
1047 if (binary_search($rev->getName(), $this->links) != false)
1055 unset ($this->links);
1059 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1061 function PageMatchRevisionIterator ($revisions, $match) {
1062 $this->_revisions = $revisions;
1063 $this->search = new TextSearchQuery($match, true);
1067 while (($rev = $this->_revisions->next())) {
1068 if ($this->search->match($rev->getName()))
1076 unset ($this->search);
1083 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1085 function AuthorPageRevisionIterator ($revisions, $author) {
1086 $this->_revisions = $revisions;
1087 $this->_author = $author;
1091 while (($rev = $this->_revisions->next())) {
1092 if ($rev->get('author_id') == $this->_author)
1103 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1105 function OwnerPageRevisionIterator ($revisions, $owner) {
1106 $this->_revisions = $revisions;
1107 $this->_owner = $owner;
1111 while (($rev = $this->_revisions->next())) {
1112 $page = $rev->getPage();
1113 if ($page->getOwner() == $this->_owner)
1121 class WikiPlugin_RecentChanges
1124 function getName () {
1125 return _("RecentChanges");
1128 function getVersion() {
1129 return preg_replace("/[Revision: $]/", '',
1133 function managesValidators() {
1134 // Note that this is a bit of a fig.
1135 // We set validators based on the most recently changed page,
1136 // but this fails when the most-recent page is deleted.
1137 // (Consider that the Last-Modified time will decrease
1138 // when this happens.)
1140 // We might be better off, leaving this as false (and junking
1141 // the validator logic above) and just falling back to the
1142 // default behavior (handled by WikiPlugin) of just using
1143 // the WikiDB global timestamp as the mtime.
1145 // Nevertheless, for now, I leave this here, mostly as an
1146 // example for how to use appendValidators() and managesValidators().
1151 function getDefaultArguments() {
1152 return array('days' => 2,
1153 'show_minor' => false,
1154 'show_major' => true,
1155 'show_all' => false,
1156 'show_deleted' => 'sometimes',
1157 'only_new' => false,
1163 'difflinks' => true,
1164 'historylinks' => false,
1171 function getArgs ($argstr, $request, $defaults = false) {
1172 if (!$defaults) $defaults = $this->getDefaultArguments();
1173 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1175 $action = $request->getArg('action');
1176 if ($action != 'browse' && ! $request->isActionPage($action))
1177 $args['format'] = false; // default -> HTML
1179 if ($args['format'] == 'rss' && empty($args['limit']))
1180 $args['limit'] = 15; // Fix default value for RSS.
1181 if ($args['format'] == 'rss2' && empty($args['limit']))
1182 $args['limit'] = 15; // Fix default value for RSS2.
1184 if ($args['format'] == 'sidebar' && empty($args['limit']))
1185 $args['limit'] = 10; // Fix default value for sidebar.
1190 function getMostRecentParams (&$args) {
1191 $show_all = false; $show_minor = false; $show_major = false;
1195 $params = array('include_minor_revisions' => $show_minor,
1196 'exclude_major_revisions' => !$show_major,
1197 'include_all_revisions' => !empty($show_all));
1199 $params['limit'] = $limit;
1200 if (!empty($args['author'])) {
1202 if ($args['author'] == '[]')
1203 $args['author'] = $request->_user->getID();
1204 $params['author'] = $args['author'];
1206 if (!empty($args['owner'])) {
1208 if ($args['owner'] == '[]')
1209 $args['owner'] = $request->_user->getID();
1210 $params['owner'] = $args['owner'];
1212 if (!empty($days)) {
1214 $params['since'] = time() - 24 * 3600 * $days;
1215 elseif ($days < 0.0)
1216 $params['since'] = 24 * 3600 * $days - time();
1222 function getChanges ($dbi, $args) {
1223 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1225 $show_deleted = @$args['show_deleted'];
1226 $show_all = @$args['show_all'];
1227 if ($show_deleted == 'sometimes')
1228 $show_deleted = @$args['show_minor'];
1230 // only pages (e.g. PageHistory of subpages)
1231 if (!empty($args['pagematch'])) {
1232 require_once("lib/TextSearchQuery.php");
1233 $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1235 if (!empty($args['category'])) {
1236 require_once("lib/TextSearchQuery.php");
1237 $changes = new LinkRevisionIterator($changes, $args['category']);
1239 if (!empty($args['only_new']))
1240 $changes = new NewPageRevisionIterator($changes);
1241 if (!empty($args['author']))
1242 $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1243 if (!empty($args['owner']))
1244 $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1246 $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1251 function format ($changes, $args) {
1253 $format = $args['format'];
1255 $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1257 if ($format == 'rss')
1258 $fmt_class = '_RecentChanges_RssFormatter';
1259 elseif ($format == 'rss2')
1260 $fmt_class = '_RecentChanges_Rss2Formatter';
1261 elseif ($format == 'atom')
1262 $fmt_class = '_RecentChanges_AtomFormatter';
1263 elseif ($format == 'rss091') {
1264 include_once "lib/RSSWriter091.php";
1265 $fmt_class = '_RecentChanges_RssFormatter091';
1267 elseif ($format == 'sidebar')
1268 $fmt_class = '_RecentChanges_SideBarFormatter';
1269 elseif ($format == 'box')
1270 $fmt_class = '_RecentChanges_BoxFormatter';
1271 elseif ($format == 'contribs')
1272 $fmt_class = '_RecentChanges_UserContribsFormatter';
1274 $fmt_class = '_RecentChanges_HtmlFormatter';
1277 $fmt = new $fmt_class($args);
1278 return $fmt->format($changes);
1281 function run($dbi, $argstr, &$request, $basepage) {
1282 $args = $this->getArgs($argstr, $request);
1284 // HACKish: fix for SF bug #622784 (1000 years of RecentChanges ought
1285 // to be enough for anyone.)
1286 $args['days'] = min($args['days'], 365000);
1288 // Within Categories just display Category Backlinks
1289 if (empty($args['category']) and empty($args['pagematch'])
1290 and preg_match("/^Category/", $request->getArg('pagename')))
1292 $args['category'] = $request->getArg('pagename');
1295 // Hack alert: format() is a NORETURN for rss formatters.
1296 return $this->format($this->getChanges($dbi, $args), $args);
1299 // box is used to display a fixed-width, narrow version with common header.
1300 // just a numbered list of limit pagenames, without date.
1301 function box($args = false, $request = false, $basepage = false) {
1302 if (!$request) $request =& $GLOBALS['request'];
1303 if (!isset($args['limit'])) $args['limit'] = 15;
1304 $args['format'] = 'box';
1305 $args['show_minor'] = false;
1306 $args['show_major'] = true;
1307 $args['show_deleted'] = 'sometimes';
1308 $args['show_all'] = false;
1310 return $this->makeBox(WikiLink($this->getName(),'',
1311 SplitPagename($this->getName())),
1313 ($this->getChanges($request->_dbi, $args), $args));
1319 class DayButtonBar extends HtmlElement {
1321 function DayButtonBar ($plugin_args) {
1322 $this->__construct('p', array('class' => 'wiki-rc-action'));
1324 // Display days selection buttons
1325 extract($plugin_args);
1330 $caption = _("Show minor edits for:");
1332 $caption = _("Show all changes for:");
1334 $caption = _("Show changes for:");
1336 $caption = _("All new pages since:");
1339 $this->pushContent($caption, ' ');
1342 $sep = $WikiTheme->getButtonSeparator();
1345 foreach (explode(",", $daylist) as $days) {
1347 $this->pushContent($sep);
1348 $this->pushContent($this->_makeDayButton($days));
1352 function _makeDayButton ($days) {
1353 global $WikiTheme, $request;
1356 $label = _("1 day");
1358 $label = "..."; //alldays
1360 $label = sprintf(_("%s days"), abs($days));
1362 $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1364 return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
1368 // (c-file-style: "gnu")
1372 // c-basic-offset: 4
1373 // c-hanging-comment-ender-p: nil
1374 // indent-tabs-mode: nil