2 rcs_id('$Id: PageHistory.php,v 1.26 2003-02-27 21:15:14 dairiki 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 _javascript($script) {
102 return HTML::script(array('language' => 'JavaScript',
103 'type' => 'text/javascript'),
104 new RawXml("<!-- //\n$script\n// -->"));
107 function description() {
108 // Doesn't work (PHP bug?): $desc = parent::description() . "\n";
109 $button = HTML::input(array('type' => 'submit',
110 'value' => _("compare revisions"),
111 'class' => 'wikiaction'));
112 return array(_RecentChanges_HtmlFormatter::description(), "\n",
113 $this->_javascript(sprintf('document.write("%s");',
114 _("Check any two boxes to compare revisions."))),
115 HTML::noscript(fmt("Check any two boxes then %s.", $button)));
119 function format ($changes) {
120 $this->_itemcount = 0;
122 $pagename = $this->_args['page'];
124 $html[] = _RecentChanges_HtmlFormatter::format($changes);
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 'name' => '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) {
175 $class = 'rc-' . $this->importance($rev);
177 $time = $this->time($rev);
178 if ($rev->get('is_minor_edit')) {
179 $minor_flag = HTML(" ",
180 HTML::span(array('class' => 'pageinfo-minoredit'),
181 "(" . _("minor edit") . ")"));
184 $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
188 return HTML::li(array('class' => $class),
189 $this->diffLink($rev), ' ',
190 $this->pageLink($rev), ' ',
192 $this->summaryAsHTML($rev),
194 $this->authorLink($rev),
200 class _PageHistory_RssFormatter
201 extends _RecentChanges_RssFormatter
203 function include_versions_in_URLs() {
207 function image_properties () {
211 function textinput_properties () {
215 function channel_properties () {
218 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
220 $title = sprintf(_("%s: %s"),
222 split_pagename($this->_args['page']));
224 return array('title' => $title,
225 'dc:description' => _("History of changes."),
227 'dc:date' => Iso8601DateTime(time()));
231 function item_properties ($rev) {
232 if (!($title = $this->summary($rev)))
233 $title = sprintf(_("Version %d"), $rev->getVersion());
235 return array( 'title' => $title,
236 'link' => $this->pageURL($rev),
237 'dc:date' => $this->time($rev),
238 'dc:contributor' => $rev->get('author'),
239 'wiki:version' => $rev->getVersion(),
240 'wiki:importance' => $this->importance($rev),
241 'wiki:status' => $this->status($rev),
242 'wiki:diff' => $this->diffURL($rev),
247 class WikiPlugin_PageHistory
248 extends WikiPlugin_RecentChanges
250 function getName () {
251 return _("PageHistory");
254 function getDescription () {
255 return sprintf(_("List PageHistory for %s"),'[pagename]');
258 function getVersion() {
259 return preg_replace("/[Revision: $]/", '',
260 "\$Revision: 1.26 $");
263 function getDefaultArguments() {
264 return array('days' => false,
265 'show_minor' => true,
266 'show_major' => true,
268 'page' => '[pagename]',
272 function getDefaultFormArguments() {
273 $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
274 $dflts['textinput'] = 'page';
278 function getMostRecentParams ($args) {
279 $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
280 $params['include_all_revisions'] = true;
284 function getChanges ($dbi, $args) {
285 $page = $dbi->getPage($args['page']);
286 $iter = $page->getAllRevisions();
287 $params = $this->getMostRecentParams($args);
288 return new _PageHistory_PageRevisionIter($iter, $params);
291 function format ($changes, $args) {
293 $format = $args['format'];
295 $fmt_class = $Theme->getFormatter('PageHistory', $format);
297 if ($format == 'rss')
298 $fmt_class = '_PageHistory_RssFormatter';
300 $fmt_class = '_PageHistory_HtmlFormatter';
303 $fmt = new $fmt_class($args);
304 return $fmt->format($changes);
307 function run ($dbi, $argstr, $request) {
308 $args = $this->getArgs($argstr, $request);
309 $pagename = $args['page'];
310 if (empty($pagename))
311 return $this->makeForm("", $request);
313 $page = $dbi->getPage($pagename);
314 $current = $page->getCurrentRevision();
315 if ($current->getVersion() < 1) {
316 return HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.",
317 WikiLink($pagename, 'unknown'))),
318 $this->makeForm("", $request));
320 // Hack alert: format() is a NORETURN for rss formatters.
321 return $this->format($this->getChanges($dbi, $args), $args);
325 // $Log: not supported by cvs2svn $
326 // Revision 1.25 2003/02/17 02:19:01 dairiki
327 // Fix so that PageHistory will work when the current revision
328 // of a page has been "deleted".
330 // Revision 1.24 2003/01/18 21:49:00 carstenklapp
332 // Reformatting & tabs to spaces;
333 // Added copyleft, getVersion, getDescription, rcs_id.
335 // Revision 1.23 2003/01/04 23:27:39 carstenklapp
336 // New: Gracefully handle non-existant pages. Added copyleft;
337 // getVersion() for PluginManager.
340 // (c-file-style: "gnu")
345 // c-hanging-comment-ender-p: nil
346 // indent-tabs-mode: nil