Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionBrowseController.php
| Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | if ($view !== 'raw') { | ||||
| $time_limit = 10; | $time_limit = 10; | ||||
| $params += array( | $params += array( | ||||
| 'timeout' => $time_limit, | 'timeout' => $time_limit, | ||||
| 'byteLimit' => $byte_limit, | 'byteLimit' => $byte_limit, | ||||
| ); | ); | ||||
| } | } | ||||
| $file_content = DiffusionFileContent::newFromConduit( | $response = $this->callConduitWithDiffusionRequest( | ||||
| $this->callConduitWithDiffusionRequest( | |||||
| 'diffusion.filecontentquery', | 'diffusion.filecontentquery', | ||||
| $params)); | $params); | ||||
| $data = $file_content->getCorpus(); | |||||
| if ($view === 'raw') { | |||||
| return $this->buildRawResponse($path, $data); | |||||
| } | |||||
| $this->loadLintMessages(); | $hit_byte_limit = $response['tooHuge']; | ||||
| $this->coverage = $drequest->loadCoverage(); | $hit_time_limit = $response['tooSlow']; | ||||
| if ($byte_limit && (strlen($data) == $byte_limit)) { | $file_phid = $response['filePHID']; | ||||
| if ($hit_byte_limit) { | |||||
| $corpus = $this->buildErrorCorpus( | $corpus = $this->buildErrorCorpus( | ||||
| pht( | pht( | ||||
| 'This file is larger than %s byte(s), and too large to display '. | 'This file is larger than %s byte(s), and too large to display '. | ||||
| 'in the web UI.', | 'in the web UI.', | ||||
| $byte_limit)); | phutil_format_bytes($byte_limit))); | ||||
| } else if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) { | } else if ($hit_time_limit) { | ||||
| $file = $this->loadFileForData($path, $data); | $corpus = $this->buildErrorCorpus( | ||||
| pht( | |||||
| 'This file took too long to load from the repository (more than '. | |||||
| '%s second(s)).', | |||||
| new PhutilNumber($time_limit))); | |||||
| } else { | |||||
| $file = id(new PhabricatorFileQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withPHIDs(array($file_phid)) | |||||
| ->executeOne(); | |||||
| if (!$file) { | |||||
| throw new Exception(pht('Failed to load content file!')); | |||||
| } | |||||
| if ($view === 'raw') { | |||||
| return $file->getRedirectResponse(); | |||||
| } | |||||
| $data = $file->loadFileData(); | |||||
| if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) { | |||||
| $file_uri = $file->getBestURI(); | $file_uri = $file->getBestURI(); | ||||
| if ($file->isViewableImage()) { | if ($file->isViewableImage()) { | ||||
| $corpus = $this->buildImageCorpus($file_uri); | $corpus = $this->buildImageCorpus($file_uri); | ||||
| } else { | } else { | ||||
| $corpus = $this->buildBinaryCorpus($file_uri, $data); | $corpus = $this->buildBinaryCorpus($file_uri, $data); | ||||
| } | } | ||||
| } else { | } else { | ||||
| $this->loadLintMessages(); | |||||
| $this->coverage = $drequest->loadCoverage(); | |||||
| // Build the content of the file. | // Build the content of the file. | ||||
| $corpus = $this->buildCorpus( | $corpus = $this->buildCorpus( | ||||
| $show_blame, | $show_blame, | ||||
| $show_color, | $show_color, | ||||
| $file_content, | $data, | ||||
| $needs_blame, | $needs_blame, | ||||
| $drequest, | $drequest, | ||||
| $path, | $path, | ||||
| $data); | $data); | ||||
| } | } | ||||
| } | |||||
| if ($request->isAjax()) { | if ($request->isAjax()) { | ||||
| return id(new AphrontAjaxResponse())->setContent($corpus); | return id(new AphrontAjaxResponse())->setContent($corpus); | ||||
| } | } | ||||
| require_celerity_resource('diffusion-source-css'); | require_celerity_resource('diffusion-source-css'); | ||||
| // Render the page. | // Render the page. | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | if (!$results->isValidResults()) { | ||||
| $browse_panel = new PHUIObjectBoxView(); | $browse_panel = new PHUIObjectBoxView(); | ||||
| $browse_panel->setHeaderText($drequest->getPath(), '/'); | $browse_panel->setHeaderText($drequest->getPath(), '/'); | ||||
| $browse_panel->setTable($browse_table); | $browse_panel->setTable($browse_table); | ||||
| $content[] = $browse_panel; | $content[] = $browse_panel; | ||||
| } | } | ||||
| $content[] = $this->buildOpenRevisions(); | $content[] = $this->buildOpenRevisions(); | ||||
| $content[] = $this->renderDirectoryReadme($results); | |||||
| $readme_path = $results->getReadmePath(); | |||||
| if ($readme_path) { | |||||
| $readme_content = $this->callConduitWithDiffusionRequest( | |||||
| 'diffusion.filecontentquery', | |||||
| array( | |||||
| 'path' => $readme_path, | |||||
| 'commit' => $drequest->getStableCommit(), | |||||
| )); | |||||
| if ($readme_content) { | |||||
| $content[] = id(new DiffusionReadmeView()) | |||||
| ->setUser($this->getViewer()) | |||||
| ->setPath($readme_path) | |||||
| ->setContent($readme_content['corpus']); | |||||
| } | |||||
| } | |||||
| $crumbs = $this->buildCrumbs( | $crumbs = $this->buildCrumbs( | ||||
| array( | array( | ||||
| 'branch' => true, | 'branch' => true, | ||||
| 'path' => true, | 'path' => true, | ||||
| 'view' => 'browse', | 'view' => 'browse', | ||||
| )); | )); | ||||
| ▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | $this->lintMessages = queryfx_all( | ||||
| $branch->getID(), | $branch->getID(), | ||||
| $where, | $where, | ||||
| '/'.$drequest->getPath()); | '/'.$drequest->getPath()); | ||||
| } | } | ||||
| private function buildCorpus( | private function buildCorpus( | ||||
| $show_blame, | $show_blame, | ||||
| $show_color, | $show_color, | ||||
| DiffusionFileContent $file_content, | $file_corpus, | ||||
| $needs_blame, | $needs_blame, | ||||
| DiffusionRequest $drequest, | DiffusionRequest $drequest, | ||||
| $path, | $path, | ||||
| $data) { | $data) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $blame_timeout = 15; | $blame_timeout = 15; | ||||
| $blame_failed = false; | $blame_failed = false; | ||||
| $file_corpus = $file_content->getCorpus(); | |||||
| $highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT; | $highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT; | ||||
| $blame_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT; | $blame_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT; | ||||
| $can_highlight = (strlen($file_corpus) <= $highlight_limit); | $can_highlight = (strlen($file_corpus) <= $highlight_limit); | ||||
| $can_blame = (strlen($file_corpus) <= $blame_limit); | $can_blame = (strlen($file_corpus) <= $blame_limit); | ||||
| if ($needs_blame && $can_blame) { | if ($needs_blame && $can_blame) { | ||||
| $blame = $this->loadBlame($path, $drequest->getCommit(), $blame_timeout); | $blame = $this->loadBlame($path, $drequest->getCommit(), $blame_timeout); | ||||
| list($blame_list, $blame_commits) = $blame; | list($blame_list, $blame_commits) = $blame; | ||||
| ▲ Show 20 Lines • Show All 645 Lines • ▼ Show 20 Lines | foreach ($inlines as $inline) { | ||||
| } | } | ||||
| $rows[] = phutil_tag('tr', array('class' => 'inline'), $row); | $rows[] = phutil_tag('tr', array('class' => 'inline'), $row); | ||||
| } | } | ||||
| return $rows; | return $rows; | ||||
| } | } | ||||
| private function loadFileForData($path, $data) { | |||||
| $file = PhabricatorFile::buildFromFileDataOrHash( | |||||
| $data, | |||||
| array( | |||||
| 'name' => basename($path), | |||||
| 'ttl' => time() + 60 * 60 * 24, | |||||
| 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, | |||||
| )); | |||||
| $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | |||||
| $file->attachToObject( | |||||
| $this->getDiffusionRequest()->getRepository()->getPHID()); | |||||
| unset($unguarded); | |||||
| return $file; | |||||
| } | |||||
| private function buildRawResponse($path, $data) { | |||||
| $file = $this->loadFileForData($path, $data); | |||||
| return $file->getRedirectResponse(); | |||||
| } | |||||
| private function buildImageCorpus($file_uri) { | private function buildImageCorpus($file_uri) { | ||||
| $properties = new PHUIPropertyListView(); | $properties = new PHUIPropertyListView(); | ||||
| $properties->addImageContent( | $properties->addImageContent( | ||||
| phutil_tag( | phutil_tag( | ||||
| 'img', | 'img', | ||||
| array( | array( | ||||
| 'src' => $file_uri, | 'src' => $file_uri, | ||||
| ))); | ))); | ||||
| $file = $this->renderFileButton($file_uri); | $file = $this->renderFileButton($file_uri); | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader(pht('Image')) | ->setHeader(pht('Image')) | ||||
| ->addActionLink($file); | ->addActionLink($file); | ||||
| return id(new PHUIObjectBoxView()) | return id(new PHUIObjectBoxView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->addPropertyList($properties); | ->addPropertyList($properties); | ||||
| } | } | ||||
| private function buildBinaryCorpus($file_uri, $data) { | private function buildBinaryCorpus($file_uri, $data) { | ||||
| $size = new PhutilNumber(strlen($data)); | $size = new PhutilNumber(strlen($data)); | ||||
| $text = pht('This is a binary file. It is %s byte(s) in length.', $size); | $text = pht('This is a binary file. It is %s byte(s) in length.', $size); | ||||
| $text = id(new PHUIBoxView()) | $text = id(new PHUIBoxView()) | ||||
| ->addPadding(PHUI::PADDING_LARGE) | ->addPadding(PHUI::PADDING_LARGE) | ||||
| ->appendChild($text); | ->appendChild($text); | ||||
| $file = $this->renderFileButton($file_uri); | $file = $this->renderFileButton($file_uri); | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ▲ Show 20 Lines • Show All 584 Lines • Show Last 20 Lines | |||||