2 rcs_id('$Id: PageHistory.php,v 1.17 2002-01-30 23:41:54 dairiki Exp $');
5 require_once('lib/plugin/RecentChanges.php');
7 class _PageHistory_PageRevisionIter
8 extends WikiDB_PageRevisionIterator
10 function _PageHistory_PageRevisionIter($rev_iter, $params) {
12 $this->_iter = $rev_iter;
17 $this->_since = $since;
19 $this->_include_major = empty($exclude_major_revisions);
20 if (! $this->_include_major)
21 $this->_include_minor = true;
23 $this->_include_minor = !empty($include_minor_revisions);
25 if (empty($include_all_revisions))
27 else if (isset($limit))
28 $this->_limit = $limit;
35 if (isset($this->_limit)) {
36 if ($this->_limit <= 0) {
43 while ( ($rev = $this->_iter->next()) ) {
44 if (isset($this->_since) && $rev->get('mtime') < $this->_since) {
48 if ($rev->get('is_minor_edit') ? $this->_include_minor : $this->_include_major)
63 class _PageHistory_HtmlFormatter
64 extends _RecentChanges_HtmlFormatter
66 function include_versions_in_URLs() {
71 return array(fmt("PageHistory for %s",
72 WikiLink($this->_args['page'])),
77 function _javascript($script) {
78 return HTML::script(array('language' => 'JavaScript',
79 'type' => 'text/javascript'),
80 new RawXml("<!-- //\n$script\n// -->"));
83 function description() {
84 // Doesn't work (PHP bug?): $desc = parent::description() . "\n";
85 $button = HTML::input(array('type' => 'submit',
86 'value' => _("compare revisions")));
87 return array(_RecentChanges_HtmlFormatter::description(), "\n",
88 $this->_javascript(sprintf('document.write("%s");',
89 _("Check any two boxes to compare revisions."))),
90 HTML::noscript(fmt("Check any two boxes then %s.", $button)));
94 function format ($changes) {
95 $this->_itemcount = 0;
97 $pagename = $this->_args['page'];
99 $html[] = _RecentChanges_HtmlFormatter::format($changes);
101 $html[] = HTML::input(array('type' => 'hidden',
105 $action = WikiURL($pagename);
108 $action = SCRIPT_NAME;
109 $html[] = HTML::input(array('type' => 'hidden',
110 'name' => 'pagename',
111 'value' => $pagename));
114 return HTML(HTML::form(array('method' => 'get',
116 'name' => 'diff-select'),
120 var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
122 function diffCkBox_onclick() {
123 // If two checkboxes are checked, submit form
125 for (i = 0; i < diffCkBoxes.length; i++)
126 if (diffCkBoxes[i].checked && ++nchecked >= 2)
130 for (i = 0; i < diffCkBoxes.length; i++)
131 diffCkBoxes[i].onclick = diffCkBox_onclick;'));
134 function diffLink ($rev) {
135 return HTML::input(array('type' => 'checkbox',
136 'name' => 'versions[]',
137 'value' => $rev->getVersion()));
140 function pageLink ($rev) {
141 return HTML::a(array('href' => $this->pageURL($rev),
143 fmt("Version %d", $rev->getVersion()));
146 function format_revision ($rev) {
147 $class = 'rc-' . $this->importance($rev);
149 $time = $this->time($rev);
150 if ($rev->get('is_minor_edit')) {
151 $minor_flag = HTML::small(HTML::em(" (" . _("minor edit") . ")"));
154 $time = HTML::strong($time);
158 return HTML::li(array('class' => $class),
159 $this->diffLink($rev), ' ',
160 $this->pageLink($rev), ' ',
162 $this->summaryAsHTML($rev),
164 $this->authorLink($rev),
170 class _PageHistory_RssFormatter
171 extends _RecentChanges_RssFormatter
173 function include_versions_in_URLs() {
177 function image_properties () {
181 function textinput_properties () {
185 function channel_properties () {
188 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
190 $title = sprintf("%s: %s",
192 split_pagename($this->_args['page']));
194 return array('title' => $title,
195 'dc:description' => _("History of changes."),
197 'dc:date' => Iso8601DateTime(time()));
201 function item_properties ($rev) {
202 if (!($title = $this->summary($rev)))
203 $title = sprintf(_("Version %d"), $rev->getVersion());
205 return array( 'title' => $title,
206 'link' => $this->pageURL($rev),
207 'dc:date' => $this->time($rev),
208 'dc:contributor' => $rev->get('author'),
209 'wiki:version' => $rev->getVersion(),
210 'wiki:importance' => $this->importance($rev),
211 'wiki:status' => $this->status($rev),
212 'wiki:diff' => $this->diffURL($rev),
217 class WikiPlugin_PageHistory
218 extends WikiPlugin_RecentChanges
220 function getName () {
221 return _("PageHistory");
224 function getDescription () {
225 return sprintf(_("List PageHistory for %s"),'[pagename]');
228 function getDefaultArguments() {
229 return array('days' => false,
230 'show_minor' => true,
231 'show_major' => true,
233 'page' => '[pagename]',
237 function getDefaultFormArguments() {
238 $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
239 $dflts['textinput'] = 'page';
243 function getMostRecentParams ($args) {
244 $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
245 $params['include_all_revisions'] = true;
249 function getChanges ($dbi, $args) {
250 $page = $dbi->getPage($args['page']);
251 $iter = $page->getAllRevisions();
252 $params = $this->getMostRecentParams($args);
253 return new _PageHistory_PageRevisionIter($iter, $params);
256 function format ($changes, $args) {
258 $format = $args['format'];
260 $fmt_class = $Theme->getFormatter('PageHistory', $format);
262 if ($format == 'rss')
263 $fmt_class = '_PageHistory_RssFormatter';
265 $fmt_class = '_PageHistory_HtmlFormatter';
268 $fmt = new $fmt_class($args);
269 return $fmt->format($changes);
272 function run ($dbi, $argstr, $request) {
273 $args = $this->getArgs($argstr, $request);
274 if (empty($args['page']))
275 return $this->makeForm("", $request);
276 // Hack alert: format() is a NORETURN for rss formatters.
277 return $this->format($this->getChanges($dbi, $args), $args);
282 // (c-file-style: "gnu")
287 // c-hanging-comment-ender-p: nil
288 // indent-tabs-mode: nil