mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 03:02:43 +01:00
afc3099ee7
Summary: See PHI604. Ref T13130. Ref T13105. There's currently no way to turn blame off in Diffusion. Add a "Hide Blame" option to the "View Options" dropdown so it can be toggled off. Also fix a couple of bugs around this: for example, if you loaded a Jupyter notebook and then switched to "Source" view, blame would incorrectly fail to activate because the original rendering of the "stage" used an asynchronous engine so `willRenderRef()` wasn't called to populate blame. Test Plan: - Viewed a source file, toggled blame off/on, reloaded page to see state stick in URL. - Viewed a Jupyter notebook, toggled to "Source" view, saw blame. - Viewed stuff in Files (no blame UI options). - Tried to do some invalid stuff like toggle blame on a non-blame engine (options disable properly). Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13130, T13105 Differential Revision: https://secure.phabricator.com/D19414
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
final class PhabricatorSourceDocumentEngine
|
|
extends PhabricatorTextDocumentEngine {
|
|
|
|
const ENGINEKEY = 'source';
|
|
|
|
public function getViewAsLabel(PhabricatorDocumentRef $ref) {
|
|
return pht('View as Source');
|
|
}
|
|
|
|
public function canConfigureHighlighting(PhabricatorDocumentRef $ref) {
|
|
return true;
|
|
}
|
|
|
|
public function canBlame(PhabricatorDocumentRef $ref) {
|
|
return true;
|
|
}
|
|
|
|
protected function getDocumentIconIcon(PhabricatorDocumentRef $ref) {
|
|
return 'fa-code';
|
|
}
|
|
|
|
protected function getContentScore(PhabricatorDocumentRef $ref) {
|
|
return 1500;
|
|
}
|
|
|
|
protected function newDocumentContent(PhabricatorDocumentRef $ref) {
|
|
$content = $this->loadTextData($ref);
|
|
|
|
$messages = array();
|
|
|
|
$highlighting = $this->getHighlightingConfiguration();
|
|
if ($highlighting !== null) {
|
|
$content = PhabricatorSyntaxHighlighter::highlightWithLanguage(
|
|
$highlighting,
|
|
$content);
|
|
} else {
|
|
$highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
|
|
if (strlen($content) > $highlight_limit) {
|
|
$messages[] = $this->newMessage(
|
|
pht(
|
|
'This file is larger than %s, so syntax highlighting was skipped.',
|
|
phutil_format_bytes($highlight_limit)));
|
|
} else {
|
|
$content = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
|
$ref->getName(),
|
|
$content);
|
|
}
|
|
}
|
|
|
|
$options = array();
|
|
if ($ref->getBlameURI() && $this->getBlameEnabled()) {
|
|
$content = phutil_split_lines($content);
|
|
$blame = range(1, count($content));
|
|
$blame = array_fuse($blame);
|
|
$options['blame'] = $blame;
|
|
}
|
|
|
|
if ($ref->getCoverage()) {
|
|
$options['coverage'] = $ref->getCoverage();
|
|
}
|
|
|
|
return array(
|
|
$messages,
|
|
$this->newTextDocumentContent($ref, $content, $options),
|
|
);
|
|
}
|
|
|
|
}
|