@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

When a Paste has a useful alternative rendering in Files, provide a hint

Summary: Ref T13528. When a file in Paste (like a Jupyter notebook) has a good/useful document engine, provide a link to Files.

Test Plan: {F7409881}

Maniphest Tasks: T13528

Differential Revision: https://secure.phabricator.com/D21196

+76 -3
+2
src/applications/console/core/DarkConsoleCore.php
··· 121 121 $data[$key] = $this->sanitizeForJSON($value); 122 122 } 123 123 return $data; 124 + } else if (is_resource($data)) { 125 + return '<resource>'; 124 126 } else { 125 127 // Truncate huge strings. Since the data doesn't really matter much, 126 128 // just truncate bytes to avoid PhutilUTF8StringTruncator overhead.
+4
src/applications/files/document/PhabricatorDocumentEngine.php
··· 281 281 )); 282 282 } 283 283 284 + public function shouldSuggestEngine(PhabricatorDocumentRef $ref) { 285 + return false; 286 + } 287 + 284 288 }
+4
src/applications/files/document/PhabricatorJupyterDocumentEngine.php
··· 748 748 return $content; 749 749 } 750 750 751 + public function shouldSuggestEngine(PhabricatorDocumentRef $ref) { 752 + return true; 753 + } 754 + 751 755 }
+6
src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php
··· 305 305 return $crumbs; 306 306 } 307 307 308 + public function getRefViewURI( 309 + PhabricatorDocumentRef $ref, 310 + PhabricatorDocumentEngine $engine) { 311 + return $this->newRefViewURI($ref, $engine); 312 + } 313 + 308 314 abstract protected function newRefViewURI( 309 315 PhabricatorDocumentRef $ref, 310 316 PhabricatorDocumentEngine $engine);
+60 -3
src/applications/paste/controller/PhabricatorPasteViewController.php
··· 51 51 $timeline->setQuoteRef($monogram); 52 52 $comment_view->setTransactionTimeline($timeline); 53 53 54 + $recommendation_view = $this->newDocumentRecommendationView($paste); 55 + 54 56 $paste_view = id(new PHUITwoColumnView()) 55 57 ->setHeader($header) 56 58 ->setSubheader($subheader) 57 - ->setMainColumn(array( 59 + ->setMainColumn( 60 + array( 61 + $recommendation_view, 58 62 $source_code, 59 63 $timeline, 60 64 $comment_view, 61 65 )) 62 - ->setCurtain($curtain) 63 - ->addClass('ponder-question-view'); 66 + ->setCurtain($curtain); 64 67 65 68 return $this->newPage() 66 69 ->setTitle($paste->getFullName()) ··· 168 171 ->setImage($image_uri) 169 172 ->setImageHref($image_href) 170 173 ->setContent($content); 174 + } 175 + 176 + private function newDocumentRecommendationView(PhabricatorPaste $paste) { 177 + $viewer = $this->getViewer(); 178 + 179 + // See PHI1703. If a viewer is looking at a document in Paste which has 180 + // a good rendering via a DocumentEngine, suggest they view the content 181 + // in Files instead so they can see it rendered. 182 + 183 + $ref = id(new PhabricatorDocumentRef()) 184 + ->setName($paste->getTitle()) 185 + ->setData($paste->getRawContent()); 186 + 187 + $engines = PhabricatorDocumentEngine::getEnginesForRef($viewer, $ref); 188 + if (!$engines) { 189 + return null; 190 + } 191 + 192 + $engine = head($engines); 193 + if (!$engine->shouldSuggestEngine($ref)) { 194 + return null; 195 + } 196 + 197 + $file = id(new PhabricatorFileQuery()) 198 + ->setViewer($viewer) 199 + ->withPHIDs(array($paste->getFilePHID())) 200 + ->executeOne(); 201 + if (!$file) { 202 + return null; 203 + } 204 + 205 + $file_ref = id(new PhabricatorDocumentRef()) 206 + ->setFile($file); 207 + 208 + $view_uri = id(new PhabricatorFileDocumentRenderingEngine()) 209 + ->getRefViewURI($file_ref, $engine); 210 + 211 + $view_as_label = $engine->getViewAsLabel($file_ref); 212 + 213 + $view_as_hint = pht( 214 + 'This content can be rendered as a document in Files.'); 215 + 216 + return id(new PHUIInfoView()) 217 + ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) 218 + ->addButton( 219 + id(new PHUIButtonView()) 220 + ->setTag('a') 221 + ->setText($view_as_label) 222 + ->setHref($view_uri) 223 + ->setColor('grey')) 224 + ->setErrors( 225 + array( 226 + $view_as_hint, 227 + )); 171 228 } 172 229 173 230 }