2 rcs_id('$Id: RecentChanges.php,v 1.26 2002-01-21 06:55: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) {
26 return $Theme->formatDate($rev->get('mtime'));
29 function time ($rev) {
31 return $Theme->formatTime($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) {
100 return $Theme->makeButton(_("Diff"), $this->diffURL($rev), 'wikiaction');
103 function pageLink ($rev) {
104 $page = $rev->getPage();
105 return HTML::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 HTML::a(array('href' => $url, 'class' => 'wiki'), $author);
117 function summaryAsHTML ($rev) {
118 if ( !($summary = $this->summary($rev)) )
120 return HTML::strong( array('class' => 'wiki-summary'),
122 do_transform($summary, 'LinkTransform'),
126 function rss_icon () {
127 global $request, $Theme;
129 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
130 return $Theme->makeButton("RSS", $rss_url, 'rssicion');
133 function description () {
134 extract($this->_args);
136 // FIXME: say something about show_all.
138 if ($show_major && $show_minor)
141 $edits = _("major edits");
143 $edits = _("minor edits");
147 $desc = fmt("The %d most recent %s during the past %.1f days are listed below.",
148 $limit, $edits, $days);
150 $desc = fmt("The %d most recent %s are listed below.",
155 $desc = fmt("The most recent %s during the past %.1f days are listed below.",
158 $desc = fmt("All %s are listed below.", $edits);
165 extract($this->_args);
166 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
171 function format ($changes) {
172 $html[] = HTML::h2(false, $this->title());
173 if (($desc = $this->description()))
174 $html[] = HTML::p(false, $desc);
179 while ($rev = $changes->next()) {
180 if (($date = $this->date($rev)) != $last_date) {
183 $html[] = HTML::h3($date);
187 $lines->pushContent($this->format_revision($rev));
194 function format_revision ($rev) {
195 $class = 'rc-' . $this->importance($rev);
197 return HTML::li(array('class' => $class),
198 $this->diffLink($rev), ' ',
199 $this->pageLink($rev), ' ',
200 $this->time($rev), ' ',
201 $this->summaryAsHTML($rev),
203 $this->authorLink($rev));
208 class _RecentChanges_RssFormatter
209 extends _RecentChanges_Formatter
211 var $_absurls = true;
213 function time ($rev) {
214 return Iso8601DateTime($rev->get('mtime'));
217 function pageURI ($rev) {
218 $page = $rev->getPage();
219 return WikiURL($page->getName(),
220 array('version' => $rev->getVersion()),
224 function format ($changes) {
225 include_once('lib/RssWriter.php');
226 $rss = new RssWriter;
229 $rss->channel($this->channel_properties());
231 if (($props = $this->image_properties()))
233 if (($props = $this->textinput_properties()))
234 $rss->textinput($props);
236 while ($rev = $changes->next()) {
237 $rss->addItem($this->item_properties($rev),
238 $this->pageURI($rev));
242 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
243 ExitWiki(); // NORETURN!!!!
246 function image_properties () {
249 $img_url = $Theme->getImageURL('logo');
253 return array('title' => WIKI_NAME,
254 'link' => WikiURL(_("HomePage"), false, 'absurl'),
258 function textinput_properties () {
259 return array('title' => _("Search"),
260 'description' => _("Title Search"),
262 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
265 function channel_properties () {
268 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
270 return array('title' => WIKI_NAME,
271 'dc:description' => _("RecentChanges"),
273 'dc:date' => Iso8601DateTime(time()));
275 /* FIXME: other things one might like in <channel>:
284 * rss091:managingEditor
286 * rss091:lastBuildDate
294 function item_properties ($rev) {
295 $page = $rev->getPage();
296 $pagename = $page->getName();
298 return array( 'title' => split_pagename($pagename),
299 'description' => $this->summary($rev),
300 'link' => $this->pageURL($rev),
301 'dc:date' => $this->time($rev),
302 'dc:contributor' => $rev->get('author'),
303 'wiki:version' => $rev->getVersion(),
304 'wiki:importance' => $this->importance($rev),
305 'wiki:status' => $this->status($rev),
306 'wiki:diff' => $this->diffURL($rev),
307 'wiki:history' => $this->historyURL($rev)
312 class WikiPlugin_RecentChanges
315 function getName () {
316 return _("RecentChanges");
319 function getDefaultArguments() {
320 return array('days' => 2,
321 'show_minor' => false,
322 'show_major' => true,
328 function getArgs ($argstr, $request, $defaults = false) {
329 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
331 if ($request->getArg('action') != 'browse')
332 $args['format'] = false; // default -> HTML
334 if ($args['format'] == 'rss' && empty($args['limit']))
335 $args['limit'] = 15; // Fix default value for RSS.
340 function getMostRecentParams ($args) {
343 $params = array('include_minor_revisions' => $show_minor,
344 'exclude_major_revisions' => !$show_major,
345 'include_all_revisions' => !empty($show_all));
348 $params['limit'] = $limit;
351 $params['since'] = time() - 24 * 3600 * $days;
356 function getChanges ($dbi, $args) {
357 return $dbi->mostRecent($this->getMostRecentParams($args));
360 function format ($changes, $args) {
362 $format = $args['format'];
364 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
366 if ($format == 'rss')
367 $fmt_class = '_RecentChanges_RssFormatter';
368 elseif ($format == 'rss091')
370 include_once "lib/RSSWriter091.php";
371 $fmt_class = '_RecentChanges_RssFormatter091';
374 $fmt_class = '_RecentChanges_HtmlFormatter';
377 $fmt = new $fmt_class($args);
378 return $fmt->format($changes);
382 function run ($dbi, $argstr, $request) {
383 $args = $this->getArgs($argstr, $request);
384 // Hack alert: format() is a NORETURN for rss formatters.
385 return $this->format($this->getChanges($dbi, $args), $args);
390 // (c-file-style: "gnu")
395 // c-hanging-comment-ender-p: nil
396 // indent-tabs-mode: nil