From 7ebd0d1efe471b94cdff8d73d6ffd02ffd178254 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 6 May 2011 12:58:53 -0700 Subject: [PATCH] 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 --- src/__celerity_resource_map__.php | 22 +++++----- .../DifferentialChangesetViewController.php | 38 ++++++++++++++++++ .../controller/changesetview/__init__.php | 3 ++ .../DifferentialRevisionViewController.php | 1 + .../DifferentialChangesetDetailView.php | 10 ++++- .../DifferentialChangesetListView.php | 40 +++++++++++-------- .../differential/changeset-view.css | 8 ++++ 7 files changed, 94 insertions(+), 28 deletions(-) diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 4fa9111eca..2f08f070de 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -136,7 +136,7 @@ celerity_register_resource_map(array( ), 'differential-changeset-view-css' => array( - 'uri' => '/res/f26ca6f9/rsrc/css/application/differential/changeset-view.css', + 'uri' => '/res/32a8bac6/rsrc/css/application/differential/changeset-view.css', 'type' => 'css', 'requires' => array( @@ -690,7 +690,7 @@ celerity_register_resource_map(array( 'uri' => '/res/pkg/6c786373/differential.pkg.js', 'type' => 'js', ), - '8d8a971a' => + '8e4ef51b' => array ( 'name' => 'differential.pkg.css', 'symbols' => @@ -704,7 +704,7 @@ celerity_register_resource_map(array( 6 => 'differential-revision-add-comment-css', 7 => 'differential-revision-comment-list-css', ), - 'uri' => '/res/pkg/8d8a971a/differential.pkg.css', + 'uri' => '/res/pkg/8e4ef51b/differential.pkg.css', 'type' => 'css', ), 'eadf6ec3' => @@ -728,14 +728,14 @@ celerity_register_resource_map(array( 'aphront-table-view-css' => '4270730a', 'aphront-tokenizer-control-css' => '4270730a', 'aphront-typeahead-control-css' => '4270730a', - 'differential-changeset-view-css' => '8d8a971a', - 'differential-core-view-css' => '8d8a971a', - 'differential-revision-add-comment-css' => '8d8a971a', - 'differential-revision-comment-css' => '8d8a971a', - 'differential-revision-comment-list-css' => '8d8a971a', - 'differential-revision-detail-css' => '8d8a971a', - 'differential-revision-history-css' => '8d8a971a', - 'differential-table-of-contents-css' => '8d8a971a', + 'differential-changeset-view-css' => '8e4ef51b', + 'differential-core-view-css' => '8e4ef51b', + 'differential-revision-add-comment-css' => '8e4ef51b', + 'differential-revision-comment-css' => '8e4ef51b', + 'differential-revision-comment-list-css' => '8e4ef51b', + 'differential-revision-detail-css' => '8e4ef51b', + 'differential-revision-history-css' => '8e4ef51b', + 'differential-table-of-contents-css' => '8e4ef51b', 'diffusion-commit-view-css' => 'eadf6ec3', 'javelin-behavior-differential-diff-radios' => '6c786373', 'javelin-behavior-differential-edit-inline-comments' => '6c786373', diff --git a/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php b/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php index 220c8c0d56..2f5cc7362a 100644 --- a/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php +++ b/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php @@ -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); + } } diff --git a/src/applications/differential/controller/changesetview/__init__.php b/src/applications/differential/controller/changesetview/__init__.php index 3c23c13098..e3d0b1b139 100644 --- a/src/applications/differential/controller/changesetview/__init__.php +++ b/src/applications/differential/controller/changesetview/__init__.php @@ -8,8 +8,10 @@ phutil_require_module('arcanist', 'parser/diff'); +phutil_require_module('phabricator', 'aphront/response/400'); phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/ajax'); +phutil_require_module('phabricator', 'aphront/response/file'); phutil_require_module('phabricator', 'applications/differential/controller/base'); phutil_require_module('phabricator', 'applications/differential/parser/changeset'); phutil_require_module('phabricator', 'applications/differential/parser/markup'); @@ -23,6 +25,7 @@ phutil_require_module('phabricator', 'infrastructure/javelin/api'); phutil_require_module('phutil', 'filesystem'); phutil_require_module('phutil', 'filesystem/tempfile'); phutil_require_module('phutil', 'future/exec'); +phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php index f47a4e4319..fd4e76de8f 100644 --- a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php @@ -179,6 +179,7 @@ class DifferentialRevisionViewController extends DifferentialController { $changeset_view = new DifferentialChangesetListView(); $changeset_view->setChangesets($visible_changesets); $changeset_view->setEditable(true); + $changeset_view->setStandaloneViews(true); $changeset_view->setRevision($revision); $changeset_view->setVsMap($vs_map); $changeset_view->setWhitespace($whitespace); diff --git a/src/applications/differential/view/changesetdetailview/DifferentialChangesetDetailView.php b/src/applications/differential/view/changesetdetailview/DifferentialChangesetDetailView.php index 9a2ca3517c..61135cc71e 100644 --- a/src/applications/differential/view/changesetdetailview/DifferentialChangesetDetailView.php +++ b/src/applications/differential/view/changesetdetailview/DifferentialChangesetDetailView.php @@ -53,6 +53,14 @@ class DifferentialChangesetDetailView extends AphrontView { $class .= ' differential-changeset-immutable'; } + $buttons = null; + if ($this->buttons) { + $buttons = + '
'. + implode('', $this->buttons). + '
'; + } + $display_filename = $changeset->getDisplayFilename(); $output = javelin_render_tag( 'div', @@ -70,7 +78,7 @@ class DifferentialChangesetDetailView extends AphrontView { 'name' => $changeset->getAnchorName(), ), ''). - implode('', $this->buttons). + $buttons. '

'.phutil_escape_html($display_filename).'

'. '
'. $this->renderChildren()); diff --git a/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php b/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php index 2d77947dc4..0939a7c5a1 100644 --- a/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php +++ b/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php @@ -24,6 +24,7 @@ class DifferentialChangesetListView extends AphrontView { private $renderURI = '/differential/changeset/'; private $vsMap = array(); private $whitespace; + private $standaloneViews; public function setChangesets($changesets) { $this->changesets = $changesets; @@ -35,6 +36,11 @@ class DifferentialChangesetListView extends AphrontView { return $this; } + public function setStandaloneViews($has_standalone_views) { + $this->standaloneViews = $has_standalone_views; + return $this; + } + public function setRevision(DifferentialRevision $revision) { $this->revision = $revision; return $this; @@ -78,23 +84,25 @@ class DifferentialChangesetListView extends AphrontView { $ref = $changeset->getRenderingReference(); - $detail_uri = new PhutilURI($this->renderURI); - $detail_uri->setQueryParams( - array( - 'id' => $ref, - 'vs' => $vs_id, - 'whitespace' => $this->whitespace, - )); + $detail_button = null; + if ($this->standaloneViews) { + $detail_uri = new PhutilURI($this->renderURI); + $detail_uri->setQueryParams( + array( + 'id' => $ref, + 'vs' => $vs_id, + 'whitespace' => $this->whitespace, + )); - $detail_button = phutil_render_tag( - 'a', - array( - 'style' => 'float: right', - 'class' => 'button small grey', - 'href' => $detail_uri, - 'target' => '_blank', - ), - 'Standalone View'); + $detail_button = phutil_render_tag( + 'a', + array( + 'class' => 'button small grey', + 'href' => $detail_uri, + 'target' => '_blank', + ), + 'View Standalone / Raw'); + } $uniq_id = celerity_generate_unique_node_id(); diff --git a/webroot/rsrc/css/application/differential/changeset-view.css b/webroot/rsrc/css/application/differential/changeset-view.css index 779ce9abf1..b58b8aec9b 100644 --- a/webroot/rsrc/css/application/differential/changeset-view.css +++ b/webroot/rsrc/css/application/differential/changeset-view.css @@ -172,3 +172,11 @@ width: 100%; height: 12em; } + +.differential-changeset-buttons { + float: right; +} + +.differential-changeset-buttons a.button { + margin-left: 8px; +}