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';
41 function getDescription()
43 return _("Display differences between revisions.");
46 // Establish default values for each of this plugin's arguments.
47 // todo: makes only sense with more args.
48 function getDefaultArguments()
50 return array('pagename' => '[pagename]',
53 'previous' => 'major', // author, minor or major
57 function PageInfoRow($label, $rev, &$request)
62 $row = HTML::tr(HTML::td(array('align' => 'right'), $label));
64 $author = $rev->get('author');
65 $dbi = $request->getDbh();
67 $iswikipage = (isWikiWord($author) && $dbi->isWikiPage($author));
68 $authorlink = $iswikipage ? WikiLink($author) : $author;
70 $linked_version = WikiLink($rev, 'existing', $rev->getVersion());
71 $row->pushContent(HTML::td(fmt("version %s", $linked_version)),
72 HTML::td($WikiTheme->getLastModifiedMessage($rev,
74 HTML::td(fmt("by %s", $authorlink)));
76 $row->pushContent(HTML::td(array('colspan' => '3'), _("None")));
81 function run($dbi, $argstr, &$request, $basepage)
83 extract($this->getArgs($argstr, $request));
84 if (is_array($versions)) {
85 // Version selection from pageinfo.php display:
87 list ($version, $previous) = $versions;
90 // Check if user is allowed to get the Page.
91 if (!mayAccessPage('view', $pagename)) {
92 return $this->error(sprintf(_("Illegal access to page %s: no read access"),
96 // abort if page doesn't exist
97 $page = $request->getPage($pagename);
98 $current = $page->getCurrentRevision();
99 if ($current->getVersion() < 1) {
100 $html = HTML(HTML::p(fmt("Page ā%sā does not exist.",
101 WikiLink($pagename, 'unknown'))));
102 return $html; //early return
106 if (!($new = $page->getRevision($version)))
107 NoSuchRevision($request, $page, $version);
108 $new_version = fmt("version %d", $version);
111 $new_version = _("current version");
114 if (preg_match('/^\d+$/', $previous)) {
115 if (!($old = $page->getRevision($previous)))
116 NoSuchRevision($request, $page, $previous);
117 $old_version = fmt("version %d", $previous);
118 $others = array('major', 'minor', 'author');
123 while ($old = $page->getRevisionBefore($old)) {
124 if ($old->get('author') != $new->get('author'))
127 $old_version = _("revision by previous author");
128 $others = array('major', 'minor');
131 $old = $page->getRevisionBefore($new);
132 $old_version = _("previous revision");
133 $others = array('major', 'author');
138 while ($old && $old->get('is_minor_edit'))
139 $old = $page->getRevisionBefore($old);
141 $old = $page->getRevisionBefore($old);
142 $old_version = _("predecessor to the previous major change");
143 $others = array('minor', 'author');
148 $new_link = WikiLink($new, '', $new_version);
149 $old_link = $old ? WikiLink($old, '', $old_version) : $old_version;
150 $page_link = WikiLink($page);
152 $html = HTML(HTML::p(fmt("Differences between %s and %s of %s.",
153 $new_link, $old_link, $page_link)));
155 $otherdiffs = HTML::p(_("Other diffs:"));
156 $label = array('major' => _("Previous Major Revision"),
157 'minor' => _("Previous Revision"),
158 'author' => _("Previous Author"));
159 foreach ($others as $other) {
160 $args = array('pagename' => $pagename, 'previous' => $other);
162 $args['version'] = $version;
163 if (count($otherdiffs->getContent()) > 1)
164 $otherdiffs->pushContent(", ");
166 $otherdiffs->pushContent(" ");
167 $otherdiffs->pushContent(Button($args, $label[$other]));
169 $html->pushContent($otherdiffs);
171 if ($old and $old->getVersion() == 0)
174 $html->pushContent(HTML::Table($this->PageInfoRow(_("Newer page:"), $new,
176 $this->PageInfoRow(_("Older page:"), $old,
180 $diff = new Diff($old->getContent(), $new->getContent());
182 if ($diff->isEmpty()) {
183 $html->pushContent(HTML::hr(),
184 HTML::p(_("Content of versions "), $old->getVersion(),
185 _(" and "), $new->getVersion(), _(" is identical.")));
186 // If two consecutive versions have the same content, it is because the page was
187 // renamed, or metadata changed: ACL, owner, markup.
188 // We give the reason by printing the summary.
189 if (($new->getVersion() - $old->getVersion()) == 1) {
190 $html->pushContent(HTML::p(_("Version "), $new->getVersion(),
191 _(" was created because: "), $new->get('summary')));
194 $fmt = new HtmlUnifiedDiffFormatter;
195 $html->pushContent($fmt->format($diff));
207 // c-hanging-comment-ender-p: nil
208 // indent-tabs-mode: nil