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