]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChanges.php
new arg: only_new
[SourceForge/phpwiki.git] / lib / plugin / RecentChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RecentChanges.php,v 1.110 2007-01-22 23:51:36 rurban Exp $');
3 /**
4  Copyright 1999,2000,2001,2002,2007 $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         $button = $WikiTheme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
129         $button->setAttr('rel', 'nofollow');
130         return $button;
131     }
132
133     function historyLink ($rev) {
134         global $WikiTheme;
135         return $WikiTheme->makeButton(_("(hist)"), $this->historyURL($rev), 'wiki-rc-action');
136     }
137
138     function pageLink ($rev, $link_text=false) {
139
140         return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),'auto',$link_text);
141         /*
142         $page = $rev->getPage();
143         global $WikiTheme;
144         if ($this->include_versions_in_URLs()) {
145             $version = $rev->getVersion();
146             if ($rev->isCurrent())
147                 $version = false;
148             $exists = !$rev->hasDefaultContents();
149         }
150         else {
151             $version = false;
152             $cur = $page->getCurrentRevision();
153             $exists = !$cur->hasDefaultContents();
154         }
155         if ($exists)
156             return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
157         else
158             return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
159         */
160     }
161
162     function authorLink ($rev) {
163         $author = $rev->get('author');
164         if ( $this->authorHasPage($author) ) {
165             return WikiLink($author);
166         } else
167             return $author;
168     }
169
170     function summaryAsHTML ($rev) {
171         if ( !($summary = $this->summary($rev)) )
172             return '';
173         return  HTML::strong( array('class' => 'wiki-summary'),
174                               "[",
175                               TransformLinks($summary, $rev->get('markup'), $rev->getPageName()),
176                               "]");
177     }
178
179     function rss_icon () {
180         global $request, $WikiTheme;
181
182         $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
183         return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), 
184                            $WikiTheme->makeButton("RSS", $rss_url, 'rssicon'));
185     }
186     function rss2_icon () {
187         global $request, $WikiTheme;
188
189         $rss_url = $request->getURLtoSelf(array('format' => 'rss2'));
190         return HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), 
191                            $WikiTheme->makeButton("RSS2", $rss_url, 'rssicon'));
192     }
193
194     function pre_description () {
195         extract($this->_args);
196         // FIXME: say something about show_all.
197         if ($show_major && $show_minor)
198             $edits = _("edits");
199         elseif ($show_major)
200             $edits = _("major edits");
201         else
202             $edits = _("minor edits");
203         if (isset($caption) and $caption == _("Recent Comments"))
204             $edits = _("comments");
205         if ($only_new) {
206             $edits = _("created new pages");
207         }
208         if ($timespan = $days > 0) {
209             if (intval($days) != $days)
210                 $days = sprintf("%.1f", $days);
211         }
212         $lmt = abs($limit);
213         /**
214          * Depending how this text is split up it can be tricky or
215          * impossible to translate with good grammar. So the seperate
216          * strings for 1 day and %s days are necessary in this case
217          * for translating to multiple languages, due to differing
218          * overlapping ideal word cutting points.
219          *
220          * en: day/days "The %d most recent %s [during (the past] day) are listed below."
221          * de: 1 Tag    "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
222          * de: %s days  "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
223          *
224          * en: day/days "The %d most recent %s during [the past] (day) are listed below."
225          * fr: 1 jour   "Les %d %s les plus récentes pendant [le dernier (d'une] jour) sont énumérées ci-dessous."
226          * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
227          */
228         if ($limit > 0) {
229             if ($timespan) {
230                 if (intval($days) == 1)
231                     $desc = fmt("The %d most recent %s during the past day are listed below.",
232                                 $limit, $edits);
233                 else
234                     $desc = fmt("The %d most recent %s during the past %s days are listed below.",
235                                 $limit, $edits, $days);
236             } else
237                 $desc = fmt("The %d most recent %s are listed below.",
238                             $limit, $edits);
239         }
240         elseif ($limit < 0) {  //$limit < 0 means we want oldest pages
241             if ($timespan) {
242                 if (intval($days) == 1)
243                     $desc = fmt("The %d oldest %s during the past day are listed below.",
244                                 $lmt, $edits);
245                 else
246                     $desc = fmt("The %d oldest %s during the past %s days are listed below.",
247                                 $lmt, $edits, $days);
248             } else
249                 $desc = fmt("The %d oldest %s are listed below.",
250                             $lmt, $edits);
251         }
252
253         else {
254             if ($timespan) {
255                 if (intval($days) == 1)
256                     $desc = fmt("The most recent %s during the past day are listed below.",
257                                 $edits);
258                 else
259                     $desc = fmt("The most recent %s during the past %s days are listed below.",
260                                 $edits, $days);
261             } else
262                 $desc = fmt("All %s are listed below.", $edits);
263         }
264         return $desc;
265     }    
266
267     function description() {
268         return HTML::p(false, $this->pre_description());
269     }
270
271
272     function title () {
273         extract($this->_args);
274         return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
275                      ' ',
276                      $this->rss_icon(), HTML::raw('&nbsp;'), $this->rss2_icon(),
277                      $this->sidebar_link());
278     }
279
280     function empty_message () {
281         if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
282             return _("No comments found");
283         else 
284             return _("No changes found");
285     }
286         
287     function sidebar_link() {
288         extract($this->_args);
289         $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
290
291         global $request;
292         $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
293
294         $addsidebarjsfunc =
295             "function addPanel() {\n"
296             ."    window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
297             ."       \"$sidebarurl\",\"\");\n"
298             ."}\n";
299         $jsf = JavaScript($addsidebarjsfunc);
300
301         global $WikiTheme;
302         $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon');
303         $addsidebarjsclick = asXML(HTML::small(array('style' => 'font-weight:normal;vertical-align:middle;'), $sidebar_button));
304         $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
305                                 ."    (typeof window.sidebar.addPanel == 'function'))\n"
306                                 ."   {\n"
307                                 ."       document.write('$addsidebarjsclick');\n"
308                                 ."   }\n"
309                                 );
310         return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
311     }
312
313     function format ($changes) {
314         include_once('lib/InlineParser.php');
315         
316         $html = HTML(HTML::h2(false, $this->title()));
317         if (($desc = $this->description()))
318             $html->pushContent($desc);
319         
320         if ($this->_args['daylist'])
321             $html->pushContent(new DayButtonBar($this->_args));
322
323         $last_date = '';
324         $lines = false;
325         $first = true;
326
327         while ($rev = $changes->next()) {
328             if (($date = $this->date($rev)) != $last_date) {
329                 if ($lines)
330                     $html->pushContent($lines);
331                 $html->pushContent(HTML::h3($date));
332                 $lines = HTML::ul();
333                 $last_date = $date;
334
335             }
336             // enforce view permission
337             if (mayAccessPage('view', $rev->_pagename)) {
338                 $lines->pushContent($this->format_revision($rev));
339
340                 if ($first)
341                     $this->setValidators($rev);
342                 $first = false;
343             }
344         }
345         if ($lines)
346             $html->pushContent($lines);
347         if ($first)
348             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
349                                        $this->empty_message()));
350         
351         return $html;
352     }
353
354     function format_revision ($rev) {
355         $args = &$this->_args;
356
357         $class = 'rc-' . $this->importance($rev);
358
359         $time = $this->time($rev);
360         if (! $rev->get('is_minor_edit'))
361             $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
362
363         $line = HTML::li(array('class' => $class));
364
365
366         if ($args['difflinks'])
367             $line->pushContent($this->diffLink($rev), ' ');
368
369         if ($args['historylinks'])
370             $line->pushContent($this->historyLink($rev), ' ');
371
372         $line->pushContent($this->pageLink($rev), ' ',
373                            $time, ' ',
374                            $this->summaryAsHTML($rev),
375                            ' ... ',
376                            $this->authorLink($rev));
377         return $line;
378     }
379 }
380
381
382 class _RecentChanges_SideBarFormatter
383 extends _RecentChanges_HtmlFormatter
384 {
385     function rss_icon () {
386         //omit rssicon
387     }
388     function rss2_icon () { }
389     function title () {
390         //title click opens the normal RC or RE page in the main browser frame
391         extract($this->_args);
392         $titlelink = WikiLink($show_minor ? _("RecentEdits") : _("RecentChanges"));
393         $titlelink->setAttr('target', '_content');
394         return HTML($this->logo(), $titlelink);
395     }
396     function logo () {
397         //logo click opens the HomePage in the main browser frame
398         global $WikiTheme;
399         $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
400                                'border' => 0,
401                                'align' => 'right',
402                                'style' => 'height:2.5ex'
403                                ));
404         $linkurl = WikiLink(HOME_PAGE, false, $img);
405         $linkurl->setAttr('target', '_content');
406         return $linkurl;
407     }
408
409     function authorLink ($rev) {
410         $author = $rev->get('author');
411         if ( $this->authorHasPage($author) ) {
412             $linkurl = WikiLink($author);
413             $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
414             return $linkurl;
415         } else
416             return $author;
417     }
418
419     function diffLink ($rev) {
420         $linkurl = parent::diffLink($rev);
421         $linkurl->setAttr('target', '_content');
422         $linkurl->setAttr('rel', 'nofollow');
423         // FIXME: Smelly hack to get smaller diff buttons in sidebar
424         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
425         return $linkurl;
426     }
427     function historyLink ($rev) {
428         $linkurl = parent::historyLink($rev);
429         $linkurl->setAttr('target', '_content');
430         // FIXME: Smelly hack to get smaller history buttons in sidebar
431         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
432         return $linkurl;
433     }
434     function pageLink ($rev) {
435         $linkurl = parent::pageLink($rev);
436         $linkurl->setAttr('target', '_content');
437         return $linkurl;
438     }
439     // Overriding summaryAsHTML, because there is no way yet to
440     // return summary as transformed text with
441     // links setAttr('target', '_content') in Mozilla sidebar.
442     // So for now don't create clickable links inside summary
443     // in the sidebar, or else they target the sidebar and not the
444     // main content window.
445     function summaryAsHTML ($rev) {
446         if ( !($summary = $this->summary($rev)) )
447             return '';
448         return HTML::strong(array('class' => 'wiki-summary'),
449                                 "[",
450                                 /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
451                                 "]");
452     }
453
454
455     function format ($changes) {
456         $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
457         $html = _RecentChanges_HtmlFormatter::format ($changes);
458         $html = HTML::div(array('class' => 'wikitext'), $html);
459         global $request;
460         $request->discardOutput();
461         
462         printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
463         printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
464         printf('  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
465         printf('<html xmlns="http://www.w3.org/1999/xhtml">');
466
467         printf("<head>\n");
468         extract($this->_args);
469         $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
470         printf("<title>" . $title . "</title>\n");
471         global $WikiTheme;
472         $css = $WikiTheme->getCSS();
473         $css->PrintXML();
474         printf("</head>\n");
475
476         printf("<body class=\"sidebar\">\n");
477         $html->PrintXML();
478         echo '<a href="http://www.feedvalidator.org/check.cgi?url=http://phpwiki.org/RecentChanges?format=rss"><img src="themes/default/buttons/valid-rss.png" alt="[Valid RSS]" title="Validate the RSS feed" width="44" height="15" /></a>';
479         printf("\n</body>\n");
480         printf("</html>\n");
481
482         $request->finish(); // cut rest of page processing short
483     }
484 }
485
486 class _RecentChanges_BoxFormatter
487 extends _RecentChanges_HtmlFormatter
488 {
489     function rss_icon () {
490     }
491     function rss2_icon () {
492     }
493     function title () {
494     }
495     function authorLink ($rev) {
496     }
497     function diffLink ($rev) {
498     }
499     function historyLink ($rev) {
500     }
501     function summaryAsHTML ($rev) {
502     }
503     function description () {
504     }
505     function format ($changes) {
506         include_once('lib/InlineParser.php');
507         $last_date = '';
508         $first = true;
509         $html = HTML();
510         $counter = 1;
511         $sp = HTML::Raw("\n&nbsp;&middot;&nbsp;");
512         while ($rev = $changes->next()) {
513             // enforce view permission
514             if (mayAccessPage('view',$rev->_pagename)) {
515                 if ($link = $this->pageLink($rev)) // some entries may be empty 
516                                                    // (/Blog/.. interim pages)
517                     $html->pushContent($sp, $link, HTML::br());
518                 if ($first)
519                     $this->setValidators($rev);
520                 $first = false;
521             }
522         }
523         if ($first)
524             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
525                                        $this->empty_message()));
526         return $html;
527     }
528 }
529
530 class _RecentChanges_RssFormatter
531 extends _RecentChanges_Formatter
532 {
533     var $_absurls = true;
534
535     function time ($rev) {
536         return Iso8601DateTime($rev->get('mtime'));
537     }
538
539     function pageURI ($rev) {
540         return WikiURL($rev, '', 'absurl');
541     }
542
543     function format ($changes) {
544         
545         include_once('lib/RssWriter.php');
546         $rss = new RssWriter;
547
548         $rss->channel($this->channel_properties());
549
550         if (($props = $this->image_properties()))
551             $rss->image($props);
552         if (($props = $this->textinput_properties()))
553             $rss->textinput($props);
554
555         $first = true;
556         while ($rev = $changes->next()) {
557             // enforce view permission
558             if (mayAccessPage('view', $rev->_pagename)) {
559                 $rss->addItem($this->item_properties($rev),
560                               $this->pageURI($rev));
561                 if ($first)
562                     $this->setValidators($rev);
563                 $first = false;
564             }
565         }
566
567         global $request;
568         $request->discardOutput();
569         $rss->finish();
570         printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
571
572         // Flush errors in comment, otherwise it's invalid XML.
573         global $ErrorManager;
574         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
575             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
576
577         $request->finish();     // NORETURN!!!!
578     }
579
580     function image_properties () {
581         global $WikiTheme;
582
583         $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
584         if (!$img_url)
585             return false;
586
587         return array('title' => WIKI_NAME,
588                      'link' => WikiURL(HOME_PAGE, false, 'absurl'),
589                      'url' => $img_url);
590     }
591
592     function textinput_properties () {
593         return array('title' => _("Search"),
594                      'description' => _("Title Search"),
595                      'name' => 's',
596                      'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
597     }
598
599     function channel_properties () {
600         global $request;
601
602         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
603         return array('title' => WIKI_NAME,
604                      'link' => $rc_url,
605                      'description' => _("RecentChanges"),
606                      'dc:date' => Iso8601DateTime(time()),
607                      'dc:language' => $GLOBALS['LANG']);
608
609         /* FIXME: other things one might like in <channel>:
610          * sy:updateFrequency
611          * sy:updatePeriod
612          * sy:updateBase
613          * dc:subject
614          * dc:publisher
615          * dc:language
616          * dc:rights
617          * rss091:language
618          * rss091:managingEditor
619          * rss091:webmaster
620          * rss091:lastBuildDate
621          * rss091:copyright
622          */
623     }
624
625     function item_properties ($rev) {
626         $page = $rev->getPage();
627         $pagename = $page->getName();
628
629         return array( 'title'           => SplitPagename($pagename),
630                       'description'     => $this->summary($rev),
631                       'link'            => $this->pageURL($rev),
632                       'dc:date'         => $this->time($rev),
633                       'dc:contributor'  => $rev->get('author'),
634                       'wiki:version'    => $rev->getVersion(),
635                       'wiki:importance' => $this->importance($rev),
636                       'wiki:status'     => $this->status($rev),
637                       'wiki:diff'       => $this->diffURL($rev),
638                       'wiki:history'    => $this->historyURL($rev)
639                       );
640     }
641 }
642
643 /** explicit application/rss+xml Content-Type,
644  * simplified xml structure (no namespace),
645  * support for xml-rpc cloud registerProcedure (not yet)
646  */
647 class _RecentChanges_Rss2Formatter
648 extends _RecentChanges_RssFormatter {
649
650     function format ($changes) {
651         include_once('lib/RssWriter2.php');
652         $rss = new RssWriter2;
653
654         $rss->channel($this->channel_properties());
655         if (($props = $this->cloud_properties()))
656             $rss->cloud($props);
657         if (($props = $this->image_properties()))
658             $rss->image($props);
659         if (($props = $this->textinput_properties()))
660             $rss->textinput($props);
661         $first = true;
662         while ($rev = $changes->next()) {
663             // enforce view permission
664             if (mayAccessPage('view', $rev->_pagename)) {
665                 $rss->addItem($this->item_properties($rev),
666                               $this->pageURI($rev));
667                 if ($first)
668                     $this->setValidators($rev);
669                 $first = false;
670             }
671         }
672
673         global $request;
674         $request->discardOutput();
675         $rss->finish();
676         printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
677         // Flush errors in comment, otherwise it's invalid XML.
678         global $ErrorManager;
679         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
680             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
681
682         $request->finish();     // NORETURN!!!!
683     }
684
685     function channel_properties () {
686         $chann_10 = parent::channel_properties();
687         return array_merge($chann_10,
688                            array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
689                                  //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
690                                  //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
691                                  //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
692                                  'copyright' => COPYRIGHTPAGE_URL
693                                  ));
694     }
695
696     function cloud_properties () { return false; } // xml-rpc registerProcedure not yet implemented
697     function cloud_properties_test () {
698         return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
699                      'registerProcedure' => 'wiki.rssPleaseNotify',
700                      'path' => DATA_PATH.'/RPC2.php',
701                      'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
702                      'domain' => SERVER_NAME);
703     }
704 }
705
706 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
707 {
708     /** Constructor
709      *
710      * @param $revisions object a WikiDB_PageRevisionIterator.
711      */
712     function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
713         $this->_revisions = $revisions;
714         $this->_check_current_revision = $check_current_revision;
715     }
716
717     function next () {
718         while (($rev = $this->_revisions->next())) {
719             if ($this->_check_current_revision) {
720                 $page = $rev->getPage();
721                 $check_rev = $page->getCurrentRevision();
722             }
723             else {
724                 $check_rev = $rev;
725             }
726             if (! $check_rev->hasDefaultContents())
727                 return $rev;
728         }
729         $this->free();
730         return false;
731     }
732
733 }
734
735 /**
736  * only_new: Only new created pages
737  */
738 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
739 {
740     /** Constructor
741      *
742      * @param $revisions object a WikiDB_PageRevisionIterator.
743      */
744     function NewPageRevisionIterator ($revisions) {
745         $this->_revisions = $revisions;
746     }
747
748     function next () {
749         while (($rev = $this->_revisions->next())) {
750             if ($rev->getVersion() == 1)
751                 return $rev;
752         }
753         $this->free();
754         return false;
755     }
756
757 }
758
759 class WikiPlugin_RecentChanges
760 extends WikiPlugin
761 {
762     function getName () {
763         return _("RecentChanges");
764     }
765
766     function getVersion() {
767         return preg_replace("/[Revision: $]/", '',
768                             "\$Revision: 1.110 $");
769     }
770
771     function managesValidators() {
772         // Note that this is a bit of a fig.
773         // We set validators based on the most recently changed page,
774         // but this fails when the most-recent page is deleted.
775         // (Consider that the Last-Modified time will decrease
776         // when this happens.)
777
778         // We might be better off, leaving this as false (and junking
779         // the validator logic above) and just falling back to the
780         // default behavior (handled by WikiPlugin) of just using
781         // the WikiDB global timestamp as the mtime.
782
783         // Nevertheless, for now, I leave this here, mostly as an
784         // example for how to use appendValidators() and managesValidators().
785         
786         return true;
787     }
788             
789     function getDefaultArguments() {
790         return array('days'         => 2,
791                      'show_minor'   => false,
792                      'show_major'   => true,
793                      'show_all'     => false,
794                      'show_deleted' => 'sometimes',
795                      'only_new'     => false,
796                      'limit'        => false,
797                      'format'       => false,
798                      'daylist'      => false,
799                      'difflinks'    => true,
800                      'historylinks' => false,
801                      'caption'      => ''
802                      );
803     }
804
805     function getArgs ($argstr, $request, $defaults = false) {
806         if (!$defaults) $defaults = $this->getDefaultArguments();
807         $args = WikiPlugin::getArgs($argstr, $request, $defaults);
808
809         $action = $request->getArg('action');
810         if ($action != 'browse' && ! $request->isActionPage($action))
811             $args['format'] = false; // default -> HTML
812
813         if ($args['format'] == 'rss' && empty($args['limit']))
814             $args['limit'] = 15; // Fix default value for RSS.
815         if ($args['format'] == 'rss2' && empty($args['limit']))
816             $args['limit'] = 15; // Fix default value for RSS2.
817
818         if ($args['format'] == 'sidebar' && empty($args['limit']))
819             $args['limit'] = 10; // Fix default value for sidebar.
820
821         return $args;
822     }
823
824     function getMostRecentParams ($args) {
825         extract($args);
826
827         $params = array('include_minor_revisions' => $show_minor,
828                         'exclude_major_revisions' => !$show_major,
829                         'include_all_revisions' => !empty($show_all));
830         if ($limit != 0)
831             $params['limit'] = $limit;
832
833         if ($days > 0.0)
834             $params['since'] = time() - 24 * 3600 * $days;
835         elseif ($days < 0.0)
836             $params['since'] = 24 * 3600 * $days - time();
837
838         return $params;
839     }
840
841     function getChanges ($dbi, $args) {
842         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
843
844         $show_deleted = $args['show_deleted'];
845         if ($show_deleted == 'sometimes')
846             $show_deleted = $args['show_minor'];
847
848         if ($args['only_new'])
849             $changes = new NewPageRevisionIterator($changes);
850         elseif (!$show_deleted)
851             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
852
853         return $changes;
854     }
855
856     function format ($changes, $args) {
857         global $WikiTheme;
858         $format = $args['format'];
859
860         $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
861         if (!$fmt_class) {
862             if ($format == 'rss')
863                 $fmt_class = '_RecentChanges_RssFormatter';
864             elseif ($format == 'rss2')
865                 $fmt_class = '_RecentChanges_Rss2Formatter';
866             elseif ($format == 'rss091') {
867                 include_once "lib/RSSWriter091.php";
868                 $fmt_class = '_RecentChanges_RssFormatter091';
869             }
870             elseif ($format == 'sidebar')
871                 $fmt_class = '_RecentChanges_SideBarFormatter';
872             elseif ($format == 'box')
873                 $fmt_class = '_RecentChanges_BoxFormatter';
874             else
875                 $fmt_class = '_RecentChanges_HtmlFormatter';
876         }
877
878         $fmt = new $fmt_class($args);
879         return $fmt->format($changes);
880     }
881
882     function run($dbi, $argstr, &$request, $basepage) {
883         $args = $this->getArgs($argstr, $request);
884
885         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
886         // to be enough for anyone.)
887         $args['days'] = min($args['days'], 365000);
888         
889         // Hack alert: format() is a NORETURN for rss formatters.
890         return $this->format($this->getChanges($dbi, $args), $args);
891     }
892
893     // box is used to display a fixed-width, narrow version with common header.
894     // just a numbered list of limit pagenames, without date.
895     function box($args = false, $request = false, $basepage = false) {
896         if (!$request) $request =& $GLOBALS['request'];
897         if (!isset($args['limit'])) $args['limit'] = 15;
898         $args['format'] = 'box';
899         $args['show_minor'] = false;
900         $args['show_major'] = true;
901         $args['show_deleted'] = 'sometimes';
902         $args['show_all'] = false;
903         $args['days'] = 90;
904         return $this->makeBox(WikiLink($this->getName(),'',SplitPagename($this->getName())),
905                               $this->format($this->getChanges($request->_dbi, $args), $args));
906     }
907
908 };
909
910
911 class DayButtonBar extends HtmlElement {
912
913     function DayButtonBar ($plugin_args) {
914         $this->__construct('p', array('class' => 'wiki-rc-action'));
915
916         // Display days selection buttons
917         extract($plugin_args);
918
919         // Custom caption
920         if (! $caption) {
921             if ($show_minor)
922                 $caption = _("Show minor edits for:");
923             elseif ($show_all)
924                 $caption = _("Show all changes for:");
925             else
926                 $caption = _("Show changes for:");
927             if ($only_new)
928                 $caption = _("All new pages since:");
929         }
930
931         $this->pushContent($caption, ' ');
932
933         global $WikiTheme;
934         $sep = $WikiTheme->getButtonSeparator();
935
936         $n = 0;
937         foreach (explode(",", $daylist) as $days) {
938             if ($n++)
939                 $this->pushContent($sep);
940             $this->pushContent($this->_makeDayButton($days));
941         }
942     }
943
944     function _makeDayButton ($days) {
945         global $WikiTheme, $request;
946
947         if ($days == 1)
948             $label = _("1 day");
949         elseif ($days < 1)
950             $label = "..."; //alldays
951         else
952             $label = sprintf(_("%s days"), abs($days));
953
954         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days));
955
956         return $WikiTheme->makeButton($label, $url, 'wiki-rc-action');
957     }
958 }
959
960 // $Log: not supported by cvs2svn $
961 // Revision 1.109  2006/03/19 14:26:29  rurban
962 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
963 //
964 // Revision 1.108  2005/04/01 16:09:35  rurban
965 // fix defaults in RecentChanges plugins: e.g. invalid pagenames for PageHistory
966 //
967 // Revision 1.107  2005/02/04 13:45:28  rurban
968 // improve box layout a bit
969 //
970 // Revision 1.106  2005/02/02 19:39:10  rurban
971 // honor show_all=false
972 //
973 // Revision 1.105  2005/01/25 03:50:54  uckelman
974 // pre_description is a member function, so call with $this->.
975 //
976 // Revision 1.104  2005/01/24 23:15:16  uckelman
977 // The extra description for RelatedChanges was appearing in RecentChanges
978 // and PageHistory due to a bad test in _RecentChanges_HtmlFormatter. Fixed.
979 //
980 // Revision 1.103  2004/12/15 17:45:09  rurban
981 // fix box method
982 //
983 // Revision 1.102  2004/12/06 19:29:24  rurban
984 // simplify RSS: add RSS2 link (rss tag only, new content-type)
985 //
986 // Revision 1.101  2004/11/10 19:32:24  rurban
987 // * optimize increaseHitCount, esp. for mysql.
988 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
989 // * Pear_DB version logic (awful but needed)
990 // * fix broken ADODB quote
991 // * _extract_page_data simplification
992 //
993 // Revision 1.100  2004/06/28 16:35:12  rurban
994 // prevent from shell commands
995 //
996 // Revision 1.99  2004/06/20 14:42:54  rurban
997 // various php5 fixes (still broken at blockparser)
998 //
999 // Revision 1.98  2004/06/14 11:31:39  rurban
1000 // renamed global $Theme to $WikiTheme (gforge nameclash)
1001 // inherit PageList default options from PageList
1002 //   default sortby=pagename
1003 // use options in PageList_Selectable (limit, sortby, ...)
1004 // added action revert, with button at action=diff
1005 // added option regex to WikiAdminSearchReplace
1006 //
1007 // Revision 1.97  2004/06/03 18:58:27  rurban
1008 // days links requires action=RelatedChanges arg
1009 //
1010 // Revision 1.96  2004/05/18 16:23:40  rurban
1011 // rename split_pagename to SplitPagename
1012 //
1013 // Revision 1.95  2004/05/16 22:07:35  rurban
1014 // check more config-default and predefined constants
1015 // various PagePerm fixes:
1016 //   fix default PagePerms, esp. edit and view for Bogo and Password users
1017 //   implemented Creator and Owner
1018 //   BOGOUSERS renamed to BOGOUSER
1019 // fixed syntax errors in signin.tmpl
1020 //
1021 // Revision 1.94  2004/05/14 20:55:03  rurban
1022 // simplified RecentComments
1023 //
1024 // Revision 1.93  2004/05/14 17:33:07  rurban
1025 // new plugin RecentChanges
1026 //
1027 // Revision 1.92  2004/04/21 04:29:10  rurban
1028 // Two convenient RecentChanges extensions
1029 //   RelatedChanges (only links from current page)
1030 //   RecentEdits (just change the default args)
1031 //
1032 // Revision 1.91  2004/04/19 18:27:46  rurban
1033 // Prevent from some PHP5 warnings (ref args, no :: object init)
1034 //   php5 runs now through, just one wrong XmlElement object init missing
1035 // Removed unneccesary UpgradeUser lines
1036 // Changed WikiLink to omit version if current (RecentChanges)
1037 //
1038 // Revision 1.90  2004/04/18 01:11:52  rurban
1039 // more numeric pagename fixes.
1040 // fixed action=upload with merge conflict warnings.
1041 // charset changed from constant to global (dynamic utf-8 switching)
1042 //
1043 // Revision 1.89  2004/04/10 02:30:49  rurban
1044 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1045 // Fixed "cannot setlocale..." (sf.net problem)
1046 //
1047 // Revision 1.88  2004/04/01 15:57:10  rurban
1048 // simplified Sidebar theme: table, not absolute css positioning
1049 // added the new box methods.
1050 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1051 //
1052 // Revision 1.87  2004/03/30 02:14:03  rurban
1053 // fixed yet another Prefs bug
1054 // added generic PearDb_iter
1055 // $request->appendValidators no so strict as before
1056 // added some box plugin methods
1057 // PageList commalist for condensed output
1058 //
1059 // Revision 1.86  2004/03/12 13:31:43  rurban
1060 // enforce PagePermissions, errormsg if not Admin
1061 //
1062 // Revision 1.85  2004/02/17 12:11:36  rurban
1063 // 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, ...)
1064 //
1065 // Revision 1.84  2004/02/15 22:29:42  rurban
1066 // revert premature performance fix
1067 //
1068 // Revision 1.83  2004/02/15 21:34:37  rurban
1069 // PageList enhanced and improved.
1070 // fixed new WikiAdmin... plugins
1071 // editpage, Theme with exp. htmlarea framework
1072 //   (htmlarea yet committed, this is really questionable)
1073 // WikiUser... code with better session handling for prefs
1074 // enhanced UserPreferences (again)
1075 // RecentChanges for show_deleted: how should pages be deleted then?
1076 //
1077 // Revision 1.82  2004/01/25 03:58:43  rurban
1078 // use stdlib:isWikiWord()
1079 //
1080 // Revision 1.81  2003/11/28 21:06:31  carstenklapp
1081 // Enhancement: Mozilla RecentChanges sidebar now defaults to 10 changes
1082 // instead of 1. Make diff buttons smaller with css. Added description
1083 // line back in at the top.
1084 //
1085 // Revision 1.80  2003/11/27 15:17:01  carstenklapp
1086 // Theme & appearance tweaks: Converted Mozilla sidebar link into a Theme
1087 // button, to allow an image button for it to be added to Themes. Output
1088 // RSS button in small text size when theme has no button image.
1089 //
1090 // Revision 1.79  2003/04/29 14:34:20  dairiki
1091 // Bug fix: "add sidebar" link didn't work when USE_PATH_INFO was false.
1092 //
1093 // Revision 1.78  2003/03/04 01:55:05  dairiki
1094 // Fix to ensure absolute URL for logo in RSS recent changes.
1095 //
1096 // Revision 1.77  2003/02/27 23:23:38  dairiki
1097 // Fix my breakage of CSS and sidebar RecentChanges output.
1098 //
1099 // Revision 1.76  2003/02/27 22:48:44  dairiki
1100 // Fixes invalid HTML generated by PageHistory plugin.
1101 //
1102 // (<noscript> is block-level and not allowed within <p>.)
1103 //
1104 // Revision 1.75  2003/02/22 21:39:05  dairiki
1105 // Hackish fix for SF bug #622784.
1106 //
1107 // (The root of the problem is clearly a PHP bug.)
1108 //
1109 // Revision 1.74  2003/02/21 22:52:21  dairiki
1110 // Make sure to interpret relative links (like [/Subpage]) in summary
1111 // relative to correct basepage.
1112 //
1113 // Revision 1.73  2003/02/21 04:12:06  dairiki
1114 // Minor fixes for new cached markup.
1115 //
1116 // Revision 1.72  2003/02/17 02:19:01  dairiki
1117 // Fix so that PageHistory will work when the current revision
1118 // of a page has been "deleted".
1119 //
1120 // Revision 1.71  2003/02/16 20:04:48  dairiki
1121 // Refactor the HTTP validator generation/checking code.
1122 //
1123 // This also fixes a number of bugs with yesterdays validator mods.
1124 //
1125 // Revision 1.70  2003/02/16 05:09:43  dairiki
1126 // Starting to fix handling of the HTTP validator headers, Last-Modified,
1127 // and ETag.
1128 //
1129 // Last-Modified was being set incorrectly (but only when DEBUG was not
1130 // defined!)  Setting a Last-Modified without setting an appropriate
1131 // Expires: and/or Cache-Control: header results in browsers caching
1132 // the page unconditionally (for a certain period of time).
1133 // This is generally bad, since it means people don't see updated
1134 // page contents right away --- this is particularly confusing to
1135 // the people who are editing pages since their edits don't show up
1136 // next time they browse the page.
1137 //
1138 // Now, we don't allow caching of pages without revalidation
1139 // (via the If-Modified-Since and/or If-None-Match request headers.)
1140 // (You can allow caching by defining CACHE_CONTROL_MAX_AGE to an
1141 // appropriate value in index.php, but I advise against it.)
1142 //
1143 // Problems:
1144 //
1145 //   o Even when request is aborted due to the content not being
1146 //     modified, we currently still do almost all the work involved
1147 //     in producing the page.  So the only real savings from all
1148 //     this logic is in network bandwidth.
1149 //
1150 //   o Plugins which produce "dynamic" output need to be inspected
1151 //     and made to call $request->addToETag() and
1152 //     $request->setModificationTime() appropriately, otherwise the
1153 //     page can change without the change being detected.
1154 //     This leads to stale pages in cache again...
1155 //
1156 // Revision 1.69  2003/01/18 22:01:43  carstenklapp
1157 // Code cleanup:
1158 // Reformatting & tabs to spaces;
1159 // Added copyleft, getVersion, getDescription, rcs_id.
1160 //
1161
1162 // (c-file-style: "gnu")
1163 // Local Variables:
1164 // mode: php
1165 // tab-width: 8
1166 // c-basic-offset: 4
1167 // c-hanging-comment-ender-p: nil
1168 // indent-tabs-mode: nil
1169 // End:
1170 ?>