1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

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
This commit is contained in:
epriestley 2018-12-22 04:31:20 -08:00
parent e98ee73602
commit 3c65601285
5 changed files with 56 additions and 9 deletions

View file

@ -2672,6 +2672,7 @@ phutil_register_library_map(array(
'PhabricatorConfigProxySource' => 'infrastructure/env/PhabricatorConfigProxySource.php',
'PhabricatorConfigPurgeCacheController' => 'applications/config/controller/PhabricatorConfigPurgeCacheController.php',
'PhabricatorConfigRegexOptionType' => 'applications/config/custom/PhabricatorConfigRegexOptionType.php',
'PhabricatorConfigRemarkupRule' => 'infrastructure/markup/rule/PhabricatorConfigRemarkupRule.php',
'PhabricatorConfigRequestExceptionHandlerModule' => 'applications/config/module/PhabricatorConfigRequestExceptionHandlerModule.php',
'PhabricatorConfigResponse' => 'applications/config/response/PhabricatorConfigResponse.php',
'PhabricatorConfigSchemaQuery' => 'applications/config/schema/PhabricatorConfigSchemaQuery.php',
@ -8409,6 +8410,7 @@ phutil_register_library_map(array(
'PhabricatorConfigProxySource' => 'PhabricatorConfigSource',
'PhabricatorConfigPurgeCacheController' => 'PhabricatorConfigController',
'PhabricatorConfigRegexOptionType' => 'PhabricatorConfigJSONOptionType',
'PhabricatorConfigRemarkupRule' => 'PhutilRemarkupRule',
'PhabricatorConfigRequestExceptionHandlerModule' => 'PhabricatorConfigModule',
'PhabricatorConfigResponse' => 'AphrontStandaloneHTMLResponse',
'PhabricatorConfigSchemaQuery' => 'Phobject',

View file

@ -33,7 +33,7 @@ final class PhabricatorAuthenticationConfigOptions
pht(
'If true, email addresses must be verified (by clicking a link '.
'in an email) before a user can login. By default, verification '.
'is optional unless {{auth.email-domains}} is nonempty.')),
'is optional unless @{config:auth.email-domains} is nonempty.')),
$this->newOption('auth.require-approval', 'bool', true)
->setBoolOptions(
array(
@ -55,7 +55,7 @@ final class PhabricatorAuthenticationConfigOptions
"registration, you can disable the queue to reduce administrative ".
"overhead.\n\n".
"NOTE: Before you disable the queue, make sure ".
"{{auth.email-domains}} is configured correctly ".
"@{config:auth.email-domains} is configured correctly ".
"for your install!")),
$this->newOption('auth.email-domains', 'list<string>', array())
->setSummary(pht('Only allow registration from particular domains.'))
@ -66,7 +66,7 @@ final class PhabricatorAuthenticationConfigOptions
"here.\n\nUsers will only be allowed to register using email ".
"addresses at one of the domains, and will only be able to add ".
"new email addresses for these domains. If you configure this, ".
"it implies {{auth.require-email-verification}}.\n\n".
"it implies @{config:auth.require-email-verification}.\n\n".
"You should omit the `@` from domains. Note that the domain must ".
"match exactly. If you allow `yourcompany.com`, that permits ".
"`joe@yourcompany.com` but rejects `joe@mail.yourcompany.com`."))

View file

@ -209,12 +209,6 @@ final class PhabricatorConfigOption
return null;
}
// TODO: Some day, we should probably implement this as a real rule.
$description = preg_replace(
'/{{([^}]+)}}/',
'[[/config/edit/\\1/ | \\1]]',
$description);
return new PHUIRemarkupView($viewer, $description);
}

View file

@ -510,6 +510,7 @@ final class PhabricatorMarkupEngine extends Phobject {
$rules[] = new PhutilRemarkupDocumentLinkRule();
$rules[] = new PhabricatorNavigationRemarkupRule();
$rules[] = new PhabricatorKeyboardRemarkupRule();
$rules[] = new PhabricatorConfigRemarkupRule();
if ($options['youtube']) {
$rules[] = new PhabricatorYoutubeRemarkupRule();

View file

@ -0,0 +1,50 @@
<?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);
}
}