]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChanges.php
* optimize increaseHitCount, esp. for mysql.
[SourceForge/phpwiki.git] / lib / plugin / RecentChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RecentChanges.php,v 1.101 2004-11-10 19:32:24 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         $rss->channel($this->channel_properties());
528
529         if (($props = $this->image_properties()))
530             $rss->image($props);
531         if (($props = $this->textinput_properties()))
532             $rss->textinput($props);
533
534         $first = true;
535         while ($rev = $changes->next()) {
536             // enforce view permission
537             if (mayAccessPage('view', $rev->_pagename)) {
538                 $rss->addItem($this->item_properties($rev),
539                               $this->pageURI($rev));
540                 if ($first)
541                     $this->setValidators($rev);
542                 $first = false;
543             }
544         }
545
546         global $request;
547         $request->discardOutput();
548         $rss->finish();
549         printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
550
551         // Flush errors in comment, otherwise it's invalid XML.
552         global $ErrorManager;
553         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
554             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
555
556         $request->finish();     // NORETURN!!!!
557     }
558
559     function image_properties () {
560         global $WikiTheme;
561
562         $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
563         if (!$img_url)
564             return false;
565
566         return array('title' => WIKI_NAME,
567                      'link' => WikiURL(HOME_PAGE, false, 'absurl'),
568                      'url' => $img_url);
569     }
570
571     function textinput_properties () {
572         return array('title' => _("Search"),
573                      'description' => _("Title Search"),
574                      'name' => 's',
575                      'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
576     }
577
578     function channel_properties () {
579         global $request;
580
581         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
582
583         return array('title' => WIKI_NAME,
584                      'link' => $rc_url,
585                      'description' => _("RecentChanges"),
586                      'dc:date' => Iso8601DateTime(time()));
587
588         /* FIXME: other things one might like in <channel>:
589          * sy:updateFrequency
590          * sy:updatePeriod
591          * sy:updateBase
592          * dc:subject
593          * dc:publisher
594          * dc:language
595          * dc:rights
596          * rss091:language
597          * rss091:managingEditor
598          * rss091:webmaster
599          * rss091:lastBuildDate
600          * rss091:copyright
601          */
602     }
603
604     function item_properties ($rev) {
605         $page = $rev->getPage();
606         $pagename = $page->getName();
607
608         return array( 'title'           => SplitPagename($pagename),
609                       'description'     => $this->summary($rev),
610                       'link'            => $this->pageURL($rev),
611                       'dc:date'         => $this->time($rev),
612                       'dc:contributor'  => $rev->get('author'),
613                       'wiki:version'    => $rev->getVersion(),
614                       'wiki:importance' => $this->importance($rev),
615                       'wiki:status'     => $this->status($rev),
616                       'wiki:diff'       => $this->diffURL($rev),
617                       'wiki:history'    => $this->historyURL($rev)
618                       );
619     }
620 }
621
622 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
623 {
624     /** Constructor
625      *
626      * @param $revisions object a WikiDB_PageRevisionIterator.
627      */
628     function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
629         $this->_revisions = $revisions;
630         $this->_check_current_revision = $check_current_revision;
631     }
632
633     function next () {
634         while (($rev = $this->_revisions->next())) {
635             if ($this->_check_current_revision) {
636                 $page = $rev->getPage();
637                 $check_rev = $page->getCurrentRevision();
638             }
639             else {
640                 $check_rev = $rev;
641             }
642             if (! $check_rev->hasDefaultContents())
643                 return $rev;
644         }
645         $this->free();
646         return false;
647     }
648
649 }
650
651 class WikiPlugin_RecentChanges
652 extends WikiPlugin
653 {
654     function getName () {
655         return _("RecentChanges");
656     }
657
658     function getVersion() {
659         return preg_replace("/[Revision: $]/", '',
660                             "\$Revision: 1.101 $");
661     }
662
663     function managesValidators() {
664         // Note that this is a bit of a fig.
665         // We set validators based on the most recently changed page,
666         // but this fails when the most-recent page is deleted.
667         // (Consider that the Last-Modified time will decrease
668         // when this happens.)
669
670         // We might be better off, leaving this as false (and junking
671         // the validator logic above) and just falling back to the
672         // default behavior (handled by WikiPlugin) of just using
673         // the WikiDB global timestamp as the mtime.
674
675         // Nevertheless, for now, I leave this here, mostly as an
676         // example for how to use appendValidators() and managesValidators().
677         
678         return true;
679     }
680             
681     function getDefaultArguments() {
682         return array('days'         => 2,
683                      'show_minor'   => false,
684                      'show_major'   => true,
685                      'show_all'     => false,
686                      'show_deleted' => 'sometimes',
687                      'limit'        => false,
688                      'format'       => false,
689                      'daylist'      => false,
690                      'difflinks'    => true,
691                      'historylinks' => false,
692                      'caption'      => ''
693                      );
694     }
695
696     function getArgs ($argstr, $request, $defaults = false) {
697         $args = WikiPlugin::getArgs($argstr, $request, $defaults);
698
699         $action = $request->getArg('action');
700         if ($action != 'browse' && ! $request->isActionPage($action))
701             $args['format'] = false; // default -> HTML
702
703         if ($args['format'] == 'rss' && empty($args['limit']))
704             $args['limit'] = 15; // Fix default value for RSS.
705
706         if ($args['format'] == 'sidebar' && empty($args['limit']))
707             $args['limit'] = 10; // Fix default value for sidebar.
708
709         return $args;
710     }
711
712     function getMostRecentParams ($args) {
713         extract($args);
714
715         $params = array('include_minor_revisions' => $show_minor,
716                         'exclude_major_revisions' => !$show_major,
717                         'include_all_revisions' => !empty($show_all));
718         if ($limit != 0)
719             $params['limit'] = $limit;
720
721         if ($days > 0.0)
722             $params['since'] = time() - 24 * 3600 * $days;
723         elseif ($days < 0.0)
724             $params['since'] = 24 * 3600 * $days - time();
725
726         return $params;
727     }
728
729     function getChanges ($dbi, $args) {
730         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
731
732         $show_deleted = $args['show_deleted'];
733         if ($show_deleted == 'sometimes')
734             $show_deleted = $args['show_minor'];
735
736         if (!$show_deleted)
737             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
738
739         return $changes;
740     }
741
742     function format ($changes, $args) {
743         global $WikiTheme;
744         $format = $args['format'];
745
746         $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
747         if (!$fmt_class) {
748             if ($format == 'rss')
749                 $fmt_class = '_RecentChanges_RssFormatter';
750             elseif ($format == 'rss091') {
751                 include_once "lib/RSSWriter091.php";
752                 $fmt_class = '_RecentChanges_RssFormatter091';
753             }
754             elseif ($format == 'sidebar')
755                 $fmt_class = '_RecentChanges_SideBarFormatter';
756             elseif ($format == 'box')
757                 $fmt_class = '_RecentChanges_BoxFormatter';
758             else
759                 $fmt_class = '_RecentChanges_HtmlFormatter';
760         }
761
762         $fmt = new $fmt_class($args);
763         return $fmt->format($changes);
764     }
765
766     function run($dbi, $argstr, &$request, $basepage) {
767         $args = $this->getArgs($argstr, $request);
768
769         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
770         // to be enough for anyone.)
771         $args['days'] = min($args['days'], 365000);
772         
773         // Hack alert: format() is a NORETURN for rss formatters.
774         return $this->format($this->getChanges($dbi, $args), $args);
775     }
776
777     // box is used to display a fixed-width, narrow version with common header.
778     // just a numbered list of limit pagenames, without date.
779     function box($args = false, $request = false, $basepage = false) {
780         if (!$request) $request =& $GLOBALS['request'];
781         if (!isset($args['limit'])) $args['limit'] = 15;
782         $args['format'] = 'box';
783         $args['show_minor'] = false;
784         $args['show_major'] = true;
785         $args['show_deleted'] = false;
786         $args['show_all'] = false;
787         $args['days'] = 90;
788         return $this->makeBox(WikiLink($this->getName(),'',SplitPagename($this->getName())),
789                               $this->format($this->getChanges($request->_dbi, $args), $args));
790     }
791
792 };
793
794
795 class DayButtonBar extends HtmlElement {
796
797     function DayButtonBar ($plugin_args) {
798         $this->__construct('p', array('class' => 'wiki-rc-action'));
799
800         // Display days selection buttons
801         extract($plugin_args);
802
803         // Custom caption
804         if (! $caption) {
805             if ($show_minor)
806                 $caption = _("Show minor edits for:");
807             elseif ($show_all)
808                 $caption = _("Show all changes for:");
809             else
810                 $caption = _("Show changes for:");
811         }
812
813         $this->pushContent($caption, ' ');
814
815         global $WikiTheme;
816         $sep = $WikiTheme->getButtonSeparator();
817
818         $n = 0;
819         foreach (explode(",", $daylist) as $days) {
820             if ($n++)
821                 $this->pushContent($sep);
822             $this->pushContent($this->_makeDayButton($days));
823         }
824     }
825
826     function _makeDayButton ($days) {
827         global $WikiTheme, $request;
828
829         if ($days == 1)
830             $label = _("1 day");
831         elseif ($days < 1)
832             $label = "..."; //alldays
833         else
834             $label = sprintf(_("%s days"), abs($days));
835
836         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
837
838         return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
839     }
840 }
841
842 // $Log: not supported by cvs2svn $
843 // Revision 1.100  2004/06/28 16:35:12  rurban
844 // prevent from shell commands
845 //
846 // Revision 1.99  2004/06/20 14:42:54  rurban
847 // various php5 fixes (still broken at blockparser)
848 //
849 // Revision 1.98  2004/06/14 11:31:39  rurban
850 // renamed global $Theme to $WikiTheme (gforge nameclash)
851 // inherit PageList default options from PageList
852 //   default sortby=pagename
853 // use options in PageList_Selectable (limit, sortby, ...)
854 // added action revert, with button at action=diff
855 // added option regex to WikiAdminSearchReplace
856 //
857 // Revision 1.97  2004/06/03 18:58:27  rurban
858 // days links requires action=RelatedChanges arg
859 //
860 // Revision 1.96  2004/05/18 16:23:40  rurban
861 // rename split_pagename to SplitPagename
862 //
863 // Revision 1.95  2004/05/16 22:07:35  rurban
864 // check more config-default and predefined constants
865 // various PagePerm fixes:
866 //   fix default PagePerms, esp. edit and view for Bogo and Password users
867 //   implemented Creator and Owner
868 //   BOGOUSERS renamed to BOGOUSER
869 // fixed syntax errors in signin.tmpl
870 //
871 // Revision 1.94  2004/05/14 20:55:03  rurban
872 // simplified RecentComments
873 //
874 // Revision 1.93  2004/05/14 17:33:07  rurban
875 // new plugin RecentChanges
876 //
877 // Revision 1.92  2004/04/21 04:29:10  rurban
878 // Two convenient RecentChanges extensions
879 //   RelatedChanges (only links from current page)
880 //   RecentEdits (just change the default args)
881 //
882 // Revision 1.91  2004/04/19 18:27:46  rurban
883 // Prevent from some PHP5 warnings (ref args, no :: object init)
884 //   php5 runs now through, just one wrong XmlElement object init missing
885 // Removed unneccesary UpgradeUser lines
886 // Changed WikiLink to omit version if current (RecentChanges)
887 //
888 // Revision 1.90  2004/04/18 01:11:52  rurban
889 // more numeric pagename fixes.
890 // fixed action=upload with merge conflict warnings.
891 // charset changed from constant to global (dynamic utf-8 switching)
892 //
893 // Revision 1.89  2004/04/10 02:30:49  rurban
894 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
895 // Fixed "cannot setlocale..." (sf.net problem)
896 //
897 // Revision 1.88  2004/04/01 15:57:10  rurban
898 // simplified Sidebar theme: table, not absolute css positioning
899 // added the new box methods.
900 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
901 //
902 // Revision 1.87  2004/03/30 02:14:03  rurban
903 // fixed yet another Prefs bug
904 // added generic PearDb_iter
905 // $request->appendValidators no so strict as before
906 // added some box plugin methods
907 // PageList commalist for condensed output
908 //
909 // Revision 1.86  2004/03/12 13:31:43  rurban
910 // enforce PagePermissions, errormsg if not Admin
911 //
912 // Revision 1.85  2004/02/17 12:11:36  rurban
913 // 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, ...)
914 //
915 // Revision 1.84  2004/02/15 22:29:42  rurban
916 // revert premature performance fix
917 //
918 // Revision 1.83  2004/02/15 21:34:37  rurban
919 // PageList enhanced and improved.
920 // fixed new WikiAdmin... plugins
921 // editpage, Theme with exp. htmlarea framework
922 //   (htmlarea yet committed, this is really questionable)
923 // WikiUser... code with better session handling for prefs
924 // enhanced UserPreferences (again)
925 // RecentChanges for show_deleted: how should pages be deleted then?
926 //
927 // Revision 1.82  2004/01/25 03:58:43  rurban
928 // use stdlib:isWikiWord()
929 //
930 // Revision 1.81  2003/11/28 21:06:31  carstenklapp
931 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
932 // instead of 1. Make diff buttons smaller with css. Added description
933 // line back in at the top.
934 //
935 // Revision 1.80  2003/11/27 15:17:01  carstenklapp
936 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
937 // button, to allow an image button for it to be added to Themes. Output
938 // RSS button in small text size when theme has no button image.
939 //
940 // Revision 1.79  2003/04/29 14:34:20  dairiki
941 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
942 //
943 // Revision 1.78  2003/03/04 01:55:05  dairiki
944 // Fix to ensure absolute URL for logo in RSS recent changes.
945 //
946 // Revision 1.77  2003/02/27 23:23:38  dairiki
947 // Fix my breakage of CSS and sidebar RecentChanges output.
948 //
949 // Revision 1.76  2003/02/27 22:48:44  dairiki
950 // Fixes invalid HTML generated by PageHistory plugin.
951 //
952 // (<noscript> is block-level and not allowed within <p>.)
953 //
954 // Revision 1.75  2003/02/22 21:39:05  dairiki
955 // Hackish fix for SF bug #622784.
956 //
957 // (The root of the problem is clearly a PHP bug.)
958 //
959 // Revision 1.74  2003/02/21 22:52:21  dairiki
960 // Make sure to interpret relative links (like [/Subpage]) in summary
961 // relative to correct basepage.
962 //
963 // Revision 1.73  2003/02/21 04:12:06  dairiki
964 // Minor fixes for new cached markup.
965 //
966 // Revision 1.72  2003/02/17 02:19:01  dairiki
967 // Fix so that PageHistory will work when the current revision
968 // of a page has been "deleted".
969 //
970 // Revision 1.71  2003/02/16 20:04:48  dairiki
971 // Refactor the HTTP validator generation/checking code.
972 //
973 // This also fixes a number of bugs with yesterdays validator mods.
974 //
975 // Revision 1.70  2003/02/16 05:09:43  dairiki
976 // Starting to fix handling of the HTTP validator headers, Last-Modified,
977 // and ETag.
978 //
979 // Last-Modified was being set incorrectly (but only when DEBUG was not
980 // defined!)  Setting a Last-Modified without setting an appropriate
981 // Expires: and/or Cache-Control: header results in browsers caching
982 // the page unconditionally (for a certain period of time).
983 // This is generally bad, since it means people don't see updated
984 // page contents right away --- this is particularly confusing to
985 // the people who are editing pages since their edits don't show up
986 // next time they browse the page.
987 //
988 // Now, we don't allow caching of pages without revalidation
989 // (via the If-Modified-Since and/or If-None-Match request headers.)
990 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
991 // appropriate value in index.php, but I advise against it.)
992 //
993 // Problems:
994 //
995 //   o Even when request is aborted due to the content not being
996 //     modified, we currently still do almost all the work involved
997 //     in producing the page.  So the only real savings from all
998 //     this logic is in network bandwidth.
999 //
1000 //   o Plugins which produce "dynamic" output need to be inspected
1001 //     and made to call $request->addToETag() and
1002 //     $request->setModificationTime() appropriately, otherwise the
1003 //     page can change without the change being detected.
1004 //     This leads to stale pages in cache again...
1005 //
1006 // Revision 1.69  2003/01/18 22:01:43  carstenklapp
1007 // Code cleanup:
1008 // Reformatting & tabs to spaces;
1009 // Added copyleft, getVersion, getDescription, rcs_id.
1010 //
1011
1012 // (c-file-style: "gnu")
1013 // Local Variables:
1014 // mode: php
1015 // tab-width: 8
1016 // c-basic-offset: 4
1017 // c-hanging-comment-ender-p: nil
1018 // indent-tabs-mode: nil
1019 // End:
1020 ?>