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