2 rcs_id('$Id: PageHistory.php,v 1.9 2002-01-22 03:17:47 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 LinkExistingWikiWord($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 $desc[] = _RecentChanges_HtmlFormatter::description() . "\n";
87 $desc[] = $this->_javascript(sprintf('document.write("%s");',
88 _("Check any two boxes to compare revisions.")));
89 $button = HTML::input(array('type' => 'submit',
90 'value' => _("compare revisions")));
91 $desc[] = HTML::noscript(fmt("Check any two boxes then %s.", $button));
97 function format ($changes) {
98 $this->_itemcount = 0;
100 $pagename = $this->_args['page'];
102 $html = _RecentChanges_HtmlFormatter::format($changes);
104 $html[] = HTML::input(array('type' => 'hidden',
108 $action = WikiURL($pagename);
111 $action = SCRIPT_NAME;
112 $html[] = HTML::input(array('type' => 'hidden',
113 'name' => 'pagename',
114 'value' => $pagename));
117 return array(HTML::form(array('method' => 'get',
119 'name' => 'diff-select'),
123 var diffCkBoxes = document.forms["diff-select"].elements["versions[]"];
125 function diffCkBox_onclick() {
126 // If two checkboxes are checked, submit form
128 for (i = 0; i < diffCkBoxes.length; i++)
129 if (diffCkBoxes[i].checked && ++nchecked >= 2)
133 for (i = 0; i < diffCkBoxes.length; i++)
134 diffCkBoxes[i].onclick = diffCkBox_onclick;'));
137 function diffLink ($rev) {
138 return HTML::input(array('type' => 'checkbox',
139 'name' => 'versions[]',
140 'value' => $rev->getVersion()));
143 function pageLink ($rev) {
144 return HTML::a(array('href' => $this->pageURL($rev), 'class' => 'wiki'),
145 fmt("Version %d", $rev->getVersion()));
150 class _PageHistory_RssFormatter
151 extends _RecentChanges_RssFormatter
153 function include_versions_in_URLs() {
157 function image_properties () {
161 function textinput_properties () {
165 function channel_properties () {
168 $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
170 $title = sprintf("%s: %s",
172 split_pagename($this->_args['page']));
174 return array('title' => $title,
175 'dc:description' => _("History of changes."),
177 'dc:date' => Iso8601DateTime(time()));
181 function item_properties ($rev) {
182 if (!($title = $this->summary($rev)))
183 $title = sprintf(_("Version %d"), $rev->getVersion());
185 return array( 'title' => $title,
186 'link' => $this->pageURL($rev),
187 'dc:date' => $this->time($rev),
188 'dc:contributor' => $rev->get('author'),
189 'wiki:version' => $rev->getVersion(),
190 'wiki:importance' => $this->importance($rev),
191 'wiki:status' => $this->status($rev),
192 'wiki:diff' => $this->diffURL($rev),
197 class WikiPlugin_PageHistory
198 extends WikiPlugin_RecentChanges
200 function getName () {
201 return _("PageHistory");
204 function getDescription () {
205 return sprintf(_("List PageHistory for %s"),'[pagename]');
208 function getDefaultArguments() {
209 return array('days' => false,
210 'show_minor' => true,
211 'show_major' => true,
217 function getDefaultFormArguments() {
218 $dflts = WikiPlugin_RecentChanges::getDefaultFormArguments();
219 $dflts['textinput'] = 'page';
223 function getMostRecentParams ($args) {
224 $params = WikiPlugin_RecentChanges::getMostRecentParams($args);
225 $params['include_all_revisions'] = true;
229 function getChanges ($dbi, $args) {
230 $page = $dbi->getPage($args['page']);
231 $iter = $page->getAllRevisions();
232 $params = $this->getMostRecentParams($args);
233 return new _PageHistory_PageRevisionIter($iter, $params);
236 function format ($changes, $args) {
238 $format = $args['format'];
240 $fmt_class = $Theme->getFormatter('PageHistory', $format);
242 if ($format == 'rss')
243 $fmt_class = '_PageHistory_RssFormatter';
245 $fmt_class = '_PageHistory_HtmlFormatter';
248 $fmt = new $fmt_class($args);
249 return $fmt->format($changes);
252 function run ($dbi, $argstr, $request) {
253 $args = $this->getArgs($argstr, $request);
254 if (empty($args['page']))
255 return $this->makeForm("", $request);
256 // Hack alert: format() is a NORETURN for rss formatters.
257 return $this->format($this->getChanges($dbi, $args), $args);
262 // (c-file-style: "gnu")
267 // c-hanging-comment-ender-p: nil
268 // indent-tabs-mode: nil