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
30 function _PageHistory_PageRevisionIter($rev_iter, $params)
32 $this->_iter = $rev_iter;
37 $this->_since = $since;
39 $this->_include_major = empty($exclude_major_revisions);
40 if (!$this->_include_major)
41 $this->_include_minor = true;
43 $this->_include_minor = !empty($include_minor_revisions);
45 if (empty($include_all_revisions))
47 else if (isset($limit))
48 $this->_limit = $limit;
56 if (isset($this->_limit)) {
57 if ($this->_limit <= 0) {
64 while (($rev = $this->_iter->next())) {
65 if (isset($this->_since) && $rev->get('mtime') < $this->_since) {
69 if ($rev->get('is_minor_edit') ? $this->_include_minor : $this->_include_major)
83 class _PageHistory_HtmlFormatter
84 extends _RecentChanges_HtmlFormatter
86 function include_versions_in_URLs()
93 return HTML(fmt("PageHistory for %s",
94 WikiLink($this->_args['page'])),
104 return "PageHistory:" . $this->_args['page'];
107 function empty_message()
109 return _("No revisions found");
112 function description()
114 $button = HTML::input(array('type' => 'submit',
115 'value' => _("compare revisions"),
116 'class' => 'wikiaction'));
118 $js_desc = $no_js_desc = _RecentChanges_HtmlFormatter::description();
120 $js_desc->pushContent("\n", _("Check any two boxes to compare revisions."));
121 $no_js_desc->pushContent("\n", fmt("Check any two boxes then %s.", $button));
123 return IfJavaScript($js_desc, $no_js_desc);
126 function format($changes)
128 $this->_itemcount = 0;
130 $pagename = $this->_args['page'];
132 $fmt = _RecentChanges_HtmlFormatter::format($changes);
133 $fmt->action = _("PageHistory");
136 $html[] = HTML::input(array('type' => 'hidden',
140 $action = WikiURL($pagename);
142 $action = SCRIPT_NAME;
143 $html[] = HTML::input(array('type' => 'hidden',
144 'name' => 'pagename',
145 'value' => $pagename));
148 return HTML(HTML::form(array('method' => 'get',
150 'id' => 'diff-select'),
154 var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
156 function diffCkBox_onclick() {
157 var nchecked = 0, box = diffCkBoxes;
158 for (i = 0; i < box.length; i++)
159 if (box[i].checked) nchecked++;
162 else if (nchecked > 2) {
163 for (i = 0; i < box.length; i++)
164 if (box[i] != this) box[i].checked = 0;
168 for (i = 0; i < diffCkBoxes.length; i++)
169 diffCkBoxes[i].onclick = diffCkBox_onclick;'));
172 function diffLink($rev)
174 return HTML::input(array('type' => 'checkbox',
175 'name' => 'versions[]',
176 'value' => $rev->getVersion()));
179 function pageLink($rev, $link_text = false)
181 $text = fmt("Version %d", $rev->getVersion());
182 return _RecentChanges_HtmlFormatter::pageLink($rev, $text);
185 function format_revision($rev)
188 $class = 'rc-' . $this->importance($rev);
190 $time = $this->time($rev);
191 if ($rev->get('is_minor_edit')) {
192 $minor_flag = HTML(" ",
193 HTML::span(array('class' => 'pageinfo-minoredit'),
194 "(" . _("minor edit") . ")"));
196 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
199 $line = HTML::li(array('class' => $class));
200 if (is_a($WikiTheme, 'WikiTheme_MonoBook')) {
202 $this->diffLink($rev), ' ',
203 $this->pageLink($rev), ' ',
204 $time, ' ', $this->date($rev), ' . . ',
205 $this->authorLink($rev), ' ',
206 $this->authorContribs($rev), ' ',
207 $this->summaryAsHTML($rev), ' ',
211 $this->diffLink($rev), ' ',
212 $this->pageLink($rev), ' ',
214 $this->summaryAsHTML($rev),
216 $this->authorLink($rev),
223 class _PageHistory_RssFormatter
224 extends _RecentChanges_RssFormatter
226 function include_versions_in_URLs()
231 function image_properties()
236 function textinput_properties()
241 function channel_properties()
245 $rc_url = WikiURL($request->getArg('pagename'), array(), 'absurl');
247 $title = sprintf(_("%s: %s"),
249 SplitPagename($this->_args['page']));
251 return array('title' => $title,
252 'dc:description' => _("History of changes."),
254 'dc:date' => Iso8601DateTime(time()));
257 function item_properties($rev)
259 if (!($title = $this->summary($rev)))
260 $title = sprintf(_("Version %d"), $rev->getVersion());
262 return array('title' => $title,
263 'link' => $this->pageURL($rev),
264 'dc:date' => $this->time($rev),
265 'dc:contributor' => $rev->get('author'),
266 'wiki:version' => $rev->getVersion(),
267 'wiki:importance' => $this->importance($rev),
268 'wiki:status' => $this->status($rev),
269 'wiki:diff' => $this->diffURL($rev),
274 class WikiPlugin_PageHistory
275 extends WikiPlugin_RecentChanges
277 function getDescription()
279 return sprintf(_("List PageHistory for %s."), '[pagename]');
282 function getDefaultArguments()
284 return array('days' => false,
285 'show_minor' => true,
286 'show_major' => true,
288 'page' => '[pagename]',
292 function getDefaultFormArguments()
294 $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
295 $dflts['textinput'] = 'page';
299 function getMostRecentParams($args)
301 $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
302 $params['include_all_revisions'] = true;
306 function getChanges($dbi, $args)
308 $page = $dbi->getPage($args['page']);
309 $iter = $page->getAllRevisions();
310 $params = $this->getMostRecentParams($args);
311 if (empty($args['days'])) unset($params['since']);
312 return new _PageHistory_PageRevisionIter($iter, $params);
315 function format($changes, $args)
318 $format = $args['format'];
320 $fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
322 if ($format == 'rss')
323 $fmt_class = '_PageHistory_RssFormatter';
325 $fmt_class = '_PageHistory_HtmlFormatter';
328 $fmt = new $fmt_class($args);
329 $fmt->action = _("PageHistory");
330 return $fmt->format($changes);
335 * @param string $argstr
336 * @param WikiRequest $request
337 * @param string $basepage
340 function run($dbi, $argstr, &$request, $basepage)
342 $args = $this->getArgs($argstr, $request);
343 $pagename = $args['page'];
344 if (empty($pagename))
345 return $this->makeForm("", $request);
347 $page = $dbi->getPage($pagename);
348 $current = $page->getCurrentRevision();
349 if ($current->getVersion() < 1) {
350 return HTML(HTML::p(fmt("Page ā%sā does not exist.", WikiLink($pagename, 'unknown'))),
351 $this->makeForm("", $request));
353 // Hack alert: format() is a NORETURN for rss formatters.
354 return $this->format($this->getChanges($dbi, $args), $args);
362 // c-hanging-comment-ender-p: nil
363 // indent-tabs-mode: nil