1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-31 22:48:16 +02:00
phorge-phorge/src/infrastructure/markup/rule/PhabricatorConfigRemarkupRule.php
epriestley 3c65601285 Implement "@{config:...}" as a real Remarkup rule
Summary:
See <https://discourse.phabricator-community.org/t/firehose-webhook-not-working-with-self-hosted-requestbin-instance/2240/>. I want to make it easier to link to configuration from system text.

We currently use this weird hack with `{{...}}` that only works within Config itself. Instead, use `@{config:...}`, which is already used by Diviner for `@{class:...}`, etc., so it shouldn't conflict with anything.

Test Plan: Viewed config options, clicked links to other config options.

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D19928
2018-12-28 00:05:09 -08:00

50 lines
1.1 KiB
PHP

<?php
final class PhabricatorConfigRemarkupRule
extends PhutilRemarkupRule {
public function apply($text) {
return preg_replace_callback(
'(@{config:([^}]+)})',
array($this, 'markupConfig'),
$text);
}
public function getPriority() {
// We're reusing the Diviner atom syntax, so make sure we evaluate before
// the Diviner rule evaluates.
return id(new DivinerSymbolRemarkupRule())->getPriority() - 1;
}
public function markupConfig(array $matches) {
if (!$this->isFlatText($matches[0])) {
return $matches[0];
}
$config_key = $matches[1];
try {
$option = PhabricatorEnv::getEnvConfig($config_key);
} catch (Exception $ex) {
return $matches[0];
}
$is_text = $this->getEngine()->isTextMode();
$is_html_mail = $this->getEngine()->isHTMLMailMode();
if ($is_text || $is_html_mail) {
return pht('"%s"', $config_key);
}
$link = phutil_tag(
'a',
array(
'href' => urisprintf('/config/edit/%s/', $config_key),
'target' => '_blank',
),
$config_key);
return $this->getEngine()->storeText($link);
}
}