@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.

Add a JSON document rendering engine

Summary: Depends on D19254. This engine just formats JSON files in a nicer, more readable way.

Test Plan: Looked at some JSON files, saw them become formatted nicely.

Reviewers: mydeveloperday

Reviewed By: mydeveloperday

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

+65
+2
src/__phutil_library_map__.php
··· 3187 3187 'PhabricatorIteratorFileUploadSource' => 'applications/files/uploadsource/PhabricatorIteratorFileUploadSource.php', 3188 3188 'PhabricatorJIRAAuthProvider' => 'applications/auth/provider/PhabricatorJIRAAuthProvider.php', 3189 3189 'PhabricatorJSONConfigType' => 'applications/config/type/PhabricatorJSONConfigType.php', 3190 + 'PhabricatorJSONDocumentEngine' => 'applications/files/document/PhabricatorJSONDocumentEngine.php', 3190 3191 'PhabricatorJSONExportFormat' => 'infrastructure/export/format/PhabricatorJSONExportFormat.php', 3191 3192 'PhabricatorJavelinLinter' => 'infrastructure/lint/linter/PhabricatorJavelinLinter.php', 3192 3193 'PhabricatorJiraIssueHasObjectEdgeType' => 'applications/doorkeeper/edge/PhabricatorJiraIssueHasObjectEdgeType.php', ··· 8800 8801 'PhabricatorIteratorFileUploadSource' => 'PhabricatorFileUploadSource', 8801 8802 'PhabricatorJIRAAuthProvider' => 'PhabricatorOAuth1AuthProvider', 8802 8803 'PhabricatorJSONConfigType' => 'PhabricatorTextConfigType', 8804 + 'PhabricatorJSONDocumentEngine' => 'PhabricatorTextDocumentEngine', 8803 8805 'PhabricatorJSONExportFormat' => 'PhabricatorExportFormat', 8804 8806 'PhabricatorJavelinLinter' => 'ArcanistLinter', 8805 8807 'PhabricatorJiraIssueHasObjectEdgeType' => 'PhabricatorEdgeType',
+4
src/applications/files/document/PhabricatorDocumentRef.php
··· 116 116 } 117 117 118 118 $snippet = $this->getSnippet(); 119 + if (!preg_match('/^\s*[{[]/', $snippet)) { 120 + return false; 121 + } 122 + 119 123 return phutil_is_utf8($snippet); 120 124 } 121 125
+59
src/applications/files/document/PhabricatorJSONDocumentEngine.php
··· 1 + <?php 2 + 3 + final class PhabricatorJSONDocumentEngine 4 + extends PhabricatorTextDocumentEngine { 5 + 6 + const ENGINEKEY = 'json'; 7 + 8 + public function getViewAsLabel(PhabricatorDocumentRef $ref) { 9 + return pht('View as JSON'); 10 + } 11 + 12 + protected function getDocumentIconIcon(PhabricatorDocumentRef $ref) { 13 + return 'fa-database'; 14 + } 15 + 16 + protected function getContentScore(PhabricatorDocumentRef $ref) { 17 + if (preg_match('/\.json\z/', $ref->getName())) { 18 + return 2000; 19 + } 20 + 21 + if ($ref->isProbablyJSON()) { 22 + return 1750; 23 + } 24 + 25 + return 500; 26 + } 27 + 28 + protected function newDocumentContent(PhabricatorDocumentRef $ref) { 29 + $raw_data = $this->loadTextData($ref); 30 + 31 + try { 32 + $data = phutil_json_decode($raw_data); 33 + 34 + if (preg_match('/^\s*\[/', $raw_data)) { 35 + $content = id(new PhutilJSON())->encodeAsList($data); 36 + } else { 37 + $content = id(new PhutilJSON())->encodeFormatted($data); 38 + } 39 + 40 + $message = null; 41 + $content = PhabricatorSyntaxHighlighter::highlightWithLanguage( 42 + 'json', 43 + $content); 44 + } catch (PhutilJSONParserException $ex) { 45 + $message = $this->newMessage( 46 + pht( 47 + 'This document is not valid JSON: %s', 48 + $ex->getMessage())); 49 + 50 + $content = $raw_data; 51 + } 52 + 53 + return array( 54 + $message, 55 + $this->newTextDocumentContent($content), 56 + ); 57 + } 58 + 59 + }