]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChanges.php
Use __construct
[SourceForge/phpwiki.git] / lib / plugin / RecentChanges.php
1 <?php
2
3 /**
4  * Copyright 1999,2000,2001,2002,2007 $ThePhpWikiProgrammingTeam
5  * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
9  * PhpWiki is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * PhpWiki is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 include_once 'lib/WikiPlugin.php';
25
26 class _RecentChanges_Formatter
27 {
28     public $_absurls = false;
29     public $action = "RecentChanges";
30
31     function _RecentChanges_Formatter($rc_args)
32     {
33         $this->_args = $rc_args;
34         $this->_diffargs = array('action' => 'diff');
35
36         if ($rc_args['show_minor'] || !$rc_args['show_major'])
37             $this->_diffargs['previous'] = 'minor';
38
39         // PageHistoryPlugin doesn't have a 'daylist' arg.
40         if (!isset($this->_args['daylist']))
41             $this->_args['daylist'] = false;
42     }
43
44     function title()
45     {
46         global $request;
47         extract($this->_args);
48         if ($author) {
49             $title = $author;
50             if ($title == '[]') {
51                 $title = $request->_user->getID();
52             }
53             $title = _("UserContribs") . ": $title";
54         } elseif ($owner) {
55             $title = $owner;
56             if ($title == '[]') {
57                 $title = $request->_user->getID();
58             }
59             $title = _("UserContribs") . ": $title";
60         } elseif ($only_new) {
61             $title = _("RecentNewPages");
62         } elseif ($show_minor) {
63             $title = _("RecentEdits");
64         } else $title = _("RecentChanges");
65
66         if (!empty($category))
67             $title = $category;
68         elseif (!empty($pagematch))
69             $title .= ":$pagematch";
70         return $title;
71     }
72
73     function include_versions_in_URLs()
74     {
75         return (bool)$this->_args['show_all'];
76     }
77
78     function date($rev)
79     {
80         global $WikiTheme;
81         return $WikiTheme->getDay($rev->get('mtime'));
82     }
83
84     function time($rev)
85     {
86         global $WikiTheme;
87         return $WikiTheme->formatTime($rev->get('mtime'));
88     }
89
90     function diffURL($rev)
91     {
92         $args = $this->_diffargs;
93         if ($this->include_versions_in_URLs())
94             $args['version'] = $rev->getVersion();
95         $page = $rev->getPage();
96         return WikiURL($page->getName(), $args, $this->_absurls);
97     }
98
99     function historyURL($rev)
100     {
101         $page = $rev->getPage();
102         return WikiURL($page, array('action' => _("PageHistory")),
103             $this->_absurls);
104     }
105
106     function pageURL($rev)
107     {
108         return WikiURL($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
109             '', $this->_absurls);
110     }
111
112     function authorHasPage($author)
113     {
114         global $request;
115         $dbi = $request->getDbh();
116         return isWikiWord($author) && $dbi->isWikiPage($author);
117     }
118
119     function authorURL($author)
120     {
121         return $this->authorHasPage() ? WikiURL($author) : false;
122     }
123
124     function status($rev)
125     {
126         if ($rev->hasDefaultContents())
127             return 'deleted';
128         $page = $rev->getPage();
129         $prev = $page->getRevisionBefore($rev->getVersion());
130         if ($prev->hasDefaultContents())
131             return 'new';
132         return 'updated';
133     }
134
135     function importance($rev)
136     {
137         return $rev->get('is_minor_edit') ? 'minor' : 'major';
138     }
139
140     function summary($rev)
141     {
142         if (($summary = $rev->get('summary')))
143             return $summary;
144
145         switch ($this->status($rev)) {
146             case 'deleted':
147                 return _("Deleted");
148             case 'new':
149                 return _("New page");
150             default:
151                 return '';
152         }
153     }
154
155     function setValidators($most_recent_rev)
156     {
157         $rev = $most_recent_rev;
158         $validators = array('RecentChanges-top' =>
159         array($rev->getPageName(), $rev->getVersion()),
160             '%mtime' => $rev->get('mtime'));
161         global $request;
162         $request->appendValidators($validators);
163     }
164 }
165
166 class _RecentChanges_HtmlFormatter
167     extends _RecentChanges_Formatter
168 {
169     function diffLink($rev)
170     {
171         global $WikiTheme;
172         $button = $WikiTheme->makeButton(_("diff"), $this->diffURL($rev), 'wiki-rc-action');
173         $button->setAttr('rel', 'nofollow');
174         return HTML("(", $button, ")");
175     }
176
177     /* deletions: red, additions: green */
178     function diffSummary($rev)
179     {
180         $html = $this->diffURL($rev);
181         return '';
182     }
183
184     function historyLink($rev)
185     {
186         global $WikiTheme;
187         $button = $WikiTheme->makeButton(_("hist"), $this->historyURL($rev), 'wiki-rc-action');
188         $button->setAttr('rel', 'nofollow');
189         return HTML("(", $button, ")");
190     }
191
192     function pageLink($rev, $link_text = '')
193     {
194
195         return WikiLink($this->include_versions_in_URLs() ? $rev : $rev->getPage(),
196             'auto', $link_text);
197         /*
198         $page = $rev->getPage();
199         global $WikiTheme;
200         if ($this->include_versions_in_URLs()) {
201             $version = $rev->getVersion();
202             if ($rev->isCurrent())
203                 $version = false;
204             $exists = !$rev->hasDefaultContents();
205         }
206         else {
207             $version = false;
208             $cur = $page->getCurrentRevision();
209             $exists = !$cur->hasDefaultContents();
210         }
211         if ($exists)
212             return $WikiTheme->linkExistingWikiWord($page->getName(), $link_text, $version);
213         else
214             return $WikiTheme->linkUnknownWikiWord($page->getName(), $link_text);
215         */
216     }
217
218     function authorLink($rev)
219     {
220         return WikiLink($rev->get('author'), 'if_known');
221     }
222
223     /* Link to all users contributions (contribs and owns) */
224     function authorContribs($rev)
225     {
226         $author = $rev->get('author');
227         if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $author)) return '';
228         return HTML('(',
229             Button(array('action' => _("RecentChanges"),
230                     'format' => 'contribs',
231                     'author' => $author,
232                     'days' => 360),
233                 _("contribs"),
234                 $author),
235             ' | ',
236             Button(array('action' => _("RecentChanges"),
237                     'format' => 'contribs',
238                     'owner' => $author,
239                     'days' => 360),
240                 _("new pages"),
241                 $author),
242             ')');
243     }
244
245     function summaryAsHTML($rev)
246     {
247         if (!($summary = $this->summary($rev)))
248             return '';
249         return HTML::span(array('class' => 'wiki-summary'),
250             "(",
251             // TransformLinks($summary, $rev->getPageName()),
252             // We do parse the summary:
253             // 1) if the summary contains {{foo}}, the template must no be
254             //    expanded
255             // 2) if the summary contains camel case, and DISABLE_MARKUP_WIKIWORD
256             //    is true, the camel case must not be linked.
257             // Side-effect: brackets are not linked. TBD.
258             $summary,
259             ")");
260     }
261
262     function format_icon($format, $filter = array())
263     {
264         global $request, $WikiTheme;
265         $args = $this->_args;
266         // remove links not used for those formats
267         unset($args['daylist']);
268         unset($args['difflinks']);
269         unset($args['historylinks']);
270         $rss_url = $request->getURLtoSelf
271         (array_merge($args,
272             array('action' => $this->action, 'format' => $format),
273             $filter));
274         return $WikiTheme->makeButton($format, $rss_url, 'rssicon');
275     }
276
277     function rss_icon($args = array())
278     {
279         return $this->format_icon("rss", $args);
280     }
281
282     function rss2_icon($args = array())
283     {
284         return $this->format_icon("rss2", $args);
285     }
286
287     function atom_icon($args = array())
288     {
289         return $this->format_icon("atom", $args);
290     }
291
292     function rdf_icon($args = array())
293     {
294         return DEBUG ? $this->format_icon("rdf", $args) : '';
295     }
296
297     function rdfs_icon($args = array())
298     {
299         return DEBUG ? $this->format_icon("rdfs", $args) : '';
300     }
301
302     function owl_icon($args = array())
303     {
304         return DEBUG ? $this->format_icon("owl", $args) : '';
305     }
306
307     function grazr_icon($args = array())
308     {
309         global $request, $WikiTheme;
310         if (is_localhost()) return '';
311         if (SERVER_PROTOCOL == "https") return '';
312         $our_url = WikiURL($request->getArg('pagename'),
313             array_merge(array('action' => $this->action, 'format' => 'rss2'), $args),
314             true);
315         $rss_url = 'http://grazr.com/gzpanel.html?' . $our_url;
316         return $WikiTheme->makeButton("grazr", $rss_url, 'rssicon');
317     }
318
319     function pre_description()
320     {
321         extract($this->_args);
322         // FIXME: say something about show_all.
323         if ($show_major && $show_minor)
324             $edits = _("edits");
325         elseif ($show_major)
326             $edits = _("major edits"); else
327             $edits = _("minor edits");
328         if (isset($caption) and $caption == _("Recent Comments"))
329             $edits = _("comments");
330         if (!empty($only_new)) {
331             $edits = _("created new pages");
332         }
333         if (!empty($author)) {
334             global $request;
335             if ($author == '[]')
336                 $author = $request->_user->getID();
337             $edits .= sprintf(_(" for pages changed by %s"), $author);
338         }
339         if (!empty($owner)) {
340             global $request;
341             if ($owner == '[]')
342                 $owner = $request->_user->getID();
343             $edits .= sprintf(_(" for pages owned by %s"), $owner);
344         }
345         if (!empty($category)) {
346             $edits .= sprintf(_(" for all pages linking to %s"), $category);
347         }
348         if (!empty($pagematch)) {
349             $edits .= sprintf(_(" for all pages matching “%s”"), $pagematch);
350         }
351         if ($timespan = $days > 0) {
352             if (intval($days) != $days)
353                 $days = sprintf("%.1f", $days);
354         }
355         $lmt = abs($limit);
356         /**
357          * Depending how this text is split up it can be tricky or
358          * impossible to translate with good grammar. So the separate
359          * strings for 1 day and %s days are necessary in this case
360          * for translating to multiple languages, due to differing
361          * overlapping ideal word cutting points.
362          *
363          * en: day/days "The %d most recent %s [during (the past] day) are listed below."
364          * de: 1 Tag    "Die %d jüngste %s [innerhalb (von des letzten] Tages) sind unten aufgelistet."
365          * de: %s days  "Die %d jüngste %s [innerhalb (von] %s Tagen) sind unten aufgelistet."
366          *
367          * en: day/days "The %d most recent %s during [the past] (day) are listed below."
368          * fr: 1 jour   "Les %d %s les plus récentes pendant [le dernier jour) sont énumérées ci-dessous."
369          * fr: %s jours "Les %d %s les plus récentes pendant [les derniers (%s] jours) sont énumérées ci-dessous."
370          */
371         if ($limit > 0) {
372             if ($timespan) {
373                 if (intval($days) == 1)
374                     $desc = fmt("The %d most recent %s during the past day are listed below.",
375                         $limit, $edits);
376                 else
377                     $desc = fmt("The %d most recent %s during the past %s days are listed below.",
378                         $limit, $edits, $days);
379             } else
380                 $desc = fmt("The %d most recent %s are listed below.",
381                     $limit, $edits);
382         } elseif ($limit < 0) { //$limit < 0 means we want oldest pages
383             if ($timespan) {
384                 if (intval($days) == 1)
385                     $desc = fmt("The %d oldest %s during the past day are listed below.",
386                         $lmt, $edits);
387                 else
388                     $desc = fmt("The %d oldest %s during the past %s days are listed below.",
389                         $lmt, $edits, $days);
390             } else
391                 $desc = fmt("The %d oldest %s are listed below.",
392                     $lmt, $edits);
393         } else {
394             if ($timespan) {
395                 if (intval($days) == 1)
396                     $desc = fmt("The most recent %s during the past day are listed below.",
397                         $edits);
398                 else
399                     $desc = fmt("The most recent %s during the past %s days are listed below.",
400                         $edits, $days);
401             } else
402                 $desc = fmt("All %s are listed below.", $edits);
403         }
404         return $desc;
405     }
406
407     function description()
408     {
409         return HTML::p(false, $this->pre_description());
410     }
411
412     /* was title */
413     function headline()
414     {
415         extract($this->_args);
416         return array($this->title(),
417             ' ',
418             $this->rss_icon(),
419             $this->rss2_icon(),
420             $this->atom_icon(),
421             $this->rdf_icon(),
422             /*$this->rdfs_icon(),
423               $this->owl_icon(),*/
424             $this->grazr_icon(),
425             $this->sidebar_link());
426     }
427
428     function empty_message()
429     {
430         if (isset($this->_args['caption']) and $this->_args['caption'] == _("Recent Comments"))
431             return _("No comments found");
432         else
433             return _("No changes found");
434     }
435
436     function sidebar_link()
437     {
438         extract($this->_args);
439         $pagetitle = $show_minor ? _("RecentEdits") : _("RecentChanges");
440
441         $sidebarurl = WikiURL($pagetitle, array('format' => 'sidebar'), 'absurl');
442
443         $addsidebarjsfunc =
444             "function addPanel() {\n"
445                 . "    window.sidebar.addPanel (\"" . sprintf("%s - %s", WIKI_NAME, $pagetitle) . "\",\n"
446                 . "       \"$sidebarurl\",\"\");\n"
447                 . "}\n";
448         $jsf = JavaScript($addsidebarjsfunc);
449
450         global $WikiTheme;
451         $sidebar_button = $WikiTheme->makeButton("sidebar", 'javascript:addPanel();', 'sidebaricon',
452             array('title' => _("Click to add this feed to your sidebar"),
453                 'style' => 'font-size:9pt;font-weight:normal; vertical-align:middle;'));
454         $addsidebarjsclick = asXML($sidebar_button);
455         $jsc = JavaScript("if ((typeof window.sidebar == 'object') &&\n"
456                 . "    (typeof window.sidebar.addPanel == 'function'))\n"
457                 . "   {\n"
458                 . "       document.write('$addsidebarjsclick');\n"
459                 . "   }\n"
460         );
461         return HTML(new RawXML("\n"), $jsf, new RawXML("\n"), $jsc);
462     }
463
464     function format($changes)
465     {
466         include_once 'lib/InlineParser.php';
467
468         $html = HTML(HTML::h2(false, $this->headline()));
469         if (($desc = $this->description()))
470             $html->pushContent($desc);
471
472         if ($this->_args['daylist']) {
473             $html->pushContent(new OptionsButtonBars($this->_args));
474         }
475
476         $last_date = '';
477         $lines = false;
478         $first = true;
479
480         while ($rev = $changes->next()) {
481             if (($date = $this->date($rev)) != $last_date) {
482                 if ($lines)
483                     $html->pushContent($lines);
484                 // for user contributions no extra date line
485                 $html->pushContent(HTML::h3($date));
486                 $lines = HTML::ul();
487                 $last_date = $date;
488
489             }
490             // enforce view permission
491             if (mayAccessPage('view', $rev->_pagename)) {
492                 $lines->pushContent($this->format_revision($rev));
493                 if ($first)
494                     $this->setValidators($rev);
495                 $first = false;
496             }
497         }
498         if ($lines)
499             $html->pushContent($lines);
500         if ($first) {
501             if ($this->_args['daylist'])
502                 $html->pushContent // force display of OptionsButtonBars
503                 (JavaScript
504                 ("document.getElementById('rc-action-body').style.display='block';"));
505             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
506                 $this->empty_message()));
507         }
508
509         return $html;
510     }
511
512     function format_revision($rev)
513     {
514         global $WikiTheme;
515         $args = &$this->_args;
516
517         $class = 'rc-' . $this->importance($rev);
518
519         $time = $this->time($rev);
520         if ($rev->get('is_minor_edit')) {
521             $minor_flag = HTML(" ",
522                 HTML::span(array('class' => 'pageinfo-minoredit'),
523                     "(" . _("minor edit") . ")"));
524         } else {
525             $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
526             $minor_flag = '';
527         }
528
529         $line = HTML::li(array('class' => $class));
530
531         if ($args['difflinks'])
532             $line->pushContent($this->diffLink($rev), ' ');
533
534         if ($args['historylinks'])
535             $line->pushContent($this->historyLink($rev), ' ');
536
537         // Do not display a link for a deleted page, just the page name
538         if ($rev->hasDefaultContents()) {
539             $linkorname = $rev->_pagename;
540         } else {
541             $linkorname = $this->pageLink($rev);
542         }
543
544         if ((is_a($WikiTheme, 'WikiTheme_MonoBook')) or (is_a($WikiTheme, 'WikiTheme_fusionforge'))) {
545             $line->pushContent(
546                 $args['historylinks'] ? '' : $this->historyLink($rev),
547                 ' . . ', $linkorname, '; ',
548                 $time, ' . . ',
549                 $this->authorLink($rev), ' ',
550                 $this->authorContribs($rev), ' ',
551                 $this->summaryAsHTML($rev), ' ',
552                 $minor_flag);
553         } else {
554             $line->pushContent($linkorname, ' ',
555                 $time, ' ',
556                 $this->summaryAsHTML($rev),
557                 ' ... ',
558                 $this->authorLink($rev));
559         }
560         return $line;
561     }
562
563 }
564
565 /* format=contribs: no seperation into extra dates
566  * 14:41, 3 December 2006 (hist) (diff) Talk:PhpWiki (added diff link)  (top)
567  */
568 class _RecentChanges_UserContribsFormatter
569     extends _RecentChanges_HtmlFormatter
570 {
571     function headline()
572     {
573         global $request;
574         extract($this->_args);
575         if ($author == '[]') $author = $request->_user->getID();
576         if ($owner == '[]') $owner = $request->_user->getID();
577         $author_args = $owner
578             ? array('owner' => $owner)
579             : array('author' => $author);
580         return array(_("UserContribs"), ":", $owner ? $owner : $author,
581             ' ',
582             $this->rss_icon($author_args),
583             $this->rss2_icon($author_args),
584             $this->atom_icon($author_args),
585             $this->rdf_icon($author_args),
586             $this->grazr_icon($author_args));
587     }
588
589     function format($changes)
590     {
591         include_once 'lib/InlineParser.php';
592
593         $html = HTML(HTML::h2(false, $this->headline()));
594         $lines = HTML::ol();
595         $first = true;
596         $count = 0;
597         while ($rev = $changes->next()) {
598             if (mayAccessPage('view', $rev->_pagename)) {
599                 $lines->pushContent($this->format_revision($rev));
600                 if ($first)
601                     $this->setValidators($rev);
602                 $first = false;
603             }
604             $count++;
605         }
606         $this->_args['limit'] = $count;
607         if (($desc = $this->description()))
608             $html->pushContent($desc);
609         if ($this->_args['daylist']) {
610             $html->pushContent(new OptionsButtonBars($this->_args));
611         }
612         if ($first)
613             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
614                 $this->empty_message()));
615         else
616             $html->pushContent($lines);
617
618         return $html;
619     }
620
621     function format_revision($rev)
622     {
623         $class = 'rc-' . $this->importance($rev);
624         $time = $this->time($rev);
625         if (!$rev->get('is_minor_edit'))
626             $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
627
628         $line = HTML::li(array('class' => $class));
629
630         $line->pushContent($this->time($rev), ", ");
631         $line->pushContent($this->date($rev), " ");
632         $line->pushContent($this->diffLink($rev), ' ');
633         $line->pushContent($this->historyLink($rev), ' ');
634         $line->pushContent($this->pageLink($rev), ' ',
635             $this->summaryAsHTML($rev));
636         return $line;
637     }
638 }
639
640 class _RecentChanges_SideBarFormatter
641     extends _RecentChanges_HtmlFormatter
642 {
643     function rss_icon($args = array())
644     {
645         //omit rssicon
646     }
647
648     function rss2_icon($args = array())
649     {
650     }
651
652     function headline()
653     {
654         //title click opens the normal RC or RE page in the main browser frame
655         extract($this->_args);
656         $titlelink = WikiLink($this->title());
657         $titlelink->setAttr('target', '_content');
658         return HTML($this->logo(), $titlelink);
659     }
660
661     function logo()
662     {
663         //logo click opens the HomePage in the main browser frame
664         global $WikiTheme;
665         $img = HTML::img(array('src' => $WikiTheme->getImageURL('logo'),
666             'class' => 'align-right',
667             'style' => 'height:2.5ex'
668         ));
669         $linkurl = WikiLink(HOME_PAGE, false, $img);
670         $linkurl->setAttr('target', '_content');
671         return $linkurl;
672     }
673
674     function authorLink($rev)
675     {
676         $author = $rev->get('author');
677         if ($this->authorHasPage($author)) {
678             $linkurl = WikiLink($author);
679             $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
680             return $linkurl;
681         } else
682             return $author;
683     }
684
685     function diffLink($rev)
686     {
687         $linkurl = parent::diffLink($rev);
688         $linkurl->setAttr('target', '_content');
689         $linkurl->setAttr('rel', 'nofollow');
690         // FIXME: Smelly hack to get smaller diff buttons in sidebar
691         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
692         return $linkurl;
693     }
694
695     function historyLink($rev)
696     {
697         $linkurl = parent::historyLink($rev);
698         $linkurl->setAttr('target', '_content');
699         // FIXME: Smelly hack to get smaller history buttons in sidebar
700         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
701         return $linkurl;
702     }
703
704     function pageLink($rev, $link_text = false)
705     {
706         $linkurl = parent::pageLink($rev);
707         $linkurl->setAttr('target', '_content');
708         return $linkurl;
709     }
710
711     // Overriding summaryAsHTML, because there is no way yet to
712     // return summary as transformed text with
713     // links setAttr('target', '_content') in Mozilla sidebar.
714     // So for now don't create clickable links inside summary
715     // in the sidebar, or else they target the sidebar and not the
716     // main content window.
717     function summaryAsHTML($rev)
718     {
719         if (!($summary = $this->summary($rev)))
720             return '';
721         return HTML::span(array('class' => 'wiki-summary'),
722             "[",
723             /*TransformLinks(*/
724             $summary,
725             "]");
726     }
727
728     function format($changes)
729     {
730         $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
731         $html = _RecentChanges_HtmlFormatter::format($changes);
732         $html = HTML::div(array('class' => 'wikitext'), $html);
733         global $request;
734         $request->discardOutput();
735
736         print("<!DOCTYPE html>\n");
737         print("<head>\n");
738         extract($this->_args);
739         if (!empty($category))
740             $title = $category;
741         elseif (!empty($pagematch))
742             $title = $pagematch; else
743             $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
744         printf("<title>" . $title . "</title>\n");
745         global $WikiTheme;
746         $css = $WikiTheme->getCSS();
747         $css->PrintXML();
748         printf("</head>\n");
749
750         printf("<body class=\"sidebar\">\n");
751         $html->PrintXML();
752         echo '<a href="http://www.feedvalidator.org/check.cgi?url=http://phpwiki.fr/RecentChanges?format=rss"><img src="themes/default/buttons/valid-rss.png" alt="[Valid RSS]" title="Validate the RSS feed" width="44" height="15" /></a>';
753         printf("\n</body>\n");
754         printf("</html>\n");
755
756         $request->finish(); // cut rest of page processing short
757     }
758 }
759
760 class _RecentChanges_BoxFormatter
761     extends _RecentChanges_HtmlFormatter
762 {
763     function rss_icon($args = array())
764     {
765     }
766
767     function rss2_icon($args = array())
768     {
769     }
770
771     function headline()
772     {
773         return array();
774     }
775
776     function authorLink($rev)
777     {
778     }
779
780     function diffLink($rev)
781     {
782     }
783
784     function historyLink($rev)
785     {
786     }
787
788     function summaryAsHTML($rev)
789     {
790     }
791
792     function description()
793     {
794     }
795
796     function format($changes)
797     {
798         include_once 'lib/InlineParser.php';
799
800         $html = HTML::div();
801         $ul = HTML::ul();
802
803         $first = true;
804         while ($rev = $changes->next()) {
805             // enforce view permission
806             if (mayAccessPage('view', $rev->_pagename)) {
807                 if ($link = $this->pageLink($rev)) // some entries may be empty
808                     // (/Blog/.. interim pages)
809                     $ul->pushContent(HTML::li($link));
810                 if ($first)
811                     $this->setValidators($rev);
812                 $first = false;
813             }
814         }
815         if ($first) {
816             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
817                 $this->empty_message()));
818         } else {
819             $html->pushContent($ul);
820         }
821         return $html;
822     }
823 }
824
825 class _RecentChanges_RssFormatter
826     extends _RecentChanges_Formatter
827 {
828     public $_absurls = true;
829
830     function time($rev)
831     {
832         return Iso8601DateTime($rev->get('mtime'));
833     }
834
835     function pageURI($rev)
836     {
837         return WikiURL($rev, array(), 'absurl');
838     }
839
840     function format($changes)
841     {
842
843         include_once 'lib/RssWriter.php';
844         $rss = new RssWriter;
845         $rss->channel($this->channel_properties());
846
847         if (($props = $this->image_properties()))
848             $rss->image($props);
849         if (($props = $this->textinput_properties()))
850             $rss->textinput($props);
851
852         $first = true;
853         while ($rev = $changes->next()) {
854             // enforce view permission
855             if (mayAccessPage('view', $rev->_pagename)) {
856                 $rss->addItem($this->item_properties($rev),
857                     $this->pageURI($rev));
858                 if ($first)
859                     $this->setValidators($rev);
860                 $first = false;
861             }
862         }
863
864         global $request;
865         $request->discardOutput();
866         $rss->finish();
867         printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
868
869         // Flush errors in comment, otherwise it's invalid XML.
870         global $ErrorManager;
871         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
872             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
873
874         $request->finish(); // NORETURN!!!!
875     }
876
877     function image_properties()
878     {
879         global $WikiTheme;
880
881         $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
882         if (!$img_url)
883             return false;
884
885         return array('title' => WIKI_NAME,
886             'link' => WikiURL(HOME_PAGE, array(), 'absurl'),
887             'url' => $img_url);
888     }
889
890     function textinput_properties()
891     {
892         return array('title' => _("Search"),
893             'description' => _("Title Search"),
894             'name' => 's',
895             'link' => WikiURL(_("TitleSearch"), array(), 'absurl'));
896     }
897
898     function channel_properties()
899     {
900         global $request;
901
902         $rc_url = WikiURL($request->getArg('pagename'), array(), 'absurl');
903         extract($this->_args);
904         $title = WIKI_NAME;
905         $description = $this->title();
906         if ($category)
907             $title = $category;
908         elseif ($pagematch)
909             $title = $pagematch;
910         return array('title' => $title,
911             'link' => $rc_url,
912             'description' => $description,
913             'dc:date' => Iso8601DateTime(time()),
914             'dc:language' => $GLOBALS['LANG']);
915
916         /* FIXME: other things one might like in <channel>:
917          * sy:updateFrequency
918          * sy:updatePeriod
919          * sy:updateBase
920          * dc:subject
921          * dc:publisher
922          * dc:language
923          * dc:rights
924          * rss091:language
925          * rss091:managingEditor
926          * rss091:webmaster
927          * rss091:lastBuildDate
928          * rss091:copyright
929          */
930     }
931
932     function item_properties($rev)
933     {
934         $page = $rev->getPage();
935         $pagename = $page->getName();
936
937         return array('title' => SplitPagename($pagename),
938             'description' => $this->summary($rev),
939             'link' => $this->pageURL($rev),
940             'dc:date' => $this->time($rev),
941             'dc:contributor' => $rev->get('author'),
942             'wiki:version' => $rev->getVersion(),
943             'wiki:importance' => $this->importance($rev),
944             'wiki:status' => $this->status($rev),
945             'wiki:diff' => $this->diffURL($rev),
946             'wiki:history' => $this->historyURL($rev)
947         );
948     }
949 }
950
951 /** explicit application/rss+xml Content-Type,
952  * simplified xml structure (no namespace),
953  * support for xml-rpc cloud registerProcedure (not yet)
954  */
955 class _RecentChanges_Rss2Formatter
956     extends _RecentChanges_RssFormatter
957 {
958
959     function format($changes)
960     {
961         include_once 'lib/RssWriter2.php';
962         $rss = new RssWriter2;
963
964         $rss->channel($this->channel_properties());
965         if (($props = $this->cloud_properties()))
966             $rss->cloud($props);
967         if (($props = $this->image_properties()))
968             $rss->image($props);
969         if (($props = $this->textinput_properties()))
970             $rss->textinput($props);
971         $first = true;
972         while ($rev = $changes->next()) {
973             // enforce view permission
974             if (mayAccessPage('view', $rev->_pagename)) {
975                 $rss->addItem($this->item_properties($rev),
976                     $this->pageURI($rev));
977                 if ($first)
978                     $this->setValidators($rev);
979                 $first = false;
980             }
981         }
982
983         global $request;
984         $request->discardOutput();
985         $rss->finish();
986         printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
987         // Flush errors in comment, otherwise it's invalid XML.
988         global $ErrorManager;
989         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
990             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
991
992         $request->finish(); // NORETURN!!!!
993     }
994
995     function channel_properties()
996     {
997         $chann_10 = parent::channel_properties();
998         return array_merge($chann_10,
999             array('generator' => 'PhpWiki-' . PHPWIKI_VERSION,
1000                 //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
1001                 //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
1002                 //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
1003                 'copyright' => COPYRIGHTPAGE_URL
1004             ));
1005     }
1006
1007     // xml-rpc registerProcedure not yet implemented
1008     function cloud_properties()
1009     {
1010         return false;
1011     }
1012
1013     function cloud_properties_test()
1014     {
1015         return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
1016             'registerProcedure' => 'wiki.rssPleaseNotify',
1017             'path' => DATA_PATH . '/RPC2.php',
1018             'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
1019             'domain' => SERVER_NAME);
1020     }
1021 }
1022
1023 /** Explicit application/atom+xml Content-Type
1024  *  A weird, questionable format
1025  */
1026 class _RecentChanges_AtomFormatter
1027     extends _RecentChanges_RssFormatter
1028 {
1029
1030     function format($changes)
1031     {
1032         global $request;
1033         include_once 'lib/RssWriter.php';
1034         $rss = new AtomFeed;
1035
1036         // "channel" is called "feed" in atom
1037         $rc_url = WikiURL($request->getArg('pagename'), array(), 'absurl');
1038         extract($this->_args);
1039         $description = $this->title();
1040         $feed_props = array('title' => $description,
1041             'link' => array('rel' => "alternate",
1042                 'type' => "text/html",
1043                 'href' => $rc_url),
1044             'id' => md5($rc_url),
1045             'modified' => Iso8601DateTime(time()),
1046             'generator' => 'PhpWiki-' . PHPWIKI_VERSION,
1047             'tagline' => '');
1048         $rss->feed($feed_props);
1049         $first = true;
1050         while ($rev = $changes->next()) {
1051             // enforce view permission
1052             if (mayAccessPage('view', $rev->_pagename)) {
1053                 $props = $this->item_properties($rev);
1054                 $rss->addItem($props,
1055                     false,
1056                     $this->pageURI($rev));
1057                 if ($first)
1058                     $this->setValidators($rev);
1059                 $first = false;
1060             }
1061         }
1062
1063         $request->discardOutput();
1064         $rss->finish();
1065         printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
1066         // Flush errors in comment, otherwise it's invalid XML.
1067         global $ErrorManager;
1068         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
1069             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
1070
1071         $request->finish(); // NORETURN!!!!
1072     }
1073
1074     function item_properties($rev)
1075     {
1076         $page = $rev->getPage();
1077         $pagename = $page->getName();
1078         return array('title' => $pagename,
1079             'link' => array('rel' => 'alternate',
1080                 'type' => 'text/html',
1081                 'href' => $this->pageURL($rev)),
1082             'summary' => $this->summary($rev),
1083             'modified' => $this->time($rev) . "Z",
1084             'issued' => $this->time($rev),
1085             'created' => $this->time($rev) . "Z",
1086             'author' => new XmlElement('author', new XmlElement('name', $rev->get('author')))
1087         );
1088     }
1089 }
1090
1091 /**
1092  * Filter by non-empty
1093  */
1094 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
1095 {
1096     /**
1097      * @param WikiDB_PageRevisionIterator $revisions
1098      * @param bool $check_current_revision
1099      */
1100     function __construct($revisions, $check_current_revision = true)
1101     {
1102         $this->_revisions = $revisions;
1103         $this->_check_current_revision = $check_current_revision;
1104     }
1105
1106     function next()
1107     {
1108         while (($rev = $this->_revisions->next())) {
1109             if ($this->_check_current_revision) {
1110                 $page = $rev->getPage();
1111                 $check_rev = $page->getCurrentRevision();
1112             } else {
1113                 $check_rev = $rev;
1114             }
1115             if (!$check_rev->hasDefaultContents())
1116                 return $rev;
1117         }
1118         $this->free();
1119         return false;
1120     }
1121
1122 }
1123
1124 /**
1125  * Filter by only_new.
1126  * Only new created pages
1127  */
1128 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1129 {
1130     /**
1131      * @param $revisions object a WikiDB_PageRevisionIterator.
1132      */
1133     function __construct($revisions)
1134     {
1135         $this->_revisions = $revisions;
1136     }
1137
1138     function next()
1139     {
1140         while (($rev = $this->_revisions->next())) {
1141             if ($rev->getVersion() == 1)
1142                 return $rev;
1143         }
1144         $this->free();
1145         return false;
1146     }
1147 }
1148
1149 /**
1150  * Only pages with links to a certain category
1151  */
1152 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1153 {
1154     function __construct($revisions, $category)
1155     {
1156         /**
1157          * @var WikiRequest $request
1158          */
1159         global $request;
1160
1161         $this->_revisions = $revisions;
1162         if (preg_match("/[\?\.\*]/", $category)) {
1163             $backlinkiter = $this->_revisions->_wikidb->linkSearch
1164             (new TextSearchQuery("*", true),
1165                 new TextSearchQuery($category, true),
1166                 "linkfrom");
1167         } else {
1168             $basepage = $request->getPage($category);
1169             $backlinkiter = $basepage->getBackLinks(true);
1170         }
1171         $this->links = array();
1172         foreach ($backlinkiter->asArray() as $p) {
1173             if (is_object($p)) $this->links[] = $p->getName();
1174             elseif (is_array($p)) $this->links[] = $p['pagename']; else $this->links[] = $p;
1175         }
1176         $backlinkiter->free();
1177         sort($this->links);
1178     }
1179
1180     function next()
1181     {
1182         while (($rev = $this->_revisions->next())) {
1183             if (binary_search($rev->getName(), $this->links) != false)
1184                 return $rev;
1185         }
1186         $this->free();
1187         return false;
1188     }
1189
1190     function free()
1191     {
1192         unset ($this->links);
1193     }
1194 }
1195
1196 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1197 {
1198     function __construct($revisions, $match)
1199     {
1200         $this->_revisions = $revisions;
1201         $this->search = new TextSearchQuery($match, true);
1202     }
1203
1204     function next()
1205     {
1206         while (($rev = $this->_revisions->next())) {
1207             if ($this->search->match($rev->getName()))
1208                 return $rev;
1209         }
1210         $this->free();
1211         return false;
1212     }
1213
1214     function free()
1215     {
1216         unset ($this->search);
1217     }
1218 }
1219
1220 /**
1221  * Filter by author
1222  */
1223 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1224 {
1225     function __construct($revisions, $author)
1226     {
1227         $this->_revisions = $revisions;
1228         $this->_author = $author;
1229     }
1230
1231     function next()
1232     {
1233         while (($rev = $this->_revisions->next())) {
1234             if ($rev->get('author_id') == $this->_author)
1235                 return $rev;
1236         }
1237         $this->free();
1238         return false;
1239     }
1240 }
1241
1242 /**
1243  * Filter by owner
1244  */
1245 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1246 {
1247     function __construct($revisions, $owner)
1248     {
1249         $this->_revisions = $revisions;
1250         $this->_owner = $owner;
1251     }
1252
1253     function next()
1254     {
1255         while (($rev = $this->_revisions->next())) {
1256             $page = $rev->getPage();
1257             if ($page->getOwner() == $this->_owner)
1258                 return $rev;
1259         }
1260         $this->free();
1261         return false;
1262     }
1263 }
1264
1265 class WikiPlugin_RecentChanges
1266     extends WikiPlugin
1267 {
1268     function getDescription()
1269     {
1270         return _("List all recent changes in this wiki.");
1271     }
1272
1273     function managesValidators()
1274     {
1275         // Note that this is a bit of a fig.
1276         // We set validators based on the most recently changed page,
1277         // but this fails when the most-recent page is deleted.
1278         // (Consider that the Last-Modified time will decrease
1279         // when this happens.)
1280
1281         // We might be better off, leaving this as false (and junking
1282         // the validator logic above) and just falling back to the
1283         // default behavior (handled by WikiPlugin) of just using
1284         // the WikiDB global timestamp as the mtime.
1285
1286         // Nevertheless, for now, I leave this here, mostly as an
1287         // example for how to use appendValidators() and managesValidators().
1288
1289         return true;
1290     }
1291
1292     function getDefaultArguments()
1293     {
1294         return array('days' => 2,
1295             'show_minor' => false,
1296             'show_major' => true,
1297             'show_all' => false,
1298             'show_deleted' => 'sometimes',
1299             'only_new' => false,
1300             'author' => false,
1301             'owner' => false,
1302             'limit' => false,
1303             'format' => false,
1304             'daylist' => false,
1305             'difflinks' => true,
1306             'historylinks' => false,
1307             'caption' => '',
1308             'category' => '',
1309             'pagematch' => ''
1310         );
1311     }
1312
1313     /**
1314      * @param string $argstr
1315      * @param WikiRequest $request
1316      * @param array $defaults
1317      * @return array
1318      */
1319     function getArgs($argstr, $request = false, $defaults = array())
1320     {
1321         if (empty($defaults)) {
1322             $defaults = $this->getDefaultArguments();
1323         }
1324         $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1325
1326         $action = $request->getArg('action');
1327         if ($action != 'browse' && !isActionPage($action))
1328             $args['format'] = false; // default -> HTML
1329
1330         if ($args['format'] == 'rss' && empty($args['limit']))
1331             $args['limit'] = 15; // Fix default value for RSS.
1332         if ($args['format'] == 'rss2' && empty($args['limit']))
1333             $args['limit'] = 15; // Fix default value for RSS2.
1334
1335         if ($args['format'] == 'sidebar' && empty($args['limit']))
1336             $args['limit'] = 10; // Fix default value for sidebar.
1337
1338         return $args;
1339     }
1340
1341     function getMostRecentParams(&$args)
1342     {
1343         $show_all = false;
1344         $show_minor = false;
1345         $show_major = false;
1346         $limit = false;
1347         extract($args);
1348
1349         $params = array('include_minor_revisions' => $show_minor,
1350             'exclude_major_revisions' => !$show_major,
1351             'include_all_revisions' => !empty($show_all));
1352         if ($limit != 0)
1353             $params['limit'] = $limit;
1354         if (!empty($args['author'])) {
1355             global $request;
1356             if ($args['author'] == '[]')
1357                 $args['author'] = $request->_user->getID();
1358             $params['author'] = $args['author'];
1359         }
1360         if (!empty($args['owner'])) {
1361             global $request;
1362             if ($args['owner'] == '[]')
1363                 $args['owner'] = $request->_user->getID();
1364             $params['owner'] = $args['owner'];
1365         }
1366         if (!empty($days)) {
1367             if ($days > 0.0)
1368                 $params['since'] = time() - 24 * 3600 * $days;
1369             elseif ($days < 0.0)
1370                 $params['since'] = 24 * 3600 * $days - time();
1371         }
1372
1373         return $params;
1374     }
1375
1376     function getChanges($dbi, $args)
1377     {
1378         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1379
1380         $show_deleted = @$args['show_deleted'];
1381         $show_all = @$args['show_all'];
1382         if ($show_deleted == 'sometimes')
1383             $show_deleted = @$args['show_minor'];
1384
1385         // only pages (e.g. PageHistory of subpages)
1386         if (!empty($args['pagematch'])) {
1387             require_once 'lib/TextSearchQuery.php';
1388             $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1389         }
1390         if (!empty($args['category'])) {
1391             require_once 'lib/TextSearchQuery.php';
1392             $changes = new LinkRevisionIterator($changes, $args['category']);
1393         }
1394         if (!empty($args['only_new']))
1395             $changes = new NewPageRevisionIterator($changes);
1396         if (!empty($args['author']))
1397             $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1398         if (!empty($args['owner']))
1399             $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1400         if (!$show_deleted)
1401             $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1402
1403         return $changes;
1404     }
1405
1406     function format($changes, $args)
1407     {
1408         global $WikiTheme;
1409         $format = $args['format'];
1410
1411         $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1412         if (!$fmt_class) {
1413             if ($format == 'rss')
1414                 $fmt_class = '_RecentChanges_RssFormatter';
1415             elseif ($format == 'rss2')
1416                 $fmt_class = '_RecentChanges_Rss2Formatter';
1417             elseif ($format == 'atom')
1418                 $fmt_class = '_RecentChanges_AtomFormatter';
1419             elseif ($format == 'rss091') {
1420                 include_once 'lib/RSSWriter091.php';
1421                 $fmt_class = '_RecentChanges_RssFormatter091';
1422             } elseif ($format == 'sidebar')
1423                 $fmt_class = '_RecentChanges_SideBarFormatter';
1424             elseif ($format == 'box')
1425                 $fmt_class = '_RecentChanges_BoxFormatter';
1426             elseif ($format == 'contribs')
1427                 $fmt_class = '_RecentChanges_UserContribsFormatter';
1428             else
1429                 $fmt_class = '_RecentChanges_HtmlFormatter';
1430         }
1431
1432         $fmt = new $fmt_class($args);
1433         return $fmt->format($changes);
1434     }
1435
1436     /**
1437      * @param WikiDB $dbi
1438      * @param string $argstr
1439      * @param WikiRequest $request
1440      * @param string $basepage
1441      * @return mixed
1442      */
1443     function run($dbi, $argstr, &$request, $basepage)
1444     {
1445         $args = $this->getArgs($argstr, $request);
1446
1447         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
1448         // to be enough for anyone.)
1449         $args['days'] = min($args['days'], 365000);
1450
1451         // Within Categories just display Category Backlinks
1452         if (empty($args['category']) and empty($args['pagematch'])
1453             and preg_match("/^Category/", $request->getArg('pagename'))
1454         ) {
1455             $args['category'] = $request->getArg('pagename');
1456         }
1457
1458         // Hack alert: format() is a NORETURN for rss formatters.
1459         return $this->format($this->getChanges($dbi, $args), $args);
1460     }
1461
1462     // box is used to display a fixed-width, narrow version with common header.
1463     // just a numbered list of limit pagenames, without date.
1464     /**
1465      * @param string $args
1466      * @param WikiRequest $request
1467      * @param string $basepage
1468      * @return $this|HtmlElement
1469      */
1470     function box($args = '', $request = null, $basepage = '')
1471     {
1472         if (!$request)
1473             $request =& $GLOBALS['request'];
1474         if (!isset($args['limit']))
1475             $args['limit'] = 15;
1476         $args['format'] = 'box';
1477         $args['show_minor'] = false;
1478         $args['show_major'] = true;
1479         $args['show_deleted'] = 'sometimes';
1480         $args['show_all'] = false;
1481         $args['days'] = 90;
1482         return $this->makeBox(WikiLink($this->getName(), '',
1483                 SplitPagename($this->getName())),
1484             $this->format
1485             ($this->getChanges($request->_dbi, $args), $args));
1486     }
1487
1488 }
1489
1490 class OptionsButtonBars extends HtmlElement
1491 {
1492
1493     function __construct($plugin_args)
1494     {
1495         parent::__construct('fieldset', array('class' => 'wiki-rc-action'));
1496
1497         // Add ShowHideFolder button
1498         $icon = $GLOBALS['WikiTheme']->_findData('images/folderArrowOpen.png');
1499         $img = HTML::img(array('id' => 'rc-action-img',
1500             'src' => $icon,
1501             'onclick' => "showHideFolder('rc-action')",
1502             'alt' => _("Click to hide/show"),
1503             'title' => _("Click to hide/show")));
1504
1505         // Display selection buttons
1506         extract($plugin_args);
1507
1508         // Custom caption
1509         if (!$caption) {
1510             $caption = _("Show changes for:");
1511         }
1512
1513         $this->pushContent(HTML::legend($caption, ' ', $img));
1514         $table = HTML::table(array('id' => 'rc-action-body',
1515             'style' => 'display:block'));
1516
1517         $tr = HTML::tr();
1518         foreach (explode(",", $daylist) as $days_button) {
1519             $tr->pushContent($this->_makeDayButton($days_button, $days));
1520         }
1521         $table->pushContent($tr);
1522
1523         $tr = HTML::tr();
1524         $tr->pushContent($this->_makeUsersButton(0));
1525         $tr->pushContent($this->_makeUsersButton(1));
1526         $table->pushContent($tr);
1527
1528         $tr = HTML::tr();
1529         $tr->pushContent($this->_makePagesButton(0));
1530         $tr->pushContent($this->_makePagesButton(1));
1531         $table->pushContent($tr);
1532
1533         $tr = HTML::tr();
1534         $tr->pushContent($this->_makeMinorButton(1, $show_minor));
1535         $tr->pushContent($this->_makeMinorButton(0, $show_minor));
1536         $table->pushContent($tr);
1537
1538         $tr = HTML::tr();
1539         $tr->pushContent($this->_makeShowAllButton(1, $show_all));
1540         $tr->pushContent($this->_makeShowAllButton(0, $show_all));
1541         $table->pushContent($tr);
1542
1543         $tr = HTML::tr();
1544         $tr->pushContent($this->_makeNewPagesButton(0, $only_new));
1545         $tr->pushContent($this->_makeNewPagesButton(1, $only_new));
1546         $table->pushContent($tr);
1547
1548         $this->pushContent($table);
1549     }
1550
1551     private function _makeDayButton($days_button, $days)
1552     {
1553         global $request;
1554
1555         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days_button));
1556         if ($days_button == 1) {
1557             $label = _("1 day");
1558         } elseif ($days_button < 1) {
1559             $label = _("All time");
1560         } else {
1561             $label = sprintf(_("%s days"), abs($days_button));
1562         }
1563         $selected = HTML::td(array('class' => 'tdselected'), $label);
1564         $unselected = HTML::td(array('class' => 'tdunselected'),
1565             HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1566         return ($days_button == $days) ? $selected : $unselected;
1567     }
1568
1569     private function _makeUsersButton($users)
1570     {
1571         global $request;
1572
1573         if ($users == 0) {
1574             $label = _("All users");
1575             $author = "";
1576         } else {
1577             $label = _("My modifications only");
1578             $author = "[]";
1579         }
1580
1581         $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1582         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
1583         if ($url == $selfurl) {
1584             return HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1585         }
1586         return HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1587             HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1588     }
1589
1590     private function _makePagesButton($pages)
1591     {
1592         global $request;
1593
1594         if ($pages == 0) {
1595             $label = _("All pages");
1596             $owner = "";
1597         } else {
1598             $label = _("My pages only");
1599             $owner = "[]";
1600         }
1601
1602         $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1603         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1604         if ($url == $selfurl) {
1605             return HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1606         }
1607         return HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1608             HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1609     }
1610
1611     private function _makeMinorButton($minor_button, $show_minor)
1612     {
1613         global $request;
1614
1615         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor_button));
1616         $label = ($minor_button == 0) ? _("Major modifications only") : _("All modifications");
1617         $selected = HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1618         $unselected = HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1619             HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1620         return ($minor_button == $show_minor) ? $selected : $unselected;
1621     }
1622
1623     private function _makeShowAllButton($showall_button, $show_all)
1624     {
1625         global $request;
1626
1627         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall_button));
1628         $label = ($showall_button == 0) ? _("Page once only") : _("Full changes");
1629         $selected = HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1630         $unselected = HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1631             HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1632         return ($showall_button == $show_all) ? $selected : $unselected;
1633     }
1634
1635     private function _makeNewPagesButton($newpages_button, $only_new)
1636     {
1637         global $request;
1638
1639         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages_button));
1640         $label = ($newpages_button == 0) ? _("Old and new pages") : _("New pages only");
1641         $selected = HTML::td(array('colspan' => 3, 'class' => 'tdselected'), $label);
1642         $unselected = HTML::td(array('colspan' => 3, 'class' => 'tdunselected'),
1643             HTML::a(array('href' => $url, 'class' => 'wiki-rc-action'), $label));
1644         return ($newpages_button == $only_new) ? $selected : $unselected;
1645     }
1646 }
1647
1648 // Local Variables:
1649 // mode: php
1650 // tab-width: 8
1651 // c-basic-offset: 4
1652 // c-hanging-comment-ender-p: nil
1653 // indent-tabs-mode: nil
1654 // End: