From 3c65601285e9855177d829f48827482b7b658a61 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 22 Dec 2018 04:31:20 -0800 Subject: [PATCH] Implement "@{config:...}" as a real Remarkup rule Summary: See . 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 --- src/__phutil_library_map__.php | 2 + ...PhabricatorAuthenticationConfigOptions.php | 6 +-- .../config/option/PhabricatorConfigOption.php | 6 --- .../markup/PhabricatorMarkupEngine.php | 1 + .../rule/PhabricatorConfigRemarkupRule.php | 50 +++++++++++++++++++ 5 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 src/infrastructure/markup/rule/PhabricatorConfigRemarkupRule.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6320811c9a..e3fb90377b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/config/option/PhabricatorAuthenticationConfigOptions.php b/src/applications/config/option/PhabricatorAuthenticationConfigOptions.php index 2239d98858..1440714bf7 100644 --- a/src/applications/config/option/PhabricatorAuthenticationConfigOptions.php +++ b/src/applications/config/option/PhabricatorAuthenticationConfigOptions.php @@ -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', 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`.")) diff --git a/src/applications/config/option/PhabricatorConfigOption.php b/src/applications/config/option/PhabricatorConfigOption.php index 385af002c7..6d7f88bdfb 100644 --- a/src/applications/config/option/PhabricatorConfigOption.php +++ b/src/applications/config/option/PhabricatorConfigOption.php @@ -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); } diff --git a/src/infrastructure/markup/PhabricatorMarkupEngine.php b/src/infrastructure/markup/PhabricatorMarkupEngine.php index 0c56d9ed41..868bbc5676 100644 --- a/src/infrastructure/markup/PhabricatorMarkupEngine.php +++ b/src/infrastructure/markup/PhabricatorMarkupEngine.php @@ -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(); diff --git a/src/infrastructure/markup/rule/PhabricatorConfigRemarkupRule.php b/src/infrastructure/markup/rule/PhabricatorConfigRemarkupRule.php new file mode 100644 index 0000000000..f353f8c1e8 --- /dev/null +++ b/src/infrastructure/markup/rule/PhabricatorConfigRemarkupRule.php @@ -0,0 +1,50 @@ +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); + } + +}