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
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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/difflib.php');
31 require_once('lib/diff.php');
40 function getDescription () {
41 return _("Display differences between revisions");
44 function getVersion() {
45 return preg_replace("/[Revision: $]/", '',
49 // Establish default values for each of this plugin's arguments.
50 // todo: makes only sense with more args.
51 function getDefaultArguments() {
52 return array('pagename' => '[pagename]',
56 'previous' => 'major', // author, minor or major
60 function PageInfoRow ($label, $rev, &$request) {
62 global $WikiTheme, $WikiNameRegexp;
64 $row = HTML::tr(HTML::td(array('align' => 'right'), $label));
66 $author = $rev->get('author');
67 $dbi = $request->getDbh();
69 $iswikipage = (isWikiWord($author) && $dbi->isWikiPage($author));
70 $authorlink = $iswikipage ? WikiLink($author) : $author;
72 $linked_version = WikiLink($rev, 'existing', $rev->getVersion());
73 $row->pushContent(HTML::td(fmt("version %s", $linked_version)),
74 HTML::td($WikiTheme->getLastModifiedMessage($rev,
76 HTML::td(fmt("by %s", $authorlink)));
78 $row->pushContent(HTML::td(array('colspan' => '3'), _("None")));
83 function run($dbi, $argstr, &$request, $basepage) {
84 extract($this->getArgs($argstr, $request));
85 if (is_array($versions)) {
86 // Version selection from pageinfo.php display:
88 list ($version, $previous) = $versions;
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("I'm sorry, there is no such page as %s.",
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);
107 $new_version = _("current version");
110 if (preg_match('/^\d+$/', $previous)) {
111 if ( !($old = $page->getRevision($previous)) )
112 NoSuchRevision($request, $page, $previous);
113 $old_version = fmt("version %d", $previous);
114 $others = array('major', 'minor', 'author');
120 while ($old = $page->getRevisionBefore($old)) {
121 if ($old->get('author') != $new->get('author'))
124 $old_version = _("revision by previous author");
125 $others = array('major', 'minor');
129 $old = $page->getRevisionBefore($new);
130 $old_version = _("previous revision");
131 $others = array('major', 'author');
136 while ($old && $old->get('is_minor_edit'))
137 $old = $page->getRevisionBefore($old);
139 $old = $page->getRevisionBefore($old);
140 $old_version = _("predecessor to the previous major change");
141 $others = array('minor', 'author');
146 $new_link = WikiLink($new, '', $new_version);
147 $old_link = $old ? WikiLink($old, '', $old_version) : $old_version;
148 $page_link = WikiLink($page);
150 $html = HTML(HTML::p(fmt("Differences between %s and %s of %s.",
151 $new_link, $old_link, $page_link)));
153 $otherdiffs = HTML::p(_("Other diffs:"));
154 $label = array('major' => _("Previous Major Revision"),
155 'minor' => _("Previous Revision"),
156 'author'=> _("Previous Author"));
157 foreach ($others as $other) {
158 $args = array('pagename' => $pagename, 'previous' => $other);
160 $args['version'] = $version;
161 if (count($otherdiffs->getContent()) > 1)
162 $otherdiffs->pushContent(", ");
164 $otherdiffs->pushContent(" ");
165 $otherdiffs->pushContent(Button($args, $label[$other]));
167 $html->pushContent($otherdiffs);
170 if ($old and $old->getVersion() == 0)
173 $html->pushContent(HTML::Table($this->PageInfoRow(_("Newer page:"), $new,
175 $this->PageInfoRow(_("Older page:"), $old,
179 $diff = new Diff($old->getContent(), $new->getContent());
181 if ($diff->isEmpty()) {
182 $html->pushContent(HTML::hr(),
183 HTML::p('[', _("Versions are identical"),
187 // New CSS formatted unified diffs (ugly in NS4).
188 $fmt = new HtmlUnifiedDiffFormatter;
190 // Use this for old table-formatted diffs.
191 //$fmt = new TableUnifiedDiffFormatter;
192 $html->pushContent($fmt->format($diff));
196 //$html = HTML::tt(fmt('%s: %s', $salutation, WikiLink($name, 'auto')),
203 // $Log: not supported by cvs2svn $
204 // Revision 1.3 2005/09/30 18:53:10 uckelman
205 // 'final' is a reserved keyword as of PHP5, so shouldn't be used as a
206 // function name here.
208 // Revision 1.2 2004/06/14 11:31:39 rurban
209 // renamed global $Theme to $WikiTheme (gforge nameclash)
210 // inherit PageList default options from PageList
211 // default sortby=pagename
212 // use options in PageList_Selectable (limit, sortby, ...)
213 // added action revert, with button at action=diff
214 // added option regex to WikiAdminSearchReplace
216 // Revision 1.1 2004/02/26 23:02:17 rurban
217 // lib/diff.php converted to a plugin by electrawn,
218 // plugin cleaned up by rurban,
221 // Would make sense to see arbitrary diff's between any files or revisions.
230 // c-hanging-comment-ender-p: nil
231 // indent-tabs-mode: nil