2 rcs_id('$Id: PageHistory.php,v 1.30 2004-06-14 11:31:39 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002 $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
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 require_once('lib/plugin/RecentChanges.php');
27 class _PageHistory_PageRevisionIter
28 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;
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)
83 class _PageHistory_HtmlFormatter
84 extends _RecentChanges_HtmlFormatter
86 function include_versions_in_URLs() {
91 return array(fmt("PageHistory for %s",
92 WikiLink($this->_args['page'])),
97 function empty_message () {
98 return _("No revisions found");
101 function description() {
102 $button = HTML::input(array('type' => 'submit',
103 'value' => _("compare revisions"),
104 'class' => 'wikiaction'));
106 $js_desc = $no_js_desc = _RecentChanges_HtmlFormatter::description();
108 $js_desc->pushContent("\n", _("Check any two boxes to compare revisions."));
109 $no_js_desc->pushContent("\n", fmt("Check any two boxes then %s.", $button));
111 return IfJavaScript($js_desc, $no_js_desc);
115 function format ($changes) {
116 $this->_itemcount = 0;
118 $pagename = $this->_args['page'];
120 $html[] = _RecentChanges_HtmlFormatter::format($changes);
122 $html[] = HTML::input(array('type' => 'hidden',
126 $action = WikiURL($pagename);
129 $action = SCRIPT_NAME;
130 $html[] = HTML::input(array('type' => 'hidden',
131 'name' => 'pagename',
132 'value' => $pagename));
135 return HTML(HTML::form(array('method' => 'get',
137 'name' => 'diff-select'),
141 var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
143 function diffCkBox_onclick() {
144 var nchecked = 0, box = diffCkBoxes;
145 for (i = 0; i < box.length; i++)
146 if (box[i].checked) nchecked++;
149 else if (nchecked > 2) {
150 for (i = 0; i < box.length; i++)
151 if (box[i] != this) box[i].checked = 0;
155 for (i = 0; i < diffCkBoxes.length; i++)
156 diffCkBoxes[i].onclick = diffCkBox_onclick;'));
159 function diffLink ($rev) {
160 return HTML::input(array('type' => 'checkbox',
161 'name' => 'versions[]',
162 'value' => $rev->getVersion()));
165 function pageLink ($rev) {
166 $text = fmt("Version %d", $rev->getVersion());
167 return _RecentChanges_HtmlFormatter::pageLink($rev, $text);
170 function format_revision ($rev) {
171 $class = 'rc-' . $this->importance($rev);
173 $time = $this->time($rev);
174 if ($rev->get('is_minor_edit')) {
175 $minor_flag = HTML(" ",
176 HTML::span(array('class' => 'pageinfo-minoredit'),
177 "(" . _("minor edit") . ")"));
180 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
184 return HTML::li(array('class' => $class),
185 $this->diffLink($rev), ' ',
186 $this->pageLink($rev), ' ',
188 $this->summaryAsHTML($rev),
190 $this->authorLink($rev),
196 class _PageHistory_RssFormatter
197 extends _RecentChanges_RssFormatter
199 function include_versions_in_URLs() {
203 function image_properties () {
207 function textinput_properties () {
211 function channel_properties () {
214 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
216 $title = sprintf(_("%s: %s"),
218 SplitPagename($this->_args['page']));
220 return array('title' => $title,
221 'dc:description' => _("History of changes."),
223 'dc:date' => Iso8601DateTime(time()));
227 function item_properties ($rev) {
228 if (!($title = $this->summary($rev)))
229 $title = sprintf(_("Version %d"), $rev->getVersion());
231 return array( 'title' => $title,
232 'link' => $this->pageURL($rev),
233 'dc:date' => $this->time($rev),
234 'dc:contributor' => $rev->get('author'),
235 'wiki:version' => $rev->getVersion(),
236 'wiki:importance' => $this->importance($rev),
237 'wiki:status' => $this->status($rev),
238 'wiki:diff' => $this->diffURL($rev),
243 class WikiPlugin_PageHistory
244 extends WikiPlugin_RecentChanges
246 function getName () {
247 return _("PageHistory");
250 function getDescription () {
251 return sprintf(_("List PageHistory for %s"),'[pagename]');
254 function getVersion() {
255 return preg_replace("/[Revision: $]/", '',
256 "\$Revision: 1.30 $");
259 function getDefaultArguments() {
260 return array('days' => false,
261 'show_minor' => true,
262 'show_major' => true,
264 'page' => '[pagename]',
268 function getDefaultFormArguments() {
269 $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
270 $dflts['textinput'] = 'page';
274 function getMostRecentParams ($args) {
275 $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
276 $params['include_all_revisions'] = true;
280 function getChanges ($dbi, $args) {
281 $page = $dbi->getPage($args['page']);
282 $iter = $page->getAllRevisions();
283 $params = $this->getMostRecentParams($args);
284 return new _PageHistory_PageRevisionIter($iter, $params);
287 function format ($changes, $args) {
289 $format = $args['format'];
291 $fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
293 if ($format == 'rss')
294 $fmt_class = '_PageHistory_RssFormatter';
296 $fmt_class = '_PageHistory_HtmlFormatter';
299 $fmt = new $fmt_class($args);
300 return $fmt->format($changes);
303 function run($dbi, $argstr, &$request, $basepage) {
304 $args = $this->getArgs($argstr, $request);
305 $pagename = $args['page'];
306 if (empty($pagename))
307 return $this->makeForm("", $request);
309 $page = $dbi->getPage($pagename);
310 $current = $page->getCurrentRevision();
311 if ($current->getVersion() < 1) {
312 return HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.",
313 WikiLink($pagename, 'unknown'))),
314 $this->makeForm("", $request));
316 // Hack alert: format() is a NORETURN for rss formatters.
317 return $this->format($this->getChanges($dbi, $args), $args);
321 // $Log: not supported by cvs2svn $
322 // Revision 1.29 2004/05/18 16:23:40 rurban
323 // rename split_pagename to SplitPagename
325 // Revision 1.28 2004/02/17 12:11:36 rurban
326 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
328 // Revision 1.27 2003/02/27 22:48:44 dairiki
329 // Fixes invalid HTML generated by PageHistory plugin.
331 // (<noscript> is block-level and not allowed within <p>.)
333 // Revision 1.26 2003/02/27 21:15:14 dairiki
336 // Fix so that you can never have more than two checkboxes checked. (If this
337 // happens, all but the current checkbox are unchecked.)
339 // It used to be that one could view a PageHistory, check two boxes to view
340 // a diff, then hit the back button. (The originally checked two boxes are
341 // still checked at this point.) Checking a third box resulted in viewing
342 // a diff between a quasi-random pair of versions selected from the three
343 // which were selected. Now clicking the third box results in the first
344 // two being unchecked.
346 // Revision 1.25 2003/02/17 02:19:01 dairiki
347 // Fix so that PageHistory will work when the current revision
348 // of a page has been "deleted".
350 // Revision 1.24 2003/01/18 21:49:00 carstenklapp
352 // Reformatting & tabs to spaces;
353 // Added copyleft, getVersion, getDescription, rcs_id.
355 // Revision 1.23 2003/01/04 23:27:39 carstenklapp
356 // New: Gracefully handle non-existant pages. Added copyleft;
357 // getVersion() for PluginManager.
360 // (c-file-style: "gnu")
365 // c-hanging-comment-ender-p: nil
366 // indent-tabs-mode: nil