]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageHistory.php
Tying up loose ends related to PageType.php --actionPages should now have the usual...
[SourceForge/phpwiki.git] / lib / plugin / PageHistory.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PageHistory.php,v 1.21 2002-02-25 03:33:10 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         return array(fmt("PageHistory for %s",
72                          WikiLink($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         $button = HTML::input(array('type'  => 'submit',
86                                     'value' => _("compare revisions"),
87                                     'class' => 'wikiaction'));
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     function format_revision ($rev) {
148         $class = 'rc-' . $this->importance($rev);
149
150         $time = $this->time($rev);
151         if ($rev->get('is_minor_edit')) {
152             $minor_flag = HTML(" ",
153                                HTML::span(array('class' => 'pageinfo-minoredit'),
154                                           "(" . _("minor edit") . ")"));
155         }
156         else {
157             $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
158             $minor_flag = '';
159         }
160
161         return HTML::li(array('class' => $class),
162                         $this->diffLink($rev), ' ',
163                         $this->pageLink($rev), ' ',
164                         $time, ' ',
165                         $this->summaryAsHTML($rev),
166                         ' ... ',
167                         $this->authorLink($rev),
168                         $minor_flag);
169     }
170 }
171
172
173 class _PageHistory_RssFormatter
174 extends _RecentChanges_RssFormatter
175 {
176     function include_versions_in_URLs() {
177         return true;
178     }
179
180     function image_properties () {
181         return false;
182     }
183
184     function textinput_properties () {
185         return false;
186     }
187
188     function channel_properties () {
189         global $request;
190
191         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
192
193         $title = sprintf("%s: %s",
194                          WIKI_NAME,
195                          split_pagename($this->_args['page']));
196
197         return array('title'          => $title,
198                      'dc:description' => _("History of changes."),
199                      'link'           => $rc_url,
200                      'dc:date'        => Iso8601DateTime(time()));
201     }
202
203
204     function item_properties ($rev) {
205         if (!($title = $this->summary($rev)))
206             $title = sprintf(_("Version %d"), $rev->getVersion());
207
208         return array( 'title'           => $title,
209                       'link'            => $this->pageURL($rev),
210                       'dc:date'         => $this->time($rev),
211                       'dc:contributor'  => $rev->get('author'),
212                       'wiki:version'    => $rev->getVersion(),
213                       'wiki:importance' => $this->importance($rev),
214                       'wiki:status'     => $this->status($rev),
215                       'wiki:diff'       => $this->diffURL($rev),
216                       );
217     }
218 }
219
220 class WikiPlugin_PageHistory
221 extends WikiPlugin_RecentChanges
222 {
223     function getName () {
224         return _("PageHistory");
225     }
226
227     function getDescription () {
228         return sprintf(_("List PageHistory for %s"),'[pagename]');
229     }
230
231     function getDefaultArguments() {
232         return array('days'             => false,
233                      'show_minor'       => true,
234                      'show_major'       => true,
235                      'limit'            => false,
236                      'page'             => '[pagename]',
237                      'format'           => false);
238     }
239
240     function getDefaultFormArguments() {
241         $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
242         $dflts['textinput'] = 'page';
243         return $dflts;
244     }
245
246     function getMostRecentParams ($args) {
247         $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
248         $params['include_all_revisions'] = true;
249         return $params;
250     }
251
252     function getChanges ($dbi, $args) {
253         $page = $dbi->getPage($args['page']);
254         $iter = $page->getAllRevisions();
255         $params = $this->getMostRecentParams($args);
256         return new _PageHistory_PageRevisionIter($iter, $params);
257     }
258
259     function format ($changes, $args) {
260         global $Theme;
261         $format = $args['format'];
262
263         $fmt_class = $Theme->getFormatter('PageHistory', $format);
264         if (!$fmt_class) {
265             if ($format == 'rss')
266                 $fmt_class = '_PageHistory_RssFormatter';
267             else
268                 $fmt_class = '_PageHistory_HtmlFormatter';
269         }
270
271         $fmt = new $fmt_class($args);
272         return $fmt->format($changes);
273     }
274
275     function run ($dbi, $argstr, $request) {
276         $args = $this->getArgs($argstr, $request);
277         if (empty($args['page']))
278             return $this->makeForm("", $request);
279         // Hack alert: format() is a NORETURN for rss formatters.
280
281         return $this->format($this->getChanges($dbi, $args), $args);
282     }
283 };
284
285 // (c-file-style: "gnu")
286 // Local Variables:
287 // mode: php
288 // tab-width: 8
289 // c-basic-offset: 4
290 // c-hanging-comment-ender-p: nil
291 // indent-tabs-mode: nil
292 // End:
293 ?>