4 * Copyright 1999, 2000, 2001, 2002, 2007 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
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.
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.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 require_once 'lib/plugin/RecentChanges.php';
25 class _PageHistory_PageRevisionIter
26 extends WikiDB_PageRevisionIterator
28 function _PageHistory_PageRevisionIter($rev_iter, $params)
31 $this->_iter = $rev_iter;
36 $this->_since = $since;
38 $this->_include_major = empty($exclude_major_revisions);
39 if (!$this->_include_major)
40 $this->_include_minor = true;
42 $this->_include_minor = !empty($include_minor_revisions);
44 if (empty($include_all_revisions))
46 else if (isset($limit))
47 $this->_limit = $limit;
55 if (isset($this->_limit)) {
56 if ($this->_limit <= 0) {
63 while (($rev = $this->_iter->next())) {
64 if (isset($this->_since) && $rev->get('mtime') < $this->_since) {
68 if ($rev->get('is_minor_edit') ? $this->_include_minor : $this->_include_major)
82 class _PageHistory_HtmlFormatter
83 extends _RecentChanges_HtmlFormatter
85 function include_versions_in_URLs()
92 return HTML(fmt("PageHistory for %s",
93 WikiLink($this->_args['page'])),
103 return "PageHistory:" . $this->_args['page'];
106 function empty_message()
108 return _("No revisions found");
111 function description()
113 $button = HTML::input(array('type' => 'submit',
114 'value' => _("compare revisions"),
115 'class' => 'wikiaction'));
117 $js_desc = $no_js_desc = _RecentChanges_HtmlFormatter::description();
119 $js_desc->pushContent("\n", _("Check any two boxes to compare revisions."));
120 $no_js_desc->pushContent("\n", fmt("Check any two boxes then %s.", $button));
122 return IfJavaScript($js_desc, $no_js_desc);
125 function format($changes)
127 $this->_itemcount = 0;
129 $pagename = $this->_args['page'];
131 $fmt = _RecentChanges_HtmlFormatter::format($changes);
132 $fmt->action = _("PageHistory");
135 $html[] = HTML::input(array('type' => 'hidden',
139 $action = WikiURL($pagename);
141 $action = SCRIPT_NAME;
142 $html[] = HTML::input(array('type' => 'hidden',
143 'name' => 'pagename',
144 'value' => $pagename));
147 return HTML(HTML::form(array('method' => 'get',
149 'id' => 'diff-select'),
153 var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
155 function diffCkBox_onclick() {
156 var nchecked = 0, box = diffCkBoxes;
157 for (i = 0; i < box.length; i++)
158 if (box[i].checked) nchecked++;
161 else if (nchecked > 2) {
162 for (i = 0; i < box.length; i++)
163 if (box[i] != this) box[i].checked = 0;
167 for (i = 0; i < diffCkBoxes.length; i++)
168 diffCkBoxes[i].onclick = diffCkBox_onclick;'));
171 function diffLink($rev)
173 return HTML::input(array('type' => 'checkbox',
174 'name' => 'versions[]',
175 'value' => $rev->getVersion()));
178 function pageLink($rev)
180 $text = fmt("Version %d", $rev->getVersion());
181 return _RecentChanges_HtmlFormatter::pageLink($rev, $text);
184 function format_revision($rev)
187 $class = 'rc-' . $this->importance($rev);
189 $time = $this->time($rev);
190 if ($rev->get('is_minor_edit')) {
191 $minor_flag = HTML(" ",
192 HTML::span(array('class' => 'pageinfo-minoredit'),
193 "(" . _("minor edit") . ")"));
195 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
198 $line = HTML::li(array('class' => $class));
199 if (isa($WikiTheme, 'WikiTheme_MonoBook')) {
201 $this->diffLink($rev), ' ',
202 $this->pageLink($rev), ' ',
203 $time, ' ', $this->date($rev), ' . . ',
204 $this->authorLink($rev), ' ',
205 $this->authorContribs($rev), ' ',
206 $this->summaryAsHTML($rev), ' ',
210 $this->diffLink($rev), ' ',
211 $this->pageLink($rev), ' ',
213 $this->summaryAsHTML($rev),
215 $this->authorLink($rev),
222 class _PageHistory_RssFormatter
223 extends _RecentChanges_RssFormatter
225 function include_versions_in_URLs()
230 function image_properties()
235 function textinput_properties()
240 function channel_properties()
244 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
246 $title = sprintf(_("%s: %s"),
248 SplitPagename($this->_args['page']));
250 return array('title' => $title,
251 'dc:description' => _("History of changes."),
253 'dc:date' => Iso8601DateTime(time()));
256 function item_properties($rev)
258 if (!($title = $this->summary($rev)))
259 $title = sprintf(_("Version %d"), $rev->getVersion());
261 return array('title' => $title,
262 'link' => $this->pageURL($rev),
263 'dc:date' => $this->time($rev),
264 'dc:contributor' => $rev->get('author'),
265 'wiki:version' => $rev->getVersion(),
266 'wiki:importance' => $this->importance($rev),
267 'wiki:status' => $this->status($rev),
268 'wiki:diff' => $this->diffURL($rev),
273 class WikiPlugin_PageHistory
274 extends WikiPlugin_RecentChanges
278 return _("PageHistory");
281 function getDescription()
283 return sprintf(_("List PageHistory for %s"), '[pagename]');
286 function getDefaultArguments()
288 return array('days' => false,
289 'show_minor' => true,
290 'show_major' => true,
292 'page' => '[pagename]',
296 function getDefaultFormArguments()
298 $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
299 $dflts['textinput'] = 'page';
303 function getMostRecentParams($args)
305 $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
306 $params['include_all_revisions'] = true;
310 function getChanges($dbi, $args)
312 $page = $dbi->getPage($args['page']);
313 $iter = $page->getAllRevisions();
314 $params = $this->getMostRecentParams($args);
315 if (empty($args['days'])) unset($params['since']);
316 return new _PageHistory_PageRevisionIter($iter, $params);
319 function format($changes, $args)
322 $format = $args['format'];
324 $fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
326 if ($format == 'rss')
327 $fmt_class = '_PageHistory_RssFormatter';
329 $fmt_class = '_PageHistory_HtmlFormatter';
332 $fmt = new $fmt_class($args);
333 $fmt->action = _("PageHistory");
334 return $fmt->format($changes);
337 function run($dbi, $argstr, &$request, $basepage)
339 $args = $this->getArgs($argstr, $request);
340 $pagename = $args['page'];
341 if (empty($pagename))
342 return $this->makeForm("", $request);
344 $page = $dbi->getPage($pagename);
345 $current = $page->getCurrentRevision();
346 if ($current->getVersion() < 1) {
347 return HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.",
348 WikiLink($pagename, 'unknown'))),
349 $this->makeForm("", $request));
351 // Hack alert: format() is a NORETURN for rss formatters.
352 return $this->format($this->getChanges($dbi, $args), $args);
360 // c-hanging-comment-ender-p: nil
361 // indent-tabs-mode: nil