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