2 rcs_id('$Id: RecentChanges.php,v 1.23 2002-01-17 22:52:03 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) {
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, $Theme;
121 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
122 $button = $Theme->makeButton("RSS", $rss_url, 'rssicion');
123 return $button->asHTML();
126 function description () {
127 extract($this->_args);
129 // FIXME: say something about show_all.
131 if ($show_major && $show_minor)
134 $edits = _("major edits");
136 $edits = _("minor edits");
140 $desc = sprintf(_("The %d most recent %s during the past %.1f days are listed below."),
141 $limit, $edits, $days);
143 $desc = sprintf(_("The %d most recent %s are listed below."),
148 $desc = sprintf(_("The most recent %s during the past %.1f days are listed below."),
151 $desc = sprintf(_("All %s are listed below."), $edits);
153 return htmlspecialchars($desc);
158 extract($this->_args);
159 return htmlspecialchars( $show_minor ? _("RecentEdits") : _("RecentChanges") ) . "\n" . $this->rss_icon();
162 function format ($changes) {
163 $html[] = Element('h2', $this->title());
164 if (($desc = $this->description()))
165 $html[] = Element('p', $desc);
170 while ($rev = $changes->next()) {
171 if (($date = $this->date($rev)) != $last_date) {
173 $html[] = Element('ul', join("\n", $lines));
176 $html[] = QElement('h3', $date);
180 $lines[] = $this->format_revision($rev);
183 $html[] = Element('ul', join("\n", $lines));
184 return join("\n", $html) . "\n";
187 function format_revision ($rev) {
188 if (!defined('RC_SEPARATOR_A')) define('RC_SEPARATOR_A', '');
189 if (!defined('RC_SEPARATOR_B')) define('RC_SEPARATOR_B', '...');
191 if ( ($summary = $this->summary($rev)) ) {
192 $summary = do_transform($summary, 'LinkTransform');
193 $summary = Element('strong', array('class' => 'wiki-summary'), "[$summary]");
196 $class = 'rc-' . $this->importance($rev);
198 return Element('li', array('class' => $class),
199 implode(' ', array( $this->diffLink($rev),
200 $this->pageLink($rev),
205 $this->authorLink($rev) )));
211 class _RecentChanges_RssFormatter
212 extends _RecentChanges_Formatter
214 var $_absurls = true;
216 function time ($rev) {
217 return Iso8601DateTime($rev->get('mtime'));
220 function pageURI ($rev) {
221 $page = $rev->getPage();
222 return WikiURL($page->getName(),
223 array('version' => $rev->getVersion()),
227 function format ($changes) {
228 include_once('lib/RssWriter.php');
229 $rss = new RssWriter;
232 $rss->channel($this->channel_properties());
234 if (($props = $this->image_properties()))
236 if (($props = $this->textinput_properties()))
237 $rss->textinput($props);
239 while ($rev = $changes->next()) {
240 $rss->addItem($this->item_properties($rev),
241 $this->pageURI($rev));
245 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
246 ExitWiki(); // NORETURN!!!!
249 function image_properties () {
252 $img_url = $Theme->getImageURL('logo');
256 return array('title' => WIKI_NAME,
257 'link' => WikiURL(_("HomePage"), false, 'absurl'),
261 function textinput_properties () {
262 return array('title' => _("Search"),
263 'description' => _("Title Search"),
265 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
268 function channel_properties () {
271 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
273 return array('title' => WIKI_NAME,
274 'dc:description' => _("RecentChanges"),
276 'dc:date' => Iso8601DateTime(time()));
278 /* FIXME: other things one might like in <channel>:
287 * rss091:managingEditor
289 * rss091:lastBuildDate
297 function item_properties ($rev) {
298 $page = $rev->getPage();
299 $pagename = $page->getName();
301 return array( 'title' => split_pagename($pagename),
302 'description' => $this->summary($rev),
303 'link' => $this->pageURL($rev),
304 'dc:date' => $this->time($rev),
305 'dc:contributor' => $rev->get('author'),
306 'wiki:version' => $rev->getVersion(),
307 'wiki:importance' => $this->importance($rev),
308 'wiki:status' => $this->status($rev),
309 'wiki:diff' => $this->diffURL($rev),
310 'wiki:history' => $this->historyURL($rev)
315 class WikiPlugin_RecentChanges
318 function getName () {
319 return _("RecentChanges");
322 function getDefaultArguments() {
323 return array('days' => 2,
324 'show_minor' => false,
325 'show_major' => true,
331 function getArgs ($argstr, $request, $defaults = false) {
332 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
334 if ($request->getArg('action') != 'browse')
335 $args['format'] = false; // default -> HTML
337 if ($args['format'] == 'rss' && empty($args['limit']))
338 $args['limit'] = 15; // Fix default value for RSS.
343 function getMostRecentParams ($args) {
346 $params = array('include_minor_revisions' => $show_minor,
347 'exclude_major_revisions' => !$show_major,
348 'include_all_revisions' => !empty($show_all));
351 $params['limit'] = $limit;
354 $params['since'] = time() - 24 * 3600 * $days;
359 function getChanges ($dbi, $args) {
360 return $dbi->mostRecent($this->getMostRecentParams($args));
363 function format ($changes, $args) {
364 if ($args['format'] == 'rss')
365 $fmt = new _RecentChanges_RssFormatter($args);
367 $fmt = new _RecentChanges_HtmlFormatter($args);
368 return $fmt->format($changes);
372 function run ($dbi, $argstr, $request) {
373 $args = $this->getArgs($argstr, $request);
374 // Hack alert: format() is a NORETURN for rss formatters.
375 return $this->format($this->getChanges($dbi, $args), $args);
380 // (c-file-style: "gnu")
385 // c-hanging-comment-ender-p: nil
386 // indent-tabs-mode: nil