Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2889765
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/config/controller/PhabricatorConfigController.php b/src/applications/config/controller/PhabricatorConfigController.php
index a94cb7fe4c..01197efa5c 100644
--- a/src/applications/config/controller/PhabricatorConfigController.php
+++ b/src/applications/config/controller/PhabricatorConfigController.php
@@ -1,27 +1,43 @@
<?php
abstract class PhabricatorConfigController extends PhabricatorController {
public function shouldRequireAdmin() {
return true;
}
public function buildSideNavView($filter = null, $for_app = false) {
$user = $this->getRequest()->getUser();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI('filter/')));
return $nav;
}
public function buildApplicationMenu() {
return $this->buildSideNavView(null, true)->getMenu();
}
public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
return $crumbs;
}
+ /**
+ * Properly format a JSON value.
+ *
+ * @param wild Any value, but should be a raw value, not a string of JSON.
+ * @return string
+ */
+ public function prettyPrintJSON($value) {
+ // Check not only that it's an array, but that it's an "unnatural" array
+ // meaning that the keys aren't 0 -> size_of_array.
+ if (is_array($value) && array_keys($value) != range(0, count($value) - 1)) {
+ return id(new PhutilJSON())->encodeFormatted($value);
+ } else {
+ return json_encode($value);
+ }
+ }
+
}
diff --git a/src/applications/config/controller/PhabricatorConfigEditController.php b/src/applications/config/controller/PhabricatorConfigEditController.php
index 3960c44408..2145eaf416 100644
--- a/src/applications/config/controller/PhabricatorConfigEditController.php
+++ b/src/applications/config/controller/PhabricatorConfigEditController.php
@@ -1,124 +1,134 @@
<?php
final class PhabricatorConfigEditController
extends PhabricatorConfigController {
private $key;
public function willProcessRequest(array $data) {
$this->key = idx($data, 'key');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$config = id(new PhabricatorConfigFileSource('default'))
->getAllKeys();
if (!$this->key || !array_key_exists($this->key, $config)) {
return new Aphront404Response();
}
+ $default = $this->prettyPrintJSON($config[$this->key]);
+
// Check if the config key is already stored in the database.
// Grab the value if it is.
$value = null;
$config_entry = id(new PhabricatorConfigEntry())
->loadOneWhere(
'configKey = %s AND namespace=%s',
$this->key,
'default');
if ($config_entry) {
$value = $config_entry->getValue();
} else {
$config_entry = id(new PhabricatorConfigEntry())
->setConfigKey($this->key);
}
$e_value = null;
$errors = array();
if ($request->isFormPost()) {
$new_value = $request->getStr('value');
if (strlen($new_value)) {
$json = json_decode($new_value, true);
if ($json === null && strtolower($value) != 'null') {
$e_value = 'Invalid';
$errors[] = 'The given value must be valid JSON. This means, among '.
'other things, that you must wrap strings in double-quotes.';
$value = $new_value;
} else {
$value = $json;
}
} else {
// TODO: When we do Transactions, make this just set isDeleted = 1
$config_entry->delete();
}
$config_entry->setValue($value);
$config_entry->setNamespace('default');
if (!$errors) {
$config_entry->save();
return id(new AphrontRedirectResponse())
->setURI($config_entry->getURI());
}
}
$form = new AphrontFormView();
$form->setFlexible(true);
$error_view = null;
if ($errors) {
$error_view = id(new AphrontErrorView())
->setTitle('You broke everything!')
->setErrors($errors);
} else {
- // Check not only that it's an array, but that it's an "unnatural" array
- // meaning that the keys aren't 0 -> size_of_array.
- if (is_array($value) &&
- array_keys($value) != range(0, count($value) - 1)) {
- $value = id(new PhutilJSON())->encodeFormatted($value);
- } else {
- $value = json_encode($value);
- }
+ $value = $this->prettyPrintJSON($value);
}
$form
->setUser($user)
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel('JSON Value')
->setError($e_value)
->setValue($value)
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
->setCustomClass('PhabricatorMonospaced')
- ->setName('value'))
+ ->setName('value'))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($config_entry->getURI())
- ->setValue(pht('Save Config Entry')));
+ ->setValue(pht('Save Config Entry')))
+ ->appendChild(
+ phutil_render_tag(
+ 'p',
+ array(
+ 'class' => 'aphront-form-input',
+ ),
+ 'If left blank, the setting will return to its default value. '.
+ 'Its default value is:'))
+ ->appendChild(
+ phutil_render_tag(
+ 'pre',
+ array(
+ 'class' => 'aphront-form-input',
+ ),
+ phutil_escape_html($default)));
$title = pht('Edit %s', $this->key);
$short = pht('Edit');
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName($this->key)
->setHref('/config/edit/'.$this->key));
$crumbs->addCrumb(
id(new PhabricatorCrumbView())->setName($short));
return $this->buildApplicationPage(
array(
$crumbs,
id(new PhabricatorHeaderView())->setHeader($title),
$error_view,
$form,
),
array(
'title' => $title,
'device' => true,
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 12:37 (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1124643
Default Alt Text
(6 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment