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