@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.

Show all configuration defaults when editing configuration

Summary: Show the value for all loaded configuration sources.

Test Plan:
{F28469}

{F28470}

{F28471}

Reviewers: btrahan, codeblock

Reviewed By: codeblock

CC: aran

Maniphest Tasks: T2255

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

+150 -40
+2
src/__phutil_library_map__.php
··· 684 684 'PhabricatorConduitMethodCallLog' => 'applications/conduit/storage/PhabricatorConduitMethodCallLog.php', 685 685 'PhabricatorConduitTokenController' => 'applications/conduit/controller/PhabricatorConduitTokenController.php', 686 686 'PhabricatorConfigController' => 'applications/config/controller/PhabricatorConfigController.php', 687 + 'PhabricatorConfigDefaultSource' => 'infrastructure/env/PhabricatorConfigDefaultSource.php', 687 688 'PhabricatorConfigDictionarySource' => 'infrastructure/env/PhabricatorConfigDictionarySource.php', 688 689 'PhabricatorConfigEditController' => 'applications/config/controller/PhabricatorConfigEditController.php', 689 690 'PhabricatorConfigEntry' => 'applications/config/storage/PhabricatorConfigEntry.php', ··· 2019 2020 'PhabricatorConduitMethodCallLog' => 'PhabricatorConduitDAO', 2020 2021 'PhabricatorConduitTokenController' => 'PhabricatorConduitController', 2021 2022 'PhabricatorConfigController' => 'PhabricatorController', 2023 + 'PhabricatorConfigDefaultSource' => 'PhabricatorConfigProxySource', 2022 2024 'PhabricatorConfigDictionarySource' => 'PhabricatorConfigSource', 2023 2025 'PhabricatorConfigEditController' => 'PhabricatorConfigController', 2024 2026 'PhabricatorConfigEntry' => 'PhabricatorConfigEntryDAO',
+65 -27
src/applications/config/controller/PhabricatorConfigEditController.php
··· 122 122 ->setValue($examples)); 123 123 } 124 124 125 + $form->appendChild( 126 + id(new AphrontFormMarkupControl()) 127 + ->setLabel(pht('Default')) 128 + ->setValue($this->renderDefaults($option))); 125 129 126 - // TODO: This isn't quite correct -- we should read from the entire 127 - // configuration stack, ignoring database configuration. For now, though, 128 - // it's a reasonable approximation. 129 - $default = $this->prettyPrintJSON($option->getDefault()); 130 - $form 131 - ->appendChild( 132 - phutil_render_tag( 133 - 'p', 134 - array( 135 - 'class' => 'aphront-form-input', 136 - ), 137 - 'If left blank, the setting will return to its default value. '. 138 - 'Its default value is:')) 139 - ->appendChild( 140 - phutil_render_tag( 141 - 'pre', 142 - array( 143 - 'class' => 'aphront-form-input', 144 - ), 145 - phutil_escape_html($default))); 146 - 147 - $title = pht('Edit %s', $this->key); 148 - $short = pht('Edit'); 130 + $title = pht('Edit %s', $this->key); 131 + $short = pht('Edit'); 149 132 150 133 $crumbs = $this->buildApplicationCrumbs(); 151 134 $crumbs->addCrumb( ··· 302 285 } 303 286 304 287 $table = array(); 288 + $table[] = '<tr class="column-labels">'; 289 + $table[] = '<th>'.pht('Example').'</th>'; 290 + $table[] = '<th>'.pht('Value').'</th>'; 291 + $table[] = '</tr>'; 305 292 foreach ($examples as $example) { 306 293 list($value, $description) = $example; 307 294 308 295 if ($value === null) { 309 - $value = '<em>(empty)</em>'; 296 + $value = '<em>'.pht('(empty)').'</em>'; 310 297 } else { 311 298 $value = phutil_escape_html($value); 312 299 } 313 300 314 301 $table[] = '<tr>'; 315 - $table[] = '<th>'.$value.'</th>'; 316 - $table[] = '<td>'.phutil_escape_html($description).'</td>'; 302 + $table[] = '<th>'.phutil_escape_html($description).'</th>'; 303 + $table[] = '<td>'.$value.'</td>'; 304 + $table[] = '</tr>'; 305 + } 306 + 307 + require_celerity_resource('config-options-css'); 308 + 309 + return phutil_render_tag( 310 + 'table', 311 + array( 312 + 'class' => 'config-option-table', 313 + ), 314 + implode("\n", $table)); 315 + } 316 + 317 + private function renderDefaults(PhabricatorConfigOption $option) { 318 + $stack = PhabricatorEnv::getConfigSourceStack(); 319 + $stack = $stack->getStack(); 320 + 321 + /* 322 + 323 + TODO: Once DatabaseSource lands, do this: 324 + 325 + foreach ($stack as $key => $source) { 326 + unset($stack[$key]); 327 + if ($source instanceof PhabricatorConfigDatabaseSource) { 328 + break; 329 + } 330 + } 331 + 332 + */ 333 + 334 + 335 + $table = array(); 336 + $table[] = '<tr class="column-labels">'; 337 + $table[] = '<th>'.pht('Source').'</th>'; 338 + $table[] = '<th>'.pht('Value').'</th>'; 339 + $table[] = '</tr>'; 340 + foreach ($stack as $key => $source) { 341 + $value = $source->getKeys( 342 + array( 343 + $option->getKey(), 344 + )); 345 + 346 + if (!array_key_exists($option->getKey(), $value)) { 347 + $value = '<em>'.pht('(empty)').'</em>'; 348 + } else { 349 + $value = $this->prettyPrintJSON($value[$option->getKey()]); 350 + } 351 + 352 + $table[] = '<tr>'; 353 + $table[] = '<th>'.phutil_escape_html($source->getName()).'</th>'; 354 + $table[] = '<td>'.$value.'</td>'; 317 355 $table[] = '</tr>'; 318 356 } 319 357 ··· 322 360 return phutil_render_tag( 323 361 'table', 324 362 array( 325 - 'class' => 'config-option-examples', 363 + 'class' => 'config-option-table', 326 364 ), 327 365 implode("\n", $table)); 328 366 }
+16
src/infrastructure/env/PhabricatorConfigDefaultSource.php
··· 1 + <?php 2 + 3 + /** 4 + * Configuration source which reads from defaults defined in the authoritative 5 + * configuration definitions. 6 + */ 7 + final class PhabricatorConfigDefaultSource 8 + extends PhabricatorConfigProxySource { 9 + 10 + public function __construct() { 11 + $options = PhabricatorApplicationConfigOptions::loadAllOptions(); 12 + $options = mpull($options, 'getDefault'); 13 + $this->setSource(new PhabricatorConfigDictionarySource($options)); 14 + } 15 + 16 + }
+13 -2
src/infrastructure/env/PhabricatorConfigProxySource.php
··· 33 33 } 34 34 35 35 public function setKeys(array $keys) { 36 - return $this->getSource()->setKeys($keys); 36 + $this->getSource()->setKeys($keys); 37 + return $this; 37 38 } 38 39 39 40 public function deleteKeys(array $keys) { 40 - return $this->getSource()->deleteKeys(); 41 + $this->getSource()->deleteKeys(); 42 + return $this; 43 + } 44 + 45 + public function setName($name) { 46 + $this->getSource()->setName($name); 47 + return $this; 48 + } 49 + 50 + public function getName() { 51 + return $this->getSource()->getName(); 41 52 } 42 53 43 54 }
+11
src/infrastructure/env/PhabricatorConfigSource.php
··· 2 2 3 3 abstract class PhabricatorConfigSource { 4 4 5 + private $name; 6 + 7 + public function setName($name) { 8 + $this->name = $name; 9 + return $this; 10 + } 11 + 12 + public function getName() { 13 + return $this->name; 14 + } 15 + 5 16 abstract public function getKeys(array $keys); 6 17 abstract public function getAllKeys(); 7 18
+4
src/infrastructure/env/PhabricatorConfigStackSource.php
··· 24 24 return array_shift($this->stack); 25 25 } 26 26 27 + public function getStack() { 28 + return $this->stack; 29 + } 30 + 27 31 public function getKeys(array $keys) { 28 32 $result = array(); 29 33 foreach ($this->stack as $source) {
+22 -2
src/infrastructure/env/PhabricatorEnv.php
··· 96 96 private static function initializeCommonEnvironment() { 97 97 $env = self::getSelectedEnvironmentName(); 98 98 99 - self::$sourceStack = new PhabricatorConfigStackSource(); 100 - self::$sourceStack->pushSource(new PhabricatorConfigFileSource($env)); 99 + self::buildConfigurationSourceStack(); 101 100 102 101 PhutilErrorHandler::initialize(); 103 102 ··· 124 123 PhutilTranslator::getInstance() 125 124 ->setLanguage($translation->getLanguage()) 126 125 ->addTranslations($translation->getTranslations()); 126 + } 127 + 128 + private static function buildConfigurationSourceStack() { 129 + $stack = new PhabricatorConfigStackSource(); 130 + self::$sourceStack = $stack; 131 + 132 + $stack->pushSource( 133 + id(new PhabricatorConfigDefaultSource()) 134 + ->setName(pht('Global Default'))); 135 + 136 + $env = self::getSelectedEnvironmentName(); 137 + $stack->pushSource( 138 + id(new PhabricatorConfigFileSource($env)) 139 + ->setName(pht("File '%s'", $env))); 140 + 141 + $stack->pushSource( 142 + id(new PhabricatorConfigLocalSource()) 143 + ->setName(pht("Local Config"))); 127 144 } 128 145 129 146 public static function getSelectedEnvironmentName() { ··· 398 415 return self::$sourceStack->getAllKeys(); 399 416 } 400 417 418 + public static function getConfigSourceStack() { 419 + return self::$sourceStack; 420 + } 401 421 402 422 /** 403 423 * @task internal
+17 -9
webroot/rsrc/css/application/config/config-options.css
··· 2 2 * @provides config-options-css 3 3 */ 4 4 5 - .config-option-examples { 5 + .config-option-table { 6 6 width: 100%; 7 7 border-collapse: collapse; 8 8 border: 1px solid #cccccc; 9 9 } 10 10 11 - .config-option-examples th, 12 - .config-option-examples td { 13 - padding: 4px 6px; 11 + .config-option-table th, 12 + .config-option-table td { 13 + padding: 4px 12px; 14 14 border: 1px solid #cccccc; 15 15 } 16 16 17 - .config-option-examples th { 18 - background: #dfdfdf; 17 + .config-option-table th { 18 + background: #e9e9e9; 19 19 text-align: right; 20 - font-weight: bold; 20 + white-space: nowrap; 21 21 } 22 22 23 - .config-option-examples th em { 23 + .config-option-table th em { 24 24 font-weight: normal; 25 25 color: #666666; 26 26 } 27 27 28 - .config-option-examples td { 28 + .config-option-table td { 29 + color: #333333; 30 + width: 100%; 31 + } 32 + 33 + .config-option-table .column-labels th { 34 + font-weight: bold; 29 35 color: #333333; 36 + text-align: center; 37 + background: #e0e0e0; 30 38 } 31 39 32 40