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