Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/markup/rule/PhabricatorConfigRemarkupRule.php
12241 views
1
<?php
2
3
final class PhabricatorConfigRemarkupRule
4
extends PhutilRemarkupRule {
5
6
public function apply($text) {
7
return preg_replace_callback(
8
'(@{config:([^}]+)})',
9
array($this, 'markupConfig'),
10
$text);
11
}
12
13
public function getPriority() {
14
// We're reusing the Diviner atom syntax, so make sure we evaluate before
15
// the Diviner rule evaluates.
16
return id(new DivinerSymbolRemarkupRule())->getPriority() - 1;
17
}
18
19
public function markupConfig(array $matches) {
20
if (!$this->isFlatText($matches[0])) {
21
return $matches[0];
22
}
23
24
$config_key = $matches[1];
25
26
try {
27
$option = PhabricatorEnv::getEnvConfig($config_key);
28
} catch (Exception $ex) {
29
return $matches[0];
30
}
31
32
$is_text = $this->getEngine()->isTextMode();
33
$is_html_mail = $this->getEngine()->isHTMLMailMode();
34
35
if ($is_text || $is_html_mail) {
36
return pht('"%s"', $config_key);
37
}
38
39
$link = phutil_tag(
40
'a',
41
array(
42
'href' => urisprintf('/config/edit/%s/', $config_key),
43
'target' => '_blank',
44
),
45
$config_key);
46
47
return $this->getEngine()->storeText($link);
48
}
49
50
}
51
52