jablonka.czprosek.czf

websvn

Subversion Repositories:
[/] [blame.php] - Blame information for rev 3

 

Line No. Rev Author Line
11simandl<?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 
26require_once'include/setup.php';
27require_once'include/svnlook.php';
28require_once'include/utils.php';
29require_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);
373simandlif (is_string($history)) {
38 echo $history;
39 exit;
40}
411simandl$youngest = $history->entries[0]->rev;
42 
43if (empty($rev)) {
44 $rev = $youngest;
45}
46 
47if ($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 
61createDirLinks($rep, $ppath, $rev);
62 
63if ($rev != $youngest) {
643simandl $url = $config->getURL($rep, $path, 'blame');
651simandl $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&amp;isdir=0\">${lang["FILEDETAIL"]}</a>";
75 
76$url = $config->getURL($rep, $path, "log");
77$vars["fileviewloglink"] = "<a href=\"${url}rev=$rev&amp;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', '');
863simandl$highlighted = $svnrep->getFileContents($path, $tfname, $rev, '', true);
871simandl 
88if ($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 = "";
993simandl $row_class = '';
1001simandl 
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));
1253simandl if (!$highlighted) $line = replaceEntities($line, $rep);
1261simandl 
127 if ($empty) $line = '&nbsp;';
128 $listing[$index]['line'] = hardspace($line);
129 
130 $index++;
131 }
132 }
133 
134 fclose($blame);
135 }
136 
137 fclose($file);
1383simandl 
139 @unlink($tbname);
1401simandl}
141 
142@unlink($tfname);
143 
144$vars['version'] = $version;
145 
146if (!$rep->hasReadAccess($path, false)) {
147 $vars['noaccess'] = true;
148}
149 
150$vars['javascript'] = <<<HTML
151 
152<script type='text/javascript'>
153/* <![CDATA[ */
154var rev = new Array();
155var a = document.getElementsByTagName('a');
156for (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 
164function 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 
175function 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 
184function 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 
195HTML;
196 
197foreach ($seen_rev as $key => $val) {
198 $history = $svnrep->getLog($path, $key, $key, false, 1);
1993simandl if (!is_string($history)) {
2001simandl $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 
212parseTemplate($rep->getTemplatePath().'header.tmpl', $vars, $listing);
213parseTemplate($rep->getTemplatePath().'blame.tmpl', $vars, $listing);
214parseTemplate($rep->getTemplatePath().'footer.tmpl', $vars, $listing);

Powered by WebSVN 2.2.1