2 rcs_id('$Id: RecentChanges.php,v 1.28 2002-01-23 05:10:22 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, $request;
59 $dbi = $request->getDbh();
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']);
244 global $request; // FIXME
245 $request->finish(); // NORETURN!!!!
248 function image_properties () {
251 $img_url = $Theme->getImageURL('logo');
255 return array('title' => WIKI_NAME,
256 'link' => WikiURL(_("HomePage"), false, 'absurl'),
260 function textinput_properties () {
261 return array('title' => _("Search"),
262 'description' => _("Title Search"),
264 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
267 function channel_properties () {
270 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
272 return array('title' => WIKI_NAME,
273 'dc:description' => _("RecentChanges"),
275 'dc:date' => Iso8601DateTime(time()));
277 /* FIXME: other things one might like in <channel>:
286 * rss091:managingEditor
288 * rss091:lastBuildDate
296 function item_properties ($rev) {
297 $page = $rev->getPage();
298 $pagename = $page->getName();
300 return array( 'title' => split_pagename($pagename),
301 'description' => $this->summary($rev),
302 'link' => $this->pageURL($rev),
303 'dc:date' => $this->time($rev),
304 'dc:contributor' => $rev->get('author'),
305 'wiki:version' => $rev->getVersion(),
306 'wiki:importance' => $this->importance($rev),
307 'wiki:status' => $this->status($rev),
308 'wiki:diff' => $this->diffURL($rev),
309 'wiki:history' => $this->historyURL($rev)
314 class WikiPlugin_RecentChanges
317 function getName () {
318 return _("RecentChanges");
321 function getDefaultArguments() {
322 return array('days' => 2,
323 'show_minor' => false,
324 'show_major' => true,
330 function getArgs ($argstr, $request, $defaults = false) {
331 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
333 if ($request->getArg('action') != 'browse')
334 $args['format'] = false; // default -> HTML
336 if ($args['format'] == 'rss' && empty($args['limit']))
337 $args['limit'] = 15; // Fix default value for RSS.
342 function getMostRecentParams ($args) {
345 $params = array('include_minor_revisions' => $show_minor,
346 'exclude_major_revisions' => !$show_major,
347 'include_all_revisions' => !empty($show_all));
350 $params['limit'] = $limit;
353 $params['since'] = time() - 24 * 3600 * $days;
358 function getChanges ($dbi, $args) {
359 return $dbi->mostRecent($this->getMostRecentParams($args));
362 function format ($changes, $args) {
364 $format = $args['format'];
366 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
368 if ($format == 'rss')
369 $fmt_class = '_RecentChanges_RssFormatter';
370 elseif ($format == 'rss091') {
371 include_once "lib/RSSWriter091.php";
372 $fmt_class = '_RecentChanges_RssFormatter091';
375 $fmt_class = '_RecentChanges_HtmlFormatter';
378 $fmt = new $fmt_class($args);
379 return $fmt->format($changes);
383 function run ($dbi, $argstr, $request) {
384 $args = $this->getArgs($argstr, $request);
385 // Hack alert: format() is a NORETURN for rss formatters.
386 return $this->format($this->getChanges($dbi, $args), $args);
391 // (c-file-style: "gnu")
396 // c-hanging-comment-ender-p: nil
397 // indent-tabs-mode: nil