diff --git a/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php index eac0ce27ff..3dacdd7fce 100644 --- a/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php +++ b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php @@ -18,6 +18,7 @@ class DiffusionBrowseFileController extends DiffusionController { + // Image types we want to display inline using tags protected $imageTypes = array( 'png' => 'image/png', 'gif' => 'image/gif', @@ -26,6 +27,11 @@ class DiffusionBrowseFileController extends DiffusionController { 'jpeg'=> 'image/jpeg' ); + // Document types that should trigger link to ?view=raw + protected $documentTypes = array( + 'pdf'=> 'application/pdf', + 'ps' => 'application/postscript', + ); public function processRequest() { @@ -35,11 +41,33 @@ class DiffusionBrowseFileController extends DiffusionController { 'blame' => 'View as Highlighted Text with Blame', 'plain' => 'View as Plain Text', 'plainblame' => 'View as Plain Text with Blame', + 'raw' => 'View as raw document', ); $request = $this->getRequest(); + $drequest = $this->getDiffusionRequest(); + $path = $drequest->getPath(); $selected = $request->getStr('view'); + $needs_blame = ($selected == 'blame' || $selected == 'plainblame'); + $file_query = DiffusionFileContentQuery::newFromDiffusionRequest( + $this->diffusionRequest); + $file_query->setNeedsBlame($needs_blame); + $file_query->loadFileContent(); + $data = $file_query->getRawData(); + if ($selected === 'raw') { + $response = new AphrontFileResponse(); + $response->setContent($data); + $mime_type = $this->getDocumentType($path); + if ($mime_type) { + $response->setMimeType($mime_type); + } else { + $as_filename = idx(pathinfo($path), 'basename'); + $response->setDownload($as_filename); + } + return $response; + } + $select = '