public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $db_values = id(new PhabricatorConfigEntry())->loadAllWhere('namespace = %s', 'default');
     $db_values = mpull($db_values, null, 'getConfigKey');
     $rows = array();
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     ksort($options);
     foreach ($options as $option) {
         $key = $option->getKey();
         if ($option->getHidden()) {
             $value = phutil_tag('em', array(), pht('Hidden'));
         } else {
             $value = PhabricatorEnv::getEnvConfig($key);
             $value = PhabricatorConfigJSON::prettyPrintJSON($value);
         }
         $db_value = idx($db_values, $key);
         $rows[] = array(phutil_tag('a', array('href' => $this->getApplicationURI('edit/' . $key . '/')), $key), $value, $db_value && !$db_value->getIsDeleted() ? pht('Customized') : '');
     }
     $table = id(new AphrontTableView($rows))->setColumnClasses(array('', 'wide'))->setHeaders(array(pht('Key'), pht('Value'), pht('Customized')));
     $title = pht('Current Settings');
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($title);
     $panel = new PHUIObjectBoxView();
     $panel->setHeaderText(pht('Current Settings'));
     $panel->setTable($table);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('all/');
     $view = id(new PHUITwoColumnView())->setNavigation($nav)->setMainColumn(array($panel));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function getDisplayValue(PhabricatorConfigOption $option, PhabricatorConfigEntry $entry, $value)
 {
     if (is_array($value)) {
         return PhabricatorConfigJSON::prettyPrintJSON($value);
     } else {
         return $value;
     }
 }
 protected function buildAlmanacPropertiesTable(AlmanacPropertyInterface $object)
 {
     $viewer = $this->getViewer();
     $properties = $object->getAlmanacProperties();
     $this->requireResource('almanac-css');
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $object, PhabricatorPolicyCapability::CAN_EDIT);
     $field_list = PhabricatorCustomField::getObjectFields($object, PhabricatorCustomField::ROLE_DEFAULT);
     // Before reading values from the object, read defaults.
     $defaults = mpull($field_list->getFields(), 'getValueForStorage', 'getFieldKey');
     $field_list->setViewer($viewer)->readFieldsFromStorage($object);
     Javelin::initBehavior('phabricator-tooltips', array());
     $icon_builtin = id(new PHUIIconView())->setIcon('fa-circle')->addSigil('has-tooltip')->setMetadata(array('tip' => pht('Builtin Property'), 'align' => 'E'));
     $icon_custom = id(new PHUIIconView())->setIcon('fa-circle-o grey')->addSigil('has-tooltip')->setMetadata(array('tip' => pht('Custom Property'), 'align' => 'E'));
     $builtins = $object->getAlmanacPropertyFieldSpecifications();
     // Sort fields so builtin fields appear first, then fields are ordered
     // alphabetically.
     $fields = $field_list->getFields();
     $fields = msort($fields, 'getFieldKey');
     $head = array();
     $tail = array();
     foreach ($fields as $field) {
         $key = $field->getFieldKey();
         if (isset($builtins[$key])) {
             $head[$key] = $field;
         } else {
             $tail[$key] = $field;
         }
     }
     $fields = $head + $tail;
     $rows = array();
     foreach ($fields as $key => $field) {
         $value = $field->getValueForStorage();
         $is_builtin = isset($builtins[$key]);
         $delete_uri = $this->getApplicationURI('property/delete/');
         $delete_uri = id(new PhutilURI($delete_uri))->setQueryParams(array('objectPHID' => $object->getPHID(), 'key' => $key));
         $edit_uri = $this->getApplicationURI('property/edit/');
         $edit_uri = id(new PhutilURI($edit_uri))->setQueryParams(array('objectPHID' => $object->getPHID(), 'key' => $key));
         $delete = javelin_tag('a', array('class' => $can_edit ? 'button grey small' : 'button grey small disabled', 'sigil' => 'workflow', 'href' => $delete_uri), $is_builtin ? pht('Reset') : pht('Delete'));
         $default = idx($defaults, $key);
         $is_default = $default !== null && $default === $value;
         $display_value = PhabricatorConfigJSON::prettyPrintJSON($value);
         if ($is_default) {
             $display_value = phutil_tag('span', array('class' => 'almanac-default-property-value'), $display_value);
         }
         $display_key = $key;
         if ($can_edit) {
             $display_key = javelin_tag('a', array('href' => $edit_uri, 'sigil' => 'workflow'), $display_key);
         }
         $rows[] = array($is_builtin ? $icon_builtin : $icon_custom, $display_key, $display_value, $delete);
     }
     $table = id(new AphrontTableView($rows))->setNoDataString(pht('No properties.'))->setHeaders(array(null, pht('Name'), pht('Value'), null))->setColumnClasses(array(null, null, 'wide', 'action'));
     $phid = $object->getPHID();
     $add_uri = $this->getApplicationURI("property/edit/?objectPHID={$phid}");
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $object, PhabricatorPolicyCapability::CAN_EDIT);
     $add_button = id(new PHUIButtonView())->setTag('a')->setHref($add_uri)->setWorkflow(true)->setDisabled(!$can_edit)->setText(pht('Add Property'))->setIcon('fa-plus');
     $header = id(new PHUIHeaderView())->setHeader(pht('Properties'))->addActionLink($add_button);
     return id(new PHUIObjectBoxView())->setHeader($header)->setTable($table);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $db_values = id(new PhabricatorConfigEntry())->loadAllWhere('namespace = %s', 'default');
     $db_values = mpull($db_values, null, 'getConfigKey');
     $rows = array();
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     ksort($options);
     foreach ($options as $option) {
         $key = $option->getKey();
         if ($option->getMasked()) {
             $value = phutil_tag('em', array(), pht('Masked'));
         } else {
             if ($option->getHidden()) {
                 $value = phutil_tag('em', array(), pht('Hidden'));
             } else {
                 $value = PhabricatorEnv::getEnvConfig($key);
                 $value = PhabricatorConfigJSON::prettyPrintJSON($value);
             }
         }
         $db_value = idx($db_values, $key);
         $rows[] = array(phutil_tag('a', array('href' => $this->getApplicationURI('edit/' . $key . '/')), $key), $value, $db_value && !$db_value->getIsDeleted() ? pht('Customized') : '');
     }
     $table = id(new AphrontTableView($rows))->setColumnClasses(array('', 'wide'))->setHeaders(array(pht('Key'), pht('Value'), pht('Customized')));
     $title = pht('Current Settings');
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($title);
     $panel = new PHUIObjectBoxView();
     $panel->setHeaderText(pht('Current Settings'));
     $panel->appendChild($table);
     $versions = $this->loadVersions();
     $version_property_list = id(new PHUIPropertyListView());
     foreach ($versions as $version) {
         list($name, $hash) = $version;
         $version_property_list->addProperty($name, $hash);
     }
     $object_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Current Version'))->addPropertyList($version_property_list);
     $phabricator_root = dirname(phutil_get_library_root('phabricator'));
     $version_path = $phabricator_root . '/conf/local/VERSION';
     if (Filesystem::pathExists($version_path)) {
         $version_from_file = Filesystem::readFile($version_path);
         $version_property_list->addProperty(pht('Local Version'), $version_from_file);
     }
     $nav = $this->buildSideNavView();
     $nav->selectFilter('all/');
     $nav->setCrumbs($crumbs);
     $nav->appendChild($object_box);
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => $title));
 }
 public function renderChangeDetails(PhabricatorUser $viewer)
 {
     $old = $this->getOldValue();
     $new = $this->getNewValue();
     if ($old['deleted']) {
         $old_text = '';
     } else {
         $old_text = PhabricatorConfigJSON::prettyPrintJSON($old['value']);
     }
     if ($new['deleted']) {
         $new_text = '';
     } else {
         $new_text = PhabricatorConfigJSON::prettyPrintJSON($new['value']);
     }
     return $this->renderTextCorpusChangeDetails($viewer, $old_text, $new_text);
 }
 private function buildOptionList(array $options)
 {
     assert_instances_of($options, 'PhabricatorConfigOption');
     require_celerity_resource('config-options-css');
     $db_values = array();
     if ($options) {
         $db_values = id(new PhabricatorConfigEntry())->loadAllWhere('configKey IN (%Ls) AND namespace = %s', mpull($options, 'getKey'), 'default');
         $db_values = mpull($db_values, null, 'getConfigKey');
     }
     $engine = id(new PhabricatorMarkupEngine())->setViewer($this->getRequest()->getUser());
     foreach ($options as $option) {
         $engine->addObject($option, 'summary');
     }
     $engine->process();
     $list = new PHUIObjectItemListView();
     $list->setBig(true);
     foreach ($options as $option) {
         $summary = $engine->getOutput($option, 'summary');
         $item = id(new PHUIObjectItemView())->setHeader($option->getKey())->setHref('/config/edit/' . $option->getKey() . '/')->addAttribute($summary);
         $label = pht('Current Value:');
         $color = null;
         $db_value = idx($db_values, $option->getKey());
         if ($db_value && !$db_value->getIsDeleted()) {
             $item->setEffect('visited');
             $color = 'violet';
             $label = pht('Customized Value:');
         }
         if ($option->getHidden()) {
             $item->setStatusIcon('fa-eye-slash grey', pht('Hidden'));
             $item->setDisabled(true);
         } else {
             if ($option->getLocked()) {
                 $item->setStatusIcon('fa-lock ' . $color, pht('Locked'));
             } else {
                 $item->setStatusIcon('fa-pencil-square-o ' . $color, pht('Editable'));
             }
         }
         if (!$option->getHidden()) {
             $current_value = PhabricatorEnv::getEnvConfig($option->getKey());
             $current_value = PhabricatorConfigJSON::prettyPrintJSON($current_value);
             $current_value = phutil_tag('div', array('class' => 'config-options-current-value'), array(phutil_tag('span', array(), $label), ' ' . $current_value));
             $item->appendChild($current_value);
         }
         $list->addItem($item);
     }
     return $list;
 }
 private function renderValueForDisplay($value)
 {
     if ($value === null) {
         return phutil_tag('em', array(), 'null');
     } else {
         if ($value === false) {
             return phutil_tag('em', array(), 'false');
         } else {
             if ($value === true) {
                 return phutil_tag('em', array(), 'true');
             } else {
                 if ($value === '') {
                     return phutil_tag('em', array(), 'empty string');
                 } else {
                     if ($value instanceof PhutilSafeHTML) {
                         return $value;
                     } else {
                         return PhabricatorConfigJSON::prettyPrintJSON($value);
                     }
                 }
             }
         }
     }
 }
 private function getDisplayValue(PhabricatorConfigOption $option, PhabricatorConfigEntry $entry, $value)
 {
     if ($option->isCustomType()) {
         return $option->getCustomObject()->getDisplayValue($option, $entry, $value);
     } else {
         $type = $option->getType();
         switch ($type) {
             case 'int':
             case 'string':
             case 'enum':
             case 'class':
                 return $value;
             case 'bool':
                 return $value ? 'true' : 'false';
             case 'list<string>':
             case 'list<regex>':
                 return implode("\n", nonempty($value, array()));
             case 'set':
                 return implode("\n", nonempty(array_keys($value), array()));
             default:
                 return PhabricatorConfigJSON::prettyPrintJSON($value);
         }
     }
 }