]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChanges.php
use all filters, not just the first, ignoring the others. improve wording a bit
[SourceForge/phpwiki.git] / lib / plugin / RecentChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RecentChanges.php,v 1.116 2007-05-13 18:13:41 rurban Exp $');
3 /**
4  Copyright 1999,2000,2001,2002,2007 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
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.
12
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.
17
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
21  */
22
23 include_once("lib/WikiPlugin.php");
24
25 /**
26  */
27 class _RecentChanges_Formatter
28 {
29     var $_absurls = false;
30
31     function _RecentChanges_Formatter ($rc_args) {
32         $this->_args = $rc_args;
33         $this->_diffargs = array('action' => 'diff');
34
35         if ($rc_args['show_minor'] || !$rc_args['show_major'])
36             $this->_diffargs['previous'] = 'minor';
37
38         // PageHistoryPlugin doesn't have a 'daylist' arg.
39         if (!isset($this->_args['daylist']))
40             $this->_args['daylist'] = false;
41     }
42
43     function include_versions_in_URLs() {
44         return (bool) $this->_args['show_all'];
45     }
46
47     function date ($rev) {
48         global $WikiTheme;
49         return $WikiTheme->getDay($rev->get('mtime'));
50     }
51
52     function time ($rev) {
53         global $WikiTheme;
54         return $WikiTheme->formatTime($rev->get('mtime'));
55     }
56
57     function diffURL ($rev) {
58         $args = $this->_diffargs;
59         if ($this->include_versions_in_URLs())
60             $args['version'] = $rev->getVersion();
61         $page = $rev->getPage();
62         return WikiURL($page->getName(), $args, $this->_absurls);
63     }
64
65     function historyURL ($rev) {
66         $page = $rev->getPage();
67         return WikiURL($page, array('action' => _("PageHistory")),
68                        $this->_absurls);
69     }
70
71     function pageURL ($rev) {
72         return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
73                        '', $this->_absurls);
74     }
75
76     function authorHasPage ($author) {
77         global $WikiNameRegexp, $request;
78         $dbi = $request->getDbh();
79         return isWikiWord($author) && $dbi->isWikiPage($author);
80     }
81
82     function authorURL ($author) {
83         return $this->authorHasPage() ? WikiURL($author) : false;
84     }
85
86
87     function status ($rev) {
88         if ($rev->hasDefaultContents())
89             return 'deleted';
90         $page = $rev->getPage();
91         $prev = $page->getRevisionBefore($rev->getVersion());
92         if ($prev->hasDefaultContents())
93             return 'new';
94         return 'updated';
95     }
96
97     function importance ($rev) {
98         return $rev->get('is_minor_edit') ? 'minor' : 'major';
99     }
100
101     function summary($rev) {
102         if ( ($summary = $rev->get('summary')) )
103             return $summary;
104
105         switch ($this->status($rev)) {
106             case 'deleted':
107                 return _("Deleted");
108             case 'new':
109                 return _("New page");
110             default:
111                 return '';
112         }
113     }
114
115     function setValidators($most_recent_rev) {
116         $rev = $most_recent_rev;
117         $validators = array('RecentChanges-top' =>
118                             array($rev->getPageName(), $rev->getVersion()),
119                             '%mtime' => $rev->get('mtime'));
120         global $request;
121         $request->appendValidators($validators);
122     }
123 }
124
125 class _RecentChanges_HtmlFormatter
126 extends _RecentChanges_Formatter
127 {
128     function diffLink ($rev) {
129         global $WikiTheme;
130         $button = $WikiTheme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
131         $button->setAttr('rel', 'nofollow');
132         return $button;
133     }
134
135     function historyLink ($rev) {
136         global $WikiTheme;
137         return $WikiTheme->makeButton(_("(hist)"), $this->historyURL($rev), 'wiki-rc-action');
138     }
139
140     function pageLink ($rev, $link_text=false) {
141
142         return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),'auto',$link_text);
143         /*
144         $page = $rev->getPage();
145         global $WikiTheme;
146         if ($this->include_versions_in_URLs()) {
147             $version = $rev->getVersion();
148             if ($rev->isCurrent())
149                 $version = false;
150             $exists = !$rev->hasDefaultContents();
151         }
152         else {
153             $version = false;
154             $cur = $page->getCurrentRevision();
155             $exists = !$cur->hasDefaultContents();
156         }
157         if ($exists)
158             return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
159         else
160             return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
161         */
162     }
163
164     function authorLink ($rev) {
165         return WikiLink($rev->get('author'), 'if_known');
166     }
167
168     function summaryAsHTML ($rev) {
169         if ( !($summary = $this->summary($rev)) )
170             return '';
171         return  HTML::strong( array('class' => 'wiki-summary'),
172                               "[",
173                               TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
174                               "]");
175     }
176
177     function rss_icon () {
178         global $request, $WikiTheme;
179
180         $rss_url = $request->getURLtoSelf(array('action' => 'RecentChanges', 'format' => 'rss'));
181         return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), 
182                            $WikiTheme->makeButton("RSS", $rss_url, 'rssicon'));
183     }
184     function rss2_icon () {
185         global $request, $WikiTheme;
186
187         $rss_url = $request->getURLtoSelf(array('action' => 'RecentChanges', 'format' => 'rss2'));
188         return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), 
189                            $WikiTheme->makeButton("xml", $rss_url, 'rssicon'));
190     }
191     function atom_icon () {
192         global $request, $WikiTheme;
193         if (DEBUG) {
194             $rss_url = $request->getURLtoSelf(array('action' => 'RecentChanges', 'format' => 'atom'));
195             return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), 
196                            $WikiTheme->makeButton("atom", $rss_url, 'rssicon'));
197         }
198     }
199     function grazr_icon () {
200         global $request, $WikiTheme;
201         $rss_url = 'http://grazr.com/gzpanel.html?' . 
202             WikiURL($request->getArg('pagename'),array('action' => 'RecentChanges', 'format' => 'rss2'),true);
203         return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), 
204                            $WikiTheme->makeButton("grazr-it", $rss_url, 'rssicon'));
205     }
206
207     function pre_description () {
208         extract($this->_args);
209         // FIXME: say something about show_all.
210         if ($show_major && $show_minor)
211             $edits = _("edits");
212         elseif ($show_major)
213             $edits = _("major edits");
214         else
215             $edits = _("minor edits");
216         if (isset($caption) and $caption == _("Recent Comments"))
217             $edits = _("comments");
218         if (!empty($only_new)) {
219             $edits = _("created new pages");
220         }
221         if (!empty($author)) {
222             global $request;
223             if ($author == '[]')
224                 $author = $request->_user->getID();
225             $edits .= sprintf(_(" for pages changed by %s"), $author);
226         }
227         if (!empty($owner)) {
228             global $request;
229             if ($owner == '[]')
230                 $owner = $request->_user->getID();
231             $edits .= sprintf(_(" for pages owned by %s"), $owner);
232         }
233         if ($timespan = $days > 0) {
234             if (intval($days) != $days)
235                 $days = sprintf("%.1f", $days);
236         }
237         $lmt = abs($limit);
238         /**
239          * Depending how this text is split up it can be tricky or
240          * impossible to translate with good grammar. So the seperate
241          * strings for 1 day and %s days are necessary in this case
242          * for translating to multiple languages, due to differing
243          * overlapping ideal word cutting points.
244          *
245          * en: day/days "The %d most recent %s [during (the past] day) are listed below."
246          * de: 1 Tag    "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
247          * de: %s days  "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
248          *
249          * en: day/days "The %d most recent %s during [the past] (day) are listed below."
250          * fr: 1 jour   "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont Ã©numérées ci-dessous."
251          * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont Ã©numérées ci-dessous."
252          */
253         if ($limit > 0) {
254             if ($timespan) {
255                 if (intval($days) == 1)
256                     $desc = fmt("The %d most recent %s during the past day are listed below.",
257                                 $limit, $edits);
258                 else
259                     $desc = fmt("The %d most recent %s during the past %s days are listed below.",
260                                 $limit, $edits, $days);
261             } else
262                 $desc = fmt("The %d most recent %s are listed below.",
263                             $limit, $edits);
264         }
265         elseif ($limit < 0) {  //$limit < 0 means we want oldest pages
266             if ($timespan) {
267                 if (intval($days) == 1)
268                     $desc = fmt("The %d oldest %s during the past day are listed below.",
269                                 $lmt, $edits);
270                 else
271                     $desc = fmt("The %d oldest %s during the past %s days are listed below.",
272                                 $lmt, $edits, $days);
273             } else
274                 $desc = fmt("The %d oldest %s are listed below.",
275                             $lmt, $edits);
276         }
277
278         else {
279             if ($timespan) {
280                 if (intval($days) == 1)
281                     $desc = fmt("The most recent %s during the past day are listed below.",
282                                 $edits);
283                 else
284                     $desc = fmt("The most recent %s during the past %s days are listed below.",
285                                 $edits, $days);
286             } else
287                 $desc = fmt("All %s are listed below.", $edits);
288         }
289         return $desc;
290     }    
291
292     function description() {
293         return HTML::p(false, $this->pre_description());
294     }
295
296
297     function title () {
298         extract($this->_args);
299         return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
300                      ' ',
301                      $this->rss_icon(), 
302                      HTML::raw('&nbsp;'), $this->rss2_icon(),
303                      HTML::raw('&nbsp;'), $this->grazr_icon(),
304                      HTML::raw('&nbsp;'), $this->atom_icon(),
305                      $this->sidebar_link());
306     }
307
308     function empty_message() {
309         if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
310             return _("No comments found");
311         else 
312             return _("No changes found");
313     }
314         
315     function sidebar_link() {
316         extract($this->_args);
317         $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
318
319         global $request;
320         $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
321
322         $addsidebarjsfunc =
323             "function addPanel() {\n"
324             ."    window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
325             ."       \"$sidebarurl\",\"\");\n"
326             ."}\n";
327         $jsf = JavaScript($addsidebarjsfunc);
328
329         global $WikiTheme;
330         $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon');
331         $addsidebarjsclick = asXML(HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), $sidebar_button));
332         $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
333                                 ."    (typeof window.sidebar.addPanel == 'function'))\n"
334                                 ."   {\n"
335                                 ."       document.write('$addsidebarjsclick');\n"
336                                 ."   }\n"
337                                 );
338         return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
339     }
340
341     function format ($changes) {
342         include_once('lib/InlineParser.php');
343         
344         $html = HTML(HTML::h2(false, $this->title()));
345         if (($desc = $this->description()))
346             $html->pushContent($desc);
347         
348         if ($this->_args['daylist'])
349             $html->pushContent(new DayButtonBar($this->_args));
350
351         $last_date = '';
352         $lines = false;
353         $first = true;
354
355         while ($rev = $changes->next()) {
356             if (($date = $this->date($rev)) != $last_date) {
357                 if ($lines)
358                     $html->pushContent($lines);
359                 $html->pushContent(HTML::h3($date));
360                 $lines = HTML::ul();
361                 $last_date = $date;
362
363             }
364             // enforce view permission
365             if (mayAccessPage('view', $rev->_pagename)) {
366                 $lines->pushContent($this->format_revision($rev));
367
368                 if ($first)
369                     $this->setValidators($rev);
370                 $first = false;
371             }
372         }
373         if ($lines)
374             $html->pushContent($lines);
375         if ($first)
376             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
377                                        $this->empty_message()));
378         
379         return $html;
380     }
381
382     function format_revision ($rev) {
383         $args = &$this->_args;
384
385         $class = 'rc-' . $this->importance($rev);
386
387         $time = $this->time($rev);
388         if (! $rev->get('is_minor_edit'))
389             $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
390
391         $line = HTML::li(array('class' => $class));
392
393
394         if ($args['difflinks'])
395             $line->pushContent($this->diffLink($rev), ' ');
396
397         if ($args['historylinks'])
398             $line->pushContent($this->historyLink($rev), ' ');
399
400         $line->pushContent($this->pageLink($rev), ' ',
401                            $time, ' ',
402                            $this->summaryAsHTML($rev),
403                            ' ... ',
404                            $this->authorLink($rev));
405         return $line;
406     }
407 }
408
409
410 class _RecentChanges_SideBarFormatter
411 extends _RecentChanges_HtmlFormatter
412 {
413     function rss_icon () {
414         //omit rssicon
415     }
416     function rss2_icon () { }
417     function title () {
418         //title click opens the normal RC or RE page in the main browser frame
419         extract($this->_args);
420         $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
421         $titlelink->setAttr('target', '_content');
422         return HTML($this->logo(), $titlelink);
423     }
424     function logo () {
425         //logo click opens the HomePage in the main browser frame
426         global $WikiTheme;
427         $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
428                                'border' => 0,
429                                'align' => 'right',
430                                'style' => 'height:2.5ex'
431                                ));
432         $linkurl = WikiLink(HOME_PAGE, false, $img);
433         $linkurl->setAttr('target', '_content');
434         return $linkurl;
435     }
436
437     function authorLink ($rev) {
438         $author = $rev->get('author');
439         if ( $this->authorHasPage($author) ) {
440             $linkurl = WikiLink($author);
441             $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
442             return $linkurl;
443         } else
444             return $author;
445     }
446
447     function diffLink ($rev) {
448         $linkurl = parent::diffLink($rev);
449         $linkurl->setAttr('target', '_content');
450         $linkurl->setAttr('rel', 'nofollow');
451         // FIXME: Smelly hack to get smaller diff buttons in sidebar
452         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
453         return $linkurl;
454     }
455     function historyLink ($rev) {
456         $linkurl = parent::historyLink($rev);
457         $linkurl->setAttr('target', '_content');
458         // FIXME: Smelly hack to get smaller history buttons in sidebar
459         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
460         return $linkurl;
461     }
462     function pageLink ($rev) {
463         $linkurl = parent::pageLink($rev);
464         $linkurl->setAttr('target', '_content');
465         return $linkurl;
466     }
467     // Overriding summaryAsHTML, because there is no way yet to
468     // return summary as transformed text with
469     // links setAttr('target', '_content') in Mozilla sidebar.
470     // So for now don't create clickable links inside summary
471     // in the sidebar, or else they target the sidebar and not the
472     // main content window.
473     function summaryAsHTML ($rev) {
474         if ( !($summary = $this->summary($rev)) )
475             return '';
476         return HTML::strong(array('class' => 'wiki-summary'),
477                                 "[",
478                                 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
479                                 "]");
480     }
481
482
483     function format ($changes) {
484         $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
485         $html = _RecentChanges_HtmlFormatter::format ($changes);
486         $html = HTML::div(array('class' => 'wikitext'), $html);
487         global $request;
488         $request->discardOutput();
489         
490         printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
491         printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
492         printf('  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
493         printf('<html xmlns="http://www.w3.org/1999/xhtml">');
494
495         printf("<head>\n");
496         extract($this->_args);
497         $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
498         printf("<title>" . $title . "</title>\n");
499         global $WikiTheme;
500         $css = $WikiTheme->getCSS();
501         $css->PrintXML();
502         printf("</head>\n");
503
504         printf("<body class=\"sidebar\">\n");
505         $html->PrintXML();
506         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>';
507         printf("\n</body>\n");
508         printf("</html>\n");
509
510         $request->finish(); // cut rest of page processing short
511     }
512 }
513
514 class _RecentChanges_BoxFormatter
515 extends _RecentChanges_HtmlFormatter
516 {
517     function rss_icon () {
518     }
519     function rss2_icon () {
520     }
521     function title () {
522     }
523     function authorLink ($rev) {
524     }
525     function diffLink ($rev) {
526     }
527     function historyLink ($rev) {
528     }
529     function summaryAsHTML ($rev) {
530     }
531     function description () {
532     }
533     function format ($changes) {
534         include_once('lib/InlineParser.php');
535         $last_date = '';
536         $first = true;
537         $html = HTML();
538         $counter = 1;
539         $sp = HTML::Raw("\n&nbsp;&middot;&nbsp;");
540         while ($rev = $changes->next()) {
541             // enforce view permission
542             if (mayAccessPage('view',$rev->_pagename)) {
543                 if ($link = $this->pageLink($rev)) // some entries may be empty 
544                                                    // (/Blog/.. interim pages)
545                     $html->pushContent($sp, $link, HTML::br());
546                 if ($first)
547                     $this->setValidators($rev);
548                 $first = false;
549             }
550         }
551         if ($first)
552             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
553                                        $this->empty_message()));
554         return $html;
555     }
556 }
557
558 class _RecentChanges_RssFormatter
559 extends _RecentChanges_Formatter
560 {
561     var $_absurls = true;
562
563     function time ($rev) {
564         return Iso8601DateTime($rev->get('mtime'));
565     }
566
567     function pageURI ($rev) {
568         return WikiURL($rev, '', 'absurl');
569     }
570
571     function format ($changes) {
572         
573         include_once('lib/RssWriter.php');
574         $rss = new RssWriter;
575
576         $rss->channel($this->channel_properties());
577
578         if (($props = $this->image_properties()))
579             $rss->image($props);
580         if (($props = $this->textinput_properties()))
581             $rss->textinput($props);
582
583         $first = true;
584         while ($rev = $changes->next()) {
585             // enforce view permission
586             if (mayAccessPage('view', $rev->_pagename)) {
587                 $rss->addItem($this->item_properties($rev),
588                               $this->pageURI($rev));
589                 if ($first)
590                     $this->setValidators($rev);
591                 $first = false;
592             }
593         }
594
595         global $request;
596         $request->discardOutput();
597         $rss->finish();
598         printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
599
600         // Flush errors in comment, otherwise it's invalid XML.
601         global $ErrorManager;
602         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
603             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
604
605         $request->finish();     // NORETURN!!!!
606     }
607
608     function image_properties () {
609         global $WikiTheme;
610
611         $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
612         if (!$img_url)
613             return false;
614
615         return array('title' => WIKI_NAME,
616                      'link' => WikiURL(HOME_PAGE, false, 'absurl'),
617                      'url' => $img_url);
618     }
619
620     function textinput_properties () {
621         return array('title' => _("Search"),
622                      'description' => _("Title Search"),
623                      'name' => 's',
624                      'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
625     }
626
627     function channel_properties () {
628         global $request;
629
630         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
631         return array('title' => WIKI_NAME,
632                      'link' => $rc_url,
633                      'description' => _("RecentChanges"),
634                      'dc:date' => Iso8601DateTime(time()),
635                      'dc:language' => $GLOBALS['LANG']);
636
637         /* FIXME: other things one might like in <channel>:
638          * sy:updateFrequency
639          * sy:updatePeriod
640          * sy:updateBase
641          * dc:subject
642          * dc:publisher
643          * dc:language
644          * dc:rights
645          * rss091:language
646          * rss091:managingEditor
647          * rss091:webmaster
648          * rss091:lastBuildDate
649          * rss091:copyright
650          */
651     }
652
653     function item_properties ($rev) {
654         $page = $rev->getPage();
655         $pagename = $page->getName();
656
657         return array( 'title'           => SplitPagename($pagename),
658                       'description'     => $this->summary($rev),
659                       'link'            => $this->pageURL($rev),
660                       'dc:date'         => $this->time($rev),
661                       'dc:contributor'  => $rev->get('author'),
662                       'wiki:version'    => $rev->getVersion(),
663                       'wiki:importance' => $this->importance($rev),
664                       'wiki:status'     => $this->status($rev),
665                       'wiki:diff'       => $this->diffURL($rev),
666                       'wiki:history'    => $this->historyURL($rev)
667                       );
668     }
669 }
670
671 /** explicit application/rss+xml Content-Type,
672  * simplified xml structure (no namespace),
673  * support for xml-rpc cloud registerProcedure (not yet)
674  */
675 class _RecentChanges_Rss2Formatter
676 extends _RecentChanges_RssFormatter {
677
678     function format ($changes) {
679         include_once('lib/RssWriter2.php');
680         $rss = new RssWriter2;
681
682         $rss->channel($this->channel_properties());
683         if (($props = $this->cloud_properties()))
684             $rss->cloud($props);
685         if (($props = $this->image_properties()))
686             $rss->image($props);
687         if (($props = $this->textinput_properties()))
688             $rss->textinput($props);
689         $first = true;
690         while ($rev = $changes->next()) {
691             // enforce view permission
692             if (mayAccessPage('view', $rev->_pagename)) {
693                 $rss->addItem($this->item_properties($rev),
694                               $this->pageURI($rev));
695                 if ($first)
696                     $this->setValidators($rev);
697                 $first = false;
698             }
699         }
700
701         global $request;
702         $request->discardOutput();
703         $rss->finish();
704         printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
705         // Flush errors in comment, otherwise it's invalid XML.
706         global $ErrorManager;
707         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
708             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
709
710         $request->finish();     // NORETURN!!!!
711     }
712
713     function channel_properties () {
714         $chann_10 = parent::channel_properties();
715         return array_merge($chann_10,
716                            array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
717                                  //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
718                                  //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
719                                  //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
720                                  'copyright' => COPYRIGHTPAGE_URL
721                                  ));
722     }
723
724     // xml-rpc registerProcedure not yet implemented
725     function cloud_properties () { return false; } 
726     function cloud_properties_test () {
727         return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
728                      'registerProcedure' => 'wiki.rssPleaseNotify',
729                      'path' => DATA_PATH.'/RPC2.php',
730                      'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
731                      'domain' => SERVER_NAME);
732     }
733 }
734
735 /**
736  * Filter by non-empty
737  */
738 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
739 {
740     /** Constructor
741      *
742      * @param $revisions object a WikiDB_PageRevisionIterator.
743      */
744     function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
745         $this->_revisions = $revisions;
746         $this->_check_current_revision = $check_current_revision;
747     }
748
749     function next () {
750         while (($rev = $this->_revisions->next())) {
751             if ($this->_check_current_revision) {
752                 $page = $rev->getPage();
753                 $check_rev = $page->getCurrentRevision();
754             }
755             else {
756                 $check_rev = $rev;
757             }
758             if (! $check_rev->hasDefaultContents())
759                 return $rev;
760         }
761         $this->free();
762         return false;
763     }
764
765 }
766
767 /**
768  * Filter by only_new.
769  * Only new created pages
770  */
771 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
772 {
773     /** Constructor
774      *
775      * @param $revisions object a WikiDB_PageRevisionIterator.
776      */
777     function NewPageRevisionIterator ($revisions) {
778         $this->_revisions = $revisions;
779     }
780
781     function next () {
782         while (($rev = $this->_revisions->next())) {
783             if ($rev->getVersion() == 1)
784                 return $rev;
785         }
786         $this->free();
787         return false;
788     }
789 }
790
791 /**
792  * Filter by author
793  */
794 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
795 {
796     function AuthorPageRevisionIterator ($revisions, $author) {
797         $this->_revisions = $revisions;
798         $this->_author = $author;
799     }
800
801     function next () {
802         while (($rev = $this->_revisions->next())) {
803             if ($rev->get('author_id') == $this->_author)
804                 return $rev;
805         }
806         $this->free();
807         return false;
808     }
809 }
810
811 /**
812  * Filter by owner
813  */
814 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
815 {
816     function OwnerPageRevisionIterator ($revisions, $owner) {
817         $this->_revisions = $revisions;
818         $this->_owner = $owner;
819     }
820
821     function next () {
822         while (($rev = $this->_revisions->next())) {
823             $page = $rev->getPage();
824             if ($page->getOwner() == $this->_owner)
825                 return $rev;
826         }
827         $this->free();
828         return false;
829     }
830 }
831
832 class WikiPlugin_RecentChanges
833 extends WikiPlugin
834 {
835     function getName () {
836         return _("RecentChanges");
837     }
838
839     function getVersion() {
840         return preg_replace("/[Revision: $]/", '',
841                             "\$Revision: 1.116 $");
842     }
843
844     function managesValidators() {
845         // Note that this is a bit of a fig.
846         // We set validators based on the most recently changed page,
847         // but this fails when the most-recent page is deleted.
848         // (Consider that the Last-Modified time will decrease
849         // when this happens.)
850
851         // We might be better off, leaving this as false (and junking
852         // the validator logic above) and just falling back to the
853         // default behavior (handled by WikiPlugin) of just using
854         // the WikiDB global timestamp as the mtime.
855
856         // Nevertheless, for now, I leave this here, mostly as an
857         // example for how to use appendValidators() and managesValidators().
858         
859         return true;
860     }
861             
862     function getDefaultArguments() {
863         return array('days'         => 2,
864                      'show_minor'   => false,
865                      'show_major'   => true,
866                      'show_all'     => false,
867                      'show_deleted' => 'sometimes',
868                      'only_new'     => false,
869                      'author'       => false,
870                      'owner'        => false,
871                      'limit'        => false,
872                      'format'       => false,
873                      'daylist'      => false,
874                      'difflinks'    => true,
875                      'historylinks' => false,
876                      'caption'      => ''
877                      );
878     }
879
880     function getArgs ($argstr, $request, $defaults = false) {
881         if (!$defaults) $defaults = $this->getDefaultArguments();
882         $args = WikiPlugin::getArgs($argstr, $request, $defaults);
883
884         $action = $request->getArg('action');
885         if ($action != 'browse' && ! $request->isActionPage($action))
886             $args['format'] = false; // default -> HTML
887
888         if ($args['format'] == 'rss' && empty($args['limit']))
889             $args['limit'] = 15; // Fix default value for RSS.
890         if ($args['format'] == 'rss2' && empty($args['limit']))
891             $args['limit'] = 15; // Fix default value for RSS2.
892
893         if ($args['format'] == 'sidebar' && empty($args['limit']))
894             $args['limit'] = 10; // Fix default value for sidebar.
895
896         return $args;
897     }
898
899     function getMostRecentParams (&$args) {
900         $show_all = false; $show_minor = false; $show_major = false;
901         $limit = false;
902         extract($args);
903
904         $params = array('include_minor_revisions' => $show_minor,
905                         'exclude_major_revisions' => !$show_major,
906                         'include_all_revisions' => !empty($show_all));
907         if ($limit != 0)
908             $params['limit'] = $limit;
909         if (!empty($args['author'])) {
910             global $request;
911             if ($args['author'] == '[]')
912                 $args['author'] = $request->_user->getID();
913             $params['author'] = $args['author'];
914         }
915         if (!empty($args['owner'])) {
916             global $request;
917             if ($args['owner'] == '[]')
918                 $args['owner'] = $request->_user->getID();
919             $params['owner'] = $args['owner'];
920         }
921         if (!empty($days)) {
922           if ($days > 0.0)
923             $params['since'] = time() - 24 * 3600 * $days;
924           elseif ($days < 0.0)
925             $params['since'] = 24 * 3600 * $days - time();
926         }
927
928         return $params;
929     }
930
931     function getChanges ($dbi, $args) {
932         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
933
934         $show_deleted = @$args['show_deleted'];
935         $show_all = @$args['show_all'];
936         if ($show_deleted == 'sometimes')
937             $show_deleted = @$args['show_minor'];
938
939         if (!empty($args['only_new']))
940             $changes = new NewPageRevisionIterator($changes);
941         if (!empty($args['author']))
942             $changes = new AuthorPageRevisionIterator($changes, $args['author']);
943         if (!empty($args['owner']))
944             $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
945         if (!$show_deleted)
946             $changes = new NonDeletedRevisionIterator($changes, !$show_all);
947
948         return $changes;
949     }
950
951     function format ($changes, $args) {
952         global $WikiTheme;
953         $format = $args['format'];
954
955         $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
956         if (!$fmt_class) {
957             if ($format == 'rss')
958                 $fmt_class = '_RecentChanges_RssFormatter';
959             elseif ($format == 'rss2')
960                 $fmt_class = '_RecentChanges_Rss2Formatter';
961             elseif ($format == 'rss091') {
962                 include_once "lib/RSSWriter091.php";
963                 $fmt_class = '_RecentChanges_RssFormatter091';
964             }
965             elseif ($format == 'sidebar')
966                 $fmt_class = '_RecentChanges_SideBarFormatter';
967             elseif ($format == 'box')
968                 $fmt_class = '_RecentChanges_BoxFormatter';
969             else
970                 $fmt_class = '_RecentChanges_HtmlFormatter';
971         }
972
973         $fmt = new $fmt_class($args);
974         return $fmt->format($changes);
975     }
976
977     function run($dbi, $argstr, &$request, $basepage) {
978         $args = $this->getArgs($argstr, $request);
979
980         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
981         // to be enough for anyone.)
982         $args['days'] = min($args['days'], 365000);
983         
984         // Hack alert: format() is a NORETURN for rss formatters.
985         return $this->format($this->getChanges($dbi, $args), $args);
986     }
987
988     // box is used to display a fixed-width, narrow version with common header.
989     // just a numbered list of limit pagenames, without date.
990     function box($args = false, $request = false, $basepage = false) {
991         if (!$request) $request =& $GLOBALS['request'];
992         if (!isset($args['limit'])) $args['limit'] = 15;
993         $args['format'] = 'box';
994         $args['show_minor'] = false;
995         $args['show_major'] = true;
996         $args['show_deleted'] = 'sometimes';
997         $args['show_all'] = false;
998         $args['days'] = 90;
999         return $this->makeBox(WikiLink($this->getName(),'',
1000                                        SplitPagename($this->getName())),
1001                               $this->format
1002                               ($this->getChanges($request->_dbi, $args), $args));
1003     }
1004
1005 };
1006
1007
1008 class DayButtonBar extends HtmlElement {
1009
1010     function DayButtonBar ($plugin_args) {
1011         $this->__construct('p', array('class' => 'wiki-rc-action'));
1012
1013         // Display days selection buttons
1014         extract($plugin_args);
1015
1016         // Custom caption
1017         if (! $caption) {
1018             if ($show_minor)
1019                 $caption = _("Show minor edits for:");
1020             elseif ($show_all)
1021                 $caption = _("Show all changes for:");
1022             else
1023                 $caption = _("Show changes for:");
1024             if ($only_new)
1025                 $caption = _("All new pages since:");
1026         }
1027
1028         $this->pushContent($caption, ' ');
1029
1030         global $WikiTheme;
1031         $sep = $WikiTheme->getButtonSeparator();
1032
1033         $n = 0;
1034         foreach (explode(",", $daylist) as $days) {
1035             if ($n++)
1036                 $this->pushContent($sep);
1037             $this->pushContent($this->_makeDayButton($days));
1038         }
1039     }
1040
1041     function _makeDayButton ($days) {
1042         global $WikiTheme, $request;
1043
1044         if ($days == 1)
1045             $label = _("1 day");
1046         elseif ($days < 1)
1047             $label = "..."; //alldays
1048         else
1049             $label = sprintf(_("%s days"), abs($days));
1050
1051         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
1052
1053         return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
1054     }
1055 }
1056
1057 // $Log: not supported by cvs2svn $
1058 // Revision 1.115  2007/04/08 16:24:10  rurban
1059 // Remove redundant code in ->authorLink(): 'if_known' does the same
1060 //
1061 // Revision 1.114  2007/02/17 22:39:44  rurban
1062 // format=rss overhaul
1063 //
1064 // Revision 1.113  2007/02/17 14:15:52  rurban
1065 // new argument owner=[] for RecentChangesMyPages
1066 //
1067 // Revision 1.112  2007/01/28 20:32:07  rurban
1068 // silence empty warning
1069 //
1070 // Revision 1.111  2007/01/25 21:48:52  rurban
1071 // new argument author=[]
1072 //
1073 // Revision 1.110  2007/01/22 23:51:36  rurban
1074 // new arg: only_new
1075 //
1076 // Revision 1.109  2006/03/19 14:26:29  rurban
1077 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
1078 //
1079 // Revision 1.108  2005/04/01 16:09:35  rurban
1080 // fix defaults in RecentChanges plugins: e.g. invalid pagenames for PageHistory
1081 //
1082 // Revision 1.107  2005/02/04 13:45:28  rurban
1083 // improve box layout a bit
1084 //
1085 // Revision 1.106  2005/02/02 19:39:10  rurban
1086 // honor show_all=false
1087 //
1088 // Revision 1.105  2005/01/25 03:50:54  uckelman
1089 // pre_description is a member function, so call with $this->.
1090 //
1091 // Revision 1.104  2005/01/24 23:15:16  uckelman
1092 // The extra description for RelatedChanges was appearing in RecentChanges
1093 // and PageHistory due to a bad test in _RecentChanges_HtmlFormatter. Fixed.
1094 //
1095 // Revision 1.103  2004/12/15 17:45:09  rurban
1096 // fix box method
1097 //
1098 // Revision 1.102  2004/12/06 19:29:24  rurban
1099 // simplify RSS: add RSS2 link (rss tag only, new content-type)
1100 //
1101 // Revision 1.101  2004/11/10 19:32:24  rurban
1102 // * optimize increaseHitCount, esp. for mysql.
1103 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1104 // * Pear_DB version logic (awful but needed)
1105 // * fix broken ADODB quote
1106 // * _extract_page_data simplification
1107 //
1108 // Revision 1.100  2004/06/28 16:35:12  rurban
1109 // prevent from shell commands
1110 //
1111 // Revision 1.99  2004/06/20 14:42:54  rurban
1112 // various php5 fixes (still broken at blockparser)
1113 //
1114 // Revision 1.98  2004/06/14 11:31:39  rurban
1115 // renamed global $Theme to $WikiTheme (gforge nameclash)
1116 // inherit PageList default options from PageList
1117 //   default sortby=pagename
1118 // use options in PageList_Selectable (limit, sortby, ...)
1119 // added action revert, with button at action=diff
1120 // added option regex to WikiAdminSearchReplace
1121 //
1122 // Revision 1.97  2004/06/03 18:58:27  rurban
1123 // days links requires action=RelatedChanges arg
1124 //
1125 // Revision 1.96  2004/05/18 16:23:40  rurban
1126 // rename split_pagename to SplitPagename
1127 //
1128 // Revision 1.95  2004/05/16 22:07:35  rurban
1129 // check more config-default and predefined constants
1130 // various PagePerm fixes:
1131 //   fix default PagePerms, esp. edit and view for Bogo and Password users
1132 //   implemented Creator and Owner
1133 //   BOGOUSERS renamed to BOGOUSER
1134 // fixed syntax errors in signin.tmpl
1135 //
1136 // Revision 1.94  2004/05/14 20:55:03  rurban
1137 // simplified RecentComments
1138 //
1139 // Revision 1.93  2004/05/14 17:33:07  rurban
1140 // new plugin RecentChanges
1141 //
1142 // Revision 1.92  2004/04/21 04:29:10  rurban
1143 // Two convenient RecentChanges extensions
1144 //   RelatedChanges (only links from current page)
1145 //   RecentEdits (just change the default args)
1146 //
1147 // Revision 1.91  2004/04/19 18:27:46  rurban
1148 // Prevent from some PHP5 warnings (ref args, no :: object init)
1149 //   php5 runs now through, just one wrong XmlElement object init missing
1150 // Removed unneccesary UpgradeUser lines
1151 // Changed WikiLink to omit version if current (RecentChanges)
1152 //
1153 // Revision 1.90  2004/04/18 01:11:52  rurban
1154 // more numeric pagename fixes.
1155 // fixed action=upload with merge conflict warnings.
1156 // charset changed from constant to global (dynamic utf-8 switching)
1157 //
1158 // Revision 1.89  2004/04/10 02:30:49  rurban
1159 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1160 // Fixed "cannot setlocale..." (sf.net problem)
1161 //
1162 // Revision 1.88  2004/04/01 15:57:10  rurban
1163 // simplified Sidebar theme: table, not absolute css positioning
1164 // added the new box methods.
1165 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1166 //
1167 // Revision 1.87  2004/03/30 02:14:03  rurban
1168 // fixed yet another Prefs bug
1169 // added generic PearDb_iter
1170 // $request->appendValidators no so strict as before
1171 // added some box plugin methods
1172 // PageList commalist for condensed output
1173 //
1174 // Revision 1.86  2004/03/12 13:31:43  rurban
1175 // enforce PagePermissions, errormsg if not Admin
1176 //
1177 // Revision 1.85  2004/02/17 12:11:36  rurban
1178 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
1179 //
1180 // Revision 1.84  2004/02/15 22:29:42  rurban
1181 // revert premature performance fix
1182 //
1183 // Revision 1.83  2004/02/15 21:34:37  rurban
1184 // PageList enhanced and improved.
1185 // fixed new WikiAdmin... plugins
1186 // editpage, Theme with exp. htmlarea framework
1187 //   (htmlarea yet committed, this is really questionable)
1188 // WikiUser... code with better session handling for prefs
1189 // enhanced UserPreferences (again)
1190 // RecentChanges for show_deleted: how should pages be deleted then?
1191 //
1192 // Revision 1.82  2004/01/25 03:58:43  rurban
1193 // use stdlib:isWikiWord()
1194 //
1195 // Revision 1.81  2003/11/28 21:06:31  carstenklapp
1196 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
1197 // instead of 1. Make diff buttons smaller with css. Added description
1198 // line back in at the top.
1199 //
1200 // Revision 1.80  2003/11/27 15:17:01  carstenklapp
1201 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
1202 // button, to allow an image button for it to be added to Themes. Output
1203 // RSS button in small text size when theme has no button image.
1204 //
1205 // Revision 1.79  2003/04/29 14:34:20  dairiki
1206 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
1207 //
1208 // Revision 1.78  2003/03/04 01:55:05  dairiki
1209 // Fix to ensure absolute URL for logo in RSS recent changes.
1210 //
1211 // Revision 1.77  2003/02/27 23:23:38  dairiki
1212 // Fix my breakage of CSS and sidebar RecentChanges output.
1213 //
1214 // Revision 1.76  2003/02/27 22:48:44  dairiki
1215 // Fixes invalid HTML generated by PageHistory plugin.
1216 //
1217 // (<noscript> is block-level and not allowed within <p>.)
1218 //
1219 // Revision 1.75  2003/02/22 21:39:05  dairiki
1220 // Hackish fix for SF bug #622784.
1221 //
1222 // (The root of the problem is clearly a PHP bug.)
1223 //
1224 // Revision 1.74  2003/02/21 22:52:21  dairiki
1225 // Make sure to interpret relative links (like [/Subpage]) in summary
1226 // relative to correct basepage.
1227 //
1228 // Revision 1.73  2003/02/21 04:12:06  dairiki
1229 // Minor fixes for new cached markup.
1230 //
1231 // Revision 1.72  2003/02/17 02:19:01  dairiki
1232 // Fix so that PageHistory will work when the current revision
1233 // of a page has been "deleted".
1234 //
1235 // Revision 1.71  2003/02/16 20:04:48  dairiki
1236 // Refactor the HTTP validator generation/checking code.
1237 //
1238 // This also fixes a number of bugs with yesterdays validator mods.
1239 //
1240 // Revision 1.70  2003/02/16 05:09:43  dairiki
1241 // Starting to fix handling of the HTTP validator headers, Last-Modified,
1242 // and ETag.
1243 //
1244 // Last-Modified was being set incorrectly (but only when DEBUG was not
1245 // defined!)  Setting a Last-Modified without setting an appropriate
1246 // Expires: and/or Cache-Control: header results in browsers caching
1247 // the page unconditionally (for a certain period of time).
1248 // This is generally bad, since it means people don't see updated
1249 // page contents right away --- this is particularly confusing to
1250 // the people who are editing pages since their edits don't show up
1251 // next time they browse the page.
1252 //
1253 // Now, we don't allow caching of pages without revalidation
1254 // (via the If-Modified-Since and/or If-None-Match request headers.)
1255 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
1256 // appropriate value in index.php, but I advise against it.)
1257 //
1258 // Problems:
1259 //
1260 //   o Even when request is aborted due to the content not being
1261 //     modified, we currently still do almost all the work involved
1262 //     in producing the page.  So the only real savings from all
1263 //     this logic is in network bandwidth.
1264 //
1265 //   o Plugins which produce "dynamic" output need to be inspected
1266 //     and made to call $request->addToETag() and
1267 //     $request->setModificationTime() appropriately, otherwise the
1268 //     page can change without the change being detected.
1269 //     This leads to stale pages in cache again...
1270 //
1271 // Revision 1.69  2003/01/18 22:01:43  carstenklapp
1272 // Code cleanup:
1273 // Reformatting & tabs to spaces;
1274 // Added copyleft, getVersion, getDescription, rcs_id.
1275 //
1276
1277 // (c-file-style: "gnu")
1278 // Local Variables:
1279 // mode: php
1280 // tab-width: 8
1281 // c-basic-offset: 4
1282 // c-hanging-comment-ender-p: nil
1283 // indent-tabs-mode: nil
1284 // End:
1285 ?>