1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

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
This commit is contained in:
Aviv Eyal 2016-11-10 00:40:09 +00:00 committed by avivey
parent 706c21375e
commit e634812a6d
3 changed files with 85 additions and 217 deletions

View file

@ -2486,7 +2486,6 @@ phutil_register_library_map(array(
'PhabricatorDifferentialRevisionTestDataGenerator' => 'applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php', 'PhabricatorDifferentialRevisionTestDataGenerator' => 'applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php',
'PhabricatorDiffusionApplication' => 'applications/diffusion/application/PhabricatorDiffusionApplication.php', 'PhabricatorDiffusionApplication' => 'applications/diffusion/application/PhabricatorDiffusionApplication.php',
'PhabricatorDiffusionBlameSetting' => 'applications/settings/setting/PhabricatorDiffusionBlameSetting.php', 'PhabricatorDiffusionBlameSetting' => 'applications/settings/setting/PhabricatorDiffusionBlameSetting.php',
'PhabricatorDiffusionColorSetting' => 'applications/settings/setting/PhabricatorDiffusionColorSetting.php',
'PhabricatorDiffusionConfigOptions' => 'applications/diffusion/config/PhabricatorDiffusionConfigOptions.php', 'PhabricatorDiffusionConfigOptions' => 'applications/diffusion/config/PhabricatorDiffusionConfigOptions.php',
'PhabricatorDisabledUserController' => 'applications/auth/controller/PhabricatorDisabledUserController.php', 'PhabricatorDisabledUserController' => 'applications/auth/controller/PhabricatorDisabledUserController.php',
'PhabricatorDisplayPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDisplayPreferencesSettingsPanel.php', 'PhabricatorDisplayPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDisplayPreferencesSettingsPanel.php',
@ -7406,7 +7405,6 @@ phutil_register_library_map(array(
'PhabricatorDifferentialRevisionTestDataGenerator' => 'PhabricatorTestDataGenerator', 'PhabricatorDifferentialRevisionTestDataGenerator' => 'PhabricatorTestDataGenerator',
'PhabricatorDiffusionApplication' => 'PhabricatorApplication', 'PhabricatorDiffusionApplication' => 'PhabricatorApplication',
'PhabricatorDiffusionBlameSetting' => 'PhabricatorInternalSetting', 'PhabricatorDiffusionBlameSetting' => 'PhabricatorInternalSetting',
'PhabricatorDiffusionColorSetting' => 'PhabricatorInternalSetting',
'PhabricatorDiffusionConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorDiffusionConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorDisabledUserController' => 'PhabricatorAuthController', 'PhabricatorDisabledUserController' => 'PhabricatorAuthController',
'PhabricatorDisplayPreferencesSettingsPanel' => 'PhabricatorEditEngineSettingsPanel', 'PhabricatorDisplayPreferencesSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',

View file

@ -106,16 +106,11 @@ final class DiffusionBrowseController extends DiffusionController {
$path = $drequest->getPath(); $path = $drequest->getPath();
$blame_key = PhabricatorDiffusionBlameSetting::SETTINGKEY; $blame_key = PhabricatorDiffusionBlameSetting::SETTINGKEY;
$color_key = PhabricatorDiffusionColorSetting::SETTINGKEY;
$show_blame = $request->getBool( $show_blame = $request->getBool(
'blame', 'blame',
$viewer->getUserSetting($blame_key)); $viewer->getUserSetting($blame_key));
$show_color = $request->getBool(
'color',
$viewer->getUserSetting($color_key));
$view = $request->getStr('view'); $view = $request->getStr('view');
if ($request->isFormPost() && $view != 'raw' && $viewer->isLoggedIn()) { if ($request->isFormPost() && $view != 'raw' && $viewer->isLoggedIn()) {
$preferences = PhabricatorUserPreferences::loadUserPreferences($viewer); $preferences = PhabricatorUserPreferences::loadUserPreferences($viewer);
@ -128,22 +123,18 @@ final class DiffusionBrowseController extends DiffusionController {
$xactions = array(); $xactions = array();
$xactions[] = $preferences->newTransaction($blame_key, $show_blame); $xactions[] = $preferences->newTransaction($blame_key, $show_blame);
$xactions[] = $preferences->newTransaction($color_key, $show_color);
$editor->applyTransactions($preferences, $xactions); $editor->applyTransactions($preferences, $xactions);
$uri = $request->getRequestURI() $uri = $request->getRequestURI()
->alter('blame', null) ->alter('blame', null);
->alter('color', null);
return id(new AphrontRedirectResponse())->setURI($uri); return id(new AphrontRedirectResponse())->setURI($uri);
} }
// We need the blame information if blame is on and we're building plain // We need the blame information if blame is on and this is an Ajax request.
// text, or blame is on and this is an Ajax request. If blame is on and // If blame is on and this is a colorized request, we don't show blame at
// this is a colorized request, we don't show blame at first (we ajax it // first (we ajax it in afterward) so we don't need to query for it.
// in afterward) so we don't need to query for it. $needs_blame = ($show_blame && $request->isAjax());
$needs_blame = ($show_blame && !$show_color) ||
($show_blame && $request->isAjax());
$params = array( $params = array(
'commit' => $drequest->getCommit(), 'commit' => $drequest->getCommit(),
@ -196,10 +187,10 @@ final class DiffusionBrowseController extends DiffusionController {
$data = $file->loadFileData(); $data = $file->loadFileData();
$ref = $this->getGitLFSRef($repository, $data); $lfs_ref = $this->getGitLFSRef($repository, $data);
if ($ref) { if ($lfs_ref) {
if ($view == 'git-lfs') { if ($view == 'git-lfs') {
$file = $this->loadGitLFSFile($ref); $file = $this->loadGitLFSFile($lfs_ref);
// Rename the file locally so we generate a better vanity URI for // Rename the file locally so we generate a better vanity URI for
// it. In storage, it just has a name like "lfs-13f9a94c0923...", // it. In storage, it just has a name like "lfs-13f9a94c0923...",
@ -211,7 +202,7 @@ final class DiffusionBrowseController extends DiffusionController {
return $file->getRedirectResponse(); return $file->getRedirectResponse();
} else { } else {
$corpus = $this->buildGitLFSCorpus($ref); $corpus = $this->buildGitLFSCorpus($lfs_ref);
} }
} else if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) { } else if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
$file_uri = $file->getBestURI(); $file_uri = $file->getBestURI();
@ -228,7 +219,6 @@ final class DiffusionBrowseController extends DiffusionController {
// Build the content of the file. // Build the content of the file.
$corpus = $this->buildCorpus( $corpus = $this->buildCorpus(
$show_blame, $show_blame,
$show_color,
$data, $data,
$needs_blame, $needs_blame,
$drequest, $drequest,
@ -248,8 +238,7 @@ final class DiffusionBrowseController extends DiffusionController {
$curtain = $this->enrichCurtain( $curtain = $this->enrichCurtain(
$view, $view,
$drequest, $drequest,
$show_blame, $show_blame);
$show_color);
$properties = $this->buildPropertyView($drequest); $properties = $this->buildPropertyView($drequest);
$header = $this->buildHeaderView($drequest); $header = $this->buildHeaderView($drequest);
@ -647,7 +636,6 @@ final class DiffusionBrowseController extends DiffusionController {
private function buildCorpus( private function buildCorpus(
$show_blame, $show_blame,
$show_color,
$file_corpus, $file_corpus,
$needs_blame, $needs_blame,
DiffusionRequest $drequest, DiffusionRequest $drequest,
@ -675,15 +663,7 @@ final class DiffusionBrowseController extends DiffusionController {
$blame_commits = array(); $blame_commits = array();
} }
if (!$show_color) {
$corpus = $this->renderPlaintextCorpus(
$file_corpus,
$blame_list,
$blame_commits,
$show_blame);
} else {
require_celerity_resource('syntax-highlighting-css'); require_celerity_resource('syntax-highlighting-css');
if ($can_highlight) { if ($can_highlight) {
$highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename( $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename(
$path, $path,
@ -701,8 +681,7 @@ final class DiffusionBrowseController extends DiffusionController {
$lines, $lines,
$blame_list, $blame_list,
$blame_commits, $blame_commits,
$show_blame, $show_blame);
$show_color);
$corpus_table = javelin_tag( $corpus_table = javelin_tag(
'table', 'table',
@ -758,7 +737,7 @@ final class DiffusionBrowseController extends DiffusionController {
$corpus_table); $corpus_table);
Javelin::initBehavior('load-blame', array('id' => $id)); Javelin::initBehavior('load-blame', array('id' => $id));
}
$edit = $this->renderEditButton(); $edit = $this->renderEditButton();
$file = $this->renderFileButton(); $file = $this->renderFileButton();
@ -808,8 +787,7 @@ final class DiffusionBrowseController extends DiffusionController {
private function enrichCurtain( private function enrichCurtain(
PHUICurtainView $curtain, PHUICurtainView $curtain,
DiffusionRequest $drequest, DiffusionRequest $drequest,
$show_blame, $show_blame) {
$show_color) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$base_uri = $this->getRequest()->getRequestURI(); $base_uri = $this->getRequest()->getRequestURI();
@ -842,24 +820,6 @@ final class DiffusionBrowseController extends DiffusionController {
->setUser($viewer) ->setUser($viewer)
->setRenderAsForm($viewer->isLoggedIn())); ->setRenderAsForm($viewer->isLoggedIn()));
if ($show_color) {
$highlight_text = pht('Disable Highlighting');
$highlight_icon = 'fa-star-o grey';
$highlight_value = 0;
} else {
$highlight_text = pht('Enable Highlighting');
$highlight_icon = 'fa-star';
$highlight_value = 1;
}
$curtain->addAction(
id(new PhabricatorActionView())
->setName($highlight_text)
->setHref($base_uri->alter('color', $highlight_value))
->setIcon($highlight_icon)
->setUser($viewer)
->setRenderAsForm($viewer->isLoggedIn()));
$href = null; $href = null;
if ($this->getRequest()->getStr('lint') !== null) { if ($this->getRequest()->getStr('lint') !== null) {
$lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages)); $lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages));
@ -1002,8 +962,7 @@ final class DiffusionBrowseController extends DiffusionController {
array $lines, array $lines,
array $blame_list, array $blame_list,
array $blame_commits, array $blame_commits,
$show_blame, $show_blame) {
$show_color) {
$request = $this->getRequest(); $request = $this->getRequest();
$viewer = $this->getViewer(); $viewer = $this->getViewer();
@ -1891,79 +1850,6 @@ final class DiffusionBrowseController extends DiffusionController {
return $links; return $links;
} }
private function renderPlaintextCorpus(
$file_corpus,
array $blame_list,
array $blame_commits,
$show_blame) {
$viewer = $this->getViewer();
if (!$show_blame) {
$corpus = $file_corpus;
} else {
$author_phids = array();
foreach ($blame_commits as $commit) {
$author_phid = $commit->getAuthorPHID();
if ($author_phid === null) {
continue;
}
$author_phids[$author_phid] = $author_phid;
}
if ($author_phids) {
$handles = $viewer->loadHandles($author_phids);
} else {
$handles = array();
}
$authors = array();
$names = array();
foreach ($blame_commits as $identifier => $commit) {
$author = $commit->renderAuthorShortName($handles);
$name = $commit->getLocalName();
$authors[$identifier] = $author;
$names[$identifier] = $name;
}
$lines = phutil_split_lines($file_corpus);
$rows = array();
foreach ($lines as $line_number => $line) {
$commit_name = null;
$author = null;
if (isset($blame_list[$line_number])) {
$identifier = $blame_list[$line_number];
if (isset($names[$identifier])) {
$commit_name = $names[$identifier];
}
if (isset($authors[$identifier])) {
$author = $authors[$identifier];
}
}
$rows[] = sprintf(
'%-10s %-20s %s',
$commit_name,
$author,
$line);
}
$corpus = implode('', $rows);
}
return phutil_tag(
'textarea',
array(
'style' => 'border: none; width: 100%; height: 80em; '.
'font-family: monospace',
),
$corpus);
}
private function getGitLFSRef(PhabricatorRepository $repository, $data) { private function getGitLFSRef(PhabricatorRepository $repository, $data) {
if (!$repository->canUseGitLFS()) { if (!$repository->canUseGitLFS()) {
return null; return null;

View file

@ -1,16 +0,0 @@
<?php
final class PhabricatorDiffusionColorSetting
extends PhabricatorInternalSetting {
const SETTINGKEY = 'diffusion-color';
public function getSettingName() {
return pht('Diffusion Color');
}
public function getSettingDefaultValue() {
return false;
}
}