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