]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChanges.php
Jeff's hacks II, continued:
[SourceForge/phpwiki.git] / lib / plugin / RecentChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RecentChanges.php,v 1.1 2001-09-18 19:19:05 dairiki Exp $');
3 /**
4  */
5 class WikiPlugin_RecentChanges
6 extends WikiPlugin
7 {
8     var $name = 'RecentChanges';
9     
10     function getDefaultArguments() {
11         return array('days'             => 2,
12                      'show_minor'       => false,
13                      'show_major'       => true,
14                      'show_all'         => false);
15     }
16
17     function run($dbi, $argstr, $request) {
18         extract($this->getArgs($argstr, $request));
19         $params = array('include_minor_revisions' => $show_minor,
20                         'exclude_major_revisions' => !$show_major,
21                         'include_all_revisions' => $show_all);
22         if ($days > 0.0) {
23             $params['since'] = time() - 24 * 3600 * $days;
24             $html = "<h3>RecentChanges in the last $days days</h3>\n";
25         }
26         else {
27             $html = sprintf("<h3>RecentChanges</h3>\n", $days);
28         }
29              
30         $changes = $dbi->mostRecent($params);
31
32         global $dateformat;
33         global $WikiNameRegexp;
34         
35         $last_date = '';
36         $lines = array();
37
38         $diffargs = array('action' => 'diff');
39
40         while ($rev = $changes->next()) {
41             $created = $rev->get('mtime');
42             $date = strftime($dateformat, $created);
43             $time = strftime("%l:%M %P", $created); // Make configurable.
44             if ($date != $last_date) {
45                 if ($lines) {
46                     $html .= Element('ul', join("\n", $lines));
47                     $lines = array();
48                 }
49                 $html .= Element('p',QElement('b', $date));
50                 $last_date = $date;
51             }
52             
53             $page = $rev->getPage();
54             $pagename = $page->getName();
55
56             if ($show_all) {
57                 // FIXME: should set previous, too, if showing only minor or major revs.
58                 //  or maybe difftype.
59                 $diffargs['version'] = $rev->getVersion();
60             }
61             
62             $diff = QElement('a',
63                              array('href' => WikiURL($pagename, $diffargs)),
64                              "(diff)");
65             
66             $wikipage = LinkWikiWord($page->getName());
67
68             $author = $rev->get('author');
69             if (preg_match("/^$WikiNameRegexp\$/", $author))
70                 $author = LinkWikiWord($author);
71             else
72                 $author = htmlspecialchars($author);
73
74             $summary = $rev->get('summary');
75             if ($summary)
76                 $summary = QElement('b', "[$summary]");
77             
78             $lines[] = Element('li',
79                                "$diff $wikipage $time $summary ... $author");
80         }
81         if ($lines)
82             $html .= Element('ul', join("\n", $lines));
83         
84         return $html;
85     }
86 };
87         
88 // (c-file-style: "gnu")
89 // Local Variables:
90 // mode: php
91 // tab-width: 8
92 // c-basic-offset: 4
93 // c-hanging-comment-ender-p: nil
94 // indent-tabs-mode: nil
95 // End:   
96 ?>