]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageHistory.php
Added MonoBook style
[SourceForge/phpwiki.git] / lib / plugin / PageHistory.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PageHistory.php,v 1.32 2007-06-02 18:24:47 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         global $WikiTheme;
172         $class = 'rc-' . $this->importance($rev);
173
174         $time = $this->time($rev);
175         if ($rev->get('is_minor_edit')) {
176             $minor_flag = HTML(" ",
177                                HTML::span(array('class' => 'pageinfo-minoredit'),
178                                           "(" . _("minor edit") . ")"));
179         }
180         else {
181             $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
182             $minor_flag = '';
183         }
184         $line = HTML::li(array('class' => $class));
185         if (isa($WikiTheme,'Theme_MonoBook')) {
186             $line->pushContent(
187                                $this->diffLink($rev), ' ',
188                                $this->pageLink($rev), ' ',
189                                $time,' ',$this->date($rev), ' . . ',
190                                $this->authorLink($rev),' ',
191                                $this->authorContribs($rev),' ',
192                                $this->summaryAsHTML($rev),' ',
193                                $minor_flag);
194         } else {
195             $line->pushContent(
196                                $this->diffLink($rev), ' ',
197                                $this->pageLink($rev), ' ',
198                                $time, ' ',
199                                $this->summaryAsHTML($rev),
200                                ' ... ',
201                                $this->authorLink($rev),
202                                $minor_flag);
203         }
204         return $line;
205     }
206 }
207
208
209 class _PageHistory_RssFormatter
210 extends _RecentChanges_RssFormatter
211 {
212     function include_versions_in_URLs() {
213         return true;
214     }
215
216     function image_properties () {
217         return false;
218     }
219
220     function textinput_properties () {
221         return false;
222     }
223
224     function channel_properties () {
225         global $request;
226
227         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
228
229         $title = sprintf(_("%s: %s"),
230                          WIKI_NAME,
231                          SplitPagename($this->_args['page']));
232
233         return array('title'          => $title,
234                      'dc:description' => _("History of changes."),
235                      'link'           => $rc_url,
236                      'dc:date'        => Iso8601DateTime(time()));
237     }
238
239
240     function item_properties ($rev) {
241         if (!($title = $this->summary($rev)))
242             $title = sprintf(_("Version %d"), $rev->getVersion());
243
244         return array( 'title'           => $title,
245                       'link'            => $this->pageURL($rev),
246                       'dc:date'         => $this->time($rev),
247                       'dc:contributor'  => $rev->get('author'),
248                       'wiki:version'    => $rev->getVersion(),
249                       'wiki:importance' => $this->importance($rev),
250                       'wiki:status'     => $this->status($rev),
251                       'wiki:diff'       => $this->diffURL($rev),
252                       );
253     }
254 }
255
256 class WikiPlugin_PageHistory
257 extends WikiPlugin_RecentChanges
258 {
259     function getName () {
260         return _("PageHistory");
261     }
262
263     function getDescription () {
264         return sprintf(_("List PageHistory for %s"),'[pagename]');
265     }
266
267     function getVersion() {
268         return preg_replace("/[Revision: $]/", '',
269                             "\$Revision: 1.32 $");
270     }
271
272     function getDefaultArguments() {
273         return array('days'         => false,
274                      'show_minor'   => true,
275                      'show_major'   => true,
276                      'limit'        => false,
277                      'page'         => '[pagename]',
278                      'format'       => false);
279     }
280
281     function getDefaultFormArguments() {
282         $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
283         $dflts['textinput'] = 'page';
284         return $dflts;
285     }
286
287     function getMostRecentParams ($args) {
288         $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
289         $params['include_all_revisions'] = true;
290         return $params;
291     }
292
293     function getChanges ($dbi, $args) {
294         $page = $dbi->getPage($args['page']);
295         $iter = $page->getAllRevisions();
296         $params = $this->getMostRecentParams($args);
297         if (empty($args['days'])) unset($params['since']);
298         return new _PageHistory_PageRevisionIter($iter, $params);
299     }
300
301     function format ($changes, $args) {
302         global $WikiTheme;
303         $format = $args['format'];
304
305         $fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
306         if (!$fmt_class) {
307             if ($format == 'rss')
308                 $fmt_class = '_PageHistory_RssFormatter';
309             else
310                 $fmt_class = '_PageHistory_HtmlFormatter';
311         }
312
313         $fmt = new $fmt_class($args);
314         return $fmt->format($changes);
315     }
316
317     function run($dbi, $argstr, &$request, $basepage) {
318         $args = $this->getArgs($argstr, $request);
319         $pagename = $args['page'];
320         if (empty($pagename))
321             return $this->makeForm("", $request);
322
323         $page = $dbi->getPage($pagename);
324         $current = $page->getCurrentRevision();
325         if ($current->getVersion() < 1) {
326             return HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.",
327                                     WikiLink($pagename, 'unknown'))),
328                         $this->makeForm("", $request));
329         }
330         // Hack alert: format() is a NORETURN for rss formatters.
331         return $this->format($this->getChanges($dbi, $args), $args);
332     }
333 };
334
335 // $Log: not supported by cvs2svn $
336 // Revision 1.31  2007/05/13 18:13:34  rurban
337 // fix for recent RecentChanges upgrade: display all versions
338 //
339 // Revision 1.30  2004/06/14 11:31:39  rurban
340 // renamed global $Theme to $WikiTheme (gforge nameclash)
341 // inherit PageList default options from PageList
342 //   default sortby=pagename
343 // use options in PageList_Selectable (limit, sortby, ...)
344 // added action revert, with button at action=diff
345 // added option regex to WikiAdminSearchReplace
346 //
347 // Revision 1.29  2004/05/18 16:23:40  rurban
348 // rename split_pagename to SplitPagename
349 //
350 // Revision 1.28  2004/02/17 12:11:36  rurban
351 // 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, ...)
352 //
353 // Revision 1.27  2003/02/27 22:48:44  dairiki
354 // Fixes invalid HTML generated by PageHistory plugin.
355 //
356 // (<noscript> is block-level and not allowed within <p>.)
357 //
358 // Revision 1.26  2003/02/27 21:15:14  dairiki
359 // Javascript fix.
360 //
361 // Fix so that you can never have more than two checkboxes checked. (If this
362 // happens, all but the current checkbox are unchecked.)
363 //
364 // It used to be that one could view a PageHistory, check two boxes to view
365 // a diff, then hit the back button.  (The originally checked two boxes are
366 // still checked at this point.)  Checking a third box resulted in viewing
367 // a diff between a quasi-random pair of versions selected from the three
368 // which were selected.   Now clicking the third box results in the first
369 // two being unchecked.
370 //
371 // Revision 1.25  2003/02/17 02:19:01  dairiki
372 // Fix so that PageHistory will work when the current revision
373 // of a page has been "deleted".
374 //
375 // Revision 1.24  2003/01/18 21:49:00  carstenklapp
376 // Code cleanup:
377 // Reformatting & tabs to spaces;
378 // Added copyleft, getVersion, getDescription, rcs_id.
379 //
380 // Revision 1.23  2003/01/04 23:27:39  carstenklapp
381 // New: Gracefully handle non-existant pages. Added copyleft;
382 // getVersion() for PluginManager.
383 //
384
385 // (c-file-style: "gnu")
386 // Local Variables:
387 // mode: php
388 // tab-width: 8
389 // c-basic-offset: 4
390 // c-hanging-comment-ender-p: nil
391 // indent-tabs-mode: nil
392 // End:
393 ?>