2 rcs_id('$Id: RecentChanges.php,v 1.6 2001-12-14 20:24:25 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 // FIXME: Make configurable.
30 return strftime("%l:%M %p", $rev->get('mtime'));
33 function diffURL ($rev) {
34 $args = $this->_diffargs;
35 if ($this->include_versions_in_URLs())
36 $args['version'] = $rev->getVersion();
37 $page = $rev->getPage();
38 return WikiURL($page->getName(), $args, $this->_absurls);
41 function pageURL ($rev) {
43 if ($this->include_versions_in_URLs())
44 $params['version'] = $rev->getVersion();
45 $page = $rev->getPage();
46 return WikiURL($page->getName(), $params, $this->_absurls);
49 function authorURL($author) {
50 global $WikiNameRegexp, $dbi;
52 if (preg_match("/^$WikiNameRegexp\$/", $author) && $dbi->isWikiPage($author))
53 return WikiURL($author);
58 function status ($rev) {
59 if ($rev->hasDefaultContents())
61 $page = $rev->getPage();
62 $prev = $page->getRevisionBefore($rev->getVersion());
63 if ($prev->hasDefaultContents())
68 function importance ($rev) {
69 return $rev->get('is_minor_edit') ? 'minor' : 'major';
72 function summary($rev) {
73 if ( ($summary = $rev->get('summary')) )
76 switch ($this->status($rev)) {
80 return _("New page.");
87 class _RecentChanges_HtmlFormatter
88 extends _RecentChanges_Formatter
90 function diffLink ($rev) {
91 return QElement('a', array('href' => $this->diffURL($rev)),
95 function pageLink ($rev) {
96 $page = $rev->getPage();
97 return QElement('a', array('href' => $this->pageURL($rev), 'class' => 'wiki'),
101 function authorLink ($rev) {
102 $author = $rev->get('author');
103 if ( ($url = $this->authorURL($author)) )
104 return QElement('a', array('href' => $url, 'class' => 'wiki'), $author);
106 return htmlspecialchars($author);
110 function rss_icon () {
113 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
114 return Element('a', array('href' => $rss_url),
115 Element('img', array('src' => DataURL('images/rss.png'),
116 'alt' => _("RSS available"),
117 'class' => 'rssicon')));
120 function description () {
121 extract($this->_args);
123 // FIXME: say something about show_all.
125 if ($show_major && $show_minor)
128 $edits = _("major edits");
130 $edits = _("minor edits");
134 $desc = sprintf(_("The %d most recent %s during the past %.1f days are listed below."),
135 $limit, $edits, $days);
137 $desc = sprintf(_("The %d most recent %s are listed below."),
142 $desc = sprintf(_("The most recent %s during the past %.1f days are listed below."),
145 $desc = sprintf(_("All %s are listed below."), $edits);
147 return htmlspecialchars($desc);
152 return htmlspecialchars(_("RecentChanges")) . "\n" . $this->rss_icon();
155 function format ($changes) {
156 $html[] = Element('h2', $this->title());
157 if (($desc = $this->description()))
158 $html[] = Element('p', $desc);
163 while ($rev = $changes->next()) {
164 if (($date = $this->date($rev)) != $last_date) {
166 $html[] = Element('ul', join("\n", $lines));
169 $html[] = QElement('h3', $date);
173 $lines[] = $this->format_revision($rev);
176 $html[] = Element('ul', join("\n", $lines));
177 return join("\n", $html) . "\n";
180 function format_revision ($rev) {
181 if ( ($summary = $this->summary($rev)) )
182 $summary = QElement('b', "[$summary]");
184 $class = 'rc-' . $this->importance($rev);
186 return Element('li', array('class' => $class),
187 implode(' ', array( $this->diffLink($rev),
188 $this->pageLink($rev),
192 $this->authorLink($rev) )));
198 class _RecentChanges_RssFormatter
199 extends _RecentChanges_Formatter
201 var $_absurls = true;
203 function time ($rev) {
204 return Iso8601DateTime($rev->get('mtime'));
207 function pageURI ($rev) {
208 $page = $rev->getPage();
209 return WikiURL($page->getName(),
210 array('version' => $rev->getVersion()),
214 function format ($changes) {
215 include_once('lib/RssWriter.php');
216 $rss = new RssWriter;
219 $rss->channel($this->channel_properties());
221 if (($props = $this->image_properties()))
223 if (($props = $this->textinput_properties()))
224 $rss->textinput($props);
226 while ($rev = $changes->next()) {
227 $rss->addItem($this->item_properties($rev),
228 $this->pageURI($rev));
232 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
233 ExitWiki(); // NORETURN!!!!
236 function image_properties () {
237 return array('title' => WIKI_NAME,
238 'link' => WikiURL(_("HomePage"), false, 'absurl'),
239 'url' => DataURL($GLOBALS['logo']));
242 function textinput_properties () {
243 return array('title' => _("Search"),
244 'description' => _("Title Search"),
246 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
249 function channel_properties () {
252 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
254 return array('title' => WIKI_NAME,
255 'dc:description' => _("RecentChanges"),
257 'dc:date' => Iso8601DateTime(time()));
259 /* FIXME: other things one might like in <channel>:
268 * rss091:managingEditor
270 * rss091:lastBuildDate
278 function item_properties ($rev) {
279 $page = $rev->getPage();
280 $pagename = $page->getName();
282 return array( 'title' => split_pagename($pagename),
283 'description' => $this->summary($rev),
284 'link' => $this->pageURL($rev),
285 'dc:date' => $this->time($rev),
286 'dc:contributor' => $rev->get('author'),
287 'wiki:version' => $rev->getVersion(),
288 'wiki:importance' => $this->importance($rev),
289 'wiki:status' => $this->status($rev),
290 'wiki:diff' => $this->diffURL($rev),
291 'wiki:history' => WikiURL($pagename,
292 array('action' => 'info'),
298 class WikiPlugin_RecentChanges
301 var $name = 'RecentChanges';
303 function getDefaultArguments() {
304 return array('days' => 2,
305 'show_minor' => false,
306 'show_major' => true,
312 function getArgs ($argstr, $request, $defaults = false) {
313 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
315 if ($request->getArg('action') != 'browse')
316 $args['format'] = false; // default -> HTML
318 if ($args['format'] == 'rss' && empty($args['limit']))
319 $args['limit'] = 15; // Fix default value for RSS.
324 function getMostRecentParams ($args) {
327 $params = array('include_minor_revisions' => $show_minor,
328 'exclude_major_revisions' => !$show_major,
329 'include_all_revisions' => !empty($show_all));
332 $params['limit'] = $limit;
335 $params['since'] = time() - 24 * 3600 * $days;
340 function getChanges ($dbi, $args) {
341 return $dbi->mostRecent($this->getMostRecentParams($args));
344 function format ($changes, $args) {
345 if ($args['format'] == 'rss')
346 $fmt = new _RecentChanges_RssFormatter($args);
348 $fmt = new _RecentChanges_HtmlFormatter($args);
349 return $fmt->format($changes);
353 function run ($dbi, $argstr, $request) {
354 $args = $this->getArgs($argstr, $request);
355 // Hack alert: format() is a NORETURN for rss formatters.
356 return $this->format($this->getChanges($dbi, $args), $args);
361 // (c-file-style: "gnu")
366 // c-hanging-comment-ender-p: nil
367 // indent-tabs-mode: nil