4 * Copyright 1999, 2000, 2001, 2002, 2004 $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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * lib/diff.php converted to a plugin by electrawn,
24 * plugin cleaned up by rurban,
27 * Would make sense to see arbitrary diff's between any files or revisions.
30 require_once 'lib/diff.php';
36 function getDescription()
38 return _("Display differences between revisions.");
41 // Establish default values for each of this plugin's arguments.
42 // todo: makes only sense with more args.
43 function getDefaultArguments()
45 return array('pagename' => '[pagename]',
48 'previous' => 'major', // author, minor or major
52 function PageInfoRow($label, $rev, &$request)
57 $row = HTML::tr(HTML::td(array('align' => 'right'), $label));
59 $author = $rev->get('author');
60 $dbi = $request->getDbh();
62 $iswikipage = (isWikiWord($author) && $dbi->isWikiPage($author));
63 $authorlink = $iswikipage ? WikiLink($author) : $author;
65 $linked_version = WikiLink($rev, 'existing', $rev->getVersion());
66 $row->pushContent(HTML::td(fmt("version %s", $linked_version)),
67 HTML::td($WikiTheme->getLastModifiedMessage($rev,
69 HTML::td(fmt("by %s", $authorlink)));
71 $row->pushContent(HTML::td(array('colspan' => '3'), _("None")));
76 function run($dbi, $argstr, &$request, $basepage)
78 extract($this->getArgs($argstr, $request));
79 if (is_array($versions)) {
80 // Version selection from pageinfo.php display:
82 list ($version, $previous) = $versions;
85 // Check if user is allowed to get the Page.
86 if (!mayAccessPage('view', $pagename)) {
87 return $this->error(sprintf(_("Illegal access to page %s: no read access"),
91 // abort if page doesn't exist
92 $page = $request->getPage($pagename);
93 $current = $page->getCurrentRevision();
94 if ($current->getVersion() < 1) {
95 $html = HTML(HTML::p(fmt("Page ā%sā does not exist.",
96 WikiLink($pagename, 'unknown'))));
97 return $html; //early return
101 if (!($new = $page->getRevision($version)))
102 NoSuchRevision($request, $page, $version);
103 $new_version = fmt("version %d", $version);
106 $new_version = _("current version");
109 if (preg_match('/^\d+$/', $previous)) {
110 if (!($old = $page->getRevision($previous)))
111 NoSuchRevision($request, $page, $previous);
112 $old_version = fmt("version %d", $previous);
113 $others = array('major', 'minor', 'author');
118 while ($old = $page->getRevisionBefore($old)) {
119 if ($old->get('author') != $new->get('author'))
122 $old_version = _("revision by previous author");
123 $others = array('major', 'minor');
126 $old = $page->getRevisionBefore($new);
127 $old_version = _("previous revision");
128 $others = array('major', 'author');
133 while ($old && $old->get('is_minor_edit'))
134 $old = $page->getRevisionBefore($old);
136 $old = $page->getRevisionBefore($old);
137 $old_version = _("predecessor to the previous major change");
138 $others = array('minor', 'author');
143 $new_link = WikiLink($new, '', $new_version);
144 $old_link = $old ? WikiLink($old, '', $old_version) : $old_version;
145 $page_link = WikiLink($page);
147 $html = HTML(HTML::p(fmt("Differences between %s and %s of %s.",
148 $new_link, $old_link, $page_link)));
150 $otherdiffs = HTML::p(_("Other diffs:"));
151 $label = array('major' => _("Previous Major Revision"),
152 'minor' => _("Previous Revision"),
153 'author' => _("Previous Author"));
154 foreach ($others as $other) {
155 $args = array('pagename' => $pagename, 'previous' => $other);
157 $args['version'] = $version;
158 if (count($otherdiffs->getContent()) > 1)
159 $otherdiffs->pushContent(", ");
161 $otherdiffs->pushContent(" ");
162 $otherdiffs->pushContent(Button($args, $label[$other]));
164 $html->pushContent($otherdiffs);
166 if ($old and $old->getVersion() == 0)
169 $html->pushContent(HTML::Table($this->PageInfoRow(_("Newer page:"), $new,
171 $this->PageInfoRow(_("Older page:"), $old,
175 $diff = new Diff($old->getContent(), $new->getContent());
177 if ($diff->isEmpty()) {
178 $html->pushContent(HTML::hr(),
179 HTML::p(_("Content of versions "), $old->getVersion(),
180 _(" and "), $new->getVersion(), _(" is identical.")));
181 // If two consecutive versions have the same content, it is because the page was
182 // renamed, or metadata changed: ACL, owner, markup.
183 // We give the reason by printing the summary.
184 if (($new->getVersion() - $old->getVersion()) == 1) {
185 $html->pushContent(HTML::p(_("Version "), $new->getVersion(),
186 _(" was created because: "), $new->get('summary')));
189 $fmt = new HtmlUnifiedDiffFormatter;
190 $html->pushContent($fmt->format($diff));
202 // c-hanging-comment-ender-p: nil
203 // indent-tabs-mode: nil