1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
<?php
// WebSVN - Subversion repository viewing via the web using PHP
// Copyright (C) 2004-2006 Tim Armes
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// --
//
// blame.php
//
// Show the blame information of a file.
//
require_once 'include/setup.php';
require_once 'include/svnlook.php';
require_once 'include/utils.php';
require_once 'include/template.php';
$vars['action'] = $lang['BLAME'];
// Make sure that we have a repository
if ($rep) {
$svnrep = new SVNRepository($rep);
// If there's no revision info, go to the lastest revision for this path
$history = $svnrep->getLog($path, 'HEAD', 1, false, 2, $peg);
$youngest = ($history) ? $history->entries[0]->rev : 0;
if (empty($rev)) {
$rev = $youngest;
} else {
$history = $svnrep->getLog($path, $rev, '', false, 2, $peg);
}
if ($path{0} != '/') {
$ppath = '/'.$path;
} else {
$ppath = $path;
}
// Find the parent path (or the whole path if it's already a directory)
$pos = strrpos($ppath, '/');
$parent = substr($ppath, 0, $pos + 1);
$vars['rev'] = $rev;
$vars['peg'] = $peg;
$vars['path'] = escape($ppath);
if ($history) {
$vars['log'] = xml_entities($history->entries[0]->msg);
$vars['date'] = $history->entries[0]->date;
$vars['author'] = $history->entries[0]->author;
}
createPathLinks($rep, $ppath, $passrev, $peg);
$passRevString = createRevAndPegString($passrev, $peg);
if ($rev != $youngest) {
$vars['goyoungesturl'] = $config->getURL($rep, $path, 'blame').($peg ? 'peg='.$peg : '');
$vars['goyoungestlink'] = '<a href="'.$vars['goyoungesturl'].'"'.($youngest ? ' title="'.$lang['REV'].' '.$youngest.'"' : '').'>'.$lang['GOYOUNGEST'].'</a>';
}
$revurl = $config->getURL($rep, $path, 'blame');
if ($rev < $youngest) {
$history2 = $svnrep->getLog($path, $rev, $youngest, false, 2, $peg);
if (isset($history2->entries[1])) {
$nextRev = $history2->entries[1]->rev;
if ($nextRev != $youngest) {
$vars['nextrev'] = $nextRev;
$vars['nextrevurl'] = $revurl.createRevAndPegString($nextRev, $peg);
}
}
unset($vars['error']);
}
if (isset($history->entries[1])) {
$prevRev = $history->entries[1]->rev;
$prevPath = $history->entries[1]->path;
$vars['prevrev'] = $prevRev;
$vars['prevrevurl'] = $revurl.createRevAndPegString($prevRev, $peg);
}
$vars['revurl'] = $config->getURL($rep, $path, 'revision').$passRevString;
$vars['revlink'] = '<a href="'.$vars['revurl'].'">'.$lang['LASTMOD'].'</a>';
$vars['logurl'] = $config->getURL($rep, $path, 'log').$passRevString;
$vars['loglink'] = '<a href="'.$vars['logurl'].'">'.$lang['VIEWLOG'].'</a>';
$vars['filedetailurl'] = $config->getURL($rep, $path, 'file').$passRevString;
$vars['filedetaillink'] = '<a href="'.$vars['filedetailurl'].'">'.$lang['FILEDETAIL'].'</a>';
if ($history == null || count($history->entries) > 1) {
$vars['diffurl'] = $config->getURL($rep, $path, 'diff').$passRevString;
$vars['difflink'] = '<a href="'.$vars['diffurl'].'">'.$lang['DIFFPREV'].'</a>';
}
if ($rep->isRssEnabled()) {
$vars['rssurl'] = $config->getURL($rep, $path, 'rss').($peg ? 'peg='.$peg : '');
$vars['rsslink'] = '<a href="'.$vars['rssurl'].'">'.$lang['RSSFEED'].'</a>';
}
// Check for binary file type before grabbing blame information.
$svnMimeType = $svnrep->getProperty($path, 'svn:mime-type', $rev, $peg);
if (!$rep->getIgnoreSvnMimeTypes() && preg_match('~application/*~', $svnMimeType)) {
$vars['warning'] = 'Cannot display blame info for binary file. (svn:mime-type = '.$svnMimeType.')';
$vars['javascript'] = '';
} else {
// Get the contents of the file
$tfname = tempnam($config->getTempDir(), '');
$highlighted = $svnrep->getFileContents($path, $tfname, $rev, $peg, '', 'line');
if ($file = fopen($tfname, 'r')) {
// Get the blame info
$tbname = tempnam($config->getTempDir(), '');
$svnrep->getBlameDetails($path, $tbname, $rev, $peg);
if ($blame = fopen($tbname, 'r')) {
// Create an array of version/author/line
$index = 0;
$seen_rev = array();
$last_rev = '';
$row_class = '';
while (!feof($blame) && !feof($file)) {
$blameline = fgets($blame);
if ($blameline != '') {
list($revision, $author, $remainder) = sscanf($blameline, '%d %s %s');
$empty = !$remainder;
$listing[$index]['lineno'] = $index + 1;
if ($last_rev != $revision) {
$url = $config->getURL($rep, $path, 'blame');
$listing[$index]['revision'] = '<a id="l'.$index.'-rev" class="blame-revision" href="'.$url.'rev='.$revision.'&peg='.$rev.'">'.$revision.'</a>';
$seen_rev[$revision] = 1;
$row_class = ($row_class == 'light') ? 'dark' : 'light';
$listing[$index]['author'] = $author;
} else {
$listing[$index]['revision'] = '';
$listing[$index]['author'] = '';
}
$listing[$index]['row_class'] = $row_class;
$last_rev = $revision;
$line = rtrim(fgets($file));
if (!$highlighted)
$line = escape(toOutputEncoding($line));
$listing[$index]['line'] = ($empty) ? ' ' : wrapInCodeTagIfNecessary($line);
$index++;
}
}
fclose($blame);
}
fclose($file);
@unlink($tbname);
}
@unlink($tfname);
// Build the necessary JavaScript as an array of lines, then join them with \n
$javascript = array();
$javascript[] = '<script type="text/javascript" src="'.$locwebsvnhttp.'/javascript/blame-popup.js"></script>';
$javascript[] = '<script type="text/javascript">';
$javascript[] = '/* <![CDATA[ */';
$javascript[] = 'var rev = new Array();';
ksort($seen_rev); // Sort revisions in descending order by key
if (empty($peg))
$peg = $rev;
if (!isset($vars['warning'])) {
foreach ($seen_rev as $key => $val) {
$history = $svnrep->getLog($path, $key, $key, false, 1, $peg);
if ($history) {
$javascript[] = 'rev['.$key.'] = \'<div class="date">'.$history->curEntry->date.'</div><div class="msg">'.addslashes(preg_replace('/\n/', ' ', $history->curEntry->msg)).'</div>\';';
}
}
}
$javascript[] = '/* ]]> */';
$javascript[] = '</script>';
$vars['javascript'] = implode("\n", $javascript);
}
if (!$rep->hasReadAccess($path, false)) {
$vars['error'] = $lang['NOACCESS'];
checkSendingAuthHeader($rep);
}
} else {
header('HTTP/1.x 404 Not Found', true, 404);
}
$vars['template'] = 'blame';
parseTemplate('header.tmpl');
parseTemplate('blame.tmpl');
parseTemplate('footer.tmpl');
|