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  
121 // There's no associated MIME type. Show the file using WebSVN.
122  
123 $url = $config->getURL($rep, $path, "file");
124  
125 if ($rev != $youngest)
126 $vars["goyoungestlink"] = "<a href=\"${url}sc=1\">${lang["GOYOUNGEST"]}</a>";
127 else
128 $vars["goyoungestlink"] = "";
129  
130 $vars["action"] = "";
131 $vars["repname"] = $rep->getDisplayName();
132 $vars["rev"] = $rev;
133 $vars["path"] = $ppath;
134  
135 createDirLinks($rep, $ppath, $passrev, $showchanged);
136  
137 $url = $config->getURL($rep, $path, "log");
138 $vars["fileviewloglink"] = "<a href=\"${url}rev=$passrev&amp;sc=$showchanged&isdir=0\">${lang["VIEWLOG"]}</a>";
139  
140 $url = $config->getURL($rep, $path, "diff");
141 $vars["prevdifflink"] = "<a href=\"${url}rev=$passrev&amp;sc=$showchanged\">${lang["DIFFPREV"]}</a>";
142  
143 $url = $config->getURL($rep, $path, "blame");
144 $vars["blamelink"] = "<a href=\"${url}rev=$passrev&amp;sc=$showchanged\">${lang["BLAME"]}</a>";
145  
146 $listing = array ();
147  
148 $vars["version"] = $version;
149  
150 if (!$rep->hasReadAccess($path, false))
151 $vars["noaccess"] = true;
152  
153 parseTemplate($rep->getTemplatePath()."header.tmpl", $vars, $listing);
154 parseTemplate($rep->getTemplatePath()."file.tmpl", $vars, $listing);
155 parseTemplate($rep->getTemplatePath()."footer.tmpl", $vars, $listing);
156 ?>