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

Remove plain-text file view of Diffusion files.

Summary:
fixes T11792.
There's no good reason any more to have this option, so just drop it.

Test Plan: Load a file, toggle remaining "blame" button. Load search results page and an image too, which are serviced by the same controller.

Reviewers: chad, #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

Maniphest Tasks: T11792

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

authored by

Aviv Eyal and committed by
avivey
e634812a 706c2137

+73 -205
-2
src/__phutil_library_map__.php
··· 2486 2486 'PhabricatorDifferentialRevisionTestDataGenerator' => 'applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php', 2487 2487 'PhabricatorDiffusionApplication' => 'applications/diffusion/application/PhabricatorDiffusionApplication.php', 2488 2488 'PhabricatorDiffusionBlameSetting' => 'applications/settings/setting/PhabricatorDiffusionBlameSetting.php', 2489 - 'PhabricatorDiffusionColorSetting' => 'applications/settings/setting/PhabricatorDiffusionColorSetting.php', 2490 2489 'PhabricatorDiffusionConfigOptions' => 'applications/diffusion/config/PhabricatorDiffusionConfigOptions.php', 2491 2490 'PhabricatorDisabledUserController' => 'applications/auth/controller/PhabricatorDisabledUserController.php', 2492 2491 'PhabricatorDisplayPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDisplayPreferencesSettingsPanel.php', ··· 7406 7405 'PhabricatorDifferentialRevisionTestDataGenerator' => 'PhabricatorTestDataGenerator', 7407 7406 'PhabricatorDiffusionApplication' => 'PhabricatorApplication', 7408 7407 'PhabricatorDiffusionBlameSetting' => 'PhabricatorInternalSetting', 7409 - 'PhabricatorDiffusionColorSetting' => 'PhabricatorInternalSetting', 7410 7408 'PhabricatorDiffusionConfigOptions' => 'PhabricatorApplicationConfigOptions', 7411 7409 'PhabricatorDisabledUserController' => 'PhabricatorAuthController', 7412 7410 'PhabricatorDisplayPreferencesSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
+73 -187
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 106 106 $path = $drequest->getPath(); 107 107 108 108 $blame_key = PhabricatorDiffusionBlameSetting::SETTINGKEY; 109 - $color_key = PhabricatorDiffusionColorSetting::SETTINGKEY; 110 109 111 110 $show_blame = $request->getBool( 112 111 'blame', 113 112 $viewer->getUserSetting($blame_key)); 114 113 115 - $show_color = $request->getBool( 116 - 'color', 117 - $viewer->getUserSetting($color_key)); 118 - 119 114 $view = $request->getStr('view'); 120 115 if ($request->isFormPost() && $view != 'raw' && $viewer->isLoggedIn()) { 121 116 $preferences = PhabricatorUserPreferences::loadUserPreferences($viewer); ··· 128 123 129 124 $xactions = array(); 130 125 $xactions[] = $preferences->newTransaction($blame_key, $show_blame); 131 - $xactions[] = $preferences->newTransaction($color_key, $show_color); 132 126 $editor->applyTransactions($preferences, $xactions); 133 127 134 128 $uri = $request->getRequestURI() 135 - ->alter('blame', null) 136 - ->alter('color', null); 129 + ->alter('blame', null); 137 130 138 131 return id(new AphrontRedirectResponse())->setURI($uri); 139 132 } 140 133 141 - // We need the blame information if blame is on and we're building plain 142 - // text, or blame is on and this is an Ajax request. If blame is on and 143 - // this is a colorized request, we don't show blame at first (we ajax it 144 - // in afterward) so we don't need to query for it. 145 - $needs_blame = ($show_blame && !$show_color) || 146 - ($show_blame && $request->isAjax()); 134 + // We need the blame information if blame is on and this is an Ajax request. 135 + // If blame is on and this is a colorized request, we don't show blame at 136 + // first (we ajax it in afterward) so we don't need to query for it. 137 + $needs_blame = ($show_blame && $request->isAjax()); 147 138 148 139 $params = array( 149 140 'commit' => $drequest->getCommit(), ··· 196 187 197 188 $data = $file->loadFileData(); 198 189 199 - $ref = $this->getGitLFSRef($repository, $data); 200 - if ($ref) { 190 + $lfs_ref = $this->getGitLFSRef($repository, $data); 191 + if ($lfs_ref) { 201 192 if ($view == 'git-lfs') { 202 - $file = $this->loadGitLFSFile($ref); 193 + $file = $this->loadGitLFSFile($lfs_ref); 203 194 204 195 // Rename the file locally so we generate a better vanity URI for 205 196 // it. In storage, it just has a name like "lfs-13f9a94c0923...", ··· 211 202 212 203 return $file->getRedirectResponse(); 213 204 } else { 214 - $corpus = $this->buildGitLFSCorpus($ref); 205 + $corpus = $this->buildGitLFSCorpus($lfs_ref); 215 206 } 216 207 } else if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) { 217 208 $file_uri = $file->getBestURI(); ··· 228 219 // Build the content of the file. 229 220 $corpus = $this->buildCorpus( 230 221 $show_blame, 231 - $show_color, 232 222 $data, 233 223 $needs_blame, 234 224 $drequest, ··· 248 238 $curtain = $this->enrichCurtain( 249 239 $view, 250 240 $drequest, 251 - $show_blame, 252 - $show_color); 241 + $show_blame); 253 242 254 243 $properties = $this->buildPropertyView($drequest); 255 244 $header = $this->buildHeaderView($drequest); ··· 647 636 648 637 private function buildCorpus( 649 638 $show_blame, 650 - $show_color, 651 639 $file_corpus, 652 640 $needs_blame, 653 641 DiffusionRequest $drequest, ··· 675 663 $blame_commits = array(); 676 664 } 677 665 678 - if (!$show_color) { 679 - $corpus = $this->renderPlaintextCorpus( 680 - $file_corpus, 681 - $blame_list, 682 - $blame_commits, 683 - $show_blame); 666 + require_celerity_resource('syntax-highlighting-css'); 667 + if ($can_highlight) { 668 + $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename( 669 + $path, 670 + $file_corpus); 684 671 } else { 685 - require_celerity_resource('syntax-highlighting-css'); 672 + // Highlight as plain text to escape the content properly. 673 + $highlighted = PhabricatorSyntaxHighlighter::highlightWithLanguage( 674 + 'txt', 675 + $file_corpus); 676 + } 686 677 687 - if ($can_highlight) { 688 - $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename( 689 - $path, 690 - $file_corpus); 691 - } else { 692 - // Highlight as plain text to escape the content properly. 693 - $highlighted = PhabricatorSyntaxHighlighter::highlightWithLanguage( 694 - 'txt', 695 - $file_corpus); 696 - } 678 + $lines = phutil_split_lines($highlighted); 697 679 698 - $lines = phutil_split_lines($highlighted); 680 + $rows = $this->buildDisplayRows( 681 + $lines, 682 + $blame_list, 683 + $blame_commits, 684 + $show_blame); 699 685 700 - $rows = $this->buildDisplayRows( 701 - $lines, 702 - $blame_list, 703 - $blame_commits, 704 - $show_blame, 705 - $show_color); 686 + $corpus_table = javelin_tag( 687 + 'table', 688 + array( 689 + 'class' => 'diffusion-source remarkup-code PhabricatorMonospaced', 690 + 'sigil' => 'phabricator-source', 691 + ), 692 + $rows); 706 693 707 - $corpus_table = javelin_tag( 708 - 'table', 709 - array( 710 - 'class' => 'diffusion-source remarkup-code PhabricatorMonospaced', 711 - 'sigil' => 'phabricator-source', 712 - ), 713 - $rows); 694 + if ($this->getRequest()->isAjax()) { 695 + return $corpus_table; 696 + } 714 697 715 - if ($this->getRequest()->isAjax()) { 716 - return $corpus_table; 717 - } 698 + $id = celerity_generate_unique_node_id(); 718 699 719 - $id = celerity_generate_unique_node_id(); 700 + $repo = $drequest->getRepository(); 701 + $symbol_repos = nonempty($repo->getSymbolSources(), array()); 702 + $symbol_repos[] = $repo->getPHID(); 720 703 721 - $repo = $drequest->getRepository(); 722 - $symbol_repos = nonempty($repo->getSymbolSources(), array()); 723 - $symbol_repos[] = $repo->getPHID(); 704 + $lang = last(explode('.', $drequest->getPath())); 705 + $repo_languages = $repo->getSymbolLanguages(); 706 + $repo_languages = nonempty($repo_languages, array()); 707 + $repo_languages = array_fill_keys($repo_languages, true); 724 708 725 - $lang = last(explode('.', $drequest->getPath())); 726 - $repo_languages = $repo->getSymbolLanguages(); 727 - $repo_languages = nonempty($repo_languages, array()); 728 - $repo_languages = array_fill_keys($repo_languages, true); 729 - 730 - $needs_symbols = true; 731 - if ($repo_languages && $symbol_repos) { 732 - $have_symbols = id(new DiffusionSymbolQuery()) 733 - ->existsSymbolsInRepository($repo->getPHID()); 734 - if (!$have_symbols) { 735 - $needs_symbols = false; 736 - } 737 - } 738 - 739 - if ($needs_symbols && $repo_languages) { 740 - $needs_symbols = isset($repo_languages[$lang]); 709 + $needs_symbols = true; 710 + if ($repo_languages && $symbol_repos) { 711 + $have_symbols = id(new DiffusionSymbolQuery()) 712 + ->existsSymbolsInRepository($repo->getPHID()); 713 + if (!$have_symbols) { 714 + $needs_symbols = false; 741 715 } 716 + } 742 717 743 - if ($needs_symbols) { 744 - Javelin::initBehavior( 745 - 'repository-crossreference', 746 - array( 747 - 'container' => $id, 748 - 'lang' => $lang, 749 - 'repositories' => $symbol_repos, 750 - )); 751 - } 718 + if ($needs_symbols && $repo_languages) { 719 + $needs_symbols = isset($repo_languages[$lang]); 720 + } 752 721 753 - $corpus = phutil_tag( 754 - 'div', 722 + if ($needs_symbols) { 723 + Javelin::initBehavior( 724 + 'repository-crossreference', 755 725 array( 756 - 'id' => $id, 757 - ), 758 - $corpus_table); 759 - 760 - Javelin::initBehavior('load-blame', array('id' => $id)); 726 + 'container' => $id, 727 + 'lang' => $lang, 728 + 'repositories' => $symbol_repos, 729 + )); 761 730 } 762 731 732 + $corpus = phutil_tag( 733 + 'div', 734 + array( 735 + 'id' => $id, 736 + ), 737 + $corpus_table); 738 + 739 + Javelin::initBehavior('load-blame', array('id' => $id)); 740 + 741 + 763 742 $edit = $this->renderEditButton(); 764 743 $file = $this->renderFileButton(); 765 744 $header = id(new PHUIHeaderView()) ··· 808 787 private function enrichCurtain( 809 788 PHUICurtainView $curtain, 810 789 DiffusionRequest $drequest, 811 - $show_blame, 812 - $show_color) { 790 + $show_blame) { 813 791 814 792 $viewer = $this->getViewer(); 815 793 $base_uri = $this->getRequest()->getRequestURI(); ··· 839 817 ->setName($blame_text) 840 818 ->setHref($base_uri->alter('blame', $blame_value)) 841 819 ->setIcon($blame_icon) 842 - ->setUser($viewer) 843 - ->setRenderAsForm($viewer->isLoggedIn())); 844 - 845 - if ($show_color) { 846 - $highlight_text = pht('Disable Highlighting'); 847 - $highlight_icon = 'fa-star-o grey'; 848 - $highlight_value = 0; 849 - } else { 850 - $highlight_text = pht('Enable Highlighting'); 851 - $highlight_icon = 'fa-star'; 852 - $highlight_value = 1; 853 - } 854 - 855 - $curtain->addAction( 856 - id(new PhabricatorActionView()) 857 - ->setName($highlight_text) 858 - ->setHref($base_uri->alter('color', $highlight_value)) 859 - ->setIcon($highlight_icon) 860 820 ->setUser($viewer) 861 821 ->setRenderAsForm($viewer->isLoggedIn())); 862 822 ··· 1002 962 array $lines, 1003 963 array $blame_list, 1004 964 array $blame_commits, 1005 - $show_blame, 1006 - $show_color) { 965 + $show_blame) { 1007 966 1008 967 $request = $this->getRequest(); 1009 968 $viewer = $this->getViewer(); ··· 1889 1848 } 1890 1849 1891 1850 return $links; 1892 - } 1893 - 1894 - private function renderPlaintextCorpus( 1895 - $file_corpus, 1896 - array $blame_list, 1897 - array $blame_commits, 1898 - $show_blame) { 1899 - 1900 - $viewer = $this->getViewer(); 1901 - 1902 - if (!$show_blame) { 1903 - $corpus = $file_corpus; 1904 - } else { 1905 - $author_phids = array(); 1906 - foreach ($blame_commits as $commit) { 1907 - $author_phid = $commit->getAuthorPHID(); 1908 - if ($author_phid === null) { 1909 - continue; 1910 - } 1911 - $author_phids[$author_phid] = $author_phid; 1912 - } 1913 - 1914 - if ($author_phids) { 1915 - $handles = $viewer->loadHandles($author_phids); 1916 - } else { 1917 - $handles = array(); 1918 - } 1919 - 1920 - $authors = array(); 1921 - $names = array(); 1922 - foreach ($blame_commits as $identifier => $commit) { 1923 - $author = $commit->renderAuthorShortName($handles); 1924 - $name = $commit->getLocalName(); 1925 - 1926 - $authors[$identifier] = $author; 1927 - $names[$identifier] = $name; 1928 - } 1929 - 1930 - $lines = phutil_split_lines($file_corpus); 1931 - 1932 - $rows = array(); 1933 - foreach ($lines as $line_number => $line) { 1934 - $commit_name = null; 1935 - $author = null; 1936 - 1937 - if (isset($blame_list[$line_number])) { 1938 - $identifier = $blame_list[$line_number]; 1939 - 1940 - if (isset($names[$identifier])) { 1941 - $commit_name = $names[$identifier]; 1942 - } 1943 - 1944 - if (isset($authors[$identifier])) { 1945 - $author = $authors[$identifier]; 1946 - } 1947 - } 1948 - 1949 - $rows[] = sprintf( 1950 - '%-10s %-20s %s', 1951 - $commit_name, 1952 - $author, 1953 - $line); 1954 - } 1955 - $corpus = implode('', $rows); 1956 - } 1957 - 1958 - return phutil_tag( 1959 - 'textarea', 1960 - array( 1961 - 'style' => 'border: none; width: 100%; height: 80em; '. 1962 - 'font-family: monospace', 1963 - ), 1964 - $corpus); 1965 1851 } 1966 1852 1967 1853 private function getGitLFSRef(PhabricatorRepository $repository, $data) {
-16
src/applications/settings/setting/PhabricatorDiffusionColorSetting.php
··· 1 - <?php 2 - 3 - final class PhabricatorDiffusionColorSetting 4 - extends PhabricatorInternalSetting { 5 - 6 - const SETTINGKEY = 'diffusion-color'; 7 - 8 - public function getSettingName() { 9 - return pht('Diffusion Color'); 10 - } 11 - 12 - public function getSettingDefaultValue() { 13 - return false; 14 - } 15 - 16 - }