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 | | | // blame.php |
22 | | | // |
23 | | | // Show the blame information 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 | | | $vars['action'] = $lang['BLAME']; |
32 | | | |
33 | | | $svnrep = new SVNRepository($rep); |
34 | | | |
35 | | | // If there's no revision info, go to the lastest revision for this path |
36 | | | $history = $svnrep->getLog($path, '', '', true); |
37 | 3 | simandl | if (is_string($history)) { |
38 | | | echo $history; |
39 | | | exit; |
40 | | | } |
41 | 1 | simandl | $youngest = $history->entries[0]->rev; |
42 | | | |
43 | | | if (empty($rev)) { |
44 | | | $rev = $youngest; |
45 | | | } |
46 | | | |
47 | | | if ($path{0} != '/') { |
48 | | | $ppath = '/'.$path; |
49 | | | } else { |
50 | | | $ppath = $path; |
51 | | | } |
52 | | | |
53 | | | // Find the parent path (or the whole path if it's already a directory) |
54 | | | $pos = strrpos($ppath, '/'); |
55 | | | $parent = substr($ppath, 0, $pos + 1); |
56 | | | |
57 | | | $vars['repname'] = htmlentities($rep->getDisplayName(), ENT_QUOTES, 'UTF-8'); |
58 | | | $vars['rev'] = $rev; |
59 | | | $vars['path'] = htmlentities($ppath, ENT_QUOTES, 'UTF-8'); |
60 | | | |
61 | | | createDirLinks($rep, $ppath, $rev); |
62 | | | |
63 | | | if ($rev != $youngest) { |
64 | 3 | simandl | $url = $config->getURL($rep, $path, 'blame'); |
65 | 1 | simandl | $vars["goyoungestlink"] = '<a href="'.$url.'">'.$lang["GOYOUNGEST"].'</a>'; |
66 | | | } else { |
67 | | | $vars["goyoungestlink"] = ""; |
68 | | | } |
69 | | | |
70 | | | $vars['indexurl'] = $config->getURL($rep, '', 'index'); |
71 | | | $vars['repurl'] = $config->getURL($rep, '', 'dir'); |
72 | | | |
73 | | | $url = $config->getURL($rep, $path, "file"); |
74 | | | $vars["filedetaillink"] = "<a href=\"${url}rev=$rev&isdir=0\">${lang["FILEDETAIL"]}</a>"; |
75 | | | |
76 | | | $url = $config->getURL($rep, $path, "log"); |
77 | | | $vars["fileviewloglink"] = "<a href=\"${url}rev=$rev&isdir=0\">${lang["VIEWLOG"]}</a>"; |
78 | | | |
79 | | | $url = $config->getURL($rep, $path, "diff"); |
80 | | | $vars["prevdifflink"] = "<a href=\"${url}rev=$rev\">${lang["DIFFPREV"]}</a>"; |
81 | | | |
82 | | | $listing = array(); |
83 | | | |
84 | | | // Get the contents of the file |
85 | | | $tfname = tempnam('temp', ''); |
86 | 3 | simandl | $highlighted = $svnrep->getFileContents($path, $tfname, $rev, '', true); |
87 | 1 | simandl | |
88 | | | if ($file = fopen($tfname, 'r')) { |
89 | | | // Get the blame info |
90 | | | $tbname = tempnam('temp', ''); |
91 | | | $svnrep->getBlameDetails($path, $tbname, $rev); |
92 | | | |
93 | | | if ($blame = fopen($tbname, 'r')) { |
94 | | | // Create an array of version/author/line |
95 | | | |
96 | | | $index = 0; |
97 | | | $seen_rev = array(); |
98 | | | $last_rev = ""; |
99 | 3 | simandl | $row_class = ''; |
100 | 1 | simandl | |
101 | | | while (!feof($blame) && !feof($file)) { |
102 | | | $blameline = fgets($blame); |
103 | | | |
104 | | | if ($blameline != '') { |
105 | | | list($revision, $author, $remainder) = sscanf($blameline, '%d %s %s'); |
106 | | | $empty = !$remainder; |
107 | | | |
108 | | | $listing[$index]['lineno'] = $index + 1; |
109 | | | |
110 | | | if ($last_rev != $revision) { |
111 | | | $url = $config->getURL($rep, $parent, 'revision'); |
112 | | | $listing[$index]['revision'] = "<a id=\"l$index-rev\" class=\"blame-revision\" href=\"${url}rev=$revision\">$revision</a>"; |
113 | | | $seen_rev[$revision] = 1; |
114 | | | $row_class = ($row_class == 'light') ? 'dark' : 'light'; |
115 | | | $listing[$index]['author'] = $author; |
116 | | | } else { |
117 | | | $listing[$index]['revision'] = ""; |
118 | | | $listing[$index]['author'] = ''; |
119 | | | } |
120 | | | |
121 | | | $listing[$index]['row_class'] = $row_class; |
122 | | | $last_rev = $revision; |
123 | | | |
124 | | | $line = rtrim(fgets($file)); |
125 | 3 | simandl | if (!$highlighted) $line = replaceEntities($line, $rep); |
126 | 1 | simandl | |
127 | | | if ($empty) $line = ' '; |
128 | | | $listing[$index]['line'] = hardspace($line); |
129 | | | |
130 | | | $index++; |
131 | | | } |
132 | | | } |
133 | | | |
134 | | | fclose($blame); |
135 | | | } |
136 | | | |
137 | | | fclose($file); |
138 | 3 | simandl | |
139 | | | @unlink($tbname); |
140 | 1 | simandl | } |
141 | | | |
142 | | | @unlink($tfname); |
143 | | | |
144 | | | $vars['version'] = $version; |
145 | | | |
146 | | | if (!$rep->hasReadAccess($path, false)) { |
147 | | | $vars['noaccess'] = true; |
148 | | | } |
149 | | | |
150 | | | $vars['javascript'] = <<<HTML |
151 | | | |
152 | | | <script type='text/javascript'> |
153 | | | /* <![CDATA[ */ |
154 | | | var rev = new Array(); |
155 | | | var a = document.getElementsByTagName('a'); |
156 | | | for (var i = 0; i < a.length; i++) { |
157 | | | if (a[i].className == 'blame-revision') { |
158 | | | var id = a[i].id; |
159 | | | addEvent(a[i], 'mouseover', function() { mouseover(this) } ); |
160 | | | addEvent(a[i], 'mouseout', function() { mouseout(this) } ); |
161 | | | } |
162 | | | } |
163 | | | |
164 | | | function mouseover(a) { |
165 | | | // Find the revision by using the link |
166 | | | var m = /rev=(\d+)/.exec(a.href); |
167 | | | var r = m[1]; |
168 | | | |
169 | | | div = document.createElement('div'); |
170 | | | div.className = 'blame-popup'; |
171 | | | div.innerHTML = rev[r]; |
172 | | | a.parentNode.appendChild(div); |
173 | | | } |
174 | | | |
175 | | | function mouseout(a) { |
176 | | | var div = a.parentNode.parentNode.getElementsByTagName('div'); |
177 | | | for (var i = 0; i < div.length; i++) { |
178 | | | if (div[i].className = 'blame-popup') { |
179 | | | div[i].parentNode.removeChild(div[i]); |
180 | | | } |
181 | | | } |
182 | | | } |
183 | | | |
184 | | | function addEvent(obj, type, func) { |
185 | | | if (obj.addEventListener) { |
186 | | | obj.addEventListener(type, func, false); |
187 | | | return true; |
188 | | | } else if (obj.attachEvent) { |
189 | | | return obj.attachEvent('on' + type, func); |
190 | | | } else { |
191 | | | return false; |
192 | | | } |
193 | | | } |
194 | | | |
195 | | | HTML; |
196 | | | |
197 | | | foreach ($seen_rev as $key => $val) { |
198 | | | $history = $svnrep->getLog($path, $key, $key, false, 1); |
199 | 3 | simandl | if (!is_string($history)) { |
200 | 1 | simandl | $vars['javascript'] .= "rev[$key] = '"; |
201 | | | $vars['javascript'] .= "<div class=\"info\">"; |
202 | | | $vars['javascript'] .= "<span class=\"date\">".$history->curEntry->date."<\/span>"; |
203 | | | $vars['javascript'] .= "<\/div>"; |
204 | | | $vars['javascript'] .= "<div class=\"msg\">".addslashes(preg_replace('/\n/', "<br />", $history->curEntry->msg))."<\/div>"; |
205 | | | $vars['javascript'] .= "';\n"; |
206 | | | } |
207 | | | } |
208 | | | $vars['javascript'] .= "/* ]]> */\n</script>"; |
209 | | | |
210 | | | // ob_start('ob_gzhandler'); |
211 | | | |
212 | | | parseTemplate($rep->getTemplatePath().'header.tmpl', $vars, $listing); |
213 | | | parseTemplate($rep->getTemplatePath().'blame.tmpl', $vars, $listing); |
214 | | | parseTemplate($rep->getTemplatePath().'footer.tmpl', $vars, $listing); |