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
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 HTML(fmt("PageHistory for %s",
92 WikiLink($this->_args['page'])),
101 return "PageHistory:".$this->_args['page'];
104 function empty_message () {
105 return _("No revisions found");
108 function description() {
109 $button = HTML::input(array('type' => 'submit',
110 'value' => _("compare revisions"),
111 'class' => 'wikiaction'));
113 $js_desc = $no_js_desc = _RecentChanges_HtmlFormatter::description();
115 $js_desc->pushContent("\n", _("Check any two boxes to compare revisions."));
116 $no_js_desc->pushContent("\n", fmt("Check any two boxes then %s.", $button));
118 return IfJavaScript($js_desc, $no_js_desc);
122 function format ($changes) {
123 $this->_itemcount = 0;
125 $pagename = $this->_args['page'];
127 $fmt = _RecentChanges_HtmlFormatter::format($changes);
128 $fmt->action = _("PageHistory");
131 $html[] = HTML::input(array('type' => 'hidden',
135 $action = WikiURL($pagename);
138 $action = SCRIPT_NAME;
139 $html[] = HTML::input(array('type' => 'hidden',
140 'name' => 'pagename',
141 'value' => $pagename));
144 return HTML(HTML::form(array('method' => 'get',
146 'name' => 'diff-select'),
150 var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
152 function diffCkBox_onclick() {
153 var nchecked = 0, box = diffCkBoxes;
154 for (i = 0; i < box.length; i++)
155 if (box[i].checked) nchecked++;
158 else if (nchecked > 2) {
159 for (i = 0; i < box.length; i++)
160 if (box[i] != this) box[i].checked = 0;
164 for (i = 0; i < diffCkBoxes.length; i++)
165 diffCkBoxes[i].onclick = diffCkBox_onclick;'));
168 function diffLink ($rev) {
169 return HTML::input(array('type' => 'checkbox',
170 'name' => 'versions[]',
171 'value' => $rev->getVersion()));
174 function pageLink ($rev) {
175 $text = fmt("Version %d", $rev->getVersion());
176 return _RecentChanges_HtmlFormatter::pageLink($rev, $text);
179 function format_revision ($rev) {
181 $class = 'rc-' . $this->importance($rev);
183 $time = $this->time($rev);
184 if ($rev->get('is_minor_edit')) {
185 $minor_flag = HTML(" ",
186 HTML::span(array('class' => 'pageinfo-minoredit'),
187 "(" . _("minor edit") . ")"));
190 $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
193 $line = HTML::li(array('class' => $class));
194 if (isa($WikiTheme,'WikiTheme_MonoBook')) {
196 $this->diffLink($rev), ' ',
197 $this->pageLink($rev), ' ',
198 $time,' ',$this->date($rev), ' . . ',
199 $this->authorLink($rev),' ',
200 $this->authorContribs($rev),' ',
201 $this->summaryAsHTML($rev),' ',
205 $this->diffLink($rev), ' ',
206 $this->pageLink($rev), ' ',
208 $this->summaryAsHTML($rev),
210 $this->authorLink($rev),
218 class _PageHistory_RssFormatter
219 extends _RecentChanges_RssFormatter
221 function include_versions_in_URLs() {
225 function image_properties () {
229 function textinput_properties () {
233 function channel_properties () {
236 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
238 $title = sprintf(_("%s: %s"),
240 SplitPagename($this->_args['page']));
242 return array('title' => $title,
243 'dc:description' => _("History of changes."),
245 'dc:date' => Iso8601DateTime(time()));
249 function item_properties ($rev) {
250 if (!($title = $this->summary($rev)))
251 $title = sprintf(_("Version %d"), $rev->getVersion());
253 return array( 'title' => $title,
254 'link' => $this->pageURL($rev),
255 'dc:date' => $this->time($rev),
256 'dc:contributor' => $rev->get('author'),
257 'wiki:version' => $rev->getVersion(),
258 'wiki:importance' => $this->importance($rev),
259 'wiki:status' => $this->status($rev),
260 'wiki:diff' => $this->diffURL($rev),
265 class WikiPlugin_PageHistory
266 extends WikiPlugin_RecentChanges
268 function getName () {
269 return _("PageHistory");
272 function getDescription () {
273 return sprintf(_("List PageHistory for %s"),'[pagename]');
276 function getVersion() {
277 return preg_replace("/[Revision: $]/", '',
281 function getDefaultArguments() {
282 return array('days' => false,
283 'show_minor' => true,
284 'show_major' => true,
286 'page' => '[pagename]',
290 function getDefaultFormArguments() {
291 $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
292 $dflts['textinput'] = 'page';
296 function getMostRecentParams ($args) {
297 $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
298 $params['include_all_revisions'] = true;
302 function getChanges ($dbi, $args) {
303 $page = $dbi->getPage($args['page']);
304 $iter = $page->getAllRevisions();
305 $params = $this->getMostRecentParams($args);
306 if (empty($args['days'])) unset($params['since']);
307 return new _PageHistory_PageRevisionIter($iter, $params);
310 function format ($changes, $args) {
312 $format = $args['format'];
314 $fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
316 if ($format == 'rss')
317 $fmt_class = '_PageHistory_RssFormatter';
319 $fmt_class = '_PageHistory_HtmlFormatter';
322 $fmt = new $fmt_class($args);
323 $fmt->action = _("PageHistory");
324 return $fmt->format($changes);
327 function run($dbi, $argstr, &$request, $basepage) {
328 $args = $this->getArgs($argstr, $request);
329 $pagename = $args['page'];
330 if (empty($pagename))
331 return $this->makeForm("", $request);
333 $page = $dbi->getPage($pagename);
334 $current = $page->getCurrentRevision();
335 if ($current->getVersion() < 1) {
336 return HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.",
337 WikiLink($pagename, 'unknown'))),
338 $this->makeForm("", $request));
340 // Hack alert: format() is a NORETURN for rss formatters.
341 return $this->format($this->getChanges($dbi, $args), $args);
345 // (c-file-style: "gnu")
350 // c-hanging-comment-ender-p: nil
351 // indent-tabs-mode: nil