]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageHistory.php
_PageHistory_PageRevisionIter is not private
[SourceForge/phpwiki.git] / lib / plugin / PageHistory.php
1 <?php
2
3 /**
4  * Copyright 1999, 2000, 2001, 2002, 2007 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 require_once 'lib/plugin/RecentChanges.php';
24
25 class _PageHistory_PageRevisionIter
26     extends WikiDB_PageRevisionIterator
27 {
28     function _PageHistory_PageRevisionIter($rev_iter, $params)
29     {
30
31         $this->_iter = $rev_iter;
32
33         extract($params);
34
35         if (isset($since))
36             $this->_since = $since;
37
38         $this->_include_major = empty($exclude_major_revisions);
39         if (!$this->_include_major)
40             $this->_include_minor = true;
41         else
42             $this->_include_minor = !empty($include_minor_revisions);
43
44         if (empty($include_all_revisions))
45             $this->_limit = 1;
46         else if (isset($limit))
47             $this->_limit = $limit;
48     }
49
50     function next()
51     {
52         if (!$this->_iter)
53             return false;
54
55         if (isset($this->_limit)) {
56             if ($this->_limit <= 0) {
57                 $this->free();
58                 return false;
59             }
60             $this->_limit--;
61         }
62
63         while (($rev = $this->_iter->next())) {
64             if (isset($this->_since) && $rev->get('mtime') < $this->_since) {
65                 $this->free();
66                 return false;
67             }
68             if ($rev->get('is_minor_edit') ? $this->_include_minor : $this->_include_major)
69                 return $rev;
70         }
71         return false;
72     }
73
74     function free()
75     {
76         if ($this->_iter)
77             $this->_iter->free();
78         $this->_iter = false;
79     }
80 }
81
82 class _PageHistory_HtmlFormatter
83     extends _RecentChanges_HtmlFormatter
84 {
85     function include_versions_in_URLs()
86     {
87         return true;
88     }
89
90     function headline()
91     {
92         return HTML(fmt("PageHistory for %s",
93                 WikiLink($this->_args['page'])),
94             "\n",
95             $this->rss_icon(),
96             $this->rss2_icon(),
97             $this->atom_icon(),
98             $this->rdf_icon());
99     }
100
101     function title()
102     {
103         return "PageHistory:" . $this->_args['page'];
104     }
105
106     function empty_message()
107     {
108         return _("No revisions found");
109     }
110
111     function description()
112     {
113         $button = HTML::input(array('type' => 'submit',
114             'value' => _("compare revisions"),
115             'class' => 'wikiaction'));
116
117         $js_desc = $no_js_desc = _RecentChanges_HtmlFormatter::description();
118
119         $js_desc->pushContent("\n", _("Check any two boxes to compare revisions."));
120         $no_js_desc->pushContent("\n", fmt("Check any two boxes then %s.", $button));
121
122         return IfJavaScript($js_desc, $no_js_desc);
123     }
124
125     function format($changes)
126     {
127         $this->_itemcount = 0;
128
129         $pagename = $this->_args['page'];
130
131         $fmt = _RecentChanges_HtmlFormatter::format($changes);
132         $fmt->action = _("PageHistory");
133         $html[] = $fmt;
134
135         $html[] = HTML::input(array('type' => 'hidden',
136             'name' => 'action',
137             'value' => 'diff'));
138         if (USE_PATH_INFO) {
139             $action = WikiURL($pagename);
140         } else {
141             $action = SCRIPT_NAME;
142             $html[] = HTML::input(array('type' => 'hidden',
143                 'name' => 'pagename',
144                 'value' => $pagename));
145         }
146
147         return HTML(HTML::form(array('method' => 'get',
148                     'action' => $action,
149                     'id' => 'diff-select'),
150                 $html),
151             "\n",
152             JavaScript('
153         var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
154
155         function diffCkBox_onclick() {
156             var nchecked = 0, box = diffCkBoxes;
157             for (i = 0; i < box.length; i++)
158                 if (box[i].checked) nchecked++;
159             if (nchecked == 2)
160                 this.form.submit();
161             else if (nchecked > 2) {
162                 for (i = 0; i < box.length; i++)
163                     if (box[i] != this) box[i].checked = 0;
164             }
165         }
166
167         for (i = 0; i < diffCkBoxes.length; i++)
168             diffCkBoxes[i].onclick = diffCkBox_onclick;'));
169     }
170
171     function diffLink($rev)
172     {
173         return HTML::input(array('type' => 'checkbox',
174             'name' => 'versions[]',
175             'value' => $rev->getVersion()));
176     }
177
178     function pageLink($rev, $link_text = false)
179     {
180         $text = fmt("Version %d", $rev->getVersion());
181         return _RecentChanges_HtmlFormatter::pageLink($rev, $text);
182     }
183
184     function format_revision($rev)
185     {
186         global $WikiTheme;
187         $class = 'rc-' . $this->importance($rev);
188
189         $time = $this->time($rev);
190         if ($rev->get('is_minor_edit')) {
191             $minor_flag = HTML(" ",
192                 HTML::span(array('class' => 'pageinfo-minoredit'),
193                     "(" . _("minor edit") . ")"));
194         } else {
195             $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
196             $minor_flag = '';
197         }
198         $line = HTML::li(array('class' => $class));
199         if (isa($WikiTheme, 'WikiTheme_MonoBook')) {
200             $line->pushContent(
201                 $this->diffLink($rev), ' ',
202                 $this->pageLink($rev), ' ',
203                 $time, ' ', $this->date($rev), ' . . ',
204                 $this->authorLink($rev), ' ',
205                 $this->authorContribs($rev), ' ',
206                 $this->summaryAsHTML($rev), ' ',
207                 $minor_flag);
208         } else {
209             $line->pushContent(
210                 $this->diffLink($rev), ' ',
211                 $this->pageLink($rev), ' ',
212                 $time, ' ',
213                 $this->summaryAsHTML($rev),
214                 ' ... ',
215                 $this->authorLink($rev),
216                 $minor_flag);
217         }
218         return $line;
219     }
220 }
221
222 class _PageHistory_RssFormatter
223     extends _RecentChanges_RssFormatter
224 {
225     function include_versions_in_URLs()
226     {
227         return true;
228     }
229
230     function image_properties()
231     {
232         return false;
233     }
234
235     function textinput_properties()
236     {
237         return false;
238     }
239
240     function channel_properties()
241     {
242         global $request;
243
244         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
245
246         $title = sprintf(_("%s: %s"),
247             WIKI_NAME,
248             SplitPagename($this->_args['page']));
249
250         return array('title' => $title,
251             'dc:description' => _("History of changes."),
252             'link' => $rc_url,
253             'dc:date' => Iso8601DateTime(time()));
254     }
255
256     function item_properties($rev)
257     {
258         if (!($title = $this->summary($rev)))
259             $title = sprintf(_("Version %d"), $rev->getVersion());
260
261         return array('title' => $title,
262             'link' => $this->pageURL($rev),
263             'dc:date' => $this->time($rev),
264             'dc:contributor' => $rev->get('author'),
265             'wiki:version' => $rev->getVersion(),
266             'wiki:importance' => $this->importance($rev),
267             'wiki:status' => $this->status($rev),
268             'wiki:diff' => $this->diffURL($rev),
269         );
270     }
271 }
272
273 class WikiPlugin_PageHistory
274     extends WikiPlugin_RecentChanges
275 {
276     function getName()
277     {
278         return _("PageHistory");
279     }
280
281     function getDescription()
282     {
283         return sprintf(_("List PageHistory for %s."), '[pagename]');
284     }
285
286     function getDefaultArguments()
287     {
288         return array('days' => false,
289             'show_minor' => true,
290             'show_major' => true,
291             'limit' => false,
292             'page' => '[pagename]',
293             'format' => false);
294     }
295
296     function getDefaultFormArguments()
297     {
298         $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
299         $dflts['textinput'] = 'page';
300         return $dflts;
301     }
302
303     function getMostRecentParams($args)
304     {
305         $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
306         $params['include_all_revisions'] = true;
307         return $params;
308     }
309
310     function getChanges($dbi, $args)
311     {
312         $page = $dbi->getPage($args['page']);
313         $iter = $page->getAllRevisions();
314         $params = $this->getMostRecentParams($args);
315         if (empty($args['days'])) unset($params['since']);
316         return new _PageHistory_PageRevisionIter($iter, $params);
317     }
318
319     function format($changes, $args)
320     {
321         global $WikiTheme;
322         $format = $args['format'];
323
324         $fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
325         if (!$fmt_class) {
326             if ($format == 'rss')
327                 $fmt_class = '_PageHistory_RssFormatter';
328             else
329                 $fmt_class = '_PageHistory_HtmlFormatter';
330         }
331
332         $fmt = new $fmt_class($args);
333         $fmt->action = _("PageHistory");
334         return $fmt->format($changes);
335     }
336
337     function run($dbi, $argstr, &$request, $basepage)
338     {
339         $args = $this->getArgs($argstr, $request);
340         $pagename = $args['page'];
341         if (empty($pagename))
342             return $this->makeForm("", $request);
343
344         $page = $dbi->getPage($pagename);
345         $current = $page->getCurrentRevision();
346         if ($current->getVersion() < 1) {
347             return HTML(HTML::p(fmt("Page ā€œ%sā€ does not exist.", WikiLink($pagename, 'unknown'))),
348                 $this->makeForm("", $request));
349         }
350         // Hack alert: format() is a NORETURN for rss formatters.
351         return $this->format($this->getChanges($dbi, $args), $args);
352     }
353 }
354
355 // Local Variables:
356 // mode: php
357 // tab-width: 8
358 // c-basic-offset: 4
359 // c-hanging-comment-ender-p: nil
360 // indent-tabs-mode: nil
361 // End: