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