diff --git a/src/applications/console/core/DarkConsoleCore.php b/src/applications/console/core/DarkConsoleCore.php --- a/src/applications/console/core/DarkConsoleCore.php +++ b/src/applications/console/core/DarkConsoleCore.php @@ -121,6 +121,8 @@ $data[$key] = $this->sanitizeForJSON($value); } return $data; + } else if (is_resource($data)) { + return ''; } else { // Truncate huge strings. Since the data doesn't really matter much, // just truncate bytes to avoid PhutilUTF8StringTruncator overhead. diff --git a/src/applications/files/document/PhabricatorDocumentEngine.php b/src/applications/files/document/PhabricatorDocumentEngine.php --- a/src/applications/files/document/PhabricatorDocumentEngine.php +++ b/src/applications/files/document/PhabricatorDocumentEngine.php @@ -281,4 +281,8 @@ )); } + public function shouldSuggestEngine(PhabricatorDocumentRef $ref) { + return false; + } + } diff --git a/src/applications/files/document/PhabricatorJupyterDocumentEngine.php b/src/applications/files/document/PhabricatorJupyterDocumentEngine.php --- a/src/applications/files/document/PhabricatorJupyterDocumentEngine.php +++ b/src/applications/files/document/PhabricatorJupyterDocumentEngine.php @@ -748,4 +748,8 @@ return $content; } + public function shouldSuggestEngine(PhabricatorDocumentRef $ref) { + return true; + } + } diff --git a/src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php b/src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php --- a/src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php +++ b/src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php @@ -305,6 +305,12 @@ return $crumbs; } + public function getRefViewURI( + PhabricatorDocumentRef $ref, + PhabricatorDocumentEngine $engine) { + return $this->newRefViewURI($ref, $engine); + } + abstract protected function newRefViewURI( PhabricatorDocumentRef $ref, PhabricatorDocumentEngine $engine); diff --git a/src/applications/paste/controller/PhabricatorPasteViewController.php b/src/applications/paste/controller/PhabricatorPasteViewController.php --- a/src/applications/paste/controller/PhabricatorPasteViewController.php +++ b/src/applications/paste/controller/PhabricatorPasteViewController.php @@ -51,16 +51,19 @@ $timeline->setQuoteRef($monogram); $comment_view->setTransactionTimeline($timeline); + $recommendation_view = $this->newDocumentRecommendationView($paste); + $paste_view = id(new PHUITwoColumnView()) ->setHeader($header) ->setSubheader($subheader) - ->setMainColumn(array( + ->setMainColumn( + array( + $recommendation_view, $source_code, $timeline, $comment_view, )) - ->setCurtain($curtain) - ->addClass('ponder-question-view'); + ->setCurtain($curtain); return $this->newPage() ->setTitle($paste->getFullName()) @@ -170,4 +173,58 @@ ->setContent($content); } + private function newDocumentRecommendationView(PhabricatorPaste $paste) { + $viewer = $this->getViewer(); + + // See PHI1703. If a viewer is looking at a document in Paste which has + // a good rendering via a DocumentEngine, suggest they view the content + // in Files instead so they can see it rendered. + + $ref = id(new PhabricatorDocumentRef()) + ->setName($paste->getTitle()) + ->setData($paste->getRawContent()); + + $engines = PhabricatorDocumentEngine::getEnginesForRef($viewer, $ref); + if (!$engines) { + return null; + } + + $engine = head($engines); + if (!$engine->shouldSuggestEngine($ref)) { + return null; + } + + $file = id(new PhabricatorFileQuery()) + ->setViewer($viewer) + ->withPHIDs(array($paste->getFilePHID())) + ->executeOne(); + if (!$file) { + return null; + } + + $file_ref = id(new PhabricatorDocumentRef()) + ->setFile($file); + + $view_uri = id(new PhabricatorFileDocumentRenderingEngine()) + ->getRefViewURI($file_ref, $engine); + + $view_as_label = $engine->getViewAsLabel($file_ref); + + $view_as_hint = pht( + 'This content can be rendered as a document in Files.'); + + return id(new PHUIInfoView()) + ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) + ->addButton( + id(new PHUIButtonView()) + ->setTag('a') + ->setText($view_as_label) + ->setHref($view_uri) + ->setColor('grey')) + ->setErrors( + array( + $view_as_hint, + )); + } + }