@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add "Core" config, with complex validation

Summary: This is more or less a copy of the validation which lives in `webroot/index.php` right now, but I don't want to wipe that out just yet because there's no way for normal users to see this new validation.

Test Plan: Tried to set "phabricator.base-uri" to crazy nonsense, was harshly rebuffed.

Reviewers: codeblock, btrahan

Reviewed By: codeblock

CC: aran

Maniphest Tasks: T2255

Differential Revision: https://secure.phabricator.com/D4316

+88
+2
src/__phutil_library_map__.php
··· 708 708 'PhabricatorContentSource' => 'applications/metamta/contentsource/PhabricatorContentSource.php', 709 709 'PhabricatorContentSourceView' => 'applications/metamta/contentsource/PhabricatorContentSourceView.php', 710 710 'PhabricatorController' => 'applications/base/controller/PhabricatorController.php', 711 + 'PhabricatorCoreConfigOptions' => 'applications/config/option/PhabricatorCoreConfigOptions.php', 711 712 'PhabricatorCountdownController' => 'applications/countdown/controller/PhabricatorCountdownController.php', 712 713 'PhabricatorCountdownDAO' => 'applications/countdown/storage/PhabricatorCountdownDAO.php', 713 714 'PhabricatorCountdownDeleteController' => 'applications/countdown/controller/PhabricatorCountdownDeleteController.php', ··· 2051 2052 'PhabricatorConfigValidationException' => 'Exception', 2052 2053 'PhabricatorContentSourceView' => 'AphrontView', 2053 2054 'PhabricatorController' => 'AphrontController', 2055 + 'PhabricatorCoreConfigOptions' => 'PhabricatorApplicationConfigOptions', 2054 2056 'PhabricatorCountdownController' => 'PhabricatorController', 2055 2057 'PhabricatorCountdownDAO' => 'PhabricatorLiskDAO', 2056 2058 'PhabricatorCountdownDeleteController' => 'PhabricatorCountdownController',
+86
src/applications/config/option/PhabricatorCoreConfigOptions.php
··· 1 + <?php 2 + 3 + final class PhabricatorCoreConfigOptions 4 + extends PhabricatorApplicationConfigOptions { 5 + 6 + public function getName() { 7 + return pht("Core"); 8 + } 9 + 10 + public function getDescription() { 11 + return pht("Configure core options, including URIs."); 12 + } 13 + 14 + public function getOptions() { 15 + return array( 16 + $this->newOption('phabricator.base-uri', 'string', null) 17 + ->setSummary(pht("URI where Phabricator is installed.")) 18 + ->setDescription( 19 + pht( 20 + "Set the URI where Phabricator is installed. Setting this ". 21 + "improves security by preventing cookies from being set on other ". 22 + "domains, and allows daemons to send emails with links that have ". 23 + "the correct domain.")) 24 + ->addExample('http://phabricator.example.com/', 'Valid Setting'), 25 + $this->newOption('phabricator.production-uri', 'string', null) 26 + ->setSummary( 27 + pht("Primary install URI, for multi-environment installs.")) 28 + ->setDescription( 29 + pht( 30 + "If you have multiple Phabricator environments (like a ". 31 + "development/staging environment for working on testing ". 32 + "Phabricator, and a production environment for deploying it), ". 33 + "set the production environment URI here so that emails and other ". 34 + "durable URIs will always generate with links pointing at the ". 35 + "production environment. If unset, defaults to ". 36 + "{{phabricator.base-uri}}. Most installs do not need to set ". 37 + "this option.")) 38 + ->addExample('http://phabricator.example.com/', 'Valid Setting') 39 + ); 40 + } 41 + 42 + protected function didValidateOption( 43 + PhabricatorConfigOption $option, 44 + $value) { 45 + 46 + $key = $option->getKey(); 47 + if ($key == 'phabricator.base-uri' || 48 + $key == 'phabricator.production-uri') { 49 + 50 + $uri = new PhutilURI($value); 51 + $protocol = $uri->getProtocol(); 52 + if ($protocol !== 'http' && $protocol !== 'https') { 53 + throw new PhabricatorConfigValidationException( 54 + pht( 55 + "Config option '%s' is invalid. The URI must start with ". 56 + "'http://' or 'https://'.", 57 + $key)); 58 + } 59 + 60 + $domain = $uri->getDomain(); 61 + if (strpos($domain, '.') === false) { 62 + throw new PhabricatorConfigValidationException( 63 + pht( 64 + "Config option '%s' is invalid. The URI must contain a dot ('.'), ". 65 + "like 'http://example.com/', not just a bare name like ". 66 + "'http://example/'. Some web browsers will not set cookies on ". 67 + "domains with no TLD.", 68 + $key)); 69 + } 70 + 71 + $path = $uri->getPath(); 72 + if ($path !== '' && $path !== '/') { 73 + throw new PhabricatorConfigValidationException( 74 + pht( 75 + "Config option '%s' is invalid. The URI must NOT have a path, ". 76 + "e.g. 'http://phabricator.example.com/' is OK, but ". 77 + "'http://example.com/phabricator/' is not. Phabricator must be ". 78 + "installed on an entire domain; it can not be installed on a ". 79 + "path.", 80 + $key)); 81 + } 82 + } 83 + } 84 + 85 + 86 + }