]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChanges.php
Change plugin arg syntax from 'rss=1' to 'format=rss'.
[SourceForge/phpwiki.git] / lib / plugin / RecentChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RecentChanges.php,v 1.3 2001-12-07 22:28:21 dairiki Exp $');
3 /**
4  */
5 define('RSS_ENCODING', 'ISO-8859-1');
6
7 class WikiPlugin_RecentChanges
8 extends WikiPlugin
9 {
10     var $name = 'RecentChanges';
11     
12     function getDefaultArguments() {
13         return array('days'             => 2,
14                      'show_minor'       => false,
15                      'show_major'       => true,
16                      'show_all'         => false,
17                      'limit'            => false,
18                      'format'           => false);
19     }
20
21     function run($dbi, $argstr, $request) {
22         $args = $this->getArgs($argstr, $request);
23         extract($args);
24         $params = array('include_minor_revisions' => $show_minor,
25                         'exclude_major_revisions' => !$show_major,
26                         'include_all_revisions' => $show_all);
27         if ($days > 0.0) {
28             $params['since'] = time() - 24 * 3600 * $days;
29             $title = sprintf(_("RecentChanges in the past %.1f days"), $args['days']);
30         }
31         else {
32             $title = _("RecentChanges");
33         }
34         
35         $changes = $dbi->mostRecent($params);
36
37         if ($request->getArg('action') != 'browse')
38             $format = false;    // default -> HTML
39         switch ($format) {
40         case 'rss':
41             if (!$args['limit'])
42                 $args['limit'] = 15;
43
44             header("Content-Type: application/xml; charset=" . RSS_ENCODING);
45             
46             $xml =  $this->__format_as_rss($changes, $title, $args, $request);
47             printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", RSS_ENCODING);
48             printf("<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
49             echo $xml;
50             ExitWiki();
51             break;
52         default:
53             return $this->__format_as_html($changes, $title, $args);
54             break;
55         }
56     }
57
58     function __format_as_html($changes, $title, $args) {
59
60         global $dateformat;
61         global $WikiNameRegexp;
62         
63         $last_date = '';
64         $lines = array();
65
66         $diffargs = array('action' => 'diff');
67
68         // FIXME: add XML icon (and link) to title?
69         $html = QElement('h3', $title);
70
71         $limit = $args['limit'];
72         while ($rev = $changes->next()) {
73             $created = $rev->get('mtime');
74             $date = strftime($dateformat, $created);
75             $time = strftime("%l:%M %P", $created); // Make configurable.
76             if ($date != $last_date) {
77                 if ($lines) {
78                     $html .= Element('ul', join("\n", $lines));
79                     $lines = array();
80                 }
81                 $html .= Element('p',QElement('b', $date));
82                 $last_date = $date;
83             }
84             
85             $page = $rev->getPage();
86             $pagename = $page->getName();
87
88             if ($args['show_all']) {
89                 // FIXME: should set previous, too, if showing only minor or major revs.
90                 //  or maybe difftype.
91                 $diffargs['version'] = $rev->getVersion();
92             }
93             
94             $diff = QElement('a',
95                              array('href' => WikiURL($pagename, $diffargs)),
96                              "(diff)");
97             
98             $wikipage = LinkWikiWord($page->getName());
99
100             $author = $rev->get('author');
101             if (preg_match("/^$WikiNameRegexp\$/", $author))
102                 $author = LinkWikiWord($author);
103             else
104                 $author = htmlspecialchars($author);
105
106             $summary = $rev->get('summary');
107             if ($summary)
108                 $summary = QElement('b', "[$summary]");
109             
110             $lines[] = Element('li',
111                                "$diff $wikipage $time $summary ... $author");
112
113             if ($limit && --$limit <= 0)
114                 break;
115         }
116         if ($lines)
117             $html .= Element('ul', join("\n", $lines));
118         
119         return $html;
120     }
121
122     function __format_as_rss($changes, $title, $args, $request) {
123         include_once('lib/RssWriter.php');
124         $rss = new RssWriter;
125         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
126         
127         $chan = array('title' => 'PhpWiki', // FIXME: this should be a config define
128                       'dc:description' => $title,
129                       'link' => $rc_url,
130                       'dc:date' => Iso8601DateTime(time()));
131
132         /* FIXME: other things one might like in <channel>:                   
133          * sy:updateFrequency
134          * sy:updatePeriod
135          * sy:updateBase
136          * dc:subject
137          * dc:publisher
138          * dc:language
139          * dc:rights
140          * rss091:language
141          * rss091:managingEditor
142          * rss091:webmaster
143          * rss091:lastBuildDate
144          * rss091:copyright
145          */
146
147         $rss->channel($chan, $rc_url);
148
149         $rss->image(array('title' => 'PhpWiki', // FIXME: this should be a config define
150                           'link' => WikiURL(_("HomePage"), false, 'absurl'),
151                           'url' => DataURL($GLOBALS['logo'])));
152         
153         $rss->textinput(array('title' => _("Search"),
154                               'description' => _("Title Search"),
155                               'name' => 's',
156                               'link' => WikiURL(_("TitleSearch"), false, 'absurl')));
157
158         $limit = $args['limit'];
159         while ($rev = $changes->next()) {
160             $page = $rev->getPage();
161
162             $urlargs = array();
163             if ($args['show_all']) {
164                 // FIXME: should set previous, too, if showing only minor or major revs.
165                 //  or maybe difftype.
166                 $urlargs['version'] = $rev->getVersion();
167             }
168             
169             $pagename = $page->getName();
170             
171             $item = array('title' => split_pagename($pagename),
172                           'description' => $rev->get('summary'),
173                           'link' => WikiURL($pagename, $urlargs, 'absurl'),
174                           'dc:date' => Iso8601DateTime($rev->get('mtime')),
175                           'dc:contributor' => $rev->get('author'),
176                           'wiki:version' => $rev->getVersion(),
177                           'wiki:importance' => $rev->get('is_minor_edit') ? 'minor' : 'major',
178                           // wiki:status = 'new' | 'updated' | 'deleted'
179                           'wiki:diff' => WikiURL($pagename,
180                                                  array_merge($urlargs,
181                                                              array('action' => 'diff',
182                                                                    'previous' => 'major')),
183                                                  'absurl'),
184                           'wiki:history' => WikiURL($pagename,
185                                                     array('action' => 'info'),
186                                                     'absurl')
187                           );
188
189
190             $uri = WikiURL($pagename, array('version' => $rev->getVersion()), 'absurl');
191             $rss->addItem($item, $uri);
192
193             if ($limit && --$limit <= 0)
194                 break;
195         }
196
197         return $rss->asXML();
198     }
199 };
200
201
202 // (c-file-style: "gnu")
203 // Local Variables:
204 // mode: php
205 // tab-width: 8
206 // c-basic-offset: 4
207 // c-hanging-comment-ender-p: nil
208 // indent-tabs-mode: nil
209 // End:   
210 ?>