]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChanges.php
rcs_id no longer makes sense with Subversion global version number
[SourceForge/phpwiki.git] / lib / plugin / RecentChanges.php
1 <?php // -*-php-*-
2 // rcs_id('$Id$');
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
20  * along with PhpWiki; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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_gforge'))) {
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                                'border' => 0,
609                                'align' => 'right',
610                                'style' => 'height:2.5ex'
611                                ));
612         $linkurl = WikiLink(HOME_PAGE, false, $img);
613         $linkurl->setAttr('target', '_content');
614         return $linkurl;
615     }
616
617     function authorLink ($rev) {
618         $author = $rev->get('author');
619         if ( $this->authorHasPage($author) ) {
620             $linkurl = WikiLink($author);
621             $linkurl->setAttr('target', '_content'); // way to do this using parent::authorLink ??
622             return $linkurl;
623         } else
624             return $author;
625     }
626
627     function diffLink ($rev) {
628         $linkurl = parent::diffLink($rev);
629         $linkurl->setAttr('target', '_content');
630         $linkurl->setAttr('rel', 'nofollow');
631         // FIXME: Smelly hack to get smaller diff buttons in sidebar
632         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
633         return $linkurl;
634     }
635     function historyLink ($rev) {
636         $linkurl = parent::historyLink($rev);
637         $linkurl->setAttr('target', '_content');
638         // FIXME: Smelly hack to get smaller history buttons in sidebar
639         $linkurl = new RawXML(str_replace('<img ', '<img style="height:2ex" ', asXML($linkurl)));
640         return $linkurl;
641     }
642     function pageLink ($rev) {
643         $linkurl = parent::pageLink($rev);
644         $linkurl->setAttr('target', '_content');
645         return $linkurl;
646     }
647     // Overriding summaryAsHTML, because there is no way yet to
648     // return summary as transformed text with
649     // links setAttr('target', '_content') in Mozilla sidebar.
650     // So for now don't create clickable links inside summary
651     // in the sidebar, or else they target the sidebar and not the
652     // main content window.
653     function summaryAsHTML ($rev) {
654         if ( !($summary = $this->summary($rev)) )
655             return '';
656         return HTML::span(array('class' => 'wiki-summary'),
657                           "[",
658                           /*TransformLinks(*/$summary,/* $rev->get('markup')),*/
659                           "]");
660     }
661
662
663     function format ($changes) {
664         $this->_args['daylist'] = false; //don't show day buttons in Mozilla sidebar
665         $html = _RecentChanges_HtmlFormatter::format ($changes);
666         $html = HTML::div(array('class' => 'wikitext'), $html);
667         global $request;
668         $request->discardOutput();
669
670         printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $GLOBALS['charset']);
671         printf('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
672         printf('  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
673         printf('<html xmlns="http://www.w3.org/1999/xhtml">');
674
675         printf("<head>\n");
676         extract($this->_args);
677         if (!empty($category))
678             $title = $category;
679         elseif (!empty($pagematch))
680             $title = $pagematch;
681         else
682             $title = WIKI_NAME . $show_minor ? _("RecentEdits") : _("RecentChanges");
683         printf("<title>" . $title . "</title>\n");
684         global $WikiTheme;
685         $css = $WikiTheme->getCSS();
686         $css->PrintXML();
687         printf("</head>\n");
688
689         printf("<body class=\"sidebar\">\n");
690         $html->PrintXML();
691         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>';
692         printf("\n</body>\n");
693         printf("</html>\n");
694
695         $request->finish(); // cut rest of page processing short
696     }
697 }
698
699 class _RecentChanges_BoxFormatter
700 extends _RecentChanges_HtmlFormatter
701 {
702     function rss_icon () {
703     }
704     function rss2_icon () {
705     }
706     function headline () {
707     }
708     function authorLink ($rev) {
709     }
710     function diffLink ($rev) {
711     }
712     function historyLink ($rev) {
713     }
714     function summaryAsHTML ($rev) {
715     }
716     function description () {
717     }
718     function format ($changes) {
719         include_once('lib/InlineParser.php');
720         $last_date = '';
721         $first = true;
722         $html = HTML();
723         $counter = 1;
724         $sp = HTML::Raw("\n&nbsp;&middot;&nbsp;");
725         while ($rev = $changes->next()) {
726             // enforce view permission
727             if (mayAccessPage('view',$rev->_pagename)) {
728                     if ($link = $this->pageLink($rev)) // some entries may be empty
729                                                        // (/Blog/.. interim pages)
730                     $html->pushContent($sp, $link, HTML::br());
731                 if ($first)
732                     $this->setValidators($rev);
733                 $first = false;
734             }
735         }
736         if ($first)
737             $html->pushContent(HTML::p(array('class' => 'rc-empty'),
738                                        $this->empty_message()));
739         return $html;
740     }
741 }
742
743 class _RecentChanges_RssFormatter
744 extends _RecentChanges_Formatter
745 {
746     var $_absurls = true;
747
748     function time ($rev) {
749         return Iso8601DateTime($rev->get('mtime'));
750     }
751
752     function pageURI ($rev) {
753         return WikiURL($rev, '', 'absurl');
754     }
755
756     function format ($changes) {
757
758         include_once('lib/RssWriter.php');
759         $rss = new RssWriter;
760         $rss->channel($this->channel_properties());
761
762         if (($props = $this->image_properties()))
763             $rss->image($props);
764         if (($props = $this->textinput_properties()))
765             $rss->textinput($props);
766
767         $first = true;
768         while ($rev = $changes->next()) {
769             // enforce view permission
770             if (mayAccessPage('view', $rev->_pagename)) {
771                 $rss->addItem($this->item_properties($rev),
772                               $this->pageURI($rev));
773                 if ($first)
774                     $this->setValidators($rev);
775                 $first = false;
776             }
777         }
778
779         global $request;
780         $request->discardOutput();
781         $rss->finish();
782         //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
783         printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
784
785         // Flush errors in comment, otherwise it's invalid XML.
786         global $ErrorManager;
787         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
788             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
789
790         $request->finish();     // NORETURN!!!!
791     }
792
793     function image_properties () {
794         global $WikiTheme;
795
796         $img_url = AbsoluteURL($WikiTheme->getImageURL('logo'));
797         if (!$img_url)
798             return false;
799
800         return array('title' => WIKI_NAME,
801                      'link' => WikiURL(HOME_PAGE, false, 'absurl'),
802                      'url' => $img_url);
803     }
804
805     function textinput_properties () {
806         return array('title' => _("Search"),
807                      'description' => _("Title Search"),
808                      'name' => 's',
809                      'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
810     }
811
812     function channel_properties () {
813         global $request;
814
815         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
816         extract($this->_args);
817         $title = WIKI_NAME;
818         $description = $this->title();
819         if ($category)
820             $title = $category;
821         elseif ($pagematch)
822             $title = $pagematch;
823         return array('title' => $title,
824                      'link' => $rc_url,
825                      'description' => $description,
826                      'dc:date' => Iso8601DateTime(time()),
827                      'dc:language' => $GLOBALS['LANG']);
828
829         /* FIXME: other things one might like in <channel>:
830          * sy:updateFrequency
831          * sy:updatePeriod
832          * sy:updateBase
833          * dc:subject
834          * dc:publisher
835          * dc:language
836          * dc:rights
837          * rss091:language
838          * rss091:managingEditor
839          * rss091:webmaster
840          * rss091:lastBuildDate
841          * rss091:copyright
842          */
843     }
844
845     function item_properties ($rev) {
846         $page = $rev->getPage();
847         $pagename = $page->getName();
848
849         return array( 'title'           => SplitPagename($pagename),
850                       'description'     => $this->summary($rev),
851                       'link'            => $this->pageURL($rev),
852                       'dc:date'         => $this->time($rev),
853                       'dc:contributor'  => $rev->get('author'),
854                       'wiki:version'    => $rev->getVersion(),
855                       'wiki:importance' => $this->importance($rev),
856                       'wiki:status'     => $this->status($rev),
857                       'wiki:diff'       => $this->diffURL($rev),
858                       'wiki:history'    => $this->historyURL($rev)
859                       );
860     }
861 }
862
863 /** explicit application/rss+xml Content-Type,
864  * simplified xml structure (no namespace),
865  * support for xml-rpc cloud registerProcedure (not yet)
866  */
867 class _RecentChanges_Rss2Formatter
868 extends _RecentChanges_RssFormatter {
869
870     function format ($changes) {
871         include_once('lib/RssWriter2.php');
872         $rss = new RssWriter2;
873
874         $rss->channel($this->channel_properties());
875         if (($props = $this->cloud_properties()))
876             $rss->cloud($props);
877         if (($props = $this->image_properties()))
878             $rss->image($props);
879         if (($props = $this->textinput_properties()))
880             $rss->textinput($props);
881         $first = true;
882         while ($rev = $changes->next()) {
883             // enforce view permission
884             if (mayAccessPage('view', $rev->_pagename)) {
885                 $rss->addItem($this->item_properties($rev),
886                               $this->pageURI($rev));
887                 if ($first)
888                     $this->setValidators($rev);
889                 $first = false;
890             }
891         }
892
893         global $request;
894         $request->discardOutput();
895         $rss->finish();
896         //header("Content-Type: application/rss+xml; charset=" . $GLOBALS['charset']);
897         printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
898         // Flush errors in comment, otherwise it's invalid XML.
899         global $ErrorManager;
900         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
901             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
902
903         $request->finish();     // NORETURN!!!!
904     }
905
906     function channel_properties () {
907         $chann_10 = parent::channel_properties();
908         return array_merge($chann_10,
909                            array('generator' => 'PhpWiki-'.PHPWIKI_VERSION,
910                                  //<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
911                                  //<lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
912                                  //<docs>http://blogs.law.harvard.edu/tech/rss</docs>
913                                  'copyright' => COPYRIGHTPAGE_URL
914                                  ));
915     }
916
917     // xml-rpc registerProcedure not yet implemented
918     function cloud_properties () { return false; }
919     function cloud_properties_test () {
920         return array('protocol' => 'xml-rpc', // xml-rpc or soap or http-post
921                      'registerProcedure' => 'wiki.rssPleaseNotify',
922                      'path' => DATA_PATH.'/RPC2.php',
923                      'port' => !SERVER_PORT ? '80' : (SERVER_PROTOCOL == 'https' ? '443' : '80'),
924                      'domain' => SERVER_NAME);
925     }
926 }
927
928 /** Explicit application/atom+xml Content-Type
929  *  A weird, questionable format
930  */
931 class _RecentChanges_AtomFormatter
932 extends _RecentChanges_RssFormatter {
933
934     function format ($changes) {
935         global $request;
936         include_once('lib/RssWriter.php');
937         $rss = new AtomFeed;
938
939         // "channel" is called "feed" in atom
940         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
941         extract($this->_args);
942         $title = WIKI_NAME;
943         $description = $this->title();
944         if ($category)
945             $title = $category;
946         elseif ($pagematch)
947             $title = $pagematch;
948         $feed_props = array('title' => $description,
949                             'link' => array('rel'=>"alternate",
950                                                 'type'=>"text/html",
951                                             'href' => $rc_url),
952                             'id' => md5($rc_url),
953                             'modified' => Iso8601DateTime(time()),
954                             'generator' => 'PhpWiki-'.PHPWIKI_VERSION,
955                             'tagline' => '');
956         $rss->feed($feed_props);
957         $first = true;
958         while ($rev = $changes->next()) {
959             // enforce view permission
960             if (mayAccessPage('view', $rev->_pagename)) {
961                 $props = $this->item_properties($rev);
962                 $rss->addItem($props,
963                               false,
964                               $this->pageURI($rev));
965                 if ($first)
966                     $this->setValidators($rev);
967                 $first = false;
968             }
969         }
970
971         $request->discardOutput();
972         $rss->finish();
973         //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
974         printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
975         // Flush errors in comment, otherwise it's invalid XML.
976         global $ErrorManager;
977         if (($errors = $ErrorManager->getPostponedErrorsAsHTML()))
978             printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
979
980         $request->finish();     // NORETURN!!!!
981     }
982
983     function item_properties ($rev) {
984         $page = $rev->getPage();
985         $pagename = $page->getName();
986         return array( 'title'           => $pagename,
987                       'link'            => array('rel' => 'alternate',
988                                                  'type' => 'text/html',
989                                                  'href' => $this->pageURL($rev)),
990                       'summary'         => $this->summary($rev),
991                       'modified'        => $this->time($rev)."Z",
992                       'issued'          => $this->time($rev),
993                       'created'         => $this->time($rev)."Z",
994                       'author'          => new XmlElement('author', new XmlElement('name', $rev->get('author')))
995                       );
996     }
997 }
998
999 /**
1000  * Filter by non-empty
1001  */
1002 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
1003 {
1004     /** Constructor
1005      *
1006      * @param $revisions object a WikiDB_PageRevisionIterator.
1007      */
1008     function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
1009         $this->_revisions = $revisions;
1010         $this->_check_current_revision = $check_current_revision;
1011     }
1012
1013     function next () {
1014         while (($rev = $this->_revisions->next())) {
1015             if ($this->_check_current_revision) {
1016                 $page = $rev->getPage();
1017                 $check_rev = $page->getCurrentRevision();
1018             }
1019             else {
1020                 $check_rev = $rev;
1021             }
1022             if (! $check_rev->hasDefaultContents())
1023                 return $rev;
1024         }
1025         $this->free();
1026         return false;
1027     }
1028
1029 }
1030
1031 /**
1032  * Filter by only_new.
1033  * Only new created pages
1034  */
1035 class NewPageRevisionIterator extends WikiDB_PageRevisionIterator
1036 {
1037     /** Constructor
1038      *
1039      * @param $revisions object a WikiDB_PageRevisionIterator.
1040      */
1041     function NewPageRevisionIterator ($revisions) {
1042         $this->_revisions = $revisions;
1043     }
1044
1045     function next () {
1046         while (($rev = $this->_revisions->next())) {
1047             if ($rev->getVersion() == 1)
1048                 return $rev;
1049         }
1050         $this->free();
1051         return false;
1052     }
1053 }
1054
1055 /**
1056  * Only pages with links to a certain category
1057  */
1058 class LinkRevisionIterator extends WikiDB_PageRevisionIterator
1059 {
1060     function LinkRevisionIterator ($revisions, $category) {
1061         $this->_revisions = $revisions;
1062         if (preg_match("/[\?\.\*]/", $category)) {
1063           $backlinkiter = $this->_revisions->_wikidb->linkSearch
1064             (new TextSearchQuery("*", true),
1065              new TextSearchQuery($category, true),
1066              "linkfrom");
1067         } else {
1068           $basepage = $GLOBALS['request']->getPage($category);
1069           $backlinkiter = $basepage->getBackLinks(true);
1070         }
1071         $this->links = array();
1072         foreach ($backlinkiter->asArray() as $p) {
1073             if (is_object($p)) $this->links[] = $p->getName();
1074             elseif (is_array($p)) $this->links[] = $p['pagename'];
1075             else $this->links[] = $p;
1076         }
1077         $backlinkiter->free();
1078         sort($this->links);
1079     }
1080
1081     function next () {
1082         while (($rev = $this->_revisions->next())) {
1083             if (binary_search($rev->getName(), $this->links) != false)
1084                 return $rev;
1085         }
1086         $this->free();
1087         return false;
1088     }
1089
1090     function free () {
1091         unset ($this->links);
1092     }
1093 }
1094
1095 class PageMatchRevisionIterator extends WikiDB_PageRevisionIterator
1096 {
1097     function PageMatchRevisionIterator ($revisions, $match) {
1098         $this->_revisions = $revisions;
1099         $this->search = new TextSearchQuery($match, true);
1100     }
1101
1102     function next () {
1103         while (($rev = $this->_revisions->next())) {
1104             if ($this->search->match($rev->getName()))
1105                 return $rev;
1106         }
1107         $this->free();
1108         return false;
1109     }
1110
1111     function free () {
1112         unset ($this->search);
1113     }
1114 }
1115
1116 /**
1117  * Filter by author
1118  */
1119 class AuthorPageRevisionIterator extends WikiDB_PageRevisionIterator
1120 {
1121     function AuthorPageRevisionIterator ($revisions, $author) {
1122         $this->_revisions = $revisions;
1123         $this->_author = $author;
1124     }
1125
1126     function next () {
1127         while (($rev = $this->_revisions->next())) {
1128             if ($rev->get('author_id') == $this->_author)
1129                 return $rev;
1130         }
1131         $this->free();
1132         return false;
1133     }
1134 }
1135
1136 /**
1137  * Filter by owner
1138  */
1139 class OwnerPageRevisionIterator extends WikiDB_PageRevisionIterator
1140 {
1141     function OwnerPageRevisionIterator ($revisions, $owner) {
1142         $this->_revisions = $revisions;
1143         $this->_owner = $owner;
1144     }
1145
1146     function next () {
1147         while (($rev = $this->_revisions->next())) {
1148             $page = $rev->getPage();
1149             if ($page->getOwner() == $this->_owner)
1150                 return $rev;
1151         }
1152         $this->free();
1153         return false;
1154     }
1155 }
1156
1157 class WikiPlugin_RecentChanges
1158 extends WikiPlugin
1159 {
1160     function getName () {
1161         return _("RecentChanges");
1162     }
1163
1164     function getDescription () {
1165         return _("List all recent changes in this wiki.");
1166     }
1167
1168     function managesValidators() {
1169         // Note that this is a bit of a fig.
1170         // We set validators based on the most recently changed page,
1171         // but this fails when the most-recent page is deleted.
1172         // (Consider that the Last-Modified time will decrease
1173         // when this happens.)
1174
1175         // We might be better off, leaving this as false (and junking
1176         // the validator logic above) and just falling back to the
1177         // default behavior (handled by WikiPlugin) of just using
1178         // the WikiDB global timestamp as the mtime.
1179
1180         // Nevertheless, for now, I leave this here, mostly as an
1181         // example for how to use appendValidators() and managesValidators().
1182
1183         return true;
1184     }
1185
1186     function getDefaultArguments() {
1187         return array('days'         => 2,
1188                      'show_minor'   => false,
1189                      'show_major'   => true,
1190                      'show_all'     => false,
1191                      'show_deleted' => 'sometimes',
1192                      'only_new'     => false,
1193                      'author'       => false,
1194                      'owner'        => false,
1195                      'limit'        => false,
1196                      'format'       => false,
1197                      'daylist'      => false,
1198                      'difflinks'    => true,
1199                      'historylinks' => false,
1200                      'caption'      => '',
1201                      'category'     => '',
1202                      'pagematch'    => ''
1203                      );
1204     }
1205
1206     function getArgs ($argstr, $request, $defaults = false) {
1207             if (!$defaults) $defaults = $this->getDefaultArguments();
1208         $args = WikiPlugin::getArgs($argstr, $request, $defaults);
1209
1210         $action = $request->getArg('action');
1211         if ($action != 'browse' && !isActionPage($action))
1212             $args['format'] = false; // default -> HTML
1213
1214         if ($args['format'] == 'rss' && empty($args['limit']))
1215             $args['limit'] = 15; // Fix default value for RSS.
1216         if ($args['format'] == 'rss2' && empty($args['limit']))
1217             $args['limit'] = 15; // Fix default value for RSS2.
1218
1219         if ($args['format'] == 'sidebar' && empty($args['limit']))
1220             $args['limit'] = 10; // Fix default value for sidebar.
1221
1222         return $args;
1223     }
1224
1225     function getMostRecentParams (&$args) {
1226             $show_all = false; $show_minor = false; $show_major = false;
1227             $limit = false;
1228         extract($args);
1229
1230         $params = array('include_minor_revisions' => $show_minor,
1231                         'exclude_major_revisions' => !$show_major,
1232                         'include_all_revisions' => !empty($show_all));
1233         if ($limit != 0)
1234             $params['limit'] = $limit;
1235         if (!empty($args['author'])) {
1236             global $request;
1237             if ($args['author'] == '[]')
1238                 $args['author'] = $request->_user->getID();
1239             $params['author'] = $args['author'];
1240         }
1241         if (!empty($args['owner'])) {
1242             global $request;
1243             if ($args['owner'] == '[]')
1244                 $args['owner'] = $request->_user->getID();
1245             $params['owner'] = $args['owner'];
1246         }
1247         if (!empty($days)) {
1248           if ($days > 0.0)
1249             $params['since'] = time() - 24 * 3600 * $days;
1250           elseif ($days < 0.0)
1251             $params['since'] = 24 * 3600 * $days - time();
1252         }
1253
1254         return $params;
1255     }
1256
1257     function getChanges ($dbi, $args) {
1258         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
1259
1260         $show_deleted = @$args['show_deleted'];
1261         $show_all = @$args['show_all'];
1262         if ($show_deleted == 'sometimes')
1263             $show_deleted = @$args['show_minor'];
1264
1265         // only pages (e.g. PageHistory of subpages)
1266         if (!empty($args['pagematch'])) {
1267             require_once("lib/TextSearchQuery.php");
1268             $changes = new PageMatchRevisionIterator($changes, $args['pagematch']);
1269         }
1270         if (!empty($args['category'])) {
1271             require_once("lib/TextSearchQuery.php");
1272             $changes = new LinkRevisionIterator($changes, $args['category']);
1273         }
1274         if (!empty($args['only_new']))
1275             $changes = new NewPageRevisionIterator($changes);
1276         if (!empty($args['author']))
1277             $changes = new AuthorPageRevisionIterator($changes, $args['author']);
1278         if (!empty($args['owner']))
1279             $changes = new OwnerPageRevisionIterator($changes, $args['owner']);
1280         if (!$show_deleted)
1281             $changes = new NonDeletedRevisionIterator($changes, !$show_all);
1282
1283         return $changes;
1284     }
1285
1286     function format ($changes, $args) {
1287         global $WikiTheme;
1288         $format = $args['format'];
1289
1290         $fmt_class = $WikiTheme->getFormatter('RecentChanges', $format);
1291         if (!$fmt_class) {
1292             if ($format == 'rss')
1293                 $fmt_class = '_RecentChanges_RssFormatter';
1294             elseif ($format == 'rss2')
1295                 $fmt_class = '_RecentChanges_Rss2Formatter';
1296             elseif ($format == 'atom')
1297                 $fmt_class = '_RecentChanges_AtomFormatter';
1298             elseif ($format == 'rss091') {
1299                 include_once "lib/RSSWriter091.php";
1300                 $fmt_class = '_RecentChanges_RssFormatter091';
1301             }
1302             elseif ($format == 'sidebar')
1303                 $fmt_class = '_RecentChanges_SideBarFormatter';
1304             elseif ($format == 'box')
1305                 $fmt_class = '_RecentChanges_BoxFormatter';
1306             elseif ($format == 'contribs')
1307                 $fmt_class = '_RecentChanges_UserContribsFormatter';
1308             else
1309                 $fmt_class = '_RecentChanges_HtmlFormatter';
1310         }
1311
1312         $fmt = new $fmt_class($args);
1313         return $fmt->format($changes);
1314     }
1315
1316     function run($dbi, $argstr, &$request, $basepage) {
1317         $args = $this->getArgs($argstr, $request);
1318
1319         // HACKish: fix for SF bug #622784  (1000 years of RecentChanges ought
1320         // to be enough for anyone.)
1321         $args['days'] = min($args['days'], 365000);
1322
1323         // Within Categories just display Category Backlinks
1324         if (empty($args['category']) and empty($args['pagematch'])
1325             and preg_match("/^Category/", $request->getArg('pagename')))
1326         {
1327             $args['category'] = $request->getArg('pagename');
1328         }
1329
1330         // Hack alert: format() is a NORETURN for rss formatters.
1331         return $this->format($this->getChanges($dbi, $args), $args);
1332     }
1333
1334     // box is used to display a fixed-width, narrow version with common header.
1335     // just a numbered list of limit pagenames, without date.
1336     function box($args = false, $request = false, $basepage = false) {
1337         if (!$request) $request =& $GLOBALS['request'];
1338         if (!isset($args['limit'])) $args['limit'] = 15;
1339         $args['format'] = 'box';
1340         $args['show_minor'] = false;
1341         $args['show_major'] = true;
1342         $args['show_deleted'] = 'sometimes';
1343         $args['show_all'] = false;
1344         $args['days'] = 90;
1345         return $this->makeBox(WikiLink($this->getName(),'',
1346                                        SplitPagename($this->getName())),
1347                               $this->format
1348                               ($this->getChanges($request->_dbi, $args), $args));
1349     }
1350
1351 };
1352
1353 class OptionsButtonBars extends HtmlElement {
1354
1355     function OptionsButtonBars ($plugin_args) {
1356         $this->__construct('fieldset', array('class' => 'wiki-rc-action'));
1357
1358             // Add ShowHideFolder button
1359         $icon = $GLOBALS['WikiTheme']->_findData('images/folderArrowOpen.png');
1360         $img = HTML::img(array('id' => 'rc-action-img',
1361                                'src' => $icon,
1362                                'onclick' => "showHideFolder('rc-action')",
1363                                'alt'  => _("Click to hide/show"),
1364                                'title'  => _("Click to hide/show")));
1365
1366         // Display selection buttons
1367         extract($plugin_args);
1368
1369         // Custom caption
1370         if (! $caption) {
1371             $caption = _("Show changes for:");
1372         }
1373
1374         $this->pushContent(HTML::legend($caption,' ',$img));
1375         $table = HTML::table(array('id' => 'rc-action-body',
1376                                    'style' => 'display:block'));
1377
1378         $tr = HTML::tr();
1379         foreach (explode(",", $daylist) as $days_button) {
1380             $tr->pushContent($this->_makeDayButton($days_button, $days));
1381         }
1382         $table->pushContent($tr);
1383
1384         $tr = HTML::tr();
1385         $tr->pushContent($this->_makeUsersButton(0));
1386         $tr->pushContent($this->_makeUsersButton(1));
1387         $table->pushContent($tr);
1388
1389         $tr = HTML::tr();
1390         $tr->pushContent($this->_makePagesButton(0));
1391         $tr->pushContent($this->_makePagesButton(1));
1392         $table->pushContent($tr);
1393
1394         $tr = HTML::tr();
1395         $tr->pushContent($this->_makeMinorButton(1, $show_minor));
1396         $tr->pushContent($this->_makeMinorButton(0, $show_minor));
1397         $table->pushContent($tr);
1398
1399         $tr = HTML::tr();
1400         $tr->pushContent($this->_makeShowAllButton(1, $show_all));
1401         $tr->pushContent($this->_makeShowAllButton(0, $show_all));
1402         $table->pushContent($tr);
1403
1404         $tr = HTML::tr();
1405         $tr->pushContent($this->_makeNewPagesButton(0, $only_new));
1406         $tr->pushContent($this->_makeNewPagesButton(1, $only_new));
1407         $table->pushContent($tr);
1408
1409         $this->pushContent($table);
1410     }
1411
1412     function _makeDayButton ($days_button, $days) {
1413         global $request;
1414
1415         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'days' => $days_button));
1416         if ($days_button == 1) {
1417             $label = _("1 day");
1418         } elseif ($days_button < 1) {
1419             $label = _("All time");
1420         } else {
1421             $label = sprintf(_("%s days"), abs($days_button));
1422         }
1423         $selected = HTML::td(array('class'=>'tdselected'), $label);
1424         $unselected = HTML::td(array('class'=>'tdunselected'),
1425                       HTML::a(array('href'  => $url, 'class' => 'wiki-rc-action'), $label));
1426         return ($days_button == $days) ? $selected : $unselected;
1427     }
1428
1429     function _makeUsersButton ($users) {
1430         global $request;
1431
1432         if ($users == 0) {
1433             $label = _("All users");
1434             $author = "";
1435         } else {
1436             $label = _("My modifications only");
1437             $author = "[]";
1438         }
1439
1440         $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1441         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'author' => $author));
1442         if ($url == $selfurl) {
1443             return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1444         }
1445         return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1446                         HTML::a(array('href'  => $url, 'class' => 'wiki-rc-action'), $label));
1447     }
1448
1449     function _makePagesButton ($pages) {
1450         global $request;
1451
1452         if ($pages == 0) {
1453             $label = _("All pages");
1454             $owner = "";
1455         } else {
1456             $label = _("My pages only");
1457             $owner = "[]";
1458         }
1459
1460         $selfurl = $request->getURLtoSelf(array('action' => $request->getArg('action')));
1461         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'owner' => $owner));
1462         if ($url == $selfurl) {
1463             return HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1464         }
1465         return HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1466                         HTML::a(array('href'  => $url, 'class' => 'wiki-rc-action'), $label));
1467     }
1468
1469     function _makeMinorButton ($minor_button, $show_minor) {
1470         global $request;
1471
1472         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_minor' => $minor_button));
1473         $label = ($minor_button == 0) ? _("Major modifications only") : _("All modifications");
1474         $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1475         $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1476                       HTML::a(array('href'  => $url, 'class' => 'wiki-rc-action'), $label));
1477         return ($minor_button == $show_minor) ? $selected : $unselected;
1478     }
1479
1480     function _makeShowAllButton ($showall_button, $show_all) {
1481         global $request;
1482
1483         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'show_all' => $showall_button));
1484         $label = ($showall_button == 0) ? _("Page once only") : _("Full changes");
1485         $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1486         $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1487                       HTML::a(array('href'  => $url, 'class' => 'wiki-rc-action'), $label));
1488         return ($showall_button == $show_all) ? $selected : $unselected;
1489     }
1490
1491     function _makeNewPagesButton ($newpages_button, $only_new) {
1492         global $request;
1493
1494         $url = $request->getURLtoSelf(array('action' => $request->getArg('action'), 'only_new' => $newpages_button));
1495         $label = ($newpages_button == 0) ? _("Old and new pages") : _("New pages only");
1496         $selected = HTML::td(array('colspan'=>3, 'class'=>'tdselected'), $label);
1497         $unselected = HTML::td(array('colspan'=>3, 'class'=>'tdunselected'),
1498                       HTML::a(array('href'  => $url, 'class' => 'wiki-rc-action'), $label));
1499         return ($newpages_button == $only_new) ? $selected : $unselected;
1500     }
1501 }
1502
1503 // (c-file-style: "gnu")
1504 // Local Variables:
1505 // mode: php
1506 // tab-width: 8
1507 // c-basic-offset: 4
1508 // c-hanging-comment-ender-p: nil
1509 // indent-tabs-mode: nil
1510 // End:
1511 ?>