2 rcs_id('$Id: RecentChanges.php,v 1.48 2002-01-31 03:18:42 dairiki Exp $');
7 class _RecentChanges_Formatter
11 function _RecentChanges_Formatter ($rc_args) {
12 $this->_args = $rc_args;
13 $this->_diffargs = array('action' => 'diff');
15 if ($rc_args['show_minor'] || !$rc_args['show_major'])
16 $this->_diffargs['previous'] = 'minor';
19 function include_versions_in_URLs() {
20 return (bool) $this->_args['show_all'];
23 function date ($rev) {
25 return $Theme->formatDate($rev->get('mtime'));
28 function time ($rev) {
30 return $Theme->formatTime($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 historyURL ($rev) {
42 $page = $rev->getPage();
43 return WikiURL($page, array('action' => _("PageHistory")),
47 function pageURL ($rev) {
48 return WikiURL($this->include_versions_in_URLs() ? $rev : $page,
52 function authorHasPage ($author) {
53 global $WikiNameRegexp, $request;
54 $dbi = $request->getDbh();
55 return preg_match("/^$WikiNameRegexp\$/", $author) && $dbi->isWikiPage($author);
58 function authorURL ($author) {
59 return $this->authorHasPage() ? WikiURL($author) : false;
63 function status ($rev) {
64 if ($rev->hasDefaultContents())
66 $page = $rev->getPage();
67 $prev = $page->getRevisionBefore($rev->getVersion());
68 if ($prev->hasDefaultContents())
73 function importance ($rev) {
74 return $rev->get('is_minor_edit') ? 'minor' : 'major';
77 function summary($rev) {
78 if ( ($summary = $rev->get('summary')) )
81 switch ($this->status($rev)) {
85 return _("New page.");
92 class _RecentChanges_HtmlFormatter
93 extends _RecentChanges_Formatter
95 function diffLink ($rev) {
97 return $Theme->makeButton(_("(diff)"), $this->diffURL($rev), 'wiki-rc-action');
100 function pageLink ($rev) {
101 $page = $rev->getPage();
103 if ($this->include_versions_in_URLs()) {
104 $version = $rev->getVersion();
105 $exists = !$rev->hasDefaultContents();
109 $cur = $page->getCurrentRevision();
110 $exists = !$cur->hasDefaultContents();
113 return $Theme->linkExistingWikiWord($page->getName(), false, $version);
115 return $Theme->linkUnknownWikiWord($page->getName(), false, $version);
118 function authorLink ($rev) {
119 $author = $rev->get('author');
120 if ( $this->authorHasPage($author) ) {
121 return WikiLink($author);
126 function summaryAsHTML ($rev) {
127 if ( !($summary = $this->summary($rev)) )
129 return HTML::strong( array('class' => 'wiki-summary'),
131 do_transform($summary, 'LinkTransform'),
135 function rss_icon () {
136 global $request, $Theme;
138 $rss_url = $request->getURLtoSelf(array('format' => 'rss'));
139 return $Theme->makeButton("RSS", $rss_url, 'rssicion');
142 function description () {
143 extract($this->_args);
145 // FIXME: say something about show_all.
147 if ($show_major && $show_minor)
150 $edits = _("major edits");
152 $edits = _("minor edits");
156 $desc = fmt("The %d most recent %s during the past %.1f days are listed below.",
157 $limit, $edits, $days);
159 $desc = fmt("The %d most recent %s are listed below.",
164 $desc = fmt("The most recent %s during the past %.1f days are listed below.",
167 $desc = fmt("All %s are listed below.", $edits);
174 extract($this->_args);
175 return array($show_minor ? _("RecentEdits") : _("RecentChanges"),
180 function format ($changes) {
181 $html = HTML(HTML::h2(false, $this->title()));
182 if (($desc = $this->description()))
183 $html->pushContent(HTML::p(false, $desc));
188 while ($rev = $changes->next()) {
189 if (($date = $this->date($rev)) != $last_date) {
191 $html->pushContent($lines);
192 $html->pushContent(HTML::h3($date));
196 $lines->pushContent($this->format_revision($rev));
199 $html->pushContent($lines);
203 function format_revision ($rev) {
204 $class = 'rc-' . $this->importance($rev);
206 return HTML::li(array('class' => $class),
207 $this->diffLink($rev), ' ',
208 $this->pageLink($rev), ' ',
209 $rev->get('is_minor_edit') ? $this->time($rev) : HTML::strong($this->time($rev)), ' ',
210 $this->summaryAsHTML($rev),
212 $this->authorLink($rev));
217 class _RecentChanges_RssFormatter
218 extends _RecentChanges_Formatter
220 var $_absurls = true;
222 function time ($rev) {
223 return Iso8601DateTime($rev->get('mtime'));
226 function pageURI ($rev) {
227 return WikiURL($rev, '', 'absurl');
230 function format ($changes) {
231 include_once('lib/RssWriter.php');
232 $rss = new RssWriter;
235 $rss->channel($this->channel_properties());
237 if (($props = $this->image_properties()))
239 if (($props = $this->textinput_properties()))
240 $rss->textinput($props);
242 while ($rev = $changes->next()) {
243 $rss->addItem($this->item_properties($rev),
244 $this->pageURI($rev));
248 printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
250 global $request; // FIXME
251 $request->finish(); // NORETURN!!!!
254 function image_properties () {
257 $img_url = $Theme->getImageURL('logo');
261 return array('title' => WIKI_NAME,
262 'link' => WikiURL(HomePage, false, 'absurl'),
266 function textinput_properties () {
267 return array('title' => _("Search"),
268 'description' => _("Title Search"),
270 'link' => WikiURL(_("TitleSearch"), false, 'absurl'));
273 function channel_properties () {
276 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
278 return array('title' => WIKI_NAME,
279 'dc:description' => _("RecentChanges"),
281 'dc:date' => Iso8601DateTime(time()));
283 /* FIXME: other things one might like in <channel>:
292 * rss091:managingEditor
294 * rss091:lastBuildDate
302 function item_properties ($rev) {
303 $page = $rev->getPage();
304 $pagename = $page->getName();
306 return array( 'title' => split_pagename($pagename),
307 'description' => $this->summary($rev),
308 'link' => $this->pageURL($rev),
309 'dc:date' => $this->time($rev),
310 'dc:contributor' => $rev->get('author'),
311 'wiki:version' => $rev->getVersion(),
312 'wiki:importance' => $this->importance($rev),
313 'wiki:status' => $this->status($rev),
314 'wiki:diff' => $this->diffURL($rev),
315 'wiki:history' => $this->historyURL($rev)
320 class NonDeletedRevisionIterator extends WikiDB_PageRevisionIterator
324 * @param $revisions object a WikiDB_PageRevisionIterator.
326 function NonDeletedRevisionIterator ($revisions, $check_current_revision = true) {
327 $this->_revisions = $revisions;
328 $this->_check_current_revision = $check_current_revision;
332 while (($rev = $this->_revisions->next())) {
333 if ($this->_check_current_revision) {
334 $page = $rev->getPage();
335 $check_rev = $page->getCurrentRevision();
340 if (! $check_rev->hasDefaultContents())
348 $this->_revisions->free();
352 class WikiPlugin_RecentChanges
355 function getName () {
356 return _("RecentChanges");
359 function getDefaultArguments() {
360 return array('days' => 2,
361 'show_minor' => false,
362 'show_major' => true,
364 'show_deleted' => 'sometimes',
372 function getArgs ($argstr, $request, $defaults = false) {
373 $args = WikiPlugin::getArgs($argstr, $request, $defaults);
375 $action = $request->getArg('action');
376 if ($action != 'browse' && ! $request->isActionPage($action))
377 $args['format'] = false; // default -> HTML
379 if ($args['format'] == 'rss' && empty($args['limit']))
380 $args['limit'] = 15; // Fix default value for RSS.
385 function getMostRecentParams ($args) {
388 $params = array('include_minor_revisions' => $show_minor,
389 'exclude_major_revisions' => !$show_major,
390 'include_all_revisions' => !empty($show_all));
393 $params['limit'] = $limit;
396 $params['since'] = time() - 24 * 3600 * $days;
401 function getChanges ($dbi, $args) {
402 $changes = $dbi->mostRecent($this->getMostRecentParams($args));
404 $show_deleted = $args['show_deleted'];
405 if ($show_deleted == 'sometimes')
406 $show_deleted = $args['show_minor'];
409 $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
414 function format ($changes, $args) {
416 $format = $args['format'];
418 $fmt_class = $Theme->getFormatter('RecentChanges', $format);
420 if ($format == 'rss')
421 $fmt_class = '_RecentChanges_RssFormatter';
422 elseif ($format == 'rss091') {
423 include_once "lib/RSSWriter091.php";
424 $fmt_class = '_RecentChanges_RssFormatter091';
427 $fmt_class = '_RecentChanges_HtmlFormatter';
430 $fmt = new $fmt_class($args);
431 return $fmt->format($changes);
434 function run ($dbi, $argstr, $request) {
435 $args = $this->getArgs($argstr, $request);
437 if (! $args['daylist']) {
438 // Display RecentChanges
440 // Hack alert: format() is a NORETURN for rss formatters.
441 return $this->format($this->getChanges($dbi, $args), $args);
443 // Display days selection buttons
446 $daysarray = explode(",", $daylist);
449 $url_show_minor = "";
453 if (($show_minor == 1)||($show_minor == true))
454 $url_show_minor = "&show_minor=1";
455 if (($show_all == 1)||($show_all == true))
456 $url_show_all = "&show_all=1";
460 $caption = _("Show changes for:");
463 $caption = _("Show all changes for:");
465 $caption = _("Show minor edits for:");
469 $b = new buttonSet();
470 $b->caption = $caption;
472 foreach ($daysarray as $daynum) {
477 $label = "..."; //alldays
479 $label = sprintf(_("%s days"), $daynum);
481 // Build the button's url
482 $b->addButton($label, "RecentChanges?days=" .$daynum
483 .$url_show_minor .$url_show_all,
486 return HTML::div(array('class'=>'wiki-rc-action'), $b->getContent());
493 function buttonSet() {
499 function addButton($label, $url, $action) {
501 $this->_b[] = $Theme->makeButton($label, $url, $action);
504 function getContent() {
505 if (empty($this->content))
506 $this->_generateContent();
507 return $this->content;
510 function _generateContent() {
511 $this->content = HTML::p($this->caption . " ");
512 // Avoid an extraneous ButtonSeparator
513 $this->content->pushContent(array_shift($this->_b));
516 foreach ($this->_b as $button) {
517 $this->content->pushContent($Theme->getButtonSeparator());
518 $this->content->pushContent($button);
525 // (c-file-style: "gnu")
530 // c-hanging-comment-ender-p: nil
531 // indent-tabs-mode: nil