2 rcs_id('$Id: RecentChanges.php,v 1.20 2002-01-11 01:46:47 dairiki 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 preg_replace('/^0/', ' ',
30 strtolower(strftime("%I:%M %p",
31 $rev->get('mtime'))));
34 function diffURL ($rev) {
35 $args = $this->_diffargs;
36 if ($this->include_versions_in_URLs())
37 $args['version'] = $rev->getVersion();
38 $page = $rev->getPage();
39 return WikiURL($page->getName(), $args, $this->_absurls);
42 function historyURL ($rev) {
43 $page = $rev->getPage();
44 return WikiURL(_("PageHistory"),
45 array('page' => $page->getName()),
49 function pageURL ($rev) {
51 if ($this->include_versions_in_URLs())
52 $params['version'] = $rev->getVersion();
53 $page = $rev->getPage();
54 return WikiURL($page->getName(), $params, $this->_absurls);
57 function authorURL($author) {
58 global $WikiNameRegexp, $dbi;
60 if (preg_match("/^$WikiNameRegexp\$/", $author) && $dbi->isWikiPage($author))
61 return WikiURL($author);
66 function status ($rev) {
67 if ($rev->hasDefaultContents())
69 $page = $rev->getPage();
70 $prev = $page->getRevisionBefore($rev->getVersion());
71 if ($prev->hasDefaultContents())
76 function importance ($rev) {
77 return $rev->get('is_minor_edit') ? 'minor' : 'major';
80 function summary($rev) {
81 if ( ($summary = $rev->get('summary')) )
84 switch ($this->status($rev)) {
88 return _("New page.");
95 class _RecentChanges_HtmlFormatter
96 extends _RecentChanges_Formatter
98 function diffLink ($rev) {
99 return QElement('a', array('href' => $this->diffURL($rev), 'class' => 'wikiaction'),
103 function pageLink ($rev) {
104 $page = $rev->getPage();
105 return QElement('a', array('href' => $this->pageURL($rev), 'class' => 'wiki'),
109 function authorLink ($rev) {
110 $author = $rev->get('author');
111 if ( ($url = $this->authorURL($author)) )
112 return QElement('a', array('href' => $url, 'class' => 'wiki'), $author);
114 return htmlspecialchars($author);
118 function rss_icon () {
119 global $request, $rssicon;
121 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
123 $rssicon = 'images/rss.png';
124 return Element('a', array('href' => $rss_url),
125 Element('img', array('src' => DataURL($rssicon),
126 'alt' => _("RSS available"),
127 'class' => 'rssicon')));
130 function description () {
131 extract($this->_args);
133 // FIXME: say something about show_all.
135 if ($show_major && $show_minor)
138 $edits = _("major edits");
140 $edits = _("minor edits");
144 $desc = sprintf(_("The %d most recent %s during the past %.1f days are listed below."),
145 $limit, $edits, $days);
147 $desc = sprintf(_("The %d most recent %s are listed below."),
152 $desc = sprintf(_("The most recent %s during the past %.1f days are listed below."),
155 $desc = sprintf(_("All %s are listed below."), $edits);
157 return htmlspecialchars($desc);
162 extract($this->_args);
163 return htmlspecialchars( $show_minor ? _("RecentEdits") : _("RecentChanges") ) . "\n" . $this->rss_icon();
166 function format ($changes) {
167 $html[] = Element('h2', $this->title());
168 if (($desc = $this->description()))
169 $html[] = Element('p', $desc);
174 while ($rev = $changes->next()) {
175 if (($date = $this->date($rev)) != $last_date) {
177 $html[] = Element('ul', join("\n", $lines));
180 $html[] = QElement('h3', $date);
184 $lines[] = $this->format_revision($rev);
187 $html[] = Element('ul', join("\n", $lines));
188 return join("\n", $html) . "\n";
191 function format_revision ($rev) {
192 if (!defined('RC_SEPARATOR_A')) define('RC_SEPARATOR_A', '');
193 if (!defined('RC_SEPARATOR_B')) define('RC_SEPARATOR_B', '...');
195 if ( ($summary = $this->summary($rev)) ) {
196 $summary = do_transform($summary, 'LinkTransform');
197 $summary = Element('strong', array('class' => 'wiki-summary'), "[$summary]");
200 $class = 'rc-' . $this->importance($rev);
202 return Element('li', array('class' => $class),
203 implode(' ', array( $this->diffLink($rev),
204 $this->pageLink($rev),
209 $this->authorLink($rev) )));
215 class _RecentChanges_RssFormatter
216 extends _RecentChanges_Formatter
218 var $_absurls = true;
220 function time ($rev) {
221 return Iso8601DateTime($rev->get('mtime'));
224 function pageURI ($rev) {
225 $page = $rev->getPage();
226 return WikiURL($page->getName(),
227 array('version' => $rev->getVersion()),
231 function format ($changes) {
232 include_once('lib/RssWriter.php');
233 $rss = new RssWriter;
236 $rss->channel($this->channel_properties());
238 if (($props = $this->image_properties()))
240 if (($props = $this->textinput_properties()))
241 $rss->textinput($props);
243 while ($rev = $changes->next()) {
244 $rss->addItem($this->item_properties($rev),
245 $this->pageURI($rev));
249 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
250 ExitWiki(); // NORETURN!!!!
253 function image_properties () {
254 return array('title' => WIKI_NAME,
255 'link' => WikiURL(_("HomePage"), false, 'absurl'),
256 'url' => DataURL($GLOBALS['logo']));
259 function textinput_properties () {
260 return array('title' => _("Search"),
261 'description' => _("Title Search"),
263 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
266 function channel_properties () {
269 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
271 return array('title' => WIKI_NAME,
272 'dc:description' => _("RecentChanges"),
274 'dc:date' => Iso8601DateTime(time()));
276 /* FIXME: other things one might like in <channel>:
285 * rss091:managingEditor
287 * rss091:lastBuildDate
295 function item_properties ($rev) {
296 $page = $rev->getPage();
297 $pagename = $page->getName();
299 return array( 'title' => split_pagename($pagename),
300 'description' => $this->summary($rev),
301 'link' => $this->pageURL($rev),
302 'dc:date' => $this->time($rev),
303 'dc:contributor' => $rev->get('author'),
304 'wiki:version' => $rev->getVersion(),
305 'wiki:importance' => $this->importance($rev),
306 'wiki:status' => $this->status($rev),
307 'wiki:diff' => $this->diffURL($rev),
308 'wiki:history' => $this->historyURL($rev)
313 class WikiPlugin_RecentChanges
316 function getName () {
317 return _("RecentChanges");
320 function getDefaultArguments() {
321 return array('days' => 2,
322 'show_minor' => false,
323 'show_major' => true,
329 function getArgs ($argstr, $request, $defaults = false) {
330 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
332 if ($request->getArg('action') != 'browse')
333 $args['format'] = false; // default -> HTML
335 if ($args['format'] == 'rss' && empty($args['limit']))
336 $args['limit'] = 15; // Fix default value for RSS.
341 function getMostRecentParams ($args) {
344 $params = array('include_minor_revisions' => $show_minor,
345 'exclude_major_revisions' => !$show_major,
346 'include_all_revisions' => !empty($show_all));
349 $params['limit'] = $limit;
352 $params['since'] = time() - 24 * 3600 * $days;
357 function getChanges ($dbi, $args) {
358 return $dbi->mostRecent($this->getMostRecentParams($args));
361 function format ($changes, $args) {
362 if ($args['format'] == 'rss')
363 $fmt = new _RecentChanges_RssFormatter($args);
365 $fmt = new _RecentChanges_HtmlFormatter($args);
366 return $fmt->format($changes);
370 function run ($dbi, $argstr, $request) {
371 $args = $this->getArgs($argstr, $request);
372 // Hack alert: format() is a NORETURN for rss formatters.
373 return $this->format($this->getChanges($dbi, $args), $args);
378 // (c-file-style: "gnu")
383 // c-hanging-comment-ender-p: nil
384 // indent-tabs-mode: nil