Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/document/PhabricatorSourceDocumentEngine.php
12241 views
1
<?php
2
3
final class PhabricatorSourceDocumentEngine
4
extends PhabricatorTextDocumentEngine {
5
6
const ENGINEKEY = 'source';
7
8
public function getViewAsLabel(PhabricatorDocumentRef $ref) {
9
return pht('View as Source');
10
}
11
12
public function canConfigureHighlighting(PhabricatorDocumentRef $ref) {
13
return true;
14
}
15
16
public function canBlame(PhabricatorDocumentRef $ref) {
17
return true;
18
}
19
20
protected function getDocumentIconIcon(PhabricatorDocumentRef $ref) {
21
return 'fa-code';
22
}
23
24
protected function getContentScore(PhabricatorDocumentRef $ref) {
25
return 1500;
26
}
27
28
protected function newDocumentContent(PhabricatorDocumentRef $ref) {
29
$content = $this->loadTextData($ref);
30
31
$messages = array();
32
33
$highlighting = $this->getHighlightingConfiguration();
34
if ($highlighting !== null) {
35
$content = PhabricatorSyntaxHighlighter::highlightWithLanguage(
36
$highlighting,
37
$content);
38
} else {
39
$highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
40
if (strlen($content) > $highlight_limit) {
41
$messages[] = $this->newMessage(
42
pht(
43
'This file is larger than %s, so syntax highlighting was skipped.',
44
phutil_format_bytes($highlight_limit)));
45
} else {
46
$content = PhabricatorSyntaxHighlighter::highlightWithFilename(
47
$ref->getName(),
48
$content);
49
}
50
}
51
52
$options = array();
53
if ($ref->getBlameURI() && $this->getBlameEnabled()) {
54
$content = phutil_split_lines($content);
55
$blame = range(1, count($content));
56
$blame = array_fuse($blame);
57
$options['blame'] = $blame;
58
}
59
60
if ($ref->getCoverage()) {
61
$options['coverage'] = $ref->getCoverage();
62
}
63
64
return array(
65
$messages,
66
$this->newTextDocumentContent($ref, $content, $options),
67
);
68
}
69
70
}
71
72