mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-25 14:08:19 +01:00
Improve actions for binary files and images in Diffusion
Summary: We currently render something kind of goofy; integrate these with the other actions. Test Plan: Viewed `aphlict.swf`, some PNG in Diffusion. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7052
This commit is contained in:
parent
43bf21daa5
commit
e8205a2d1e
1 changed files with 41 additions and 50 deletions
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||||
|
|
||||||
private $corpusType = 'text';
|
|
||||||
|
|
||||||
private $lintCommit;
|
private $lintCommit;
|
||||||
private $lintMessages;
|
private $lintMessages;
|
||||||
|
|
||||||
|
@ -71,15 +69,28 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||||
|
|
||||||
$this->loadLintMessages();
|
$this->loadLintMessages();
|
||||||
|
|
||||||
// Build the content of the file.
|
$binary_uri = null;
|
||||||
$corpus = $this->buildCorpus(
|
if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
|
||||||
$show_blame,
|
$file = $this->loadFileForData($path, $data);
|
||||||
$show_color,
|
$file_uri = $file->getBestURI();
|
||||||
$file_content,
|
|
||||||
$needs_blame,
|
if ($file->isViewableImage()) {
|
||||||
$drequest,
|
$corpus = $this->buildImageCorpus($file_uri);
|
||||||
$path,
|
} else {
|
||||||
$data);
|
$corpus = $this->buildBinaryCorpus($file_uri, $data);
|
||||||
|
$binary_uri = $file_uri;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Build the content of the file.
|
||||||
|
$corpus = $this->buildCorpus(
|
||||||
|
$show_blame,
|
||||||
|
$show_color,
|
||||||
|
$file_content,
|
||||||
|
$needs_blame,
|
||||||
|
$drequest,
|
||||||
|
$path,
|
||||||
|
$data);
|
||||||
|
}
|
||||||
|
|
||||||
if ($request->isAjax()) {
|
if ($request->isAjax()) {
|
||||||
return id(new AphrontAjaxResponse())->setContent($corpus);
|
return id(new AphrontAjaxResponse())->setContent($corpus);
|
||||||
|
@ -96,7 +107,8 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||||
$view,
|
$view,
|
||||||
$drequest,
|
$drequest,
|
||||||
$show_blame,
|
$show_blame,
|
||||||
$show_color);
|
$show_color,
|
||||||
|
$binary_uri);
|
||||||
$content[] = $this->buildPropertyView($drequest);
|
$content[] = $this->buildPropertyView($drequest);
|
||||||
|
|
||||||
$follow = $request->getStr('follow');
|
$follow = $request->getStr('follow');
|
||||||
|
@ -190,19 +202,6 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||||
$path,
|
$path,
|
||||||
$data) {
|
$data) {
|
||||||
|
|
||||||
if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
|
|
||||||
$file = $this->loadFileForData($path, $data);
|
|
||||||
$file_uri = $file->getBestURI();
|
|
||||||
|
|
||||||
if ($file->isViewableImage()) {
|
|
||||||
$this->corpusType = 'image';
|
|
||||||
return $this->buildImageCorpus($file_uri);
|
|
||||||
} else {
|
|
||||||
$this->corpusType = 'binary';
|
|
||||||
return $this->buildBinaryCorpus($file_uri, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$show_color) {
|
if (!$show_color) {
|
||||||
$style =
|
$style =
|
||||||
"margin: 1em 2em; width: 90%; height: 80em; font-family: monospace";
|
"margin: 1em 2em; width: 90%; height: 80em; font-family: monospace";
|
||||||
|
@ -309,7 +308,8 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||||
PhabricatorActionListView $view,
|
PhabricatorActionListView $view,
|
||||||
DiffusionRequest $drequest,
|
DiffusionRequest $drequest,
|
||||||
$show_blame,
|
$show_blame,
|
||||||
$show_color) {
|
$show_color,
|
||||||
|
$binary_uri) {
|
||||||
|
|
||||||
$viewer = $this->getRequest()->getUser();
|
$viewer = $this->getRequest()->getUser();
|
||||||
$base_uri = $this->getRequest()->getRequestURI();
|
$base_uri = $this->getRequest()->getRequestURI();
|
||||||
|
@ -361,7 +361,6 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
->setRenderAsForm(true));
|
->setRenderAsForm(true));
|
||||||
|
|
||||||
|
|
||||||
$href = null;
|
$href = null;
|
||||||
if ($this->getRequest()->getStr('lint') !== null) {
|
if ($this->getRequest()->getStr('lint') !== null) {
|
||||||
$lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages));
|
$lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages));
|
||||||
|
@ -386,11 +385,19 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||||
->setIcon('warning')
|
->setIcon('warning')
|
||||||
->setDisabled(!$href));
|
->setDisabled(!$href));
|
||||||
|
|
||||||
$view->addAction(
|
if ($binary_uri) {
|
||||||
id(new PhabricatorActionView())
|
$view->addAction(
|
||||||
->setName(pht('View Raw File'))
|
id(new PhabricatorActionView())
|
||||||
->setHref($base_uri->alter('view', 'raw'))
|
->setName(pht('Download Raw File'))
|
||||||
->setIcon('file'));
|
->setHref($binary_uri)
|
||||||
|
->setIcon('download'));
|
||||||
|
} else {
|
||||||
|
$view->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setName(pht('View Raw File'))
|
||||||
|
->setHref($base_uri->alter('view', 'raw'))
|
||||||
|
->setIcon('file'));
|
||||||
|
}
|
||||||
|
|
||||||
$view->addAction($this->createEditAction());
|
$view->addAction($this->createEditAction());
|
||||||
|
|
||||||
|
@ -820,12 +827,7 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||||
'src' => $file_uri,
|
'src' => $file_uri,
|
||||||
)));
|
)));
|
||||||
|
|
||||||
$actions = id(new PhabricatorActionListView())
|
return $properties;
|
||||||
->setUser($this->getRequest()->getUser())
|
|
||||||
->setObjectURI($this->getRequest()->getRequestURI())
|
|
||||||
->addAction($this->createEditAction());
|
|
||||||
|
|
||||||
return array($actions, $properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildBinaryCorpus($file_uri, $data) {
|
private function buildBinaryCorpus($file_uri, $data) {
|
||||||
|
@ -837,18 +839,7 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||||
'This is a binary file. It is %s byte(s) in length.',
|
'This is a binary file. It is %s byte(s) in length.',
|
||||||
new PhutilNumber($size)));
|
new PhutilNumber($size)));
|
||||||
|
|
||||||
$actions = id(new PhabricatorActionListView())
|
return $properties;
|
||||||
->setUser($this->getRequest()->getUser())
|
|
||||||
->setObjectURI($this->getRequest()->getRequestURI())
|
|
||||||
->addAction($this->createEditAction())
|
|
||||||
->addAction(
|
|
||||||
id(new PhabricatorActionView())
|
|
||||||
->setName(pht('Download Binary File...'))
|
|
||||||
->setIcon('download')
|
|
||||||
->setHref($file_uri));
|
|
||||||
|
|
||||||
return array($actions, $properties);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildBeforeResponse($before) {
|
private function buildBeforeResponse($before) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue