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