]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageHistory.php
moved "(minor edit)" indicator to RecentChanges (it won't appear in RecentChanges...
[SourceForge/phpwiki.git] / lib / plugin / PageHistory.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PageHistory.php,v 1.14 2002-01-28 18:51:52 carstenklapp Exp $');
3 /**
4  */
5 require_once('lib/plugin/RecentChanges.php');
6
7 class _PageHistory_PageRevisionIter
8     extends WikiDB_PageRevisionIterator
9 {
10     function _PageHistory_PageRevisionIter($rev_iter, $params) {
11
12         $this->_iter = $rev_iter;
13
14         extract($params);
15
16         if (isset($since))
17             $this->_since = $since;
18
19         $this->_include_major = empty($exclude_major_revisions);
20         if (! $this->_include_major)
21             $this->_include_minor = true;
22         else
23             $this->_include_minor = !empty($include_minor_revisions);
24
25         if (empty($include_all_revisions))
26             $this->_limit = 1;
27         else if (isset($limit))
28             $this->_limit = $limit;
29     }
30
31     function next() {
32         if (!$this->_iter)
33             return false;
34
35         if (isset($this->_limit)) {
36             if ($this->_limit <= 0) {
37                 $this->free();
38                 return false;
39             }
40             $this->_limit--;
41         }
42
43         while ( ($rev = $this->_iter->next()) ) {
44             if (isset($this->_since) && $rev->get('mtime') < $this->_since) {
45                 $this->free();
46                 return false;
47             }
48             if ($rev->get('is_minor_edit') ? $this->_include_minor : $this->_include_major)
49                 return $rev;
50         }
51         return false;
52     }
53
54
55     function free() {
56         if ($this->_iter)
57             $this->_iter->free();
58         $this->_iter = false;
59     }
60 }
61
62
63 class _PageHistory_HtmlFormatter
64 extends _RecentChanges_HtmlFormatter
65 {
66     function include_versions_in_URLs() {
67         return true;
68     }
69
70     function title() {
71         global $Theme;
72         return array(fmt("PageHistory for %s",
73                          $Theme->LinkExistingWikiWord($this->_args['page'])),
74                      "\n",
75                      $this->rss_icon());
76     }
77
78     function _javascript($script) {
79         return HTML::script(array('language' => 'JavaScript',
80                                   'type'     => 'text/javascript'),
81                             new RawXml("<!-- //\n$script\n// -->"));
82     }
83
84     function description() {
85         // Doesn't work (PHP bug?): $desc = parent::description() . "\n";
86         $button = HTML::input(array('type'  => 'submit',
87                                     'value' => _("compare revisions")));
88         return array(_RecentChanges_HtmlFormatter::description(), "\n",
89                      $this->_javascript(sprintf('document.write("%s");',
90                                                 _("Check any two boxes to compare revisions."))),
91                      HTML::noscript(fmt("Check any two boxes then %s.", $button)));
92     }
93
94
95     function format ($changes) {
96         $this->_itemcount = 0;
97
98         $pagename = $this->_args['page'];
99
100         $html[] = _RecentChanges_HtmlFormatter::format($changes);
101
102         $html[] = HTML::input(array('type'  => 'hidden',
103                                     'name'  => 'action',
104                                     'value' => 'diff'));
105         if (USE_PATH_INFO) {
106             $action = WikiURL($pagename);
107         }
108         else {
109             $action = SCRIPT_NAME;
110             $html[] = HTML::input(array('type'  => 'hidden',
111                                         'name'  => 'pagename',
112                                         'value' => $pagename));
113         }
114
115         return HTML(HTML::form(array('method' => 'get',
116                                      'action' => $action,
117                                      'name'   => 'diff-select'),
118                                $html),
119                     "\n",
120                     $this->_javascript('
121         var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
122
123         function diffCkBox_onclick() {
124           // If two checkboxes are checked, submit form
125           var nchecked = 0;
126           for (i = 0; i < diffCkBoxes.length; i++)
127             if (diffCkBoxes[i].checked && ++nchecked >= 2)
128               this.form.submit();
129         }
130
131         for (i = 0; i < diffCkBoxes.length; i++)
132           diffCkBoxes[i].onclick = diffCkBox_onclick;'));
133     }
134     
135     function diffLink ($rev) {
136         return HTML::input(array('type'  => 'checkbox',
137                                  'name'  => 'versions[]',
138                                  'value' => $rev->getVersion()));
139     }
140
141     function pageLink ($rev) {
142         return HTML::a(array('href'  => $this->pageURL($rev),
143                              'class' => 'wiki'),
144                        fmt("Version %d", $rev->getVersion()));
145     }
146
147 }
148
149
150 class _PageHistory_RssFormatter
151 extends _RecentChanges_RssFormatter
152 {
153     function include_versions_in_URLs() {
154         return true;
155     }
156
157     function image_properties () {
158         return false;
159     }
160
161     function textinput_properties () {
162         return false;
163     }
164
165     function channel_properties () {
166         global $request;
167
168         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
169
170         $title = sprintf("%s: %s",
171                          WIKI_NAME,
172                          split_pagename($this->_args['page']));
173
174         return array('title'          => $title,
175                      'dc:description' => _("History of changes."),
176                      'link'           => $rc_url,
177                      'dc:date'        => Iso8601DateTime(time()));
178     }
179
180
181     function item_properties ($rev) {
182         if (!($title = $this->summary($rev)))
183             $title = sprintf(_("Version %d"), $rev->getVersion());
184  
185         return array( 'title'           => $title,
186                       'link'            => $this->pageURL($rev),
187                       'dc:date'         => $this->time($rev),
188                       'dc:contributor'  => $rev->get('author'),
189                       'wiki:version'    => $rev->getVersion(),
190                       'wiki:importance' => $this->importance($rev),
191                       'wiki:status'     => $this->status($rev),
192                       'wiki:diff'       => $this->diffURL($rev),
193                       );
194     }
195 }
196
197 class WikiPlugin_PageHistory
198 extends WikiPlugin_RecentChanges
199 {
200     function getName () {
201         return _("PageHistory");
202     }
203
204     function getDescription () {
205         return sprintf(_("List PageHistory for %s"),'[pagename]');
206     }
207     
208     function getDefaultArguments() {
209         return array('days'             => false,
210                      'show_minor'       => true,
211                      'show_major'       => true,
212                      'limit'            => false,
213                      'page'             => '[pagename]',
214                      'format'           => false);
215     }
216
217     function getDefaultFormArguments() {
218         $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
219         $dflts['textinput'] = 'page';
220         return $dflts;
221     }
222
223     function getMostRecentParams ($args) {
224         $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
225         $params['include_all_revisions'] = true;
226         return $params;
227     }
228
229     function getChanges ($dbi, $args) {
230         $page = $dbi->getPage($args['page']);
231         $iter = $page->getAllRevisions();
232         $params = $this->getMostRecentParams($args);
233         return new _PageHistory_PageRevisionIter($iter, $params);
234     }
235
236     function format ($changes, $args) {
237         global $Theme;
238         $format = $args['format'];
239
240         $fmt_class = $Theme->getFormatter('PageHistory', $format);
241         if (!$fmt_class) {
242             if ($format == 'rss')
243                 $fmt_class = '_PageHistory_RssFormatter';
244             else
245                 $fmt_class = '_PageHistory_HtmlFormatter';
246         }
247
248         $fmt = new $fmt_class($args);
249         return $fmt->format($changes);
250     }
251
252     function run ($dbi, $argstr, $request) {
253         $args = $this->getArgs($argstr, $request);
254         if (empty($args['page']))
255             return $this->makeForm("", $request);
256         // Hack alert: format() is a NORETURN for rss formatters.
257         return $this->format($this->getChanges($dbi, $args), $args);
258     }
259 };
260
261
262 // (c-file-style: "gnu")
263 // Local Variables:
264 // mode: php
265 // tab-width: 8
266 // c-basic-offset: 4
267 // c-hanging-comment-ender-p: nil
268 // indent-tabs-mode: nil
269 // End:   
270 ?>