Rev Author Line No. Line
185 miho 1 <?php
2 # vim:et:ts=3:sts=3:sw=3:fdm=marker:
3  
4 // WebSVN - Subversion repository viewing via the web using PHP
5 // Copyright © 2004-2006 Tim Armes, Matt Sicker
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // --
22 //
23 // blame.php
24 //
25 // Show the blame information of a file.
26 //
27  
28 require_once 'include/setup.inc';
29 require_once 'include/svnlook.inc';
30 require_once 'include/utils.inc';
31 require_once 'include/template.inc';
32  
33 $vars['action'] = $lang['BLAME'];
34  
35 $svnrep = new SVNRepository($rep);
36  
37 // If there's no revision info, go to the lastest revision for this path
38 $history = $svnrep->getLog($path, '', '', true);
39 $youngest = $history->entries[0]->rev;
40  
41 if (empty($rev))
42 $rev = $youngest;
43  
44 if ($path{0} != '/')
45 $ppath = '/'.$path;
46 else
47 $ppath = $path;
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'] = $rep->getDisplayName();
54 $vars['rev'] = $rev;
55 $vars['path'] = $ppath;
56  
57 createDirLinks($rep, $ppath, $rev, $showchanged);
58  
59 $listing = array();
60  
61 // Get the contents of the file
62 $tfname = tempnam('temp', '');
63 $svnrep->getFileContents($path, $tfname, $rev, '', true);
64  
65 $filecache = array();
66  
67 if ($file = fopen($tfname, 'r'))
68 {
69 // Get the blame info
70 $tbname = tempnam('temp', '');
71 $svnrep->getBlameDetails($path, $tbname, $rev);
72  
73 $ent = true;
74 $extension = strrchr(basename($path), '.');
75 if (($extension && isset($extEnscript[$extension]) && ('php' == $extEnscript[$extension])) || ($config->useEnscript))
76 $ent = false;
77  
78 if ($blame = fopen($tbname, 'r'))
79 {
80 // Create an array of version/author/line
81  
82 $index = 0;
83  
84 while (!feof($blame) && !feof($file))
85 {
86 $blameline = fgets($blame);
87  
88 if ($blameline != '')
89 {
90 list($revision, $author) = sscanf($blameline, '%d %s');
91  
92 $listing[$index]['lineno'] = $index + 1;
93  
94 $url = $config->getURL($rep, $parent, 'dir');
95 $listing[$index]['revision'] = "<a href=\"${url}rev=$revision&amp;sc=1\">$revision</a>";
96  
97 $listing[$index]['author'] = $author;
98  
99 if ($ent)
100 $line = replaceEntities(rtrim(fgets($file)), $rep);
101 else
102 $line = rtrim(fgets($file));
103  
104 $listing[$index]['line'] = hardspace($line);
105  
106 if (trim($listing[$index]['line']) == '')
107 $listing[$index]['line'] = '&nbsp;';
108  
109 $index++;
110 }
111 }
112  
113 fclose($blame);
114 }
115  
116 fclose($file);
117 }
118  
119 unlink($tfname);
120 unlink($tbname);
121  
122 $vars['version'] = $version;
123  
124 if (!$rep->hasReadAccess($path, false))
125 $vars['noaccess'] = true;
126  
127 parseTemplate($rep->getTemplatePath().'header.tmpl', $vars, $listing);
128 parseTemplate($rep->getTemplatePath().'blame.tmpl', $vars, $listing);
129 parseTemplate($rep->getTemplatePath().'footer.tmpl', $vars, $listing);
130  
131 ?>