]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageHistory.php
fix for recent RecentChanges upgrade: display all versions
[SourceForge/phpwiki.git] / lib / plugin / PageHistory.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PageHistory.php,v 1.31 2007-05-13 18:13:34 rurban Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $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
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  */
25 require_once('lib/plugin/RecentChanges.php');
26
27 class _PageHistory_PageRevisionIter
28 extends WikiDB_PageRevisionIterator
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         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
75     function free() {
76         if ($this->_iter)
77             $this->_iter->free();
78         $this->_iter = false;
79     }
80 }
81
82
83 class _PageHistory_HtmlFormatter
84 extends _RecentChanges_HtmlFormatter
85 {
86     function include_versions_in_URLs() {
87         return true;
88     }
89
90     function title() {
91         return array(fmt("PageHistory for %s",
92                          WikiLink($this->_args['page'])),
93                      "\n",
94                      $this->rss_icon());
95     }
96
97     function empty_message () {
98         return _("No revisions found");
99     }
100
101     function description() {
102         $button = HTML::input(array('type'  => 'submit',
103                                     'value' => _("compare revisions"),
104                                     'class' => 'wikiaction'));
105
106         $js_desc = $no_js_desc = _RecentChanges_HtmlFormatter::description();
107
108         $js_desc->pushContent("\n", _("Check any two boxes to compare revisions."));
109         $no_js_desc->pushContent("\n", fmt("Check any two boxes then %s.", $button));
110
111         return IfJavaScript($js_desc, $no_js_desc);
112     }
113
114
115     function format ($changes) {
116         $this->_itemcount = 0;
117
118         $pagename = $this->_args['page'];
119
120         $html[] = _RecentChanges_HtmlFormatter::format($changes);
121
122         $html[] = HTML::input(array('type'  => 'hidden',
123                                     'name'  => 'action',
124                                     'value' => 'diff'));
125         if (USE_PATH_INFO) {
126             $action = WikiURL($pagename);
127         }
128         else {
129             $action = SCRIPT_NAME;
130             $html[] = HTML::input(array('type'  => 'hidden',
131                                         'name'  => 'pagename',
132                                         'value' => $pagename));
133         }
134
135         return HTML(HTML::form(array('method' => 'get',
136                                      'action' => $action,
137                                      'name'   => 'diff-select'),
138                                $html),
139                     "\n",
140                     JavaScript('
141         var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
142
143         function diffCkBox_onclick() {
144             var nchecked = 0, box = diffCkBoxes;
145             for (i = 0; i < box.length; i++)
146                 if (box[i].checked) nchecked++;
147             if (nchecked == 2)
148                 this.form.submit();
149             else if (nchecked > 2) {
150                 for (i = 0; i < box.length; i++)
151                     if (box[i] != this) box[i].checked = 0;
152             }
153         }
154
155         for (i = 0; i < diffCkBoxes.length; i++)
156             diffCkBoxes[i].onclick = diffCkBox_onclick;'));
157     }
158
159     function diffLink ($rev) {
160         return HTML::input(array('type'  => 'checkbox',
161                                  'name'  => 'versions[]',
162                                  'value' => $rev->getVersion()));
163     }
164
165     function pageLink ($rev) {
166         $text = fmt("Version %d", $rev->getVersion());
167         return _RecentChanges_HtmlFormatter::pageLink($rev, $text);
168     }
169
170     function format_revision ($rev) {
171         $class = 'rc-' . $this->importance($rev);
172
173         $time = $this->time($rev);
174         if ($rev->get('is_minor_edit')) {
175             $minor_flag = HTML(" ",
176                                HTML::span(array('class' => 'pageinfo-minoredit'),
177                                           "(" . _("minor edit") . ")"));
178         }
179         else {
180             $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
181             $minor_flag = '';
182         }
183
184         return HTML::li(array('class' => $class),
185                         $this->diffLink($rev), ' ',
186                         $this->pageLink($rev), ' ',
187                         $time, ' ',
188                         $this->summaryAsHTML($rev),
189                         ' ... ',
190                         $this->authorLink($rev),
191                         $minor_flag);
192     }
193 }
194
195
196 class _PageHistory_RssFormatter
197 extends _RecentChanges_RssFormatter
198 {
199     function include_versions_in_URLs() {
200         return true;
201     }
202
203     function image_properties () {
204         return false;
205     }
206
207     function textinput_properties () {
208         return false;
209     }
210
211     function channel_properties () {
212         global $request;
213
214         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
215
216         $title = sprintf(_("%s: %s"),
217                          WIKI_NAME,
218                          SplitPagename($this->_args['page']));
219
220         return array('title'          => $title,
221                      'dc:description' => _("History of changes."),
222                      'link'           => $rc_url,
223                      'dc:date'        => Iso8601DateTime(time()));
224     }
225
226
227     function item_properties ($rev) {
228         if (!($title = $this->summary($rev)))
229             $title = sprintf(_("Version %d"), $rev->getVersion());
230
231         return array( 'title'           => $title,
232                       'link'            => $this->pageURL($rev),
233                       'dc:date'         => $this->time($rev),
234                       'dc:contributor'  => $rev->get('author'),
235                       'wiki:version'    => $rev->getVersion(),
236                       'wiki:importance' => $this->importance($rev),
237                       'wiki:status'     => $this->status($rev),
238                       'wiki:diff'       => $this->diffURL($rev),
239                       );
240     }
241 }
242
243 class WikiPlugin_PageHistory
244 extends WikiPlugin_RecentChanges
245 {
246     function getName () {
247         return _("PageHistory");
248     }
249
250     function getDescription () {
251         return sprintf(_("List PageHistory for %s"),'[pagename]');
252     }
253
254     function getVersion() {
255         return preg_replace("/[Revision: $]/", '',
256                             "\$Revision: 1.31 $");
257     }
258
259     function getDefaultArguments() {
260         return array('days'         => false,
261                      'show_minor'   => true,
262                      'show_major'   => true,
263                      'limit'        => false,
264                      'page'         => '[pagename]',
265                      'format'       => false);
266     }
267
268     function getDefaultFormArguments() {
269         $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
270         $dflts['textinput'] = 'page';
271         return $dflts;
272     }
273
274     function getMostRecentParams ($args) {
275         $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
276         $params['include_all_revisions'] = true;
277         return $params;
278     }
279
280     function getChanges ($dbi, $args) {
281         $page = $dbi->getPage($args['page']);
282         $iter = $page->getAllRevisions();
283         $params = $this->getMostRecentParams($args);
284         if (empty($args['days'])) unset($params['since']);
285         return new _PageHistory_PageRevisionIter($iter, $params);
286     }
287
288     function format ($changes, $args) {
289         global $WikiTheme;
290         $format = $args['format'];
291
292         $fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
293         if (!$fmt_class) {
294             if ($format == 'rss')
295                 $fmt_class = '_PageHistory_RssFormatter';
296             else
297                 $fmt_class = '_PageHistory_HtmlFormatter';
298         }
299
300         $fmt = new $fmt_class($args);
301         return $fmt->format($changes);
302     }
303
304     function run($dbi, $argstr, &$request, $basepage) {
305         $args = $this->getArgs($argstr, $request);
306         $pagename = $args['page'];
307         if (empty($pagename))
308             return $this->makeForm("", $request);
309
310         $page = $dbi->getPage($pagename);
311         $current = $page->getCurrentRevision();
312         if ($current->getVersion() < 1) {
313             return HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.",
314                                     WikiLink($pagename, 'unknown'))),
315                         $this->makeForm("", $request));
316         }
317         // Hack alert: format() is a NORETURN for rss formatters.
318         return $this->format($this->getChanges($dbi, $args), $args);
319     }
320 };
321
322 // $Log: not supported by cvs2svn $
323 // Revision 1.30  2004/06/14 11:31:39  rurban
324 // renamed global $Theme to $WikiTheme (gforge nameclash)
325 // inherit PageList default options from PageList
326 //   default sortby=pagename
327 // use options in PageList_Selectable (limit, sortby, ...)
328 // added action revert, with button at action=diff
329 // added option regex to WikiAdminSearchReplace
330 //
331 // Revision 1.29  2004/05/18 16:23:40  rurban
332 // rename split_pagename to SplitPagename
333 //
334 // Revision 1.28  2004/02/17 12:11:36  rurban
335 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
336 //
337 // Revision 1.27  2003/02/27 22:48:44  dairiki
338 // Fixes invalid HTML generated by PageHistory plugin.
339 //
340 // (<noscript> is block-level and not allowed within <p>.)
341 //
342 // Revision 1.26  2003/02/27 21:15:14  dairiki
343 // Javascript fix.
344 //
345 // Fix so that you can never have more than two checkboxes checked. (If this
346 // happens, all but the current checkbox are unchecked.)
347 //
348 // It used to be that one could view a PageHistory, check two boxes to view
349 // a diff, then hit the back button.  (The originally checked two boxes are
350 // still checked at this point.)  Checking a third box resulted in viewing
351 // a diff between a quasi-random pair of versions selected from the three
352 // which were selected.   Now clicking the third box results in the first
353 // two being unchecked.
354 //
355 // Revision 1.25  2003/02/17 02:19:01  dairiki
356 // Fix so that PageHistory will work when the current revision
357 // of a page has been "deleted".
358 //
359 // Revision 1.24  2003/01/18 21:49:00  carstenklapp
360 // Code cleanup:
361 // Reformatting & tabs to spaces;
362 // Added copyleft, getVersion, getDescription, rcs_id.
363 //
364 // Revision 1.23  2003/01/04 23:27:39  carstenklapp
365 // New: Gracefully handle non-existant pages. Added copyleft;
366 // getVersion() for PluginManager.
367 //
368
369 // (c-file-style: "gnu")
370 // Local Variables:
371 // mode: php
372 // tab-width: 8
373 // c-basic-offset: 4
374 // c-hanging-comment-ender-p: nil
375 // indent-tabs-mode: nil
376 // End:
377 ?>