Rev Author Line No. Line
185 miho 1 <?php
2 // WebSVN - Subversion repository viewing via the web using PHP
4988 kaklik 3 // Copyright (C) 2004-2006 Tim Armes
185 miho 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
4988 kaklik 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
185 miho 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
4988 kaklik 17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
185 miho 18 //
19 // --
20 //
21 // filedetails.php
22 //
23 // Simply lists the contents of a file
24  
4988 kaklik 25 require_once 'include/setup.php';
26 require_once 'include/svnlook.php';
27 require_once 'include/utils.php';
28 require_once 'include/template.php';
185 miho 29  
30 // Make sure that we have a repository
4988 kaklik 31 if (!$rep)
185 miho 32 {
4988 kaklik 33 renderTemplate404('file','NOREP');
185 miho 34 }
35  
36 $svnrep = new SVNRepository($rep);
37  
4988 kaklik 38 if ($path[0] != '/')
39 {
40 $ppath = '/'.$path;
41 }
42 else
43 {
44 $ppath = $path;
45 }
185 miho 46  
4988 kaklik 47 $useMime = false;
185 miho 48  
49 // If there's no revision info, go to the lastest revision for this path
4988 kaklik 50 $history = $svnrep->getLog($path, 'HEAD', 1, false, 2, ($path == '/') ? '' : $peg);
185 miho 51  
4988 kaklik 52 if (!$history)
53 {
54 unset($vars['error']);
55 $history = $svnrep->getLog($path, '', '', false, 2, ($path == '/') ? '' : $peg);
56 if (!$history)
57 {
58 renderTemplate404('file','NOPATH');
59 }
60 }
185 miho 61  
4988 kaklik 62 $youngest = ($history && isset($history->entries[0])) ? $history->entries[0]->rev : false;
185 miho 63  
4988 kaklik 64 if (empty($rev))
65 {
66 $rev = !$peg ? $youngest : min($peg, $youngest);
67 }
68  
69 $extn = strtolower(strrchr($path, '.'));
70  
185 miho 71 // Check to see if the user has requested that this type be zipped and sent
72 // to the browser as an attachment
73  
4988 kaklik 74 if ($history && isset($zipped) && in_array($extn, $zipped) && $rep->hasReadAccess($path, false))
185 miho 75 {
4988 kaklik 76 $base = basename($path);
77 header('Content-Type: application/gzip');
78 header("Content-Disposition: attachment; filename*=UTF-8''".rawurlencode($base).'.gz');
185 miho 79  
4988 kaklik 80 // Get the file contents and pipe into gzip. All this without creating
81 // a temporary file. Damn clever.
82 $svnrep->getFileContents($path, '', $rev, $peg, '| '.$config->gzip.' -n -f');
83 exit;
185 miho 84 }
85  
86 // Check to see if we should serve it with a particular content-type.
87 // The content-type could come from an svn:mime-type property on the
4988 kaklik 88 // file, or from the $contentType array in setup.php.
185 miho 89  
90 if (!$rep->getIgnoreSvnMimeTypes())
91 {
4988 kaklik 92 $svnMimeType = $svnrep->getProperty($path, 'svn:mime-type', $rev);
185 miho 93 }
94  
95 if (!$rep->getIgnoreWebSVNContentTypes())
96 {
4988 kaklik 97 $setupContentType = @$contentType[$extn];
185 miho 98 }
99  
4988 kaklik 100 // Use the documented priorities when establishing what content-type to use.
185 miho 101 if (!empty($svnMimeType) && $svnMimeType != 'application/octet-stream')
102 {
4988 kaklik 103 $mimeType = $svnMimeType;
185 miho 104 }
4988 kaklik 105 else if (!empty($setupContentType))
185 miho 106 {
4988 kaklik 107 $mimeType = $setupContentType;
108 }
109 else if (!empty($svnMimeType))
185 miho 110 {
4988 kaklik 111 $mimeType = $svnMimeType; // Use SVN's default of 'application/octet-stream'
185 miho 112 }
4988 kaklik 113 else
114 {
115 $mimeType = '';
116 }
185 miho 117  
4988 kaklik 118 $useMime = ($mimeType) ? @$_REQUEST['usemime'] : false;
185 miho 119  
4988 kaklik 120 if ($history && !empty($mimeType) && !$useMime)
185 miho 121 {
4988 kaklik 122 $useMime = $mimeType; // Save MIME type for later before possibly clobbering
123 // If a MIME type exists but is set to be ignored, set it to an empty string.
124 foreach ($config->inlineMimeTypes as $inlineType)
125 {
126 if (preg_match('|'.$inlineType.'|', $mimeType))
127 {
128 $mimeType = '';
129 break;
130 }
131 }
185 miho 132 }
133  
4988 kaklik 134 // If a MIME type is associated with the file, deliver with Content-Type header.
135 if ($history && !empty($mimeType) && $rep->hasReadAccess($path, false))
1189 miho 136 {
4988 kaklik 137 $base = basename($path);
138 header('Content-Type: '.$mimeType);
139 //header('Content-Length: '.$size);
140 header("Content-Disposition: inline; filename*=UTF-8''".rawurlencode($base));
141 $svnrep->getFileContents($path, '', $rev, $peg);
142 exit;
143 }
1189 miho 144  
4988 kaklik 145 // Display the file inline using WebSVN.
1189 miho 146  
4988 kaklik 147 $vars['action'] = '';
148 $vars['path'] = str_replace('%2F', '/', rawurlencode($ppath));
149 $vars['safepath'] = escape($ppath);
1189 miho 150  
4988 kaklik 151 if (isset($history->entries[0]))
152 {
153 $vars['log'] = xml_entities($history->entries[0]->msg);
154 $vars['date'] = $history->entries[0]->date;
155 $vars['age'] = datetimeFormatDuration(time() - strtotime($history->entries[0]->date));
156 $vars['author'] = $history->entries[0]->author;
1189 miho 157 }
158  
4988 kaklik 159 createPathLinks($rep, $ppath, !$passrev && $peg ? $rev : $passrev, $peg);
160 $passRevString = createRevAndPegString($rev, $peg);
185 miho 161  
4988 kaklik 162 if ($rev != $youngest)
163 {
164 $vars['goyoungesturl'] = $config->getURL($rep, $path, 'file').createRevAndPegString($youngest, $peg);
165 $vars['goyoungestlink'] = '<a href="'.$vars['goyoungesturl'].'"'.($youngest ? ' title="'.$lang['REV'].' '.$youngest.'"' : '').'>'.$lang['GOYOUNGEST'].'</a>';
166 }
185 miho 167  
4988 kaklik 168 $revurl = $config->getURL($rep, $path, 'file');
185 miho 169  
4988 kaklik 170 if ($rev < $youngest)
171 {
172 $history2 = $svnrep->getLog($path, $rev, $youngest, true, 2, $peg ? $peg : 'HEAD');
185 miho 173  
4988 kaklik 174 if (isset($history2->entries[1]))
175 {
176 $nextRev = $history2->entries[1]->rev;
177 if ($nextRev != $youngest)
178 {
179 $vars['nextrev'] = $nextRev;
180 $vars['nextrevurl'] = $revurl.createRevAndPegString($nextRev, $peg);
181 }
182 }
185 miho 183  
4988 kaklik 184 unset($vars['error']);
185 }
185 miho 186  
4988 kaklik 187 $history3 = $svnrep->getLog($path, $rev, 1, true, 2, $peg ? $peg : 'HEAD');
185 miho 188  
4988 kaklik 189 if (isset($history3->entries[1]))
190 {
191 $prevRev = $history3->entries[1]->rev;
192 $prevPath = $history3->entries[1]->path;
193 $vars['prevrev'] = $prevRev;
194 $vars['prevrevurl'] = $revurl.createRevAndPegString($prevRev, $peg);
195 }
185 miho 196  
4988 kaklik 197 unset($vars['error']);
1189 miho 198  
4988 kaklik 199 $vars['revurl'] = $config->getURL($rep, $path, 'revision').$passRevString;
200 $vars['revlink'] = '<a href="'.$vars['revurl'].'">'.$lang['LASTMOD'].'</a>';
185 miho 201  
4988 kaklik 202 $vars['logurl'] = $config->getURL($rep, $path, 'log').$passRevString;
203 $vars['loglink'] = '<a href="'.$vars['logurl'].'">'.$lang['VIEWLOG'].'</a>';
185 miho 204  
4988 kaklik 205 $vars['blameurl'] = $config->getURL($rep, $path, 'blame').$passRevString;
206 $vars['blamelink'] = '<a href="'.$vars['blameurl'].'">'.$lang['BLAME'].'</a>';
185 miho 207  
4988 kaklik 208 if ($history == null || count($history->entries) > 1)
209 {
210 $vars['diffurl'] = $config->getURL($rep, $path, 'diff').$passRevString;
211 $vars['difflink'] = '<a href="'.$vars['diffurl'].'">'.$lang['DIFFPREV'].'</a>';
212 }
213  
214 if ($rep->isDownloadAllowed($path))
215 {
216 $vars['downloadlurl'] = $config->getURL($rep, $path, 'dl').$passRevString;
217 $vars['downloadlink'] = '<a href="'.$vars['downloadlurl'].'">'.$lang['DOWNLOAD'].'</a>';
218 }
219  
220 if ($rep->isRssEnabled())
221 {
222 $vars['rssurl'] = $config->getURL($rep, $path, 'rss').createRevAndPegString('', $peg);
223 $vars['rsslink'] = '<a href="'.$vars['rssurl'].'">'.$lang['RSSFEED'].'</a>';
224 }
225  
226 $mimeType = $useMime; // Restore preserved value to use for 'mimelink' variable.
227 // If there was a MIME type, create a link to display file with that type.
228 if ($mimeType && !isset($vars['warning']))
229 {
230 $vars['mimeurl'] = $config->getURL($rep, $path, 'file').'usemime=1&amp;'.$passRevString;
231 $vars['mimelink'] = '<a href="'.$vars['mimeurl'].'">'.$lang['VIEWAS'].' "'.$mimeType.'"</a>';
232 }
233  
234 $vars['rev'] = $rev;
235 $vars['peg'] = $peg;
236  
237 if (!$rep->hasReadAccess($path))
238 {
239 $vars['error'] = $lang['NOACCESS'];
240 sendHeaderForbidden();
241 }
242 else if (!$svnrep->isFile($path, $rev, $peg))
243 {
244 renderTemplate404('file','NOPATH');
245 }
246  
247 // $listing is populated with file data when file.tmpl calls [websvn-getlisting]
248 renderTemplate('file');