1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
4 include '../inc/common.php';
5 MTrackACL::requireAllRights('Browser', 'read');
7 $pi = mtrack_get_pathinfo(true);
9 $data = explode('@', $pi);
11 if (isset($data[1])) {
12 $_GET['rev'] = $data[1];
15 $crumbs = MTrackSCM::makeBreadcrumbs($pi);
16 if (!strlen($pi) || $pi == '/') {
19 $repo = MTrackSCM::factory($pi);
23 throw new Exception("invalid path $pi");
25 MTrackACL::requireAllRights("repo:$repo->repoid", 'read');
27 if (isset($_GET['rev'])) {
28 $file = $repo->file($pi, 'rev', $_GET['rev']);
30 $file = $repo->file($pi);
33 $ent = $file->getChangeEvent();
35 if (isset($_GET['raw']) && $_GET['raw'] == 1) {
36 $filename = basename($pi);
37 header("Content-Type: application/octet-stream; name=\"$filename\"");
38 header("Content-Disposition: attachment; filename=\"$filename\"");
39 fpassthru($file->cat());
43 mtrack_head("File $pi @ " . $file->rev);
45 /* Render a bread-crumb enabled location indicator */
46 echo "<div class='browselocation'>Location: ";
48 $last = array_pop($crumbs);
49 if (isset($_GET['jump'])) {
50 $jump = '?jump=' . urlencode($_GET['jump']);
54 foreach ($crumbs as $path) {
58 $location .= '/' . urlencode($path);
60 $path = htmlentities($path, ENT_QUOTES, 'utf-8');
61 echo "<a href='{$ABSWEB}browse.php$location$jump'>$path</a> / ";
64 echo "$last @ " . mtrack_changeset($ent->rev, $repo);
67 echo "<div class='revinfo'>\n";
68 echo MTrackWiki::format_to_html($ent->changelog);
69 echo "<div class='changeinfo'>\n";
70 echo mtrack_username($ent->changeby, array('size' => 32));
72 echo mtrack_date($ent->ctime, true) . "<br>\n";
73 echo "Revision: $repo->shortname $ent->rev";
74 foreach ($ent->branches as $b) {
75 echo " " . mtrack_branch($b);
77 foreach ($ent->tags as $t) {
78 echo " " . mtrack_tag($t);
80 echo "</div></div>\n";
82 echo "<br><a href='{$ABSWEB}log.php/" .
83 $repo->getBrowseRootName() .
84 htmlentities("/$pi$jump", ENT_QUOTES, 'utf-8') .
85 "'>Show revision log</a>";
87 /* Do we want to show the file? */
89 $finfo = pathinfo($file->name);
93 stream_copy_to_stream($data, $t);
98 $location = stream_get_meta_data($t);
99 $location = $location['uri'];
101 $mimetype = mtrack_mime_detect($location, $file->name);
102 list($major) = explode('/', $mimetype, 2);
104 // Obscure-ish special cases for mime types;
105 // some .y files look like old image format data
106 if ($mimetype == 'image/x-3ds') {
108 } elseif ($mimetype == 'application/xml') {
115 $raw_url = $ABSWEB . 'file.php' . (isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '') .
116 '?' . http_build_query($p);
118 if ($major == 'text') {
120 $ann = $file->annotate();
121 if ($ann === 'DELETED') {
122 echo "<div>Deleted</div>\n";
126 $data = stream_get_contents($t);
127 $data = MTrackSyntaxHighlight::highlightSource($data, null, $file->name);
132 <button type='button' class='toggle-ann'>Blame</button>
133 <button type='button' class='toggle-line'>Line #s</button>
135 echo MTrackSyntaxHighlight::getSchemeSelect();
138 $(document).ready(function () {
141 $('.toggle-ann').click(function () {
144 $('table.codeann .user').show();
145 $('table.codeann .changeset').show();
147 $('table.codeann .user').hide();
148 $('table.codeann .changeset').hide();
151 $('.toggle-line').click(function () {
154 $('table.codeann .line').show();
156 $('table.codeann .line').hide();
163 echo "<br><br><table class='codeann'><tr><th class='changeset'>rev</th><th class='user'>who</th><th class='line'>line</th><th class='code'>code</th></tr>\n";
165 while (isset($ann[$i])) {
168 "<td class='changeset'>" . mtrack_changeset($a->rev, $repo) . "</td>" .
169 "<td class='user'>" . mtrack_username($a->changeby,
170 array('no_image' => true)) . "</td>" .
171 "<td class='line'><a name='l$i'></a><a href='#l$i'>$i</a></td>";
174 $nlines = count($ann);
175 echo "<td rowspan='$nlines' width='100%' class='source-code wezterm'>$data</td>";
184 } elseif ($major == 'image') {
185 echo "<br><br><img src='$raw_url'>\n";
187 echo "<br><br><a href='$raw_url'>Download File</a> ($mimetype)\n";