1 | 1 | simandl | <?php |
2 | | | // WebSVN - Subversion repository viewing via the web using PHP |
3 | | | // Copyright (C) 2004-2006 Tim Armes |
4 | | | // |
5 | | | // This program is free software; you can redistribute it and/or modify |
6 | | | // it under the terms of the GNU General Public License as published by |
7 | | | // the Free Software Foundation; either version 2 of the License, or |
8 | | | // (at your option) any later version. |
9 | | | // |
10 | | | // This program is distributed in the hope that it will be useful, |
11 | | | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | | // GNU General Public License for more details. |
14 | | | // |
15 | | | // You should have received a copy of the GNU General Public License |
16 | | | // along with this program; if not, write to the Free Software |
17 | | | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | | | // |
19 | | | // -- |
20 | | | // |
21 | | | // diff.php |
22 | | | // |
23 | | | // Show the differences between 2 revisions of a file. |
24 | | | // |
25 | | | |
26 | | | require_once("include/setup.php"); |
27 | | | require_once("include/svnlook.php"); |
28 | | | require_once("include/utils.php"); |
29 | | | require_once("include/template.php"); |
30 | | | |
31 | 3 | simandl | require_once("include/diff_inc.php"); |
32 | 1 | simandl | |
33 | | | $vars["action"] = $lang["DIFF"]; |
34 | 3 | simandl | $all = (@$_REQUEST["all"] == 1); |
35 | | | $ignoreWhitespace = (@$_REQUEST["ignorews"] == 1); |
36 | 1 | simandl | |
37 | | | // Make sure that we have a repository |
38 | | | if (!isset($rep)) { |
39 | | | echo $lang["NOREP"]; |
40 | | | exit; |
41 | | | } |
42 | | | |
43 | | | $svnrep = new SVNRepository($rep); |
44 | | | |
45 | | | // If there's no revision info, go to the lastest revision for this path |
46 | | | $history = $svnrep->getLog($path, "", "", true); |
47 | 3 | simandl | if (is_string($history)) { |
48 | | | echo $history; |
49 | | | exit; |
50 | | | } |
51 | 1 | simandl | $youngest = $history->entries[0]->rev; |
52 | | | |
53 | | | if (empty($rev)) { |
54 | | | $rev = $youngest; |
55 | | | } |
56 | | | |
57 | | | $history = $svnrep->getLog($path, $rev); |
58 | 3 | simandl | if (is_string($history)) { |
59 | | | echo $history; |
60 | | | exit; |
61 | | | } |
62 | 1 | simandl | |
63 | | | if ($path{0} != "/") { |
64 | | | $ppath = "/".$path; |
65 | | | } else { |
66 | | | $ppath = $path; |
67 | | | } |
68 | | | |
69 | | | $prevrev = @$history->entries[1]->rev; |
70 | | | |
71 | | | $vars["repname"] = htmlentities($rep->getDisplayName(), ENT_QUOTES, 'UTF-8'); |
72 | | | $vars["rev"] = $rev; |
73 | | | $vars["path"] = htmlentities($ppath, ENT_QUOTES, 'UTF-8'); |
74 | | | $vars["prevrev"] = $prevrev; |
75 | | | |
76 | | | $vars["rev1"] = $history->entries[0]->rev; |
77 | | | $vars["rev2"] = $prevrev; |
78 | | | |
79 | | | createDirLinks($rep, $ppath, $rev); |
80 | | | |
81 | | | $listing = array(); |
82 | | | |
83 | | | $url = $config->getURL($rep, $path, "file"); |
84 | | | if ($rev != $youngest) { |
85 | | | $vars["goyoungestlink"] = '<a href="'.$url.'">'.$lang['GOYOUNGEST'].'</a>'; |
86 | | | } else { |
87 | | | $vars["goyoungestlink"] = ""; |
88 | | | } |
89 | | | |
90 | | | $vars['indexurl'] = $config->getURL($rep, '', 'index'); |
91 | | | $vars['repurl'] = $config->getURL($rep, '', 'dir'); |
92 | | | |
93 | | | $url = $config->getURL($rep, $path, "file"); |
94 | | | $vars["filedetaillink"] = "<a href=\"${url}rev=$rev&isdir=0\">${lang["FILEDETAIL"]}</a>"; |
95 | | | |
96 | | | $url = $config->getURL($rep, $path, "log"); |
97 | | | $vars["fileviewloglink"] = "<a href=\"${url}rev=$rev&isdir=0\">${lang["VIEWLOG"]}</a>"; |
98 | | | |
99 | | | $url = $config->getURL($rep, $path, "diff"); |
100 | | | $vars["prevdifflink"] = "<a href=\"${url}rev=$rev\">${lang["DIFFPREV"]}</a>"; |
101 | | | |
102 | | | $url = $config->getURL($rep, $path, "blame"); |
103 | | | $vars["blamelink"] = "<a href=\"${url}rev=$rev\">${lang["BLAME"]}</a>"; |
104 | | | |
105 | | | if ($prevrev) { |
106 | | | $url = $config->getURL($rep, $path, "diff"); |
107 | | | |
108 | | | if (!$all) { |
109 | 3 | simandl | $vars["showalllink"] = '<a href="'.$url.'rev='.$rev.'&all=1&ignorews='.($ignoreWhitespace ? '1' : '0').'">'.$lang['SHOWENTIREFILE'].'</a>'; |
110 | | | $vars["showcompactlink"] = ''; |
111 | 1 | simandl | } else { |
112 | 3 | simandl | $vars["showcompactlink"] = '<a href="'.$url.'rev='.$rev.'&all=0&ignorews='.($ignoreWhitespace ? '1' : '0').'">'.$lang['SHOWCOMPACT'].'</a>'; |
113 | | | $vars["showalllink"] = ''; |
114 | 1 | simandl | } |
115 | 3 | simandl | if (!$ignoreWhitespace) { |
116 | | | $vars['ignorewhitespacelink'] = '<a href="'.$url.'rev='.$rev.'&all='.($all ? '1' : '0').'&ignorews=1">'.$lang['IGNOREWHITESPACE'].'</a>'; |
117 | | | $vars['regardwhitespacelink'] = ''; |
118 | | | } else { |
119 | | | $vars['regardwhitespacelink'] = '<a href="'.$url.'rev='.$rev.'&all='.($all ? '1' : '0').'&ignorews=0">'.$lang['REGARDWHITESPACE'].'</a>'; |
120 | | | $vars['ignorewhitespacelink'] = ''; |
121 | | | } |
122 | 1 | simandl | |
123 | | | // Get the contents of the two files |
124 | | | $newtname = tempnam("temp", ""); |
125 | 3 | simandl | $highlightedNew = $svnrep->getFileContents($history->entries[0]->path, $newtname, $history->entries[0]->rev, "", true); |
126 | 1 | simandl | |
127 | | | $oldtname = tempnam("temp", ""); |
128 | 3 | simandl | $highlightedOld = $svnrep->getFileContents($history->entries[1]->path, $oldtname, $history->entries[1]->rev, "", true); |
129 | 1 | simandl | |
130 | 3 | simandl | $ent = (!$highlightedNew && !$highlightedOld); |
131 | | | $listing = do_diff($all, $ignoreWhitespace, $rep, $ent, $newtname, $oldtname); |
132 | 1 | simandl | |
133 | | | // Remove our temporary files |
134 | | | @unlink($oldtname); |
135 | | | @unlink($newtname); |
136 | | | |
137 | | | } else { |
138 | | | $vars["noprev"] = 1; |
139 | | | $url = $config->getURL($rep, $path, "file"); |
140 | | | $vars["filedetaillink"] = "<a href=\"${url}rev=$rev\">${lang["SHOWENTIREFILE"]}.</a>"; |
141 | | | } |
142 | | | |
143 | | | $vars["version"] = $version; |
144 | | | |
145 | | | if (!$rep->hasReadAccess($path, false)) { |
146 | | | $vars["noaccess"] = true; |
147 | | | } |
148 | | | |
149 | | | parseTemplate($rep->getTemplatePath()."header.tmpl", $vars, $listing); |
150 | | | parseTemplate($rep->getTemplatePath()."diff.tmpl", $vars, $listing); |
151 | | | parseTemplate($rep->getTemplatePath()."footer.tmpl", $vars, $listing); |