2 // $Id: PageHistory.php 8071 2011-05-18 14:56:14Z vargenau $
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)
81 class _PageHistory_HtmlFormatter
82 extends _RecentChanges_HtmlFormatter
84 function include_versions_in_URLs() {
89 return HTML(fmt("PageHistory for %s",
90 WikiLink($this->_args['page'])),
99 return "PageHistory:".$this->_args['page'];
102 function empty_message () {
103 return _("No revisions found");
106 function description() {
107 $button = HTML::input(array('type' => 'submit',
108 'value' => _("compare revisions"),
109 'class' => 'wikiaction'));
111 $js_desc = $no_js_desc = _RecentChanges_HtmlFormatter::description();
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));
116 return IfJavaScript($js_desc, $no_js_desc);
120 function format ($changes) {
121 $this->_itemcount = 0;
123 $pagename = $this->_args['page'];
125 $fmt = _RecentChanges_HtmlFormatter::format($changes);
126 $fmt->action = _("PageHistory");
129 $html[] = HTML::input(array('type' => 'hidden',
133 $action = WikiURL($pagename);
136 $action = SCRIPT_NAME;
137 $html[] = HTML::input(array('type' => 'hidden',
138 'name' => 'pagename',
139 'value' => $pagename));
142 return HTML(HTML::form(array('method' => 'get',
144 'id' => 'diff-select'),
148 var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
150 function diffCkBox_onclick() {
151 var nchecked = 0, box = diffCkBoxes;
152 for (i = 0; i < box.length; i++)
153 if (box[i].checked) nchecked++;
156 else if (nchecked > 2) {
157 for (i = 0; i < box.length; i++)
158 if (box[i] != this) box[i].checked = 0;
162 for (i = 0; i < diffCkBoxes.length; i++)
163 diffCkBoxes[i].onclick = diffCkBox_onclick;'));
166 function diffLink ($rev) {
167 return HTML::input(array('type' => 'checkbox',
168 'name' => 'versions[]',
169 'value' => $rev->getVersion()));
172 function pageLink ($rev) {
173 $text = fmt("Version %d", $rev->getVersion());
174 return _RecentChanges_HtmlFormatter::pageLink($rev, $text);
177 function format_revision ($rev) {
179 $class = 'rc-' . $this->importance($rev);
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") . ")"));
188 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
191 $line = HTML::li(array('class' => $class));
192 if (isa($WikiTheme,'WikiTheme_MonoBook')) {
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),' ',
203 $this->diffLink($rev), ' ',
204 $this->pageLink($rev), ' ',
206 $this->summaryAsHTML($rev),
208 $this->authorLink($rev),
216 class _PageHistory_RssFormatter
217 extends _RecentChanges_RssFormatter
219 function include_versions_in_URLs() {
223 function image_properties () {
227 function textinput_properties () {
231 function channel_properties () {
234 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
236 $title = sprintf(_("%s: %s"),
238 SplitPagename($this->_args['page']));
240 return array('title' => $title,
241 'dc:description' => _("History of changes."),
243 'dc:date' => Iso8601DateTime(time()));
247 function item_properties ($rev) {
248 if (!($title = $this->summary($rev)))
249 $title = sprintf(_("Version %d"), $rev->getVersion());
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),
263 class WikiPlugin_PageHistory
264 extends WikiPlugin_RecentChanges
266 function getName () {
267 return _("PageHistory");
270 function getDescription () {
271 return sprintf(_("List PageHistory for %s"),'[pagename]');
274 function getDefaultArguments() {
275 return array('days' => false,
276 'show_minor' => true,
277 'show_major' => true,
279 'page' => '[pagename]',
283 function getDefaultFormArguments() {
284 $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
285 $dflts['textinput'] = 'page';
289 function getMostRecentParams ($args) {
290 $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
291 $params['include_all_revisions'] = true;
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);
303 function format ($changes, $args) {
305 $format = $args['format'];
307 $fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
309 if ($format == 'rss')
310 $fmt_class = '_PageHistory_RssFormatter';
312 $fmt_class = '_PageHistory_HtmlFormatter';
315 $fmt = new $fmt_class($args);
316 $fmt->action = _("PageHistory");
317 return $fmt->format($changes);
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);
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));
333 // Hack alert: format() is a NORETURN for rss formatters.
334 return $this->format($this->getChanges($dbi, $args), $args);
342 // c-hanging-comment-ender-p: nil
343 // indent-tabs-mode: nil