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