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