| 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 | 3 | simandl | if (is_string($history)) { |
| 49 | | | echo $history; |
| 50 | | | exit; |
| 51 | | | } |
| 52 | 1 | simandl | $youngest = isset($history->entries[0]) ? $history->entries[0]->rev: false; |
| 53 | | | |
| 54 | | | if (empty($rev)) { |
| 55 | | | $rev = $youngest; |
| 56 | | | } |
| 57 | | | |
| 58 | | | $extn = strtolower(strrchr($path, ".")); |
| 59 | | | |
| 60 | | | // Check to see if the user has requested that this type be zipped and sent |
| 61 | | | // to the browser as an attachment |
| 62 | | | |
| 63 | | | if (in_array($extn, $zipped) && $rep->hasReadAccess($path, false)) { |
| 64 | | | $base = basename($path); |
| 65 | | | header("Content-Type: application/x-gzip"); |
| 66 | | | header("Content-Disposition: attachment; filename=".urlencode($base).".gz"); |
| 67 | | | |
| 68 | | | // Get the file contents and pipe into gzip. All this without creating |
| 69 | | | // a temporary file. Damn clever. |
| 70 | | | $svnrep->getFileContents($path, "", $rev, "| ".$config->gzip." -n -f"); |
| 71 | | | |
| 72 | | | exit; |
| 73 | | | } |
| 74 | | | |
| 75 | | | // Check to see if we should serve it with a particular content-type. |
| 76 | | | // The content-type could come from an svn:mime-type property on the |
| 77 | | | // file, or from the $contentType array in setup.php. |
| 78 | | | |
| 79 | | | if (!$rep->getIgnoreSvnMimeTypes()) { |
| 80 | | | $svnMimeType = $svnrep->getProperty($path, 'svn:mime-type', $rev); |
| 81 | | | } |
| 82 | | | |
| 83 | | | if (!$rep->getIgnoreWebSVNContentTypes()) { |
| 84 | | | $setupContentType = @$contentType[$extn]; |
| 85 | | | } |
| 86 | | | |
| 87 | 3 | simandl | // Use the documented priorities when establishing what content-type to use. |
| 88 | 1 | simandl | if (!empty($svnMimeType) && $svnMimeType != 'application/octet-stream') { |
| 89 | 3 | simandl | $mimeType = $svnMimeType; |
| 90 | 1 | simandl | } else if (!empty($setupContentType)) { |
| 91 | 3 | simandl | $mimeType = $setupContentType; |
| 92 | 1 | simandl | } else if (!empty($svnMimeType)) { |
| 93 | 3 | simandl | $mimeType = $svnMimeType; // Use SVN's default of "application/octet-stream" |
| 94 | 1 | simandl | } |
| 95 | | | |
| 96 | 3 | simandl | // If the MIME type exists but is set to be ignored, set it to an empty string. |
| 97 | | | if (!empty($mimeType)) { |
| 98 | | | foreach ($config->inlineMimeTypes as $inlineType) { |
| 99 | | | if (preg_match('|'.$inlineType.'|', $mimeType)) { |
| 100 | | | $mimeType = ''; |
| 101 | | | break; |
| 102 | | | } |
| 103 | | | } |
| 104 | | | } |
| 105 | 1 | simandl | |
| 106 | 3 | simandl | // If a MIME type is associated with the file, deliver with Content-Type header. |
| 107 | | | if (!empty($mimeType) && $rep->hasReadAccess($path, false)) { |
| 108 | 1 | simandl | $base = basename($path); |
| 109 | 3 | simandl | header('Content-Type: '.$mimeType); |
| 110 | | | //header('Content-Length: '.$size); |
| 111 | | | header('Content-Disposition: inline; filename='.urlencode($base)); |
| 112 | 1 | simandl | $svnrep->getFileContents($path, "", $rev); |
| 113 | | | exit; |
| 114 | | | } |
| 115 | | | |
| 116 | 3 | simandl | // Display the file inline using WebSVN. |
| 117 | 1 | simandl | |
| 118 | | | $url = $config->getURL($rep, $path, "file"); |
| 119 | | | |
| 120 | | | if ($rev != $youngest) { |
| 121 | | | $vars["goyoungestlink"] = "<a href=\"${url}\">${lang["GOYOUNGEST"]}</a>"; |
| 122 | | | } else { |
| 123 | | | $vars["goyoungestlink"] = ""; |
| 124 | | | } |
| 125 | | | |
| 126 | | | $vars["action"] = ""; |
| 127 | | | $vars["repname"] = htmlentities($rep->getDisplayName(), ENT_QUOTES, 'UTF-8'); |
| 128 | | | $vars["rev"] = htmlentities($rev, ENT_QUOTES, 'UTF-8'); |
| 129 | | | $vars["path"] = htmlentities($ppath, ENT_QUOTES, 'UTF-8'); |
| 130 | | | |
| 131 | | | createDirLinks($rep, $ppath, $passrev); |
| 132 | | | |
| 133 | | | $vars['indexurl'] = $config->getURL($rep, '', 'index'); |
| 134 | | | $vars['repurl'] = $config->getURL($rep, '', 'dir'); |
| 135 | | | |
| 136 | | | $url = $config->getURL($rep, $path, "log"); |
| 137 | | | $vars["fileviewloglink"] = "<a href=\"${url}rev=$passrev&isdir=0\">${lang["VIEWLOG"]}</a>"; |
| 138 | | | |
| 139 | | | $url = $config->getURL($rep, $path, "diff"); |
| 140 | | | $vars["prevdifflink"] = "<a href=\"${url}rev=$passrev\">${lang["DIFFPREV"]}</a>"; |
| 141 | | | |
| 142 | | | $url = $config->getURL($rep, $path, "blame"); |
| 143 | | | $vars["blamelink"] = "<a href=\"${url}rev=$passrev\">${lang["BLAME"]}</a>"; |
| 144 | | | |
| 145 | 3 | simandl | if ($rep->isDownloadAllowed($path)) { |
| 146 | | | $url = $config->getURL($rep, $path, "dl"); |
| 147 | | | $vars["dllink"] = "<a href=\"${url}rev=$passrev\">${lang["DOWNLOAD"]}</a>"; |
| 148 | | | } |
| 149 | | | |
| 150 | 1 | simandl | $listing = array(); |
| 151 | | | |
| 152 | | | $vars["version"] = $version; |
| 153 | | | |
| 154 | | | if (!$rep->hasReadAccess($path, false)) { |
| 155 | | | $vars["noaccess"] = true; |
| 156 | | | } |
| 157 | | | |
| 158 | | | parseTemplate($rep->getTemplatePath()."header.tmpl", $vars, $listing); |
| 159 | | | parseTemplate($rep->getTemplatePath()."file.tmpl", $vars, $listing); |
| 160 | | | parseTemplate($rep->getTemplatePath()."footer.tmpl", $vars, $listing); |