Provide a web interface to view raw source text in Differential

Summary:
Add links to the 'standalone view' to grab the raw source text. I think this
operation is rare enough that it's okay to hide it like this. I changed
'Standalone View' to 'View Standalone / Raw' to improve discoverability.

This also fixes the broken Standalone View links in Diffusion by no longer
rendering them.

Test Plan:
viewed old and new sources for a changeset

Reviewed By: tuomaspelkonen
Reviewers: tuomaspelkonen, jungejason, aran
CC: aran, tuomaspelkonen
Differential Revision: 243
This commit is contained in:
epriestley
2011-05-06 12:58:53 -07:00
parent 7566f50d8f
commit 7ebd0d1efe
7 changed files with 94 additions and 28 deletions

View File

@@ -33,6 +33,19 @@ class DifferentialChangesetViewController extends DifferentialController {
return new Aphront404Response();
}
$view = $request->getStr('view');
if ($view) {
$changeset->attachHunks($changeset->loadHunks());
switch ($view) {
case 'new':
return $this->buildRawFileResponse($changeset->makeNewFile());
case 'old':
return $this->buildRawFileResponse($changeset->makeOldFile());
default:
return new Aphront400Response();
}
}
if ($vs && ($vs != -1)) {
$vs_changeset = id(new DifferentialChangeset())->load($vs);
if (!$vs_changeset) {
@@ -177,6 +190,26 @@ class DifferentialChangesetViewController extends DifferentialController {
$detail = new DifferentialChangesetDetailView();
$detail->setChangeset($changeset);
$detail->appendChild($output);
if (!$vs) {
$detail->addButton(
phutil_render_tag(
'a',
array(
'href' => $request->getRequestURI()->alter('view', 'old'),
'class' => 'grey button small',
),
'View Raw File (Old Version)'));
$detail->addButton(
phutil_render_tag(
'a',
array(
'href' => $request->getRequestURI()->alter('view', 'new'),
'class' => 'grey button small',
),
'View Raw File (New Version)'));
}
$detail->setRevisionID($request->getInt('revision_id'));
$output =
@@ -202,5 +235,10 @@ class DifferentialChangesetViewController extends DifferentialController {
$author_phid);
}
private function buildRawFileResponse($text) {
return id(new AphrontFileResponse())
->setMimeType('text/plain')
->setContent($text);
}
}