mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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:
parent
706c21375e
commit
e634812a6d
3 changed files with 85 additions and 217 deletions
|
@ -2486,7 +2486,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDifferentialRevisionTestDataGenerator' => 'applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php',
|
||||
'PhabricatorDiffusionApplication' => 'applications/diffusion/application/PhabricatorDiffusionApplication.php',
|
||||
'PhabricatorDiffusionBlameSetting' => 'applications/settings/setting/PhabricatorDiffusionBlameSetting.php',
|
||||
'PhabricatorDiffusionColorSetting' => 'applications/settings/setting/PhabricatorDiffusionColorSetting.php',
|
||||
'PhabricatorDiffusionConfigOptions' => 'applications/diffusion/config/PhabricatorDiffusionConfigOptions.php',
|
||||
'PhabricatorDisabledUserController' => 'applications/auth/controller/PhabricatorDisabledUserController.php',
|
||||
'PhabricatorDisplayPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDisplayPreferencesSettingsPanel.php',
|
||||
|
@ -7406,7 +7405,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDifferentialRevisionTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||
'PhabricatorDiffusionApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorDiffusionBlameSetting' => 'PhabricatorInternalSetting',
|
||||
'PhabricatorDiffusionColorSetting' => 'PhabricatorInternalSetting',
|
||||
'PhabricatorDiffusionConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorDisabledUserController' => 'PhabricatorAuthController',
|
||||
'PhabricatorDisplayPreferencesSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
|
||||
|
|
|
@ -106,16 +106,11 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
$path = $drequest->getPath();
|
||||
|
||||
$blame_key = PhabricatorDiffusionBlameSetting::SETTINGKEY;
|
||||
$color_key = PhabricatorDiffusionColorSetting::SETTINGKEY;
|
||||
|
||||
$show_blame = $request->getBool(
|
||||
'blame',
|
||||
$viewer->getUserSetting($blame_key));
|
||||
|
||||
$show_color = $request->getBool(
|
||||
'color',
|
||||
$viewer->getUserSetting($color_key));
|
||||
|
||||
$view = $request->getStr('view');
|
||||
if ($request->isFormPost() && $view != 'raw' && $viewer->isLoggedIn()) {
|
||||
$preferences = PhabricatorUserPreferences::loadUserPreferences($viewer);
|
||||
|
@ -128,22 +123,18 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
|
||||
$xactions = array();
|
||||
$xactions[] = $preferences->newTransaction($blame_key, $show_blame);
|
||||
$xactions[] = $preferences->newTransaction($color_key, $show_color);
|
||||
$editor->applyTransactions($preferences, $xactions);
|
||||
|
||||
$uri = $request->getRequestURI()
|
||||
->alter('blame', null)
|
||||
->alter('color', null);
|
||||
->alter('blame', null);
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI($uri);
|
||||
}
|
||||
|
||||
// We need the blame information if blame is on and we're building plain
|
||||
// text, or blame is on and this is an Ajax request. If blame is on and
|
||||
// this is a colorized request, we don't show blame at first (we ajax it
|
||||
// in afterward) so we don't need to query for it.
|
||||
$needs_blame = ($show_blame && !$show_color) ||
|
||||
($show_blame && $request->isAjax());
|
||||
// We need the blame information if blame is on and this is an Ajax request.
|
||||
// If blame is on and this is a colorized request, we don't show blame at
|
||||
// first (we ajax it in afterward) so we don't need to query for it.
|
||||
$needs_blame = ($show_blame && $request->isAjax());
|
||||
|
||||
$params = array(
|
||||
'commit' => $drequest->getCommit(),
|
||||
|
@ -196,10 +187,10 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
|
||||
$data = $file->loadFileData();
|
||||
|
||||
$ref = $this->getGitLFSRef($repository, $data);
|
||||
if ($ref) {
|
||||
$lfs_ref = $this->getGitLFSRef($repository, $data);
|
||||
if ($lfs_ref) {
|
||||
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
|
||||
// it. In storage, it just has a name like "lfs-13f9a94c0923...",
|
||||
|
@ -211,7 +202,7 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
|
||||
return $file->getRedirectResponse();
|
||||
} else {
|
||||
$corpus = $this->buildGitLFSCorpus($ref);
|
||||
$corpus = $this->buildGitLFSCorpus($lfs_ref);
|
||||
}
|
||||
} else if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
|
||||
$file_uri = $file->getBestURI();
|
||||
|
@ -228,7 +219,6 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
// Build the content of the file.
|
||||
$corpus = $this->buildCorpus(
|
||||
$show_blame,
|
||||
$show_color,
|
||||
$data,
|
||||
$needs_blame,
|
||||
$drequest,
|
||||
|
@ -248,8 +238,7 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
$curtain = $this->enrichCurtain(
|
||||
$view,
|
||||
$drequest,
|
||||
$show_blame,
|
||||
$show_color);
|
||||
$show_blame);
|
||||
|
||||
$properties = $this->buildPropertyView($drequest);
|
||||
$header = $this->buildHeaderView($drequest);
|
||||
|
@ -647,7 +636,6 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
|
||||
private function buildCorpus(
|
||||
$show_blame,
|
||||
$show_color,
|
||||
$file_corpus,
|
||||
$needs_blame,
|
||||
DiffusionRequest $drequest,
|
||||
|
@ -675,15 +663,7 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
$blame_commits = array();
|
||||
}
|
||||
|
||||
if (!$show_color) {
|
||||
$corpus = $this->renderPlaintextCorpus(
|
||||
$file_corpus,
|
||||
$blame_list,
|
||||
$blame_commits,
|
||||
$show_blame);
|
||||
} else {
|
||||
require_celerity_resource('syntax-highlighting-css');
|
||||
|
||||
if ($can_highlight) {
|
||||
$highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
||||
$path,
|
||||
|
@ -701,8 +681,7 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
$lines,
|
||||
$blame_list,
|
||||
$blame_commits,
|
||||
$show_blame,
|
||||
$show_color);
|
||||
$show_blame);
|
||||
|
||||
$corpus_table = javelin_tag(
|
||||
'table',
|
||||
|
@ -758,7 +737,7 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
$corpus_table);
|
||||
|
||||
Javelin::initBehavior('load-blame', array('id' => $id));
|
||||
}
|
||||
|
||||
|
||||
$edit = $this->renderEditButton();
|
||||
$file = $this->renderFileButton();
|
||||
|
@ -808,8 +787,7 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
private function enrichCurtain(
|
||||
PHUICurtainView $curtain,
|
||||
DiffusionRequest $drequest,
|
||||
$show_blame,
|
||||
$show_color) {
|
||||
$show_blame) {
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
$base_uri = $this->getRequest()->getRequestURI();
|
||||
|
@ -842,24 +820,6 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
->setUser($viewer)
|
||||
->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;
|
||||
if ($this->getRequest()->getStr('lint') !== null) {
|
||||
$lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages));
|
||||
|
@ -1002,8 +962,7 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
array $lines,
|
||||
array $blame_list,
|
||||
array $blame_commits,
|
||||
$show_blame,
|
||||
$show_color) {
|
||||
$show_blame) {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$viewer = $this->getViewer();
|
||||
|
@ -1891,79 +1850,6 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
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) {
|
||||
if (!$repository->canUseGitLFS()) {
|
||||
return null;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue