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