2 rcs_id('$Id: RecentChanges.php,v 1.18 2002-01-05 18:33:51 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 (!defined('RC_SEPARATOR_A')) define('RC_SEPARATOR_A', '');
191 if (!defined('RC_SEPARATOR_B')) define('RC_SEPARATOR_B', '...');
193 if ( ($summary = $this->summary($rev)) ) {
194 $summary = do_transform($summary, 'LinkTransform');
195 $summary = Element('b', array('class' => 'wiki-summary'), "[$summary]");
198 $class = 'rc-' . $this->importance($rev);
200 return Element('li', array('class' => $class),
201 implode(' ', array( $this->diffLink($rev),
202 $this->pageLink($rev),
207 $this->authorLink($rev) )));
213 class _RecentChanges_RssFormatter
214 extends _RecentChanges_Formatter
216 var $_absurls = true;
218 function time ($rev) {
219 return Iso8601DateTime($rev->get('mtime'));
222 function pageURI ($rev) {
223 $page = $rev->getPage();
224 return WikiURL($page->getName(),
225 array('version' => $rev->getVersion()),
229 function format ($changes) {
230 include_once('lib/RssWriter.php');
231 $rss = new RssWriter;
234 $rss->channel($this->channel_properties());
236 if (($props = $this->image_properties()))
238 if (($props = $this->textinput_properties()))
239 $rss->textinput($props);
241 while ($rev = $changes->next()) {
242 $rss->addItem($this->item_properties($rev),
243 $this->pageURI($rev));
247 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
248 ExitWiki(); // NORETURN!!!!
251 function image_properties () {
252 return array('title' => WIKI_NAME,
253 'link' => WikiURL(_("HomePage"), false, 'absurl'),
254 'url' => DataURL($GLOBALS['logo']));
257 function textinput_properties () {
258 return array('title' => _("Search"),
259 'description' => _("Title Search"),
261 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
264 function channel_properties () {
267 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
269 return array('title' => WIKI_NAME,
270 'dc:description' => _("RecentChanges"),
272 'dc:date' => Iso8601DateTime(time()));
274 /* FIXME: other things one might like in <channel>:
283 * rss091:managingEditor
285 * rss091:lastBuildDate
293 function item_properties ($rev) {
294 $page = $rev->getPage();
295 $pagename = $page->getName();
297 return array( 'title' => split_pagename($pagename),
298 'description' => $this->summary($rev),
299 'link' => $this->pageURL($rev),
300 'dc:date' => $this->time($rev),
301 'dc:contributor' => $rev->get('author'),
302 'wiki:version' => $rev->getVersion(),
303 'wiki:importance' => $this->importance($rev),
304 'wiki:status' => $this->status($rev),
305 'wiki:diff' => $this->diffURL($rev),
306 'wiki:history' => $this->historyURL($rev)
311 class WikiPlugin_RecentChanges
314 function getName () {
315 return _("RecentChanges");
318 function getDefaultArguments() {
319 return array('days' => 2,
320 'show_minor' => false,
321 'show_major' => true,
327 function getArgs ($argstr, $request, $defaults = false) {
328 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
330 if ($request->getArg('action') != 'browse')
331 $args['format'] = false; // default -> HTML
333 if ($args['format'] == 'rss' && empty($args['limit']))
334 $args['limit'] = 15; // Fix default value for RSS.
339 function getMostRecentParams ($args) {
342 $params = array('include_minor_revisions' => $show_minor,
343 'exclude_major_revisions' => !$show_major,
344 'include_all_revisions' => !empty($show_all));
347 $params['limit'] = $limit;
350 $params['since'] = time() - 24 * 3600 * $days;
355 function getChanges ($dbi, $args) {
356 return $dbi->mostRecent($this->getMostRecentParams($args));
359 function format ($changes, $args) {
360 if ($args['format'] == 'rss')
361 $fmt = new _RecentChanges_RssFormatter($args);
363 $fmt = new _RecentChanges_HtmlFormatter($args);
364 return $fmt->format($changes);
368 function run ($dbi, $argstr, $request) {
369 $args = $this->getArgs($argstr, $request);
370 // Hack alert: format() is a NORETURN for rss formatters.
371 return $this->format($this->getChanges($dbi, $args), $args);
376 // (c-file-style: "gnu")
381 // c-hanging-comment-ender-p: nil
382 // indent-tabs-mode: nil