]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageHistory.php
Generalized "ActionPages". To get LikePage for SomePage, now,
[SourceForge/phpwiki.git] / lib / plugin / PageHistory.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PageHistory.php,v 1.11 2002-01-28 01:01:27 dairiki Exp $');
3 /**
4  */
5 require_once('lib/plugin/RecentChanges.php');
6
7 class _PageHistory_PageRevisionIter
8     extends WikiDB_PageRevisionIterator
9 {
10     function _PageHistory_PageRevisionIter($rev_iter, $params) {
11
12         $this->_iter = $rev_iter;
13
14         extract($params);
15
16         if (isset($since))
17             $this->_since = $since;
18
19         $this->_include_major = empty($exclude_major_revisions);
20         if (! $this->_include_major)
21             $this->_include_minor = true;
22         else
23             $this->_include_minor = !empty($include_minor_revisions);
24
25         if (empty($include_all_revisions))
26             $this->_limit = 1;
27         else if (isset($limit))
28             $this->_limit = $limit;
29     }
30
31     function next() {
32         if (!$this->_iter)
33             return false;
34
35         if (isset($this->_limit)) {
36             if ($this->_limit <= 0) {
37                 $this->free();
38                 return false;
39             }
40             $this->_limit--;
41         }
42
43         while ( ($rev = $this->_iter->next()) ) {
44             if (isset($this->_since) && $rev->get('mtime') < $this->_since) {
45                 $this->free();
46                 return false;
47             }
48             if ($rev->get('is_minor_edit') ? $this->_include_minor : $this->_include_major)
49                 return $rev;
50         }
51         return false;
52     }
53
54
55     function free() {
56         if ($this->_iter)
57             $this->_iter->free();
58         $this->_iter = false;
59     }
60 }
61
62
63 class _PageHistory_HtmlFormatter
64 extends _RecentChanges_HtmlFormatter
65 {
66     function include_versions_in_URLs() {
67         return true;
68     }
69
70     function title() {
71         global $Theme;
72         return array(fmt("PageHistory for %s",
73                          $Theme->LinkExistingWikiWord($this->_args['page'])),
74                      "\n",
75                      $this->rss_icon());
76     }
77
78     function _javascript($script) {
79         return HTML::script(array('language' => 'JavaScript',
80                                   'type'     => 'text/javascript'),
81                             new RawXml("<!-- //\n$script\n// -->"));
82     }
83
84     function description() {
85         // Doesn't work (PHP bug?): $desc = parent::description() . "\n";
86         $button = HTML::input(array('type'  => 'submit',
87                                     'value' => _("compare revisions")));
88         return array(_RecentChanges_HtmlFormatter::description(), "\n",
89                      $this->_javascript(sprintf('document.write("%s");',
90                                                 _("Check any two boxes to compare revisions."))),
91                      HTML::noscript(fmt("Check any two boxes then %s.", $button)));
92     }
93
94
95     function format ($changes) {
96         $this->_itemcount = 0;
97
98         $pagename = $this->_args['page'];
99
100         $html = _RecentChanges_HtmlFormatter::format($changes);
101
102         $html[] = HTML::input(array('type'  => 'hidden',
103                                     'name'  => 'action',
104                                     'value' => 'diff'));
105         if (USE_PATH_INFO) {
106             $action = WikiURL($pagename);
107         }
108         else {
109             $action = SCRIPT_NAME;
110             $html[] = HTML::input(array('type'  => 'hidden',
111                                         'name'  => 'pagename',
112                                         'value' => $pagename));
113         }
114
115         return array(HTML::form(array('method' => 'get',
116                                       'action' => $action,
117                                       'name'   => 'diff-select'),
118                                 $html),
119                      "\n",
120                      $this->_javascript('
121         var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
122
123         function diffCkBox_onclick() {
124           // If two checkboxes are checked, submit form
125           var nchecked = 0;
126           for (i = 0; i < diffCkBoxes.length; i++)
127             if (diffCkBoxes[i].checked && ++nchecked >= 2)
128               this.form.submit();
129         }
130
131         for (i = 0; i < diffCkBoxes.length; i++)
132           diffCkBoxes[i].onclick = diffCkBox_onclick;'));
133     }
134     
135     function diffLink ($rev) {
136         return HTML::input(array('type'  => 'checkbox',
137                                  'name'  => 'versions[]',
138                                  'value' => $rev->getVersion()));
139     }
140
141     function pageLink ($rev) {
142         return HTML::a(array('href'  => $this->pageURL($rev),
143                              'class' => 'wiki'),
144                        fmt("Version %d", $rev->getVersion()));
145     }
146 }
147
148
149 class _PageHistory_RssFormatter
150 extends _RecentChanges_RssFormatter
151 {
152     function include_versions_in_URLs() {
153         return true;
154     }
155
156     function image_properties () {
157         return false;
158     }
159
160     function textinput_properties () {
161         return false;
162     }
163
164     function channel_properties () {
165         global $request;
166
167         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
168
169         $title = sprintf("%s: %s",
170                          WIKI_NAME,
171                          split_pagename($this->_args['page']));
172
173         return array('title'          => $title,
174                      'dc:description' => _("History of changes."),
175                      'link'           => $rc_url,
176                      'dc:date'        => Iso8601DateTime(time()));
177     }
178
179
180     function item_properties ($rev) {
181         if (!($title = $this->summary($rev)))
182             $title = sprintf(_("Version %d"), $rev->getVersion());
183  
184         return array( 'title'           => $title,
185                       'link'            => $this->pageURL($rev),
186                       'dc:date'         => $this->time($rev),
187                       'dc:contributor'  => $rev->get('author'),
188                       'wiki:version'    => $rev->getVersion(),
189                       'wiki:importance' => $this->importance($rev),
190                       'wiki:status'     => $this->status($rev),
191                       'wiki:diff'       => $this->diffURL($rev),
192                       );
193     }
194 }
195
196 class WikiPlugin_PageHistory
197 extends WikiPlugin_RecentChanges
198 {
199     function getName () {
200         return _("PageHistory");
201     }
202
203     function getDescription () {
204         return sprintf(_("List PageHistory for %s"),'[pagename]');
205     }
206     
207     function getDefaultArguments() {
208         return array('days'             => false,
209                      'show_minor'       => true,
210                      'show_major'       => true,
211                      'limit'            => false,
212                      'page'             => '[pagename]',
213                      'format'           => false);
214     }
215
216     function getDefaultFormArguments() {
217         $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
218         $dflts['textinput'] = 'page';
219         return $dflts;
220     }
221
222     function getMostRecentParams ($args) {
223         $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
224         $params['include_all_revisions'] = true;
225         return $params;
226     }
227
228     function getChanges ($dbi, $args) {
229         $page = $dbi->getPage($args['page']);
230         $iter = $page->getAllRevisions();
231         $params = $this->getMostRecentParams($args);
232         return new _PageHistory_PageRevisionIter($iter, $params);
233     }
234
235     function format ($changes, $args) {
236         global $Theme;
237         $format = $args['format'];
238
239         $fmt_class = $Theme->getFormatter('PageHistory', $format);
240         if (!$fmt_class) {
241             if ($format == 'rss')
242                 $fmt_class = '_PageHistory_RssFormatter';
243             else
244                 $fmt_class = '_PageHistory_HtmlFormatter';
245         }
246
247         $fmt = new $fmt_class($args);
248         return $fmt->format($changes);
249     }
250
251     function run ($dbi, $argstr, $request) {
252         $args = $this->getArgs($argstr, $request);
253         if (empty($args['page']))
254             return $this->makeForm("", $request);
255         // Hack alert: format() is a NORETURN for rss formatters.
256         return $this->format($this->getChanges($dbi, $args), $args);
257     }
258 };
259
260
261 // (c-file-style: "gnu")
262 // Local Variables:
263 // mode: php
264 // tab-width: 8
265 // c-basic-offset: 4
266 // c-hanging-comment-ender-p: nil
267 // indent-tabs-mode: nil
268 // End:   
269 ?>