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) {
30 $this->_iter = $rev_iter;
35 $this->_since = $since;
37 $this->_include_major = empty($exclude_major_revisions);
38 if (! $this->_include_major)
39 $this->_include_minor = true;
41 $this->_include_minor = !empty($include_minor_revisions);
43 if (empty($include_all_revisions))
45 else if (isset($limit))
46 $this->_limit = $limit;
53 if (isset($this->_limit)) {
54 if ($this->_limit <= 0) {
61 while ( ($rev = $this->_iter->next()) ) {
62 if (isset($this->_since) && $rev->get('mtime') < $this->_since) {
66 if ($rev->get('is_minor_edit') ? $this->_include_minor : $this->_include_major)
79 class _PageHistory_HtmlFormatter
80 extends _RecentChanges_HtmlFormatter
82 function include_versions_in_URLs() {
87 return HTML(fmt("PageHistory for %s",
88 WikiLink($this->_args['page'])),
97 return "PageHistory:".$this->_args['page'];
100 function empty_message () {
101 return _("No revisions found");
104 function description() {
105 $button = HTML::input(array('type' => 'submit',
106 'value' => _("compare revisions"),
107 'class' => 'wikiaction'));
109 $js_desc = $no_js_desc = _RecentChanges_HtmlFormatter::description();
111 $js_desc->pushContent("\n", _("Check any two boxes to compare revisions."));
112 $no_js_desc->pushContent("\n", fmt("Check any two boxes then %s.", $button));
114 return IfJavaScript($js_desc, $no_js_desc);
117 function format ($changes) {
118 $this->_itemcount = 0;
120 $pagename = $this->_args['page'];
122 $fmt = _RecentChanges_HtmlFormatter::format($changes);
123 $fmt->action = _("PageHistory");
126 $html[] = HTML::input(array('type' => 'hidden',
130 $action = WikiURL($pagename);
133 $action = SCRIPT_NAME;
134 $html[] = HTML::input(array('type' => 'hidden',
135 'name' => 'pagename',
136 'value' => $pagename));
139 return HTML(HTML::form(array('method' => 'get',
141 'id' => 'diff-select'),
145 var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
147 function diffCkBox_onclick() {
148 var nchecked = 0, box = diffCkBoxes;
149 for (i = 0; i < box.length; i++)
150 if (box[i].checked) nchecked++;
153 else if (nchecked > 2) {
154 for (i = 0; i < box.length; i++)
155 if (box[i] != this) box[i].checked = 0;
159 for (i = 0; i < diffCkBoxes.length; i++)
160 diffCkBoxes[i].onclick = diffCkBox_onclick;'));
163 function diffLink ($rev) {
164 return HTML::input(array('type' => 'checkbox',
165 'name' => 'versions[]',
166 'value' => $rev->getVersion()));
169 function pageLink ($rev) {
170 $text = fmt("Version %d", $rev->getVersion());
171 return _RecentChanges_HtmlFormatter::pageLink($rev, $text);
174 function format_revision ($rev) {
176 $class = 'rc-' . $this->importance($rev);
178 $time = $this->time($rev);
179 if ($rev->get('is_minor_edit')) {
180 $minor_flag = HTML(" ",
181 HTML::span(array('class' => 'pageinfo-minoredit'),
182 "(" . _("minor edit") . ")"));
185 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
188 $line = HTML::li(array('class' => $class));
189 if (isa($WikiTheme,'WikiTheme_MonoBook')) {
191 $this->diffLink($rev), ' ',
192 $this->pageLink($rev), ' ',
193 $time,' ',$this->date($rev), ' . . ',
194 $this->authorLink($rev),' ',
195 $this->authorContribs($rev),' ',
196 $this->summaryAsHTML($rev),' ',
200 $this->diffLink($rev), ' ',
201 $this->pageLink($rev), ' ',
203 $this->summaryAsHTML($rev),
205 $this->authorLink($rev),
212 class _PageHistory_RssFormatter
213 extends _RecentChanges_RssFormatter
215 function include_versions_in_URLs() {
219 function image_properties () {
223 function textinput_properties () {
227 function channel_properties () {
230 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
232 $title = sprintf(_("%s: %s"),
234 SplitPagename($this->_args['page']));
236 return array('title' => $title,
237 'dc:description' => _("History of changes."),
239 'dc:date' => Iso8601DateTime(time()));
242 function item_properties ($rev) {
243 if (!($title = $this->summary($rev)))
244 $title = sprintf(_("Version %d"), $rev->getVersion());
246 return array( 'title' => $title,
247 'link' => $this->pageURL($rev),
248 'dc:date' => $this->time($rev),
249 'dc:contributor' => $rev->get('author'),
250 'wiki:version' => $rev->getVersion(),
251 'wiki:importance' => $this->importance($rev),
252 'wiki:status' => $this->status($rev),
253 'wiki:diff' => $this->diffURL($rev),
258 class WikiPlugin_PageHistory
259 extends WikiPlugin_RecentChanges
261 function getName () {
262 return _("PageHistory");
265 function getDescription () {
266 return sprintf(_("List PageHistory for %s"),'[pagename]');
269 function getDefaultArguments() {
270 return array('days' => false,
271 'show_minor' => true,
272 'show_major' => true,
274 'page' => '[pagename]',
278 function getDefaultFormArguments() {
279 $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
280 $dflts['textinput'] = 'page';
284 function getMostRecentParams ($args) {
285 $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
286 $params['include_all_revisions'] = true;
290 function getChanges ($dbi, $args) {
291 $page = $dbi->getPage($args['page']);
292 $iter = $page->getAllRevisions();
293 $params = $this->getMostRecentParams($args);
294 if (empty($args['days'])) unset($params['since']);
295 return new _PageHistory_PageRevisionIter($iter, $params);
298 function format ($changes, $args) {
300 $format = $args['format'];
302 $fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
304 if ($format == 'rss')
305 $fmt_class = '_PageHistory_RssFormatter';
307 $fmt_class = '_PageHistory_HtmlFormatter';
310 $fmt = new $fmt_class($args);
311 $fmt->action = _("PageHistory");
312 return $fmt->format($changes);
315 function run($dbi, $argstr, &$request, $basepage) {
316 $args = $this->getArgs($argstr, $request);
317 $pagename = $args['page'];
318 if (empty($pagename))
319 return $this->makeForm("", $request);
321 $page = $dbi->getPage($pagename);
322 $current = $page->getCurrentRevision();
323 if ($current->getVersion() < 1) {
324 return HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.",
325 WikiLink($pagename, 'unknown'))),
326 $this->makeForm("", $request));
328 // Hack alert: format() is a NORETURN for rss formatters.
329 return $this->format($this->getChanges($dbi, $args), $args);
337 // c-hanging-comment-ender-p: nil
338 // indent-tabs-mode: nil