Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Detects file types

Author Dave Jarvis <email>
Date 2026-02-08 21:26:27 GMT-0800
Commit 192e04657992c16992f2fd81722fdaf0b213af66
Parent 53a4440
Delta 13 lines added, 5 lines removed, 8-line increase
new/File.php
}
+ public function isBinary(): bool {
+ return MediaTypeSniffer::isBinary($this->getSniffBuffer(), $this->name);
+ }
+
private function getSniffBuffer(): string {
if ($this->isDir || !file_exists($this->name)) return '';
new/FileRenderer.php
string $size = ''
): void {
- $url = '?repo=' . urlencode($this->repoSafeName) . '&hash=' . $sha;
+ // UPDATED: Added '&name=' to the URL
+ $url = '?repo=' . urlencode($this->repoSafeName) . '&hash=' . $sha . '&name=' . urlencode($name);
echo '<a href="' . $url . '" class="file-item">';
new/Views.php
});
- // We pass an empty filename '' because the blob view URL doesn't always contain the filename
- $category = MediaTypeSniffer::isCategory($buffer, '');
- $mimeType = MediaTypeSniffer::isMediaType($buffer, '');
+ // UPDATED: Retrieve the filename from the URL to assist detection
+ $filename = $_GET['name'] ?? '';
+ $category = MediaTypeSniffer::isCategory($buffer, $filename);
+ $mimeType = MediaTypeSniffer::isMediaType($buffer, $filename);
$this->renderBreadcrumbs($targetHash, 'File');
$content = '';
$this->git->stream($targetHash, function($d) use (&$content) { $content .= $d; });
- echo '<div class="blob-content"><div class="blob-code">' . htmlspecialchars($content) . '</div></div>';
+ // UPDATED: Changed from div to pre to preserve whitespace
+ echo '<div class="blob-content"><pre class="blob-code">' . htmlspecialchars($content) . '</pre></div>';
} else {
$this->renderDownloadState($targetHash, "This is a binary file.");
}
}
+