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 | | | // filedetails.php |
22 | | | // |
23 | | | // Simply lists the contents of a file |
24 | | | |
25 | | | require_once("include/setup.php"); |
26 | | | require_once("include/svnlook.php"); |
27 | | | require_once("include/utils.php"); |
28 | | | require_once("include/template.php"); |
29 | | | |
30 | | | // Make sure that we have a repository |
31 | | | if (!isset($rep)) { |
32 | | | echo $lang["NOREP"]; |
33 | | | exit; |
34 | | | } |
35 | | | |
36 | | | $svnrep = new SVNRepository($rep); |
37 | | | |
38 | | | if ($path{0} != "/") { |
39 | | | $ppath = "/".$path; |
40 | | | } else { |
41 | | | $ppath = $path; |
42 | | | } |
43 | | | |
44 | | | $passrev = $rev; |
45 | | | |
46 | | | // If there's no revision info, go to the lastest revision for this path |
47 | | | $history = $svnrep->getLog($path, "", "", true); |
48 | | | $youngest = isset($history->entries[0]) ? $history->entries[0]->rev: false; |
49 | | | |
50 | | | if (empty($rev)) { |
51 | | | $rev = $youngest; |
52 | | | } |
53 | | | |
54 | | | $extn = strtolower(strrchr($path, ".")); |
55 | | | |
56 | | | // Check to see if the user has requested that this type be zipped and sent |
57 | | | // to the browser as an attachment |
58 | | | |
59 | | | if (in_array($extn, $zipped) && $rep->hasReadAccess($path, false)) { |
60 | | | $base = basename($path); |
61 | | | header("Content-Type: application/x-gzip"); |
62 | | | header("Content-Disposition: attachment; filename=".urlencode($base).".gz"); |
63 | | | |
64 | | | // Get the file contents and pipe into gzip. All this without creating |
65 | | | // a temporary file. Damn clever. |
66 | | | $svnrep->getFileContents($path, "", $rev, "| ".$config->gzip." -n -f"); |
67 | | | |
68 | | | exit; |
69 | | | } |
70 | | | |
71 | | | // Check to see if we should serve it with a particular content-type. |
72 | | | // The content-type could come from an svn:mime-type property on the |
73 | | | // file, or from the $contentType array in setup.php. |
74 | | | |
75 | | | if (!$rep->getIgnoreSvnMimeTypes()) { |
76 | | | $svnMimeType = $svnrep->getProperty($path, 'svn:mime-type', $rev); |
77 | | | } |
78 | | | |
79 | | | if (!$rep->getIgnoreWebSVNContentTypes()) { |
80 | | | $setupContentType = @$contentType[$extn]; |
81 | | | } |
82 | | | |
83 | | | // Use this set of priorities when establishing what content-type to |
84 | | | // actually use. |
85 | | | |
86 | | | if (!empty($svnMimeType) && $svnMimeType != 'application/octet-stream') { |
87 | | | $cont = $svnMimeType; |
88 | | | } else if (!empty($setupContentType)) { |
89 | | | $cont = $setupContentType; |
90 | | | } else if (!empty($svnMimeType)) { |
91 | | | // It now is equal to application/octet-stream due to logic |
92 | | | // above.... |
93 | | | $cont = $svnMimeType; |
94 | | | } |
95 | | | |
96 | | | // If there's a MIME type associated with this format, then we deliver it |
97 | | | // with this information |
98 | | | |
99 | | | if (!empty($cont) && $rep->hasReadAccess($path, false)) { |
100 | | | $base = basename($path); |
101 | | | |
102 | | | header("Content-Type: $cont"); |
103 | | | //header("Content-Length: $size"); |
104 | | | header("Content-Disposition: inline; filename=".urlencode($base)); |
105 | | | |
106 | | | $svnrep->getFileContents($path, "", $rev); |
107 | | | |
108 | | | exit; |
109 | | | } |
110 | | | |
111 | | | // There's no associated MIME type. Show the file using WebSVN. |
112 | | | |
113 | | | $url = $config->getURL($rep, $path, "file"); |
114 | | | |
115 | | | if ($rev != $youngest) { |
116 | | | $vars["goyoungestlink"] = "<a href=\"${url}\">${lang["GOYOUNGEST"]}</a>"; |
117 | | | } else { |
118 | | | $vars["goyoungestlink"] = ""; |
119 | | | } |
120 | | | |
121 | | | $vars["action"] = ""; |
122 | | | $vars["repname"] = htmlentities($rep->getDisplayName(), ENT_QUOTES, 'UTF-8'); |
123 | | | $vars["rev"] = htmlentities($rev, ENT_QUOTES, 'UTF-8'); |
124 | | | $vars["path"] = htmlentities($ppath, ENT_QUOTES, 'UTF-8'); |
125 | | | |
126 | | | createDirLinks($rep, $ppath, $passrev); |
127 | | | |
128 | | | $vars['indexurl'] = $config->getURL($rep, '', 'index'); |
129 | | | $vars['repurl'] = $config->getURL($rep, '', 'dir'); |
130 | | | |
131 | | | $url = $config->getURL($rep, $path, "log"); |
132 | | | $vars["fileviewloglink"] = "<a href=\"${url}rev=$passrev&isdir=0\">${lang["VIEWLOG"]}</a>"; |
133 | | | |
134 | | | $url = $config->getURL($rep, $path, "diff"); |
135 | | | $vars["prevdifflink"] = "<a href=\"${url}rev=$passrev\">${lang["DIFFPREV"]}</a>"; |
136 | | | |
137 | | | $url = $config->getURL($rep, $path, "blame"); |
138 | | | $vars["blamelink"] = "<a href=\"${url}rev=$passrev\">${lang["BLAME"]}</a>"; |
139 | | | |
140 | | | $listing = array(); |
141 | | | |
142 | | | $vars["version"] = $version; |
143 | | | |
144 | | | if (!$rep->hasReadAccess($path, false)) { |
145 | | | $vars["noaccess"] = true; |
146 | | | } |
147 | | | |
148 | | | parseTemplate($rep->getTemplatePath()."header.tmpl", $vars, $listing); |
149 | | | parseTemplate($rep->getTemplatePath()."file.tmpl", $vars, $listing); |
150 | | | parseTemplate($rep->getTemplatePath()."footer.tmpl", $vars, $listing); |