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