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