]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageHistory.php
Finish conversion to new OO HTML generation scheme.
[SourceForge/phpwiki.git] / lib / plugin / PageHistory.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PageHistory.php,v 1.9 2002-01-22 03:17:47 dairiki 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         return array(fmt("PageHistory for %s",
72                          LinkExistingWikiWord($this->_args['page'])),
73                      "\n",
74                      $this->rss_icon());
75     }
76
77     function _javascript($script) {
78         return HTML::script(array('language' => 'JavaScript',
79                                   'type' => 'text/javascript'),
80                             new RawXml("<!-- //\n$script\n// -->"));
81     }
82     
83     function description() {
84         // Doesn't work (PHP bug?): $desc = parent::description() . "\n";
85         $desc[] = _RecentChanges_HtmlFormatter::description() . "\n";
86
87         $desc[] = $this->_javascript(sprintf('document.write("%s");',
88                                              _("Check any two boxes to compare revisions.")));
89         $button = HTML::input(array('type' => 'submit',
90                                     'value' => _("compare revisions")));
91         $desc[] = HTML::noscript(fmt("Check any two boxes then %s.", $button));
92
93         return $desc;
94     }
95     
96                          
97     function format ($changes) {
98         $this->_itemcount = 0;
99         
100         $pagename = $this->_args['page'];
101         
102         $html = _RecentChanges_HtmlFormatter::format($changes);
103
104         $html[] = HTML::input(array('type' => 'hidden',
105                                     'name' => 'action',
106                                     'value' => 'diff'));
107         if (USE_PATH_INFO) {
108             $action = WikiURL($pagename);
109         }
110         else {
111             $action = SCRIPT_NAME;
112             $html[] = HTML::input(array('type' => 'hidden',
113                                         'name' => 'pagename',
114                                         'value' => $pagename));
115         }
116
117         return array(HTML::form(array('method' => 'get',
118                                       'action' => $action,
119                                       'name' => 'diff-select'),
120                                 $html),
121                      "\n",
122                      $this->_javascript('
123         var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
124
125         function diffCkBox_onclick() {
126           // If two checkboxes are checked, submit form
127           var nchecked = 0;
128           for (i = 0; i < diffCkBoxes.length; i++)
129             if (diffCkBoxes[i].checked && ++nchecked >= 2)
130               this.form.submit();
131         }
132
133         for (i = 0; i < diffCkBoxes.length; i++)
134           diffCkBoxes[i].onclick = diffCkBox_onclick;'));
135     }
136     
137     function diffLink ($rev) {
138         return HTML::input(array('type' => 'checkbox',
139                                  'name' => 'versions[]',
140                                  'value' => $rev->getVersion()));
141     }
142
143     function pageLink ($rev) {
144         return HTML::a(array('href' => $this->pageURL($rev), 'class' => 'wiki'),
145                        fmt("Version %d", $rev->getVersion()));
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'             => false,
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 ?>