PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/src/applications/config/option/PhabricatorCoreConfigOptions.php

http://github.com/facebook/phabricator
PHP | 321 lines | 294 code | 27 blank | 0 comment | 17 complexity | 105ee7d9c1581ad370f6c30e4e27b02e MD5 | raw file
Possible License(s): JSON, MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-3-Clause, LGPL-2.0, MIT, LGPL-2.1, LGPL-3.0
  1. <?php
  2. final class PhabricatorCoreConfigOptions
  3. extends PhabricatorApplicationConfigOptions {
  4. public function getName() {
  5. return pht('Core');
  6. }
  7. public function getDescription() {
  8. return pht('Configure core options, including URIs.');
  9. }
  10. public function getIcon() {
  11. return 'fa-bullseye';
  12. }
  13. public function getGroup() {
  14. return 'core';
  15. }
  16. public function getOptions() {
  17. if (phutil_is_windows()) {
  18. $paths = array();
  19. } else {
  20. $paths = array(
  21. '/bin',
  22. '/usr/bin',
  23. '/usr/local/bin',
  24. );
  25. }
  26. $path = getenv('PATH');
  27. $proto_doc_href = PhabricatorEnv::getDoclink(
  28. 'User Guide: Prototype Applications');
  29. $proto_doc_name = pht('User Guide: Prototype Applications');
  30. $applications_app_href = '/applications/';
  31. $silent_description = $this->deformat(pht(<<<EOREMARKUP
  32. This option allows you to stop Phabricator from sending data to most external
  33. services: it will disable email, SMS, repository mirroring, remote builds,
  34. Doorkeeper writes, and webhooks.
  35. This option is intended to allow a Phabricator instance to be exported, copied,
  36. imported, and run in a test environment without impacting users. For example,
  37. if you are migrating to new hardware, you could perform a test migration first
  38. with this flag set, make sure things work, and then do a production cutover
  39. later with higher confidence and less disruption.
  40. Without making use of this flag to silence the temporary test environment,
  41. users would receive duplicate email during the time the test instance and old
  42. production instance were both in operation.
  43. EOREMARKUP
  44. ));
  45. $timezone_description = $this->deformat(pht(<<<EOREMARKUP
  46. PHP date functions will emit a warning if they are called when no default
  47. server timezone is configured.
  48. Usually, you configure a default timezone in `php.ini` by setting the
  49. configuration value `date.timezone`.
  50. If you prefer, you can configure a default timezone here instead. To configure
  51. a default timezone, select a timezone from the
  52. [[ %s | PHP List of Supported Timezones ]].
  53. EOREMARKUP
  54. ,
  55. 'https://php.net/manual/timezones.php'));
  56. return array(
  57. $this->newOption('phabricator.base-uri', 'string', null)
  58. ->setLocked(true)
  59. ->setSummary(pht('URI where Phabricator is installed.'))
  60. ->setDescription(
  61. pht(
  62. 'Set the URI where Phabricator is installed. Setting this '.
  63. 'improves security by preventing cookies from being set on other '.
  64. 'domains, and allows daemons to send emails with links that have '.
  65. 'the correct domain.'))
  66. ->addExample('http://phabricator.example.com/', pht('Valid Setting')),
  67. $this->newOption('phabricator.production-uri', 'string', null)
  68. ->setSummary(
  69. pht('Primary install URI, for multi-environment installs.'))
  70. ->setDescription(
  71. pht(
  72. 'If you have multiple Phabricator environments (like a '.
  73. 'development/staging environment for working on testing '.
  74. 'Phabricator, and a production environment for deploying it), '.
  75. 'set the production environment URI here so that emails and other '.
  76. 'durable URIs will always generate with links pointing at the '.
  77. 'production environment. If unset, defaults to `%s`. Most '.
  78. 'installs do not need to set this option.',
  79. 'phabricator.base-uri'))
  80. ->addExample('http://phabricator.example.com/', pht('Valid Setting')),
  81. $this->newOption('phabricator.allowed-uris', 'list<string>', array())
  82. ->setLocked(true)
  83. ->setSummary(pht('Alternative URIs that can access Phabricator.'))
  84. ->setDescription(
  85. pht(
  86. "These alternative URIs will be able to access 'normal' pages ".
  87. "on your Phabricator install. Other features such as OAuth ".
  88. "won't work. The major use case for this is moving installs ".
  89. "across domains."))
  90. ->addExample(
  91. "http://phabricator2.example.com/\n".
  92. "http://phabricator3.example.com/",
  93. pht('Valid Setting')),
  94. $this->newOption('phabricator.timezone', 'string', null)
  95. ->setSummary(
  96. pht('The timezone Phabricator should use.'))
  97. ->setDescription($timezone_description)
  98. ->addExample('America/New_York', pht('US East (EDT)'))
  99. ->addExample('America/Chicago', pht('US Central (CDT)'))
  100. ->addExample('America/Boise', pht('US Mountain (MDT)'))
  101. ->addExample('America/Los_Angeles', pht('US West (PDT)')),
  102. $this->newOption('phabricator.cookie-prefix', 'string', null)
  103. ->setLocked(true)
  104. ->setSummary(
  105. pht(
  106. 'Set a string Phabricator should use to prefix cookie names.'))
  107. ->setDescription(
  108. pht(
  109. 'Cookies set for x.com are also sent for y.x.com. Assuming '.
  110. 'Phabricator instances are running on both domains, this will '.
  111. 'create a collision preventing you from logging in.'))
  112. ->addExample('dev', pht('Prefix cookie with "%s"', 'dev')),
  113. $this->newOption('phabricator.show-prototypes', 'bool', false)
  114. ->setLocked(true)
  115. ->setBoolOptions(
  116. array(
  117. pht('Enable Prototypes'),
  118. pht('Disable Prototypes'),
  119. ))
  120. ->setSummary(
  121. pht(
  122. 'Install applications which are still under development.'))
  123. ->setDescription(
  124. pht(
  125. "IMPORTANT: The upstream does not provide support for prototype ".
  126. "applications.".
  127. "\n\n".
  128. "Phabricator includes prototype applications which are in an ".
  129. "**early stage of development**. By default, prototype ".
  130. "applications are not installed, because they are often not yet ".
  131. "developed enough to be generally usable. You can enable ".
  132. "this option to install them if you're developing Phabricator ".
  133. "or are interested in previewing upcoming features.".
  134. "\n\n".
  135. "To learn more about prototypes, see [[ %s | %s ]].".
  136. "\n\n".
  137. "After enabling prototypes, you can selectively uninstall them ".
  138. "(like normal applications).",
  139. $proto_doc_href,
  140. $proto_doc_name)),
  141. $this->newOption('phabricator.serious-business', 'bool', false)
  142. ->setBoolOptions(
  143. array(
  144. pht('Serious business'),
  145. pht('Shenanigans'), // That should be interesting to translate. :P
  146. ))
  147. ->setSummary(
  148. pht('Allows you to remove levity and jokes from the UI.'))
  149. ->setDescription(
  150. pht(
  151. 'By default, Phabricator includes some flavor text in the UI, '.
  152. 'like a prompt to "Weigh In" rather than "Add Comment" in '.
  153. 'Maniphest. If you\'d prefer more traditional UI strings like '.
  154. '"Add Comment", you can set this flag to disable most of the '.
  155. 'extra flavor.')),
  156. $this->newOption('remarkup.ignored-object-names', 'string', '/^(Q|V)\d$/')
  157. ->setSummary(
  158. pht('Text values that match this regex and are also object names '.
  159. 'will not be linked.'))
  160. ->setDescription(
  161. pht(
  162. 'By default, Phabricator links object names in Remarkup fields '.
  163. 'to the corresponding object. This regex can be used to modify '.
  164. 'this behavior; object names that match this regex will not be '.
  165. 'linked.')),
  166. $this->newOption('environment.append-paths', 'list<string>', $paths)
  167. ->setSummary(
  168. pht(
  169. 'These paths get appended to your %s environment variable.',
  170. '$PATH'))
  171. ->setDescription(
  172. pht(
  173. "Phabricator occasionally shells out to other binaries on the ".
  174. "server. An example of this is the `%s` command, used to ".
  175. "syntax-highlight code written in languages other than PHP. By ".
  176. "default, it is assumed that these binaries are in the %s of the ".
  177. "user running Phabricator (normally 'apache', 'httpd', or ".
  178. "'nobody'). Here you can add extra directories to the %s ".
  179. "environment variable, for when these binaries are in ".
  180. "non-standard locations.\n\n".
  181. "Note that you can also put binaries in `%s` (for example, by ".
  182. "symlinking them).\n\n".
  183. "The current value of PATH after configuration is applied is:\n\n".
  184. " lang=text\n".
  185. " %s",
  186. 'pygmentize',
  187. '$PATH',
  188. '$PATH',
  189. 'phabricator/support/bin/',
  190. $path))
  191. ->setLocked(true)
  192. ->addExample('/usr/local/bin', pht('Add One Path'))
  193. ->addExample("/usr/bin\n/usr/local/bin", pht('Add Multiple Paths')),
  194. $this->newOption('config.lock', 'set', array())
  195. ->setLocked(true)
  196. ->setDescription(pht('Additional configuration options to lock.')),
  197. $this->newOption('config.hide', 'set', array())
  198. ->setLocked(true)
  199. ->setDescription(pht('Additional configuration options to hide.')),
  200. $this->newOption('config.ignore-issues', 'set', array())
  201. ->setLocked(true)
  202. ->setDescription(pht('Setup issues to ignore.')),
  203. $this->newOption('phabricator.env', 'string', null)
  204. ->setLocked(true)
  205. ->setDescription(pht('Internal.')),
  206. $this->newOption('test.value', 'wild', null)
  207. ->setLocked(true)
  208. ->setDescription(pht('Unit test value.')),
  209. $this->newOption('phabricator.uninstalled-applications', 'set', array())
  210. ->setLocked(true)
  211. ->setLockedMessage(pht(
  212. 'Use the %s to manage installed applications.',
  213. phutil_tag(
  214. 'a',
  215. array(
  216. 'href' => $applications_app_href,
  217. ),
  218. pht('Applications application'))))
  219. ->setDescription(
  220. pht('Array containing list of uninstalled applications.')),
  221. $this->newOption('phabricator.application-settings', 'wild', array())
  222. ->setLocked(true)
  223. ->setDescription(
  224. pht('Customized settings for Phabricator applications.')),
  225. $this->newOption('phabricator.cache-namespace', 'string', 'phabricator')
  226. ->setLocked(true)
  227. ->setDescription(pht('Cache namespace.')),
  228. $this->newOption('phabricator.silent', 'bool', false)
  229. ->setLocked(true)
  230. ->setBoolOptions(
  231. array(
  232. pht('Run Silently'),
  233. pht('Run Normally'),
  234. ))
  235. ->setSummary(pht('Stop Phabricator from sending any email, etc.'))
  236. ->setDescription($silent_description),
  237. );
  238. }
  239. protected function didValidateOption(
  240. PhabricatorConfigOption $option,
  241. $value) {
  242. $key = $option->getKey();
  243. if ($key == 'phabricator.base-uri' ||
  244. $key == 'phabricator.production-uri') {
  245. $uri = new PhutilURI($value);
  246. $protocol = $uri->getProtocol();
  247. if ($protocol !== 'http' && $protocol !== 'https') {
  248. throw new PhabricatorConfigValidationException(
  249. pht(
  250. 'Config option "%s" is invalid. The URI must start with '.
  251. '"%s" or "%s".',
  252. $key,
  253. 'http://',
  254. 'https://'));
  255. }
  256. $domain = $uri->getDomain();
  257. if (strpos($domain, '.') === false) {
  258. throw new PhabricatorConfigValidationException(
  259. pht(
  260. 'Config option "%s" is invalid. The URI must contain a dot '.
  261. '("%s"), like "%s", not just a bare name like "%s". Some web '.
  262. 'browsers will not set cookies on domains with no TLD.',
  263. $key,
  264. '.',
  265. 'http://example.com/',
  266. 'http://example/'));
  267. }
  268. $path = $uri->getPath();
  269. if ($path !== '' && $path !== '/') {
  270. throw new PhabricatorConfigValidationException(
  271. pht(
  272. "Config option '%s' is invalid. The URI must NOT have a path, ".
  273. "e.g. '%s' is OK, but '%s' is not. Phabricator must be installed ".
  274. "on an entire domain; it can not be installed on a path.",
  275. $key,
  276. 'http://phabricator.example.com/',
  277. 'http://example.com/phabricator/'));
  278. }
  279. }
  280. if ($key === 'phabricator.timezone') {
  281. $old = date_default_timezone_get();
  282. $ok = @date_default_timezone_set($value);
  283. @date_default_timezone_set($old);
  284. if (!$ok) {
  285. throw new PhabricatorConfigValidationException(
  286. pht(
  287. 'Config option "%s" is invalid. The timezone identifier must '.
  288. 'be a valid timezone identifier recognized by PHP, like "%s".',
  289. $key,
  290. 'America/Los_Angeles'));
  291. }
  292. }
  293. }
  294. }