]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChanges.php
Prevent from some PHP5 warnings (ref args, no :: object init)
[SourceForge/phpwiki.git] / lib / plugin / RecentChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RecentChanges.php,v 1.91 2004-04-19 18:27:46 rurban Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $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 $Theme;
47         return $Theme->getDay($rev->get('mtime'));
48     }
49
50     function time ($rev) {
51         global $Theme;
52         return $Theme->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 $Theme;
128         return $Theme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
129     }
130
131     function historyLink ($rev) {
132         global $Theme;
133         return $Theme->makeButton(_("(hist)"), $this->historyURL($rev), 'wiki-rc-action');
134     }
135
136     function pageLink ($rev, $link_text=false) {
137
138         return WikiLink($rev,'auto',$link_text);
139         /*
140         $page = $rev->getPage();
141         global $Theme;
142         if ($this->include_versions_in_URLs()) {
143             $version = $rev->getVersion();
144             if ($rev->isCurrent())
145                 $version = false;
146             $exists = !$rev->hasDefaultContents();
147         }
148         else {
149             $version = false;
150             $cur = $page->getCurrentRevision();
151             $exists = !$cur->hasDefaultContents();
152         }
153         if ($exists)
154             return $Theme->linkExistingWikiWord($page->getName(), $link_text, $version);
155         else
156             return $Theme->linkUnknownWikiWord($page->getName(), $link_text);
157         */
158     }
159
160     function authorLink ($rev) {
161         $author = $rev->get('author');
162         if ( $this->authorHasPage($author) ) {
163             return WikiLink($author);
164         } else
165             return $author;
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, $Theme;
179
180         $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
181         return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), $Theme->makeButton("RSS", $rss_url, 'rssicon'));
182     }
183
184     function description () {
185         extract($this->_args);
186         // FIXME: say something about show_all.
187         if ($show_major && $show_minor)
188             $edits = _("edits");
189         elseif ($show_major)
190             $edits = _("major edits");
191         else
192             $edits = _("minor edits");
193
194         if ($timespan = $days > 0) {
195             if (intval($days) != $days)
196                 $days = sprintf("%.1f", $days);
197         }
198         $lmt = abs($limit);
199         /**
200          * Depending how this text is split up it can be tricky or
201          * impossible to translate with good grammar. So the seperate
202          * strings for 1 day and %s days are necessary in this case
203          * for translating to multiple languages, due to differing
204          * overlapping ideal word cutting points.
205          *
206          * en: day/days "The %d most recent %s [during (the past] day) are listed below."
207          * de: 1 Tag    "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
208          * de: %s days  "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
209          *
210          * en: day/days "The %d most recent %s during [the past] (day) are listed below."
211          * fr: 1 jour   "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
212          * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
213          */
214         if ($limit > 0) {
215             if ($timespan) {
216                 if (intval($days) == 1)
217                     $desc = fmt("The %d most recent %s during the past day are listed below.",
218                                 $limit, $edits);
219                 else
220                     $desc = fmt("The %d most recent %s during the past %s days are listed below.",
221                                 $limit, $edits, $days);
222             } else
223                 $desc = fmt("The %d most recent %s are listed below.",
224                             $limit, $edits);
225         }
226         elseif ($limit < 0) {  //$limit < 0 means we want oldest pages
227             if ($timespan) {
228                 if (intval($days) == 1)
229                     $desc = fmt("The %d oldest %s during the past day are listed below.",
230                                 $lmt, $edits);
231                 else
232                     $desc = fmt("The %d oldest %s during the past %s days are listed below.",
233                                 $lmt, $edits, $days);
234             } else
235                 $desc = fmt("The %d oldest %s are listed below.",
236                             $lmt, $edits);
237         }
238
239         else {
240             if ($timespan) {
241                 if (intval($days) == 1)
242                     $desc = fmt("The most recent %s during the past day are listed below.",
243                                 $edits);
244                 else
245                     $desc = fmt("The most recent %s during the past %s days are listed below.",
246                                 $edits, $days);
247             } else
248                 $desc = fmt("All %s are listed below.", $edits);
249         }
250         return HTML::p(false, $desc);
251     }
252
253
254     function title () {
255         extract($this->_args);
256         return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
257                      ' ',
258                      $this->rss_icon(),
259                      $this->sidebar_link());
260     }
261
262     function empty_message () {
263         return _("No changes found");
264     }
265         
266     function sidebar_link() {
267         extract($this->_args);
268         $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
269
270         global $request;
271         $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
272
273         $addsidebarjsfunc =
274             "function addPanel() {\n"
275             ."    window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
276             ."       \"$sidebarurl\",\"\");\n"
277             ."}\n";
278         $jsf = JavaScript($addsidebarjsfunc);
279
280         global $Theme;
281         $sidebar_button = $Theme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon');
282         $addsidebarjsclick = asXML(HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), $sidebar_button));
283         $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
284                                 ."    (typeof window.sidebar.addPanel == 'function'))\n"
285                                 ."   {\n"
286                                 ."       document.write('$addsidebarjsclick');\n"
287                                 ."   }\n"
288                                 );
289         return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
290     }
291
292     function format ($changes) {
293         include_once('lib/InlineParser.php');
294         
295         $html = HTML(HTML::h2(false, $this->title()));
296         if (($desc = $this->description()))
297             $html->pushContent($desc);
298         
299         if ($this->_args['daylist'])
300             $html->pushContent(new DayButtonBar($this->_args));
301
302         $last_date = '';
303         $lines = false;
304         $first = true;
305
306         while ($rev = $changes->next()) {
307             if (($date = $this->date($rev)) != $last_date) {
308                 if ($lines)
309                     $html->pushContent($lines);
310                 $html->pushContent(HTML::h3($date));
311                 $lines = HTML::ul();
312                 $last_date = $date;
313
314             }
315             // enforce view permission
316             if (mayAccessPage('view',$rev->_pagename)) {
317                 $lines->pushContent($this->format_revision($rev));
318
319                 if ($first)
320                     $this->setValidators($rev);
321                 $first = false;
322             }
323         }
324         if ($lines)
325             $html->pushContent($lines);
326         if ($first)
327             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
328                                        $this->empty_message()));
329         
330         return $html;
331     }
332
333     function format_revision ($rev) {
334         $args = &$this->_args;
335
336         $class = 'rc-' . $this->importance($rev);
337
338         $time = $this->time($rev);
339         if (! $rev->get('is_minor_edit'))
340             $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
341
342         $line = HTML::li(array('class' => $class));
343
344
345         if ($args['difflinks'])
346             $line->pushContent($this->diffLink($rev), ' ');
347
348         if ($args['historylinks'])
349             $line->pushContent($this->historyLink($rev), ' ');
350
351         $line->pushContent($this->pageLink($rev), ' ',
352                            $time, ' ',
353                            $this->summaryAsHTML($rev),
354                            ' ... ',
355                            $this->authorLink($rev));
356         return $line;
357     }
358 }
359
360
361 class _RecentChanges_SideBarFormatter
362 extends _RecentChanges_HtmlFormatter
363 {
364     function rss_icon () {
365         //omit rssicon
366     }
367     function title () {
368         //title click opens the normal RC or RE page in the main browser frame
369         extract($this->_args);
370         $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
371         $titlelink->setAttr('target', '_content');
372         return HTML($this->logo(), $titlelink);
373     }
374     function logo () {
375         //logo click opens the HomePage in the main browser frame
376         global $Theme;
377         $img = HTML::img(array('src' => $Theme->getImageURL('logo'),
378                                'border' => 0,
379                                'align' => 'right',
380                                'style' => 'height:2.5ex'
381                                ));
382         $linkurl = WikiLink(HOME_PAGE, false, $img);
383         $linkurl->setAttr('target', '_content');
384         return $linkurl;
385     }
386
387     function authorLink ($rev) {
388         $author = $rev->get('author');
389         if ( $this->authorHasPage($author) ) {
390             $linkurl = WikiLink($author);
391             $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
392             return $linkurl;
393         } else
394             return $author;
395     }
396
397     function diffLink ($rev) {
398         $linkurl = parent::diffLink($rev);
399         $linkurl->setAttr('target', '_content');
400         // FIXME: Smelly hack to get smaller diff buttons in sidebar
401         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
402         return $linkurl;
403     }
404     function historyLink ($rev) {
405         $linkurl = parent::historyLink($rev);
406         $linkurl->setAttr('target', '_content');
407         // FIXME: Smelly hack to get smaller history buttons in sidebar
408         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
409         return $linkurl;
410     }
411     function pageLink ($rev) {
412         $linkurl = parent::pageLink($rev);
413         $linkurl->setAttr('target', '_content');
414         return $linkurl;
415     }
416     // Overriding summaryAsHTML, because there is no way yet to
417     // return summary as transformed text with
418     // links setAttr('target', '_content') in Mozilla sidebar.
419     // So for now don't create clickable links inside summary
420     // in the sidebar, or else they target the sidebar and not the
421     // main content window.
422     function summaryAsHTML ($rev) {
423         if ( !($summary = $this->summary($rev)) )
424             return '';
425         return HTML::strong(array('class' => 'wiki-summary'),
426                                 "[",
427                                 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
428                                 "]");
429     }
430
431
432     function format ($changes) {
433         $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
434         $html = _RecentChanges_HtmlFormatter::format ($changes);
435         $html = HTML::div(array('class' => 'wikitext'), $html);
436         global $request;
437         $request->discardOutput();
438         
439         printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
440         printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
441         printf('  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
442         printf('<html xmlns="http://www.w3.org/1999/xhtml">');
443
444         printf("<head>\n");
445         extract($this->_args);
446         $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
447         printf("<title>" . $title . "</title>\n");
448         global $Theme;
449         $css = $Theme->getCSS();
450         $css->PrintXML();
451         printf("</head>\n");
452
453         printf("<body class=\"sidebar\">\n");
454         $html->PrintXML();
455         printf("\n</body>\n");
456         printf("</html>\n");
457
458         $request->finish(); // cut rest of page processing short
459     }
460 }
461
462 class _RecentChanges_BoxFormatter
463 extends _RecentChanges_HtmlFormatter
464 {
465     function rss_icon () {
466     }
467     function title () {
468     }
469     function authorLink ($rev) {
470     }
471     function diffLink ($rev) {
472     }
473     function historyLink ($rev) {
474     }
475     function summaryAsHTML ($rev) {
476     }
477     function description () {
478     }
479     function format ($changes) {
480         include_once('lib/InlineParser.php');
481         $last_date = '';
482         $first = true;
483         $html = HTML();
484         $counter = 1;
485         $sp = HTML::Raw('&middot; ');
486         while ($rev = $changes->next()) {
487             // enforce view permission
488             if (mayAccessPage('view',$rev->_pagename)) {
489                 $html->pushContent($sp,$this->pageLink($rev),HTML::br());
490                 if ($first)
491                     $this->setValidators($rev);
492                 $first = false;
493             }
494         }
495         if ($first)
496             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
497                                        $this->empty_message()));
498         return $html;
499     }
500 }
501
502 class _RecentChanges_RssFormatter
503 extends _RecentChanges_Formatter
504 {
505     var $_absurls = true;
506
507     function time ($rev) {
508         return Iso8601DateTime($rev->get('mtime'));
509     }
510
511     function pageURI ($rev) {
512         return WikiURL($rev, '', 'absurl');
513     }
514
515     function format ($changes) {
516         
517         include_once('lib/RssWriter.php');
518         $rss = new RssWriter;
519
520
521         $rss->channel($this->channel_properties());
522
523         if (($props = $this->image_properties()))
524             $rss->image($props);
525         if (($props = $this->textinput_properties()))
526             $rss->textinput($props);
527
528         $first = true;
529         while ($rev = $changes->next()) {
530             // enforce view permission
531             if (mayAccessPage('view',$rev->_pagename)) {
532                 $rss->addItem($this->item_properties($rev),
533                               $this->pageURI($rev));
534                 if ($first)
535                     $this->setValidators($rev);
536                 $first = false;
537             }
538         }
539
540         global $request;
541         $request->discardOutput();
542         $rss->finish();
543         printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
544
545         // Flush errors in comment, otherwise it's invalid XML.
546         global $ErrorManager;
547         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
548             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
549
550         $request->finish();     // NORETURN!!!!
551     }
552
553     function image_properties () {
554         global $Theme;
555
556         $img_url = AbsoluteURL($Theme->getImageURL('logo'));
557         if (!$img_url)
558             return false;
559
560         return array('title' => WIKI_NAME,
561                      'link' => WikiURL(HOME_PAGE, false, 'absurl'),
562                      'url' => $img_url);
563     }
564
565     function textinput_properties () {
566         return array('title' => _("Search"),
567                      'description' => _("Title Search"),
568                      'name' => 's',
569                      'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
570     }
571
572     function channel_properties () {
573         global $request;
574
575         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
576
577         return array('title' => WIKI_NAME,
578                      'link' => $rc_url,
579                      'description' => _("RecentChanges"),
580                      'dc:date' => Iso8601DateTime(time()));
581
582         /* FIXME: other things one might like in <channel>:
583          * sy:updateFrequency
584          * sy:updatePeriod
585          * sy:updateBase
586          * dc:subject
587          * dc:publisher
588          * dc:language
589          * dc:rights
590          * rss091:language
591          * rss091:managingEditor
592          * rss091:webmaster
593          * rss091:lastBuildDate
594          * rss091:copyright
595          */
596     }
597
598
599
600
601     function item_properties ($rev) {
602         $page = $rev->getPage();
603         $pagename = $page->getName();
604
605         return array( 'title'           => split_pagename($pagename),
606                       'description'     => $this->summary($rev),
607                       'link'            => $this->pageURL($rev),
608                       'dc:date'         => $this->time($rev),
609                       'dc:contributor'  => $rev->get('author'),
610                       'wiki:version'    => $rev->getVersion(),
611                       'wiki:importance' => $this->importance($rev),
612                       'wiki:status'     => $this->status($rev),
613                       'wiki:diff'       => $this->diffURL($rev),
614                       'wiki:history'    => $this->historyURL($rev)
615                       );
616     }
617 }
618
619 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
620 {
621     /** Constructor
622      *
623      * @param $revisions object a WikiDB_PageRevisionIterator.
624      */
625     function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
626         $this->_revisions = $revisions;
627         $this->_check_current_revision = $check_current_revision;
628     }
629
630     function next () {
631         while (($rev = $this->_revisions->next())) {
632             if ($this->_check_current_revision) {
633                 $page = $rev->getPage();
634                 $check_rev = $page->getCurrentRevision();
635             }
636             else {
637                 $check_rev = $rev;
638             }
639             if (! $check_rev->hasDefaultContents())
640                 return $rev;
641         }
642         $this->free();
643         return false;
644     }
645
646     function free () {
647         $this->_revisions->free();
648     }
649 }
650
651 class WikiPlugin_RecentChanges
652 extends WikiPlugin
653 {
654     function getName () {
655         return _("RecentChanges");
656     }
657
658     function getVersion() {
659         return preg_replace("/[Revision: $]/", '',
660                             "\$Revision: 1.91 $");
661     }
662
663     function managesValidators() {
664         // Note that this is a bit of a fig.
665         // We set validators based on the most recently changed page,
666         // but this fails when the most-recent page is deleted.
667         // (Consider that the Last-Modified time will decrease
668         // when this happens.)
669
670         // We might be better off, leaving this as false (and junking
671         // the validator logic above) and just falling back to the
672         // default behavior (handled by WikiPlugin) of just using
673         // the WikiDB global timestamp as the mtime.
674
675         // Nevertheless, for now, I leave this here, mostly as an
676         // example for how to use appendValidators() and managesValidators().
677         
678         return true;
679     }
680             
681     function getDefaultArguments() {
682         return array('days'         => 2,
683                      'show_minor'   => false,
684                      'show_major'   => true,
685                      'show_all'     => false,
686                      'show_deleted' => 'sometimes',
687                      'limit'        => false,
688                      'format'       => false,
689                      'daylist'      => false,
690                      'difflinks'    => true,
691                      'historylinks' => false,
692                      'caption'      => ''
693                      );
694     }
695
696     function getArgs ($argstr, $request, $defaults = false) {
697         $args = WikiPlugin::getArgs($argstr, $request, $defaults);
698
699         $action = $request->getArg('action');
700         if ($action != 'browse' && ! $request->isActionPage($action))
701             $args['format'] = false; // default -> HTML
702
703         if ($args['format'] == 'rss' && empty($args['limit']))
704             $args['limit'] = 15; // Fix default value for RSS.
705
706         if ($args['format'] == 'sidebar' && empty($args['limit']))
707             $args['limit'] = 10; // Fix default value for sidebar.
708
709         return $args;
710     }
711
712     function getMostRecentParams ($args) {
713         extract($args);
714
715         $params = array('include_minor_revisions' => $show_minor,
716                         'exclude_major_revisions' => !$show_major,
717                         'include_all_revisions' => !empty($show_all));
718
719         if ($limit != 0)
720             $params['limit'] = $limit;
721
722         if ($days > 0.0)
723             $params['since'] = time() - 24 * 3600 * $days;
724         elseif ($days < 0.0)
725             $params['since'] = 24 * 3600 * $days - time();
726
727
728         return $params;
729     }
730
731     function getChanges ($dbi, $args) {
732         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
733
734         $show_deleted = $args['show_deleted'];
735         if ($show_deleted == 'sometimes')
736             $show_deleted = $args['show_minor'];
737
738         if (!$show_deleted)
739             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
740
741         return $changes;
742     }
743
744     function format ($changes, $args) {
745         global $Theme;
746         $format = $args['format'];
747
748         $fmt_class = $Theme->getFormatter('RecentChanges', $format);
749         if (!$fmt_class) {
750             if ($format == 'rss')
751                 $fmt_class = '_RecentChanges_RssFormatter';
752             elseif ($format == 'rss091') {
753                 include_once "lib/RSSWriter091.php";
754                 $fmt_class = '_RecentChanges_RssFormatter091';
755             }
756             elseif ($format == 'sidebar')
757                 $fmt_class = '_RecentChanges_SideBarFormatter';
758             elseif ($format == 'box')
759                 $fmt_class = '_RecentChanges_BoxFormatter';
760             else
761                 $fmt_class = '_RecentChanges_HtmlFormatter';
762         }
763
764         $fmt = new $fmt_class($args);
765         return $fmt->format($changes);
766     }
767
768     function run($dbi, $argstr, &$request, $basepage) {
769         $args = $this->getArgs($argstr, $request);
770
771         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
772         // to be enough for anyone.)
773         $args['days'] = min($args['days'], 365000);
774         
775         // Hack alert: format() is a NORETURN for rss formatters.
776         return $this->format($this->getChanges($dbi, $args), $args);
777     }
778
779     // box is used to display a fixed-width, narrow version with common header.
780     // just a numbered list of limit pagenames, without date.
781     function box($args = false, $request = false, $basepage = false) {
782         if (!$request) $request =& $GLOBALS['request'];
783         if (!isset($args['limit'])) $args['limit'] = 15;
784         $args['format'] = 'box';
785         $args['show_minor'] = false;
786         $args['show_major'] = true;
787         $args['show_deleted'] = false;
788         $args['show_all'] = false;
789         $args['days'] = 90;
790         return $this->makeBox(WikiLink(_("RecentChanges"),'',_("Recent Changes")),
791                               $this->format($this->getChanges($request->_dbi, $args), $args));
792     }
793
794 };
795
796
797 class DayButtonBar extends HtmlElement {
798
799     function DayButtonBar ($plugin_args) {
800         $this->HtmlElement('p', array('class' => 'wiki-rc-action'));
801
802         // Display days selection buttons
803         extract($plugin_args);
804
805         // Custom caption
806         if (! $caption) {
807             if ($show_minor)
808                 $caption = _("Show minor edits for:");
809             elseif ($show_all)
810                 $caption = _("Show all changes for:");
811             else
812                 $caption = _("Show changes for:");
813         }
814
815         $this->pushContent($caption, ' ');
816
817         global $Theme;
818         $sep = $Theme->getButtonSeparator();
819
820         $n = 0;
821         foreach (explode(",", $daylist) as $days) {
822             if ($n++)
823                 $this->pushContent($sep);
824             $this->pushContent($this->_makeDayButton($days));
825         }
826     }
827
828     function _makeDayButton ($days) {
829         global $Theme, $request;
830
831         if ($days == 1)
832             $label = _("1 day");
833         elseif ($days < 1)
834             $label = "..."; //alldays
835         else
836             $label = sprintf(_("%s days"), abs($days));
837
838         $url = $request->getURLtoSelf(array('action' => 'browse', 'days' => $days));
839
840         return $Theme->makeButton($label, $url, 'wiki-rc-action');
841     }
842 }
843
844 // $Log: not supported by cvs2svn $
845 // Revision 1.90  2004/04/18 01:11:52  rurban
846 // more numeric pagename fixes.
847 // fixed action=upload with merge conflict warnings.
848 // charset changed from constant to global (dynamic utf-8 switching)
849 //
850 // Revision 1.89  2004/04/10 02:30:49  rurban
851 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
852 // Fixed "cannot setlocale..." (sf.net problem)
853 //
854 // Revision 1.88  2004/04/01 15:57:10  rurban
855 // simplified Sidebar theme: table, not absolute css positioning
856 // added the new box methods.
857 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
858 //
859 // Revision 1.87  2004/03/30 02:14:03  rurban
860 // fixed yet another Prefs bug
861 // added generic PearDb_iter
862 // $request->appendValidators no so strict as before
863 // added some box plugin methods
864 // PageList commalist for condensed output
865 //
866 // Revision 1.86  2004/03/12 13:31:43  rurban
867 // enforce PagePermissions, errormsg if not Admin
868 //
869 // Revision 1.85  2004/02/17 12:11:36  rurban
870 // 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, ...)
871 //
872 // Revision 1.84  2004/02/15 22:29:42  rurban
873 // revert premature performance fix
874 //
875 // Revision 1.83  2004/02/15 21:34:37  rurban
876 // PageList enhanced and improved.
877 // fixed new WikiAdmin... plugins
878 // editpage, Theme with exp. htmlarea framework
879 //   (htmlarea yet committed, this is really questionable)
880 // WikiUser... code with better session handling for prefs
881 // enhanced UserPreferences (again)
882 // RecentChanges for show_deleted: how should pages be deleted then?
883 //
884 // Revision 1.82  2004/01/25 03:58:43  rurban
885 // use stdlib:isWikiWord()
886 //
887 // Revision 1.81  2003/11/28 21:06:31  carstenklapp
888 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
889 // instead of 1. Make diff buttons smaller with css. Added description
890 // line back in at the top.
891 //
892 // Revision 1.80  2003/11/27 15:17:01  carstenklapp
893 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
894 // button, to allow an image button for it to be added to Themes. Output
895 // RSS button in small text size when theme has no button image.
896 //
897 // Revision 1.79  2003/04/29 14:34:20  dairiki
898 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
899 //
900 // Revision 1.78  2003/03/04 01:55:05  dairiki
901 // Fix to ensure absolute URL for logo in RSS recent changes.
902 //
903 // Revision 1.77  2003/02/27 23:23:38  dairiki
904 // Fix my breakage of CSS and sidebar RecentChanges output.
905 //
906 // Revision 1.76  2003/02/27 22:48:44  dairiki
907 // Fixes invalid HTML generated by PageHistory plugin.
908 //
909 // (<noscript> is block-level and not allowed within <p>.)
910 //
911 // Revision 1.75  2003/02/22 21:39:05  dairiki
912 // Hackish fix for SF bug #622784.
913 //
914 // (The root of the problem is clearly a PHP bug.)
915 //
916 // Revision 1.74  2003/02/21 22:52:21  dairiki
917 // Make sure to interpret relative links (like [/Subpage]) in summary
918 // relative to correct basepage.
919 //
920 // Revision 1.73  2003/02/21 04:12:06  dairiki
921 // Minor fixes for new cached markup.
922 //
923 // Revision 1.72  2003/02/17 02:19:01  dairiki
924 // Fix so that PageHistory will work when the current revision
925 // of a page has been "deleted".
926 //
927 // Revision 1.71  2003/02/16 20:04:48  dairiki
928 // Refactor the HTTP validator generation/checking code.
929 //
930 // This also fixes a number of bugs with yesterdays validator mods.
931 //
932 // Revision 1.70  2003/02/16 05:09:43  dairiki
933 // Starting to fix handling of the HTTP validator headers, Last-Modified,
934 // and ETag.
935 //
936 // Last-Modified was being set incorrectly (but only when DEBUG was not
937 // defined!)  Setting a Last-Modified without setting an appropriate
938 // Expires: and/or Cache-Control: header results in browsers caching
939 // the page unconditionally (for a certain period of time).
940 // This is generally bad, since it means people don't see updated
941 // page contents right away --- this is particularly confusing to
942 // the people who are editing pages since their edits don't show up
943 // next time they browse the page.
944 //
945 // Now, we don't allow caching of pages without revalidation
946 // (via the If-Modified-Since and/or If-None-Match request headers.)
947 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
948 // appropriate value in index.php, but I advise against it.)
949 //
950 // Problems:
951 //
952 //   o Even when request is aborted due to the content not being
953 //     modified, we currently still do almost all the work involved
954 //     in producing the page.  So the only real savings from all
955 //     this logic is in network bandwidth.
956 //
957 //   o Plugins which produce "dynamic" output need to be inspected
958 //     and made to call $request->addToETag() and
959 //     $request->setModificationTime() appropriately, otherwise the
960 //     page can change without the change being detected.
961 //     This leads to stale pages in cache again...
962 //
963 // Revision 1.69  2003/01/18 22:01:43  carstenklapp
964 // Code cleanup:
965 // Reformatting & tabs to spaces;
966 // Added copyleft, getVersion, getDescription, rcs_id.
967 //
968
969 // (c-file-style: "gnu")
970 // Local Variables:
971 // mode: php
972 // tab-width: 8
973 // c-basic-offset: 4
974 // c-hanging-comment-ender-p: nil
975 // indent-tabs-mode: nil
976 // End:
977 ?>