1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
|
<?php // -*-php-*-
rcs_id('$Id: PageHistory.php,v 1.30 2004/06/14 11:31:39 rurban Exp $');
/**
Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
This file is part of PhpWiki.
PhpWiki is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PhpWiki is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PhpWiki; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
*/
require_once('lib/plugin/RecentChanges.php');
class _PageHistory_PageRevisionIter
extends WikiDB_PageRevisionIterator
{
function _PageHistory_PageRevisionIter($rev_iter, $params) {
$this->_iter = $rev_iter;
extract($params);
if (isset($since))
$this->_since = $since;
$this->_include_major = empty($exclude_major_revisions);
if (! $this->_include_major)
$this->_include_minor = true;
else
$this->_include_minor = !empty($include_minor_revisions);
if (empty($include_all_revisions))
$this->_limit = 1;
else if (isset($limit))
$this->_limit = $limit;
}
function next() {
if (!$this->_iter)
return false;
if (isset($this->_limit)) {
if ($this->_limit <= 0) {
$this->free();
return false;
}
$this->_limit--;
}
while ( ($rev = $this->_iter->next()) ) {
if (isset($this->_since) && $rev->get('mtime') < $this->_since) {
$this->free();
return false;
}
if ($rev->get('is_minor_edit') ? $this->_include_minor : $this->_include_major)
return $rev;
}
return false;
}
function free() {
if ($this->_iter)
$this->_iter->free();
$this->_iter = false;
}
}
class _PageHistory_HtmlFormatter
extends _RecentChanges_HtmlFormatter
{
function include_versions_in_URLs() {
return true;
}
function title() {
return array(fmt("PageHistory for %s",
WikiLink($this->_args['page'])),
"\n",
$this->rss_icon());
}
function empty_message () {
return _("No revisions found");
}
function description() {
$button = HTML::input(array('type' => 'submit',
'value' => _("compare revisions"),
'class' => 'wikiaction'));
$js_desc = $no_js_desc = _RecentChanges_HtmlFormatter::description();
$js_desc->pushContent("\n", _("Check any two boxes to compare revisions."));
$no_js_desc->pushContent("\n", fmt("Check any two boxes then %s.", $button));
return IfJavaScript($js_desc, $no_js_desc);
}
function format ($changes) {
$this->_itemcount = 0;
$pagename = $this->_args['page'];
$html[] = _RecentChanges_HtmlFormatter::format($changes);
$html[] = HTML::input(array('type' => 'hidden',
'name' => 'action',
'value' => 'diff'));
if (USE_PATH_INFO) {
$action = WikiURL($pagename);
}
else {
$action = SCRIPT_NAME;
$html[] = HTML::input(array('type' => 'hidden',
'name' => 'pagename',
'value' => $pagename));
}
return HTML(HTML::form(array('method' => 'get',
'action' => $action,
'name' => 'diff-select'),
$html),
"\n",
JavaScript('
var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
function diffCkBox_onclick() {
var nchecked = 0, box = diffCkBoxes;
for (i = 0; i < box.length; i++)
if (box[i].checked) nchecked++;
if (nchecked == 2)
this.form.submit();
else if (nchecked > 2) {
for (i = 0; i < box.length; i++)
if (box[i] != this) box[i].checked = 0;
}
}
for (i = 0; i < diffCkBoxes.length; i++)
diffCkBoxes[i].onclick = diffCkBox_onclick;'));
}
function diffLink ($rev) {
return HTML::input(array('type' => 'checkbox',
'name' => 'versions[]',
'value' => $rev->getVersion()));
}
function pageLink ($rev) {
$text = fmt("Version %d", $rev->getVersion());
return _RecentChanges_HtmlFormatter::pageLink($rev, $text);
}
function format_revision ($rev) {
$class = 'rc-' . $this->importance($rev);
$time = $this->time($rev);
if ($rev->get('is_minor_edit')) {
$minor_flag = HTML(" ",
HTML::span(array('class' => 'pageinfo-minoredit'),
"(" . _("minor edit") . ")"));
}
else {
$time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
$minor_flag = '';
}
return HTML::li(array('class' => $class),
$this->diffLink($rev), ' ',
$this->pageLink($rev), ' ',
$time, ' ',
$this->summaryAsHTML($rev),
' ... ',
$this->authorLink($rev),
$minor_flag);
}
}
class _PageHistory_RssFormatter
extends _RecentChanges_RssFormatter
{
function include_versions_in_URLs() {
return true;
}
function image_properties () {
return false;
}
function textinput_properties () {
return false;
}
function channel_properties () {
global $request;
$rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
$title = sprintf(_("%s: %s"),
WIKI_NAME,
SplitPagename($this->_args['page']));
return array('title' => $title,
'dc:description' => _("History of changes."),
'link' => $rc_url,
'dc:date' => Iso8601DateTime(time()));
}
function item_properties ($rev) {
if (!($title = $this->summary($rev)))
$title = sprintf(_("Version %d"), $rev->getVersion());
return array( 'title' => $title,
'link' => $this->pageURL($rev),
'dc:date' => $this->time($rev),
'dc:contributor' => $rev->get('author'),
'wiki:version' => $rev->getVersion(),
'wiki:importance' => $this->importance($rev),
'wiki:status' => $this->status($rev),
'wiki:diff' => $this->diffURL($rev),
);
}
}
class WikiPlugin_PageHistory
extends WikiPlugin_RecentChanges
{
function getName () {
return _("PageHistory");
}
function getDescription () {
return sprintf(_("List PageHistory for %s"),'[pagename]');
}
function getVersion() {
return preg_replace("/[Revision: $]/", '',
"\$Revision: 1.30 $");
}
function getDefaultArguments() {
return array('days' => false,
'show_minor' => true,
'show_major' => true,
'limit' => false,
'page' => '[pagename]',
'format' => false);
}
function getDefaultFormArguments() {
$dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
$dflts['textinput'] = 'page';
return $dflts;
}
function getMostRecentParams ($args) {
$params = WikiPlugin_RecentChanges::getMostRecentParams($args);
$params['include_all_revisions'] = true;
return $params;
}
function getChanges ($dbi, $args) {
$page = $dbi->getPage($args['page']);
$iter = $page->getAllRevisions();
$params = $this->getMostRecentParams($args);
return new _PageHistory_PageRevisionIter($iter, $params);
}
function format ($changes, $args) {
global $WikiTheme;
$format = $args['format'];
$fmt_class = $WikiTheme->getFormatter('PageHistory', $format);
if (!$fmt_class) {
if ($format == 'rss')
$fmt_class = '_PageHistory_RssFormatter';
else
$fmt_class = '_PageHistory_HtmlFormatter';
}
$fmt = new $fmt_class($args);
return $fmt->format($changes);
}
function run($dbi, $argstr, &$request, $basepage) {
$args = $this->getArgs($argstr, $request);
$pagename = $args['page'];
if (empty($pagename))
return $this->makeForm("", $request);
$page = $dbi->getPage($pagename);
$current = $page->getCurrentRevision();
if ($current->getVersion() < 1) {
return HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.",
WikiLink($pagename, 'unknown'))),
$this->makeForm("", $request));
}
// Hack alert: format() is a NORETURN for rss formatters.
return $this->format($this->getChanges($dbi, $args), $args);
}
};
// $Log: PageHistory.php,v $
// Revision 1.30 2004/06/14 11:31:39 rurban
// renamed global $Theme to $WikiTheme (gforge nameclash)
// inherit PageList default options from PageList
// default sortby=pagename
// use options in PageList_Selectable (limit, sortby, ...)
// added action revert, with button at action=diff
// added option regex to WikiAdminSearchReplace
//
// Revision 1.29 2004/05/18 16:23:40 rurban
// rename split_pagename to SplitPagename
//
// Revision 1.28 2004/02/17 12:11:36 rurban
// 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, ...)
//
// Revision 1.27 2003/02/27 22:48:44 dairiki
// Fixes invalid HTML generated by PageHistory plugin.
//
// (<noscript> is block-level and not allowed within <p>.)
//
// Revision 1.26 2003/02/27 21:15:14 dairiki
// Javascript fix.
//
// Fix so that you can never have more than two checkboxes checked. (If this
// happens, all but the current checkbox are unchecked.)
//
// It used to be that one could view a PageHistory, check two boxes to view
// a diff, then hit the back button. (The originally checked two boxes are
// still checked at this point.) Checking a third box resulted in viewing
// a diff between a quasi-random pair of versions selected from the three
// which were selected. Now clicking the third box results in the first
// two being unchecked.
//
// Revision 1.25 2003/02/17 02:19:01 dairiki
// Fix so that PageHistory will work when the current revision
// of a page has been "deleted".
//
// Revision 1.24 2003/01/18 21:49:00 carstenklapp
// Code cleanup:
// Reformatting & tabs to spaces;
// Added copyleft, getVersion, getDescription, rcs_id.
//
// Revision 1.23 2003/01/04 23:27:39 carstenklapp
// New: Gracefully handle non-existant pages. Added copyleft;
// getVersion() for PluginManager.
//
// (c-file-style: "gnu")
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:
?>
|