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