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