2 rcs_id('$Id: RecentChanges.php,v 1.17 2002-01-05 11:46:03 carstenklapp Exp $');
8 class _RecentChanges_Formatter
10 var $_absurls = false;
12 function _RecentChanges_Formatter ($rc_args) {
13 $this->_args = $rc_args;
14 $this->_diffargs = array('action' => 'diff');
16 if ($rc_args['show_major'] && !$rc_args['show_minor'])
17 $this->_diffargs['previous'] = 'major';
20 function include_versions_in_URLs() {
21 return (bool) $this->_args['show_all'];
24 function date ($rev) {
25 return strftime($GLOBALS['dateformat'], $rev->get('mtime'));
28 function time ($rev) {
29 return strtolower(strftime("%l:%M %p", $rev->get('mtime')));
32 function diffURL ($rev) {
33 $args = $this->_diffargs;
34 if ($this->include_versions_in_URLs())
35 $args['version'] = $rev->getVersion();
36 $page = $rev->getPage();
37 return WikiURL($page->getName(), $args, $this->_absurls);
40 function historyURL ($rev) {
41 $page = $rev->getPage();
42 return WikiURL(_("PageHistory"),
43 array('page' => $page->getName()),
47 function pageURL ($rev) {
49 if ($this->include_versions_in_URLs())
50 $params['version'] = $rev->getVersion();
51 $page = $rev->getPage();
52 return WikiURL($page->getName(), $params, $this->_absurls);
55 function authorURL($author) {
56 global $WikiNameRegexp, $dbi;
58 if (preg_match("/^$WikiNameRegexp\$/", $author) && $dbi->isWikiPage($author))
59 return WikiURL($author);
64 function status ($rev) {
65 if ($rev->hasDefaultContents())
67 $page = $rev->getPage();
68 $prev = $page->getRevisionBefore($rev->getVersion());
69 if ($prev->hasDefaultContents())
74 function importance ($rev) {
75 return $rev->get('is_minor_edit') ? 'minor' : 'major';
78 function summary($rev) {
79 if ( ($summary = $rev->get('summary')) )
82 switch ($this->status($rev)) {
86 return _("New page.");
93 class _RecentChanges_HtmlFormatter
94 extends _RecentChanges_Formatter
96 function diffLink ($rev) {
97 return QElement('a', array('href' => $this->diffURL($rev), 'class' => 'wikiaction'),
101 function pageLink ($rev) {
102 $page = $rev->getPage();
103 return QElement('a', array('href' => $this->pageURL($rev), 'class' => 'wiki'),
107 function authorLink ($rev) {
108 $author = $rev->get('author');
109 if ( ($url = $this->authorURL($author)) )
110 return QElement('a', array('href' => $url, 'class' => 'wiki'), $author);
112 return htmlspecialchars($author);
116 function rss_icon () {
117 global $request, $rssicon;
119 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
121 $rssicon = 'images/rss.png';
122 return Element('a', array('href' => $rss_url),
123 Element('img', array('src' => DataURL($rssicon),
124 'alt' => _("RSS available"),
125 'class' => 'rssicon')));
128 function description () {
129 extract($this->_args);
131 // FIXME: say something about show_all.
133 if ($show_major && $show_minor)
136 $edits = _("major edits");
138 $edits = _("minor edits");
142 $desc = sprintf(_("The %d most recent %s during the past %.1f days are listed below."),
143 $limit, $edits, $days);
145 $desc = sprintf(_("The %d most recent %s are listed below."),
150 $desc = sprintf(_("The most recent %s during the past %.1f days are listed below."),
153 $desc = sprintf(_("All %s are listed below."), $edits);
155 return htmlspecialchars($desc);
160 extract($this->_args);
161 return htmlspecialchars( $show_minor ? _("RecentEdits") : _("RecentChanges") ) . "\n" . $this->rss_icon();
164 function format ($changes) {
165 $html[] = Element('h2', $this->title());
166 if (($desc = $this->description()))
167 $html[] = Element('p', $desc);
172 while ($rev = $changes->next()) {
173 if (($date = $this->date($rev)) != $last_date) {
175 $html[] = Element('ul', join("\n", $lines));
178 $html[] = QElement('h3', $date);
182 $lines[] = $this->format_revision($rev);
185 $html[] = Element('ul', join("\n", $lines));
186 return join("\n", $html) . "\n";
189 function format_revision ($rev) {
190 if ( ($summary = $this->summary($rev)) ) {
191 $summary = do_transform($summary, 'LinkTransform');
192 $summary = Element('b', array('class' => 'wiki-summary'), "[$summary]");
195 $class = 'rc-' . $this->importance($rev);
197 return Element('li', array('class' => $class),
198 implode(' ', array( $this->diffLink($rev),
199 $this->pageLink($rev),
203 $this->authorLink($rev) )));
209 class _RecentChanges_RssFormatter
210 extends _RecentChanges_Formatter
212 var $_absurls = true;
214 function time ($rev) {
215 return Iso8601DateTime($rev->get('mtime'));
218 function pageURI ($rev) {
219 $page = $rev->getPage();
220 return WikiURL($page->getName(),
221 array('version' => $rev->getVersion()),
225 function format ($changes) {
226 include_once('lib/RssWriter.php');
227 $rss = new RssWriter;
230 $rss->channel($this->channel_properties());
232 if (($props = $this->image_properties()))
234 if (($props = $this->textinput_properties()))
235 $rss->textinput($props);
237 while ($rev = $changes->next()) {
238 $rss->addItem($this->item_properties($rev),
239 $this->pageURI($rev));
243 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
244 ExitWiki(); // NORETURN!!!!
247 function image_properties () {
248 return array('title' => WIKI_NAME,
249 'link' => WikiURL(_("HomePage"), false, 'absurl'),
250 'url' => DataURL($GLOBALS['logo']));
253 function textinput_properties () {
254 return array('title' => _("Search"),
255 'description' => _("Title Search"),
257 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
260 function channel_properties () {
263 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
265 return array('title' => WIKI_NAME,
266 'dc:description' => _("RecentChanges"),
268 'dc:date' => Iso8601DateTime(time()));
270 /* FIXME: other things one might like in <channel>:
279 * rss091:managingEditor
281 * rss091:lastBuildDate
289 function item_properties ($rev) {
290 $page = $rev->getPage();
291 $pagename = $page->getName();
293 return array( 'title' => split_pagename($pagename),
294 'description' => $this->summary($rev),
295 'link' => $this->pageURL($rev),
296 'dc:date' => $this->time($rev),
297 'dc:contributor' => $rev->get('author'),
298 'wiki:version' => $rev->getVersion(),
299 'wiki:importance' => $this->importance($rev),
300 'wiki:status' => $this->status($rev),
301 'wiki:diff' => $this->diffURL($rev),
302 'wiki:history' => $this->historyURL($rev)
307 class WikiPlugin_RecentChanges
310 function getName () {
311 return _("RecentChanges");
314 function getDefaultArguments() {
315 return array('days' => 2,
316 'show_minor' => false,
317 'show_major' => true,
323 function getArgs ($argstr, $request, $defaults = false) {
324 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
326 if ($request->getArg('action') != 'browse')
327 $args['format'] = false; // default -> HTML
329 if ($args['format'] == 'rss' && empty($args['limit']))
330 $args['limit'] = 15; // Fix default value for RSS.
335 function getMostRecentParams ($args) {
338 $params = array('include_minor_revisions' => $show_minor,
339 'exclude_major_revisions' => !$show_major,
340 'include_all_revisions' => !empty($show_all));
343 $params['limit'] = $limit;
346 $params['since'] = time() - 24 * 3600 * $days;
351 function getChanges ($dbi, $args) {
352 return $dbi->mostRecent($this->getMostRecentParams($args));
355 function format ($changes, $args) {
356 if ($args['format'] == 'rss')
357 $fmt = new _RecentChanges_RssFormatter($args);
359 $fmt = new _RecentChanges_HtmlFormatter($args);
360 return $fmt->format($changes);
364 function run ($dbi, $argstr, $request) {
365 $args = $this->getArgs($argstr, $request);
366 // Hack alert: format() is a NORETURN for rss formatters.
367 return $this->format($this->getChanges($dbi, $args), $args);
372 // (c-file-style: "gnu")
377 // c-hanging-comment-ender-p: nil
378 // indent-tabs-mode: nil