@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 "View as..." option to diff dropdowns for selecting between document engines

Summary:
Depends on D20831. Ref T13425. As an escape hatch to get out of future DocumentEngine rendering behavior, provide a "View As.." option.

Now I can break DocumentEngine real bad and no one can complain.

Test Plan: Used "View As" to swap document engines for image files.

Maniphest Tasks: T13425

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

+143 -25
+20 -20
resources/celerity/map.php
··· 12 12 'core.pkg.css' => 'c69171e6', 13 13 'core.pkg.js' => '6e5c894f', 14 14 'differential.pkg.css' => 'eef74643', 15 - 'differential.pkg.js' => '0b037a4f', 15 + 'differential.pkg.js' => '49515551', 16 16 'diffusion.pkg.css' => '42c75c37', 17 17 'diffusion.pkg.js' => 'a98c0bf7', 18 18 'maniphest.pkg.css' => '35995d6d', ··· 376 376 'rsrc/js/application/dashboard/behavior-dashboard-move-panels.js' => 'a2ab19be', 377 377 'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '1e413dc9', 378 378 'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8', 379 - 'rsrc/js/application/diff/DiffChangeset.js' => 'd0a85a85', 380 - 'rsrc/js/application/diff/DiffChangesetList.js' => '04023d82', 379 + 'rsrc/js/application/diff/DiffChangeset.js' => 'a31ffc00', 380 + 'rsrc/js/application/diff/DiffChangesetList.js' => '40850e53', 381 381 'rsrc/js/application/diff/DiffInline.js' => 'a4a14a94', 382 382 'rsrc/js/application/diff/behavior-preview-link.js' => 'f51e9c17', 383 383 'rsrc/js/application/differential/behavior-diff-radios.js' => '925fe8cd', ··· 773 773 'phabricator-darklog' => '3b869402', 774 774 'phabricator-darkmessage' => '26cd4b73', 775 775 'phabricator-dashboard-css' => '5a205b9d', 776 - 'phabricator-diff-changeset' => 'd0a85a85', 777 - 'phabricator-diff-changeset-list' => '04023d82', 776 + 'phabricator-diff-changeset' => 'a31ffc00', 777 + 'phabricator-diff-changeset-list' => '40850e53', 778 778 'phabricator-diff-inline' => 'a4a14a94', 779 779 'phabricator-drag-and-drop-file-upload' => '4370900d', 780 780 'phabricator-draggable-list' => 'c9ad6f70', ··· 944 944 '03e8891f' => array( 945 945 'javelin-install', 946 946 ), 947 - '04023d82' => array( 948 - 'javelin-install', 949 - 'phuix-button-view', 950 - ), 951 947 '04f8a1e3' => array( 952 948 'javelin-behavior', 953 949 'javelin-stratcom', ··· 1262 1258 '407ee861' => array( 1263 1259 'javelin-behavior', 1264 1260 'javelin-uri', 1261 + ), 1262 + '40850e53' => array( 1263 + 'javelin-install', 1264 + 'phuix-button-view', 1265 1265 ), 1266 1266 '4234f572' => array( 1267 1267 'syntax-default-css', ··· 1788 1788 'javelin-workflow', 1789 1789 'phabricator-draggable-list', 1790 1790 ), 1791 + 'a31ffc00' => array( 1792 + 'javelin-dom', 1793 + 'javelin-util', 1794 + 'javelin-stratcom', 1795 + 'javelin-install', 1796 + 'javelin-workflow', 1797 + 'javelin-router', 1798 + 'javelin-behavior-device', 1799 + 'javelin-vector', 1800 + 'phabricator-diff-inline', 1801 + ), 1791 1802 'a4356cde' => array( 1792 1803 'javelin-install', 1793 1804 'javelin-dom', ··· 2033 2044 'javelin-behavior', 2034 2045 'javelin-dom', 2035 2046 'javelin-stratcom', 2036 - ), 2037 - 'd0a85a85' => array( 2038 - 'javelin-dom', 2039 - 'javelin-util', 2040 - 'javelin-stratcom', 2041 - 'javelin-install', 2042 - 'javelin-workflow', 2043 - 'javelin-router', 2044 - 'javelin-behavior-device', 2045 - 'javelin-vector', 2046 - 'phabricator-diff-inline', 2047 2047 ), 2048 2048 'd12d214f' => array( 2049 2049 'javelin-install',
+2
src/__phutil_library_map__.php
··· 4876 4876 'PhabricatorSystemRemoveWorkflow' => 'applications/system/management/PhabricatorSystemRemoveWorkflow.php', 4877 4877 'PhabricatorSystemSelectEncodingController' => 'applications/system/controller/PhabricatorSystemSelectEncodingController.php', 4878 4878 'PhabricatorSystemSelectHighlightController' => 'applications/system/controller/PhabricatorSystemSelectHighlightController.php', 4879 + 'PhabricatorSystemSelectViewAsController' => 'applications/system/controller/PhabricatorSystemSelectViewAsController.php', 4879 4880 'PhabricatorTOTPAuthFactor' => 'applications/auth/factor/PhabricatorTOTPAuthFactor.php', 4880 4881 'PhabricatorTOTPAuthFactorTestCase' => 'applications/auth/factor/__tests__/PhabricatorTOTPAuthFactorTestCase.php', 4881 4882 'PhabricatorTaskmasterDaemon' => 'infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php', ··· 11503 11504 'PhabricatorSystemRemoveWorkflow' => 'PhabricatorManagementWorkflow', 11504 11505 'PhabricatorSystemSelectEncodingController' => 'PhabricatorController', 11505 11506 'PhabricatorSystemSelectHighlightController' => 'PhabricatorController', 11507 + 'PhabricatorSystemSelectViewAsController' => 'PhabricatorController', 11506 11508 'PhabricatorTOTPAuthFactor' => 'PhabricatorAuthFactor', 11507 11509 'PhabricatorTOTPAuthFactorTestCase' => 'PhabricatorTestCase', 11508 11510 'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon',
+24 -5
src/applications/differential/parser/DifferentialChangesetParser.php
··· 59 59 60 60 private $highlightEngine; 61 61 private $viewer; 62 + private $documentEngineKey; 62 63 63 64 public function setRange($start, $end) { 64 65 $this->rangeStart = $start; ··· 159 160 return $this->viewer; 160 161 } 161 162 163 + public function setDocumentEngineKey($document_engine_key) { 164 + $this->documentEngineKey = $document_engine_key; 165 + return $this; 166 + } 167 + 168 + public function getDocumentEngineKey() { 169 + return $this->documentEngineKey; 170 + } 171 + 162 172 public static function getDefaultRendererForViewer(PhabricatorUser $viewer) { 163 173 $is_unified = $viewer->compareUserSetting( 164 174 PhabricatorUnifiedDiffsSetting::SETTINGKEY, ··· 174 184 public function readParametersFromRequest(AphrontRequest $request) { 175 185 $this->setCharacterEncoding($request->getStr('encoding')); 176 186 $this->setHighlightAs($request->getStr('highlight')); 187 + $this->setDocumentEngineKey($request->getStr('engine')); 177 188 178 189 $renderer = null; 179 190 ··· 1695 1706 1696 1707 $shared_engines = array_intersect_key($old_engines, $new_engines); 1697 1708 1698 - $document_engine = null; 1699 - foreach ($shared_engines as $shared_engine) { 1700 - if ($shared_engine->canDiffDocuments($old_ref, $new_ref)) { 1701 - $document_engine = $shared_engine; 1702 - break; 1709 + foreach ($shared_engines as $key => $shared_engine) { 1710 + if (!$shared_engine->canDiffDocuments($old_ref, $new_ref)) { 1711 + unset($shared_engines[$key]); 1703 1712 } 1704 1713 } 1705 1714 1715 + $engine_key = $this->getDocumentEngineKey(); 1716 + if (strlen($engine_key)) { 1717 + if (isset($shared_engines[$engine_key])) { 1718 + $document_engine = $shared_engines[$engine_key]; 1719 + } else { 1720 + $document_engine = null; 1721 + } 1722 + } else { 1723 + $document_engine = head($shared_engines); 1724 + } 1706 1725 1707 1726 if ($document_engine) { 1708 1727 return $document_engine->newDiffView(
+1
src/applications/differential/view/DifferentialChangesetListView.php
··· 240 240 'View Unified' => pht('View Unified'), 241 241 'Change Text Encoding...' => pht('Change Text Encoding...'), 242 242 'Highlight As...' => pht('Highlight As...'), 243 + 'View As...' => pht('View As...'), 243 244 244 245 'Loading...' => pht('Loading...'), 245 246
+1
src/applications/system/application/PhabricatorSystemApplication.php
··· 22 22 '/services/' => array( 23 23 'encoding/' => 'PhabricatorSystemSelectEncodingController', 24 24 'highlight/' => 'PhabricatorSystemSelectHighlightController', 25 + 'viewas/' => 'PhabricatorSystemSelectViewAsController', 25 26 ), 26 27 '/readonly/' => array( 27 28 '(?P<reason>[^/]+)/' => 'PhabricatorSystemReadOnlyController',
+63
src/applications/system/controller/PhabricatorSystemSelectViewAsController.php
··· 1 + <?php 2 + 3 + final class PhabricatorSystemSelectViewAsController 4 + extends PhabricatorController { 5 + 6 + public function shouldRequireLogin() { 7 + return false; 8 + } 9 + 10 + public function handleRequest(AphrontRequest $request) { 11 + $viewer = $this->getViewer(); 12 + $v_engine = $request->getStr('engine'); 13 + 14 + if ($request->isFormPost()) { 15 + $result = array('engine' => $v_engine); 16 + return id(new AphrontAjaxResponse())->setContent($result); 17 + } 18 + 19 + $engines = PhabricatorDocumentEngine::getAllEngines(); 20 + 21 + 22 + // TODO: This controller isn't very good because the valid options depend 23 + // on the file being rendered and most of them can't even diff anything, 24 + // and this ref is completely bogus. 25 + 26 + // For now, we just show everything. 27 + $ref = new PhabricatorDocumentRef(); 28 + 29 + $map = array(); 30 + foreach ($engines as $engine) { 31 + $key = $engine->getDocumentEngineKey(); 32 + $label = $engine->getViewAsLabel($ref); 33 + 34 + if (!strlen($label)) { 35 + continue; 36 + } 37 + 38 + $map[$key] = $label; 39 + } 40 + 41 + asort($map); 42 + 43 + $map = array( 44 + '' => pht('(Use Default)'), 45 + ) + $map; 46 + 47 + $form = id(new AphrontFormView()) 48 + ->setViewer($viewer) 49 + ->appendRemarkupInstructions(pht('Choose a document engine to use.')) 50 + ->appendChild( 51 + id(new AphrontFormSelectControl()) 52 + ->setLabel(pht('View As')) 53 + ->setName('engine') 54 + ->setValue($v_engine) 55 + ->setOptions($map)); 56 + 57 + return $this->newDialog() 58 + ->setTitle(pht('Select Document Engine')) 59 + ->appendForm($form) 60 + ->addSubmitButton(pht('Choose Engine')) 61 + ->addCancelButton('/'); 62 + } 63 + }
+11
webroot/rsrc/js/application/diff/DiffChangeset.js
··· 24 24 this._ref = data.ref; 25 25 this._renderer = data.renderer; 26 26 this._highlight = data.highlight; 27 + this._documentEngine = data.documentEngine; 27 28 this._encoding = data.encoding; 28 29 this._loaded = data.loaded; 29 30 this._treeNodeID = data.treeNodeID; ··· 47 48 _ref: null, 48 49 _renderer: null, 49 50 _highlight: null, 51 + _documentEngine: null, 50 52 _encoding: null, 51 53 _undoTemplates: null, 52 54 ··· 310 312 ref: this._ref, 311 313 renderer: this.getRenderer() || '', 312 314 highlight: this._highlight || '', 315 + engine: this._documentEngine || '', 313 316 encoding: this._encoding || '' 314 317 }; 315 318 }, ··· 364 367 365 368 getHighlight: function() { 366 369 return this._highlight; 370 + }, 371 + 372 + setDocumentEngine: function(engine) { 373 + this._documentEngine = engine; 374 + }, 375 + 376 + getDocumentEngine: function(engine) { 377 + return this._documentEngine; 367 378 }, 368 379 369 380 getSelectableItems: function() {
+21
webroot/rsrc/js/application/diff/DiffChangesetList.js
··· 827 827 }); 828 828 list.addItem(highlight_item); 829 829 830 + var engine_item = new JX.PHUIXActionView() 831 + .setIcon('fa-file-image-o') 832 + .setName(pht('View As...')) 833 + .setHandler(function(e) { 834 + var params = { 835 + engine: changeset.getDocumentEngine(), 836 + }; 837 + 838 + new JX.Workflow('/services/viewas/', params) 839 + .setHandler(function(r) { 840 + changeset.setDocumentEngine(r.engine); 841 + changeset.reload(); 842 + }) 843 + .start(); 844 + 845 + e.prevent(); 846 + menu.close(); 847 + }); 848 + list.addItem(engine_item); 849 + 830 850 add_link('fa-arrow-left', pht('Show Raw File (Left)'), data.leftURI); 831 851 add_link('fa-arrow-right', pht('Show Raw File (Right)'), data.rightURI); 832 852 add_link('fa-pencil', pht('Open in Editor'), data.editor, true); ··· 860 880 861 881 encoding_item.setDisabled(!changeset.isLoaded()); 862 882 highlight_item.setDisabled(!changeset.isLoaded()); 883 + engine_item.setDisabled(!changeset.isLoaded()); 863 884 864 885 if (changeset.isLoaded()) { 865 886 if (changeset.getRenderer() == '2up') {