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