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