private function buildDocument(PhabricatorMarkupEngine $engine, LegalpadDocumentBody $body)
 {
     $view = new PHUIPropertyListView();
     $view->addClass('legalpad');
     $view->addSectionHeader(pht('Document'));
     $view->addTextContent($engine->getOutput($body, LegalpadDocumentBody::MARKUP_FIELD_TEXT));
     return $view;
 }
 private function buildPropertyView(PholioMock $mock, PhabricatorMarkupEngine $engine, PhabricatorActionListView $actions)
 {
     $viewer = $this->getViewer();
     $properties = id(new PHUIPropertyListView())->setUser($viewer)->setObject($mock)->setActionList($actions);
     $properties->addProperty(pht('Author'), $viewer->renderHandle($mock->getAuthorPHID()));
     $properties->addProperty(pht('Created'), phabricator_datetime($mock->getDateCreated(), $viewer));
     if ($this->getManiphestTaskPHIDs()) {
         $properties->addProperty(pht('Maniphest Tasks'), $viewer->renderHandleList($this->getManiphestTaskPHIDs()));
     }
     $properties->invokeWillRenderEvent();
     $properties->addSectionHeader(pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
     $properties->addImageContent($engine->getOutput($mock, PholioMock::MARKUP_FIELD_DESCRIPTION));
     return $properties;
 }
 private function buildDocumentView(LegalpadDocument $document, PhabricatorMarkupEngine $engine)
 {
     $viewer = $this->getViewer();
     $view = id(new PHUIPropertyListView())->setUser($viewer);
     $document_body = $document->getDocumentBody();
     $document_text = $engine->getOutput($document_body, LegalpadDocumentBody::MARKUP_FIELD_TEXT);
     $preamble_box = null;
     if (strlen($document->getPreamble())) {
         $preamble_text = new PHUIRemarkupView($viewer, $document->getPreamble());
         $view->addTextContent($preamble_text);
         $view->addSectionHeader('');
         $view->addTextContent($document_text);
     } else {
         $view->addTextContent($document_text);
     }
     return id(new PHUIObjectBoxView())->setHeaderText(pht('DOCUMENT'))->addPropertyList($view)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
 }
Ejemplo n.º 4
0
 public function renderPropertyViewValue(array $handles)
 {
     $diff = $this->getObject()->getActiveDiff();
     $ustar = DifferentialRevisionUpdateHistoryView::renderDiffUnitStar($diff);
     $umsg = DifferentialRevisionUpdateHistoryView::getDiffUnitMessage($diff);
     $rows = array();
     $rows[] = array('style' => 'star', 'name' => $ustar, 'value' => $umsg, 'show' => true);
     $excuse = $diff->getProperty('arc:unit-excuse');
     if ($excuse) {
         $rows[] = array('style' => 'excuse', 'name' => 'Excuse', 'value' => phutil_escape_html_newlines($excuse), 'show' => true);
     }
     $show_limit = 10;
     $hidden = array();
     $udata = $diff->getProperty('arc:unit');
     if ($udata) {
         $sort_map = array(ArcanistUnitTestResult::RESULT_BROKEN => 0, ArcanistUnitTestResult::RESULT_FAIL => 1, ArcanistUnitTestResult::RESULT_UNSOUND => 2, ArcanistUnitTestResult::RESULT_SKIP => 3, ArcanistUnitTestResult::RESULT_POSTPONED => 4, ArcanistUnitTestResult::RESULT_PASS => 5);
         foreach ($udata as $key => $test) {
             $udata[$key]['sort'] = idx($sort_map, idx($test, 'result'));
         }
         $udata = isort($udata, 'sort');
         $engine = new PhabricatorMarkupEngine();
         $engine->setViewer($this->getViewer());
         $markup_objects = array();
         foreach ($udata as $key => $test) {
             $userdata = idx($test, 'userdata');
             if ($userdata) {
                 if ($userdata !== false) {
                     $userdata = str_replace("", '', $userdata);
                 }
                 $markup_object = id(new PhabricatorMarkupOneOff())->setContent($userdata)->setPreserveLinebreaks(true);
                 $engine->addObject($markup_object, 'default');
                 $markup_objects[$key] = $markup_object;
             }
         }
         $engine->process();
         foreach ($udata as $key => $test) {
             $result = idx($test, 'result');
             $default_hide = false;
             switch ($result) {
                 case ArcanistUnitTestResult::RESULT_POSTPONED:
                 case ArcanistUnitTestResult::RESULT_PASS:
                     $default_hide = true;
                     break;
             }
             if ($show_limit && !$default_hide) {
                 --$show_limit;
                 $show = true;
             } else {
                 $show = false;
                 if (empty($hidden[$result])) {
                     $hidden[$result] = 0;
                 }
                 $hidden[$result]++;
             }
             $value = idx($test, 'name');
             if (!empty($test['link'])) {
                 $value = phutil_tag('a', array('href' => $test['link'], 'target' => '_blank'), $value);
             }
             $rows[] = array('style' => $this->getResultStyle($result), 'name' => ucwords($result), 'value' => $value, 'show' => $show);
             if (isset($markup_objects[$key])) {
                 $rows[] = array('style' => 'details', 'value' => $engine->getOutput($markup_objects[$key], 'default'), 'show' => false);
                 if (empty($hidden['details'])) {
                     $hidden['details'] = 0;
                 }
                 $hidden['details']++;
             }
         }
     }
     $show_string = $this->renderShowString($hidden);
     $view = new DifferentialResultsTableView();
     $view->setRows($rows);
     $view->setShowMoreString($show_string);
     return $view->render();
 }
Ejemplo n.º 5
0
 private function renderDocumentationText(DivinerLiveSymbol $symbol, PhabricatorMarkupEngine $engine)
 {
     $field = 'default';
     $content = $engine->getOutput($symbol, $field);
     if (strlen(trim($symbol->getMarkupText($field)))) {
         $content = phutil_tag('div', array('class' => 'phabricator-remarkup diviner-remarkup-section'), $content);
     } else {
         $atom = $symbol->getAtom();
         $content = phutil_tag('div', array('class' => 'diviner-message-not-documented'), DivinerAtom::getThisAtomIsNotDocumentedString($atom->getType()));
     }
     return $content;
 }
 private function buildDescriptionView(ManiphestTask $task, PhabricatorMarkupEngine $engine)
 {
     $section = null;
     if (strlen($task->getDescription())) {
         $section = new PHUIPropertyListView();
         $section->addSectionHeader(pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
         $section->addTextContent(phutil_tag('div', array('class' => 'phabricator-remarkup'), $engine->getOutput($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION)));
     }
     return $section;
 }
Ejemplo n.º 7
0
 /**
  * Given @{class:PhabricatorFeedStoryData} rows, load them into objects and
  * construct appropriate @{class:PhabricatorFeedStory} wrappers for each
  * data row.
  *
  * @param list<dict>  List of @{class:PhabricatorFeedStoryData} rows from the
  *                    database.
  * @return list<PhabricatorFeedStory>   List of @{class:PhabricatorFeedStory}
  *                                      objects.
  * @task load
  */
 public static function loadAllFromRows(array $rows, PhabricatorUser $viewer)
 {
     $stories = array();
     $data = id(new PhabricatorFeedStoryData())->loadAllFromArray($rows);
     foreach ($data as $story_data) {
         $class = $story_data->getStoryType();
         try {
             $ok = class_exists($class) && is_subclass_of($class, __CLASS__);
         } catch (PhutilMissingSymbolException $ex) {
             $ok = false;
         }
         // If the story type isn't a valid class or isn't a subclass of
         // PhabricatorFeedStory, decline to load it.
         if (!$ok) {
             continue;
         }
         $key = $story_data->getChronologicalKey();
         $stories[$key] = newv($class, array($story_data));
     }
     $object_phids = array();
     $key_phids = array();
     foreach ($stories as $key => $story) {
         $phids = array();
         foreach ($story->getRequiredObjectPHIDs() as $phid) {
             $phids[$phid] = true;
         }
         if ($story->getPrimaryObjectPHID()) {
             $phids[$story->getPrimaryObjectPHID()] = true;
         }
         $key_phids[$key] = $phids;
         $object_phids += $phids;
     }
     $object_query = id(new PhabricatorObjectQuery())->setViewer($viewer)->withPHIDs(array_keys($object_phids));
     $objects = $object_query->execute();
     foreach ($key_phids as $key => $phids) {
         if (!$phids) {
             continue;
         }
         $story_objects = array_select_keys($objects, array_keys($phids));
         if (count($story_objects) != count($phids)) {
             // An object this story requires either does not exist or is not visible
             // to the user. Decline to render the story.
             unset($stories[$key]);
             unset($key_phids[$key]);
             continue;
         }
         $stories[$key]->setObjects($story_objects);
     }
     // If stories are about PhabricatorProjectInterface objects, load the
     // projects the objects are a part of so we can render project tags
     // on the stories.
     $project_phids = array();
     foreach ($objects as $object) {
         if ($object instanceof PhabricatorProjectInterface) {
             $project_phids[$object->getPHID()] = array();
         }
     }
     if ($project_phids) {
         $edge_query = id(new PhabricatorEdgeQuery())->withSourcePHIDs(array_keys($project_phids))->withEdgeTypes(array(PhabricatorProjectObjectHasProjectEdgeType::EDGECONST));
         $edge_query->execute();
         foreach ($project_phids as $phid => $ignored) {
             $project_phids[$phid] = $edge_query->getDestinationPHIDs(array($phid));
         }
     }
     $handle_phids = array();
     foreach ($stories as $key => $story) {
         foreach ($story->getRequiredHandlePHIDs() as $phid) {
             $key_phids[$key][$phid] = true;
         }
         if ($story->getAuthorPHID()) {
             $key_phids[$key][$story->getAuthorPHID()] = true;
         }
         $object_phid = $story->getPrimaryObjectPHID();
         $object_project_phids = idx($project_phids, $object_phid, array());
         $story->setProjectPHIDs($object_project_phids);
         foreach ($object_project_phids as $dst) {
             $key_phids[$key][$dst] = true;
         }
         $handle_phids += $key_phids[$key];
     }
     // NOTE: This setParentQuery() is a little sketchy. Ideally, this whole
     // method should be inside FeedQuery and it should be the parent query of
     // both subqueries. We're just trying to share the workspace cache.
     $handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->setParentQuery($object_query)->withPHIDs(array_keys($handle_phids))->execute();
     foreach ($key_phids as $key => $phids) {
         if (!$phids) {
             continue;
         }
         $story_handles = array_select_keys($handles, array_keys($phids));
         $stories[$key]->setHandles($story_handles);
     }
     // Load and process story markup blocks.
     $engine = new PhabricatorMarkupEngine();
     $engine->setViewer($viewer);
     foreach ($stories as $story) {
         foreach ($story->getFieldStoryMarkupFields() as $field) {
             $engine->addObject($story, $field);
         }
     }
     $engine->process();
     foreach ($stories as $story) {
         foreach ($story->getFieldStoryMarkupFields() as $field) {
             $story->setMarkupFieldOutput($field, $engine->getOutput($story, $field));
         }
     }
     return $stories;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     if (empty($options[$this->key])) {
         $ancient = PhabricatorExtraConfigSetupCheck::getAncientConfig();
         if (isset($ancient[$this->key])) {
             $desc = pht("This configuration has been removed. You can safely delete " . "it.\n\n%s", $ancient[$this->key]);
         } else {
             $desc = pht('This configuration option is unknown. It may be misspelled, ' . 'or have existed in a previous version of Phabricator.');
         }
         // This may be a dead config entry, which existed in the past but no
         // longer exists. Allow it to be edited so it can be reviewed and
         // deleted.
         $option = id(new PhabricatorConfigOption())->setKey($this->key)->setType('wild')->setDefault(null)->setDescription($desc);
         $group = null;
         $group_uri = $this->getApplicationURI();
     } else {
         $option = $options[$this->key];
         $group = $option->getGroup();
         $group_uri = $this->getApplicationURI('group/' . $group->getKey() . '/');
     }
     $issue = $request->getStr('issue');
     if ($issue) {
         // If the user came here from an open setup issue, send them back.
         $done_uri = $this->getApplicationURI('issue/' . $issue . '/');
     } else {
         $done_uri = $group_uri;
     }
     // Check if the config key is already stored in the database.
     // Grab the value if it is.
     $config_entry = id(new PhabricatorConfigEntry())->loadOneWhere('configKey = %s AND namespace = %s', $this->key, 'default');
     if (!$config_entry) {
         $config_entry = id(new PhabricatorConfigEntry())->setConfigKey($this->key)->setNamespace('default')->setIsDeleted(true);
         $config_entry->setPHID($config_entry->generatePHID());
     }
     $e_value = null;
     $errors = array();
     if ($request->isFormPost() && !$option->getLocked()) {
         $result = $this->readRequest($option, $request);
         list($e_value, $value_errors, $display_value, $xaction) = $result;
         $errors = array_merge($errors, $value_errors);
         if (!$errors) {
             $editor = id(new PhabricatorConfigEditor())->setActor($user)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request);
             try {
                 $editor->applyTransactions($config_entry, array($xaction));
                 return id(new AphrontRedirectResponse())->setURI($done_uri);
             } catch (PhabricatorConfigValidationException $ex) {
                 $e_value = pht('Invalid');
                 $errors[] = $ex->getMessage();
             }
         }
     } else {
         if ($config_entry->getIsDeleted()) {
             $display_value = null;
         } else {
             $display_value = $this->getDisplayValue($option, $config_entry, $config_entry->getValue());
         }
     }
     $form = new AphrontFormView();
     $error_view = null;
     if ($errors) {
         $error_view = id(new PHUIInfoView())->setErrors($errors);
     } else {
         if ($option->getHidden()) {
             $msg = pht('This configuration is hidden and can not be edited or viewed from ' . 'the web interface.');
             $error_view = id(new PHUIInfoView())->setTitle(pht('Configuration Hidden'))->setSeverity(PHUIInfoView::SEVERITY_WARNING)->appendChild(phutil_tag('p', array(), $msg));
         } else {
             if ($option->getLocked()) {
                 $msg = $option->getLockedMessage();
                 $error_view = id(new PHUIInfoView())->setTitle(pht('Configuration Locked'))->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->appendChild(phutil_tag('p', array(), $msg));
             }
         }
     }
     if ($option->getHidden()) {
         $control = null;
     } else {
         $control = $this->renderControl($option, $display_value, $e_value);
     }
     $engine = new PhabricatorMarkupEngine();
     $engine->setViewer($user);
     $engine->addObject($option, 'description');
     $engine->process();
     $description = phutil_tag('div', array('class' => 'phabricator-remarkup'), $engine->getOutput($option, 'description'));
     $form->setUser($user)->addHiddenInput('issue', $request->getStr('issue'))->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Description'))->setValue($description));
     if ($group) {
         $extra = $group->renderContextualDescription($option, $request);
         if ($extra !== null) {
             $form->appendChild(id(new AphrontFormMarkupControl())->setValue($extra));
         }
     }
     $form->appendChild($control);
     $submit_control = id(new AphrontFormSubmitControl())->addCancelButton($done_uri);
     if (!$option->getLocked()) {
         $submit_control->setValue(pht('Save Config Entry'));
     }
     $form->appendChild($submit_control);
     $examples = $this->renderExamples($option);
     if ($examples) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Examples'))->setValue($examples));
     }
     if (!$option->getHidden()) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Default'))->setValue($this->renderDefaults($option, $config_entry)));
     }
     $title = pht('Edit %s', $this->key);
     $short = pht('Edit');
     $form_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setForm($form);
     if ($error_view) {
         $form_box->setInfoView($error_view);
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Config'), $this->getApplicationURI());
     if ($group) {
         $crumbs->addTextCrumb($group->getName(), $group_uri);
     }
     $crumbs->addTextCrumb($this->key, '/config/edit/' . $this->key);
     $timeline = $this->buildTransactionTimeline($config_entry, new PhabricatorConfigTransactionQuery());
     $timeline->setShouldTerminate(true);
     return $this->buildApplicationPage(array($crumbs, $form_box, $timeline), array('title' => $title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $e_title = null;
     $priority_map = ManiphestTaskPriority::getTaskPriorityMap();
     $task = id(new ManiphestTask())->load($this->id);
     if (!$task) {
         return new Aphront404Response();
     }
     $workflow = $request->getStr('workflow');
     $parent_task = null;
     if ($workflow && is_numeric($workflow)) {
         $parent_task = id(new ManiphestTask())->load($workflow);
     }
     $transactions = id(new ManiphestTransaction())->loadAllWhere('taskID = %d ORDER BY id ASC', $task->getID());
     $e_commit = PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT;
     $e_dep_on = PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK;
     $e_dep_by = PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK;
     $e_rev = PhabricatorEdgeConfig::TYPE_TASK_HAS_RELATED_DREV;
     $phid = $task->getPHID();
     $query = id(new PhabricatorEdgeQuery())->withSourcePHIDs(array($phid))->withEdgeTypes(array($e_commit, $e_dep_on, $e_dep_by, $e_rev));
     $edges = $query->execute();
     $commit_phids = array_keys($edges[$phid][$e_commit]);
     $dep_on_tasks = array_keys($edges[$phid][$e_dep_on]);
     $dep_by_tasks = array_keys($edges[$phid][$e_dep_by]);
     $revs = array_keys($edges[$phid][$e_rev]);
     $phids = array_fill_keys($query->getDestinationPHIDs(), true);
     foreach ($transactions as $transaction) {
         foreach ($transaction->extractPHIDs() as $phid) {
             $phids[$phid] = true;
         }
     }
     foreach ($task->getCCPHIDs() as $phid) {
         $phids[$phid] = true;
     }
     foreach ($task->getProjectPHIDs() as $phid) {
         $phids[$phid] = true;
     }
     if ($task->getOwnerPHID()) {
         $phids[$task->getOwnerPHID()] = true;
     }
     $phids[$task->getAuthorPHID()] = true;
     $attached = $task->getAttached();
     foreach ($attached as $type => $list) {
         foreach ($list as $phid => $info) {
             $phids[$phid] = true;
         }
     }
     if ($parent_task) {
         $phids[$parent_task->getPHID()] = true;
     }
     $phids = array_keys($phids);
     $handles = $this->loadViewerHandles($phids);
     $dict = array();
     $dict['Status'] = '<strong>' . ManiphestTaskStatus::getTaskStatusFullName($task->getStatus()) . '</strong>';
     $dict['Assigned To'] = $task->getOwnerPHID() ? $handles[$task->getOwnerPHID()]->renderLink() : '<em>None</em>';
     $dict['Priority'] = ManiphestTaskPriority::getTaskPriorityName($task->getPriority());
     $cc = $task->getCCPHIDs();
     if ($cc) {
         $cc_links = array();
         foreach ($cc as $phid) {
             $cc_links[] = $handles[$phid]->renderLink();
         }
         $dict['CC'] = implode(', ', $cc_links);
     } else {
         $dict['CC'] = '<em>None</em>';
     }
     $dict['Author'] = $handles[$task->getAuthorPHID()]->renderLink();
     $source = $task->getOriginalEmailSource();
     if ($source) {
         $subject = '[T' . $task->getID() . '] ' . $task->getTitle();
         $dict['From Email'] = phutil_render_tag('a', array('href' => 'mailto:' . $source . '?subject=' . $subject), phutil_escape_html($source));
     }
     $projects = $task->getProjectPHIDs();
     if ($projects) {
         $project_links = array();
         foreach ($projects as $phid) {
             $project_links[] = $handles[$phid]->renderLink();
         }
         $dict['Projects'] = implode(', ', $project_links);
     } else {
         $dict['Projects'] = '<em>None</em>';
     }
     $extensions = ManiphestTaskExtensions::newExtensions();
     $aux_fields = $extensions->getAuxiliaryFieldSpecifications();
     if ($aux_fields) {
         $task->loadAndAttachAuxiliaryAttributes();
         foreach ($aux_fields as $aux_field) {
             $aux_key = $aux_field->getAuxiliaryKey();
             $aux_field->setValue($task->getAuxiliaryAttribute($aux_key));
             $value = $aux_field->renderForDetailView();
             if (strlen($value)) {
                 $dict[$aux_field->getLabel()] = $value;
             }
         }
     }
     if ($dep_by_tasks) {
         $dict['Dependent Tasks'] = $this->renderHandleList(array_select_keys($handles, $dep_by_tasks));
     }
     if ($dep_on_tasks) {
         $dict['Depends On'] = $this->renderHandleList(array_select_keys($handles, $dep_on_tasks));
     }
     if ($revs) {
         $dict['Revisions'] = $this->renderHandleList(array_select_keys($handles, $revs));
     }
     if ($commit_phids) {
         $dict['Commits'] = $this->renderHandleList(array_select_keys($handles, $commit_phids));
     }
     $file_infos = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_FILE);
     if ($file_infos) {
         $file_phids = array_keys($file_infos);
         $files = id(new PhabricatorFile())->loadAllWhere('phid IN (%Ls)', $file_phids);
         $views = array();
         foreach ($files as $file) {
             $view = new AphrontFilePreviewView();
             $view->setFile($file);
             $views[] = $view->render();
         }
         $dict['Files'] = implode('', $views);
     }
     $context_bar = null;
     if ($parent_task) {
         $context_bar = new AphrontContextBarView();
         $context_bar->addButton(phutil_render_tag('a', array('href' => '/maniphest/task/create/?parent=' . $parent_task->getID(), 'class' => 'green button'), 'Create Another Subtask'));
         $context_bar->appendChild('Created a subtask of <strong>' . $handles[$parent_task->getPHID()]->renderLink() . '</strong>');
     } else {
         if ($workflow == 'create') {
             $context_bar = new AphrontContextBarView();
             $context_bar->addButton('<label>Create Another:</label>');
             $context_bar->addButton(phutil_render_tag('a', array('href' => '/maniphest/task/create/?template=' . $task->getID(), 'class' => 'green button'), 'Similar Task'));
             $context_bar->addButton(phutil_render_tag('a', array('href' => '/maniphest/task/create/', 'class' => 'green button'), 'Empty Task'));
             $context_bar->appendChild('New task created.');
         }
     }
     $actions = array();
     $action = new AphrontHeadsupActionView();
     $action->setName('Edit Task');
     $action->setURI('/maniphest/task/edit/' . $task->getID() . '/');
     $action->setClass('action-edit');
     $actions[] = $action;
     require_celerity_resource('phabricator-flag-css');
     $flag = PhabricatorFlagQuery::loadUserFlag($user, $task->getPHID());
     if ($flag) {
         $class = PhabricatorFlagColor::getCSSClass($flag->getColor());
         $color = PhabricatorFlagColor::getColorName($flag->getColor());
         $action = new AphrontHeadsupActionView();
         $action->setClass('flag-clear ' . $class);
         $action->setURI('/flag/delete/' . $flag->getID() . '/');
         $action->setName('Remove ' . $color . ' Flag');
         $action->setWorkflow(true);
         $actions[] = $action;
     } else {
         $action = new AphrontHeadsupActionView();
         $action->setClass('phabricator-flag-ghost');
         $action->setURI('/flag/edit/' . $task->getPHID() . '/');
         $action->setName('Flag Task');
         $action->setWorkflow(true);
         $actions[] = $action;
     }
     require_celerity_resource('phabricator-object-selector-css');
     require_celerity_resource('javelin-behavior-phabricator-object-selector');
     $action = new AphrontHeadsupActionView();
     $action->setName('Merge Duplicates');
     $action->setURI('/search/attach/' . $task->getPHID() . '/TASK/merge/');
     $action->setWorkflow(true);
     $action->setClass('action-merge');
     $actions[] = $action;
     $action = new AphrontHeadsupActionView();
     $action->setName('Create Subtask');
     $action->setURI('/maniphest/task/create/?parent=' . $task->getID());
     $action->setClass('action-branch');
     $actions[] = $action;
     $action = new AphrontHeadsupActionView();
     $action->setName('Edit Dependencies');
     $action->setURI('/search/attach/' . $task->getPHID() . '/TASK/dependencies/');
     $action->setWorkflow(true);
     $action->setClass('action-dependencies');
     $actions[] = $action;
     $action = new AphrontHeadsupActionView();
     $action->setName('Edit Differential Revisions');
     $action->setURI('/search/attach/' . $task->getPHID() . '/DREV/');
     $action->setWorkflow(true);
     $action->setClass('action-attach');
     $actions[] = $action;
     $action_list = new AphrontHeadsupActionListView();
     $action_list->setActions($actions);
     $headsup_panel = new AphrontHeadsupView();
     $headsup_panel->setObjectName('T' . $task->getID());
     $headsup_panel->setHeader($task->getTitle());
     $headsup_panel->setActionList($action_list);
     $headsup_panel->setProperties($dict);
     $engine = new PhabricatorMarkupEngine();
     $engine->setViewer($user);
     $engine->addObject($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION);
     foreach ($transactions as $xaction) {
         if ($xaction->hasComments()) {
             $engine->addObject($xaction, ManiphestTransaction::MARKUP_FIELD_BODY);
         }
     }
     $engine->process();
     $headsup_panel->appendChild('<div class="phabricator-remarkup">' . $engine->getOutput($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION) . '</div>');
     $transaction_types = ManiphestTransactionType::getTransactionTypeMap();
     $resolution_types = ManiphestTaskStatus::getTaskStatusMap();
     if ($task->getStatus() == ManiphestTaskStatus::STATUS_OPEN) {
         $resolution_types = array_select_keys($resolution_types, array(ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, ManiphestTaskStatus::STATUS_CLOSED_INVALID, ManiphestTaskStatus::STATUS_CLOSED_SPITE));
     } else {
         $resolution_types = array(ManiphestTaskStatus::STATUS_OPEN => 'Reopened');
         $transaction_types[ManiphestTransactionType::TYPE_STATUS] = 'Reopen Task';
         unset($transaction_types[ManiphestTransactionType::TYPE_PRIORITY]);
         unset($transaction_types[ManiphestTransactionType::TYPE_OWNER]);
     }
     $default_claim = array($user->getPHID() => $user->getUsername() . ' (' . $user->getRealName() . ')');
     $draft = id(new PhabricatorDraft())->loadOneWhere('authorPHID = %s AND draftKey = %s', $user->getPHID(), $task->getPHID());
     if ($draft) {
         $draft_text = $draft->getDraft();
     } else {
         $draft_text = null;
     }
     $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
     if ($is_serious) {
         // Prevent tasks from being closed "out of spite" in serious business
         // installs.
         unset($resolution_types[ManiphestTaskStatus::STATUS_CLOSED_SPITE]);
     }
     $comment_form = new AphrontFormView();
     $comment_form->setUser($user)->setAction('/maniphest/transaction/save/')->setEncType('multipart/form-data')->addHiddenInput('taskID', $task->getID())->appendChild(id(new AphrontFormSelectControl())->setLabel('Action')->setName('action')->setOptions($transaction_types)->setID('transaction-action'))->appendChild(id(new AphrontFormSelectControl())->setLabel('Resolution')->setName('resolution')->setControlID('resolution')->setControlStyle('display: none')->setOptions($resolution_types))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('Assign To')->setName('assign_to')->setControlID('assign_to')->setControlStyle('display: none')->setID('assign-tokenizer')->setDisableBehavior(true))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('CCs')->setName('ccs')->setControlID('ccs')->setControlStyle('display: none')->setID('cc-tokenizer')->setDisableBehavior(true))->appendChild(id(new AphrontFormSelectControl())->setLabel('Priority')->setName('priority')->setOptions($priority_map)->setControlID('priority')->setControlStyle('display: none')->setValue($task->getPriority()))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('Projects')->setName('projects')->setControlID('projects')->setControlStyle('display: none')->setID('projects-tokenizer')->setDisableBehavior(true))->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setControlID('file')->setControlStyle('display: none'))->appendChild(id(new PhabricatorRemarkupControl())->setLabel('Comments')->setName('comments')->setValue($draft_text)->setID('transaction-comments'))->appendChild(id(new AphrontFormDragAndDropUploadControl())->setLabel('Attached Files')->setName('files')->setActivatedClass('aphront-panel-view-drag-and-drop'))->appendChild(id(new AphrontFormSubmitControl())->setValue($is_serious ? 'Submit' : 'Avast!'));
     $control_map = array(ManiphestTransactionType::TYPE_STATUS => 'resolution', ManiphestTransactionType::TYPE_OWNER => 'assign_to', ManiphestTransactionType::TYPE_CCS => 'ccs', ManiphestTransactionType::TYPE_PRIORITY => 'priority', ManiphestTransactionType::TYPE_PROJECTS => 'projects', ManiphestTransactionType::TYPE_ATTACH => 'file');
     $tokenizer_map = array(ManiphestTransactionType::TYPE_PROJECTS => array('id' => 'projects-tokenizer', 'src' => '/typeahead/common/projects/', 'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'), 'placeholder' => 'Type a project name...'), ManiphestTransactionType::TYPE_OWNER => array('id' => 'assign-tokenizer', 'src' => '/typeahead/common/users/', 'value' => $default_claim, 'limit' => 1, 'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'), 'placeholder' => 'Type a user name...'), ManiphestTransactionType::TYPE_CCS => array('id' => 'cc-tokenizer', 'src' => '/typeahead/common/mailable/', 'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'), 'placeholder' => 'Type a user or mailing list...'));
     Javelin::initBehavior('maniphest-transaction-controls', array('select' => 'transaction-action', 'controlMap' => $control_map, 'tokenizers' => $tokenizer_map));
     Javelin::initBehavior('maniphest-transaction-preview', array('uri' => '/maniphest/transaction/preview/' . $task->getID() . '/', 'preview' => 'transaction-preview', 'comments' => 'transaction-comments', 'action' => 'transaction-action', 'map' => $control_map, 'tokenizers' => $tokenizer_map));
     $comment_panel = new AphrontPanelView();
     $comment_panel->appendChild($comment_form);
     $comment_panel->addClass('aphront-panel-accent');
     $comment_panel->setHeader($is_serious ? 'Add Comment' : 'Weigh In');
     $preview_panel = '<div class="aphront-panel-preview">
     <div id="transaction-preview">
       <div class="aphront-panel-preview-loading-text">
         Loading preview...
       </div>
     </div>
   </div>';
     $transaction_view = new ManiphestTransactionListView();
     $transaction_view->setTransactions($transactions);
     $transaction_view->setHandles($handles);
     $transaction_view->setUser($user);
     $transaction_view->setAuxiliaryFields($aux_fields);
     $transaction_view->setMarkupEngine($engine);
     PhabricatorFeedStoryNotification::updateObjectNotificationViews($user, $task->getPHID());
     return $this->buildStandardPageResponse(array($context_bar, $headsup_panel, $transaction_view, $comment_panel, $preview_panel), array('title' => 'T' . $task->getID() . ' ' . $task->getTitle(), 'pageObjects' => array($task->getPHID())));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $key = $request->getURIData('key');
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     if (empty($options[$key])) {
         $ancient = PhabricatorExtraConfigSetupCheck::getAncientConfig();
         if (isset($ancient[$key])) {
             $desc = pht("This configuration has been removed. You can safely delete " . "it.\n\n%s", $ancient[$key]);
         } else {
             $desc = pht('This configuration option is unknown. It may be misspelled, ' . 'or have existed in a previous version of Phabricator.');
         }
         // This may be a dead config entry, which existed in the past but no
         // longer exists. Allow it to be edited so it can be reviewed and
         // deleted.
         $option = id(new PhabricatorConfigOption())->setKey($key)->setType('wild')->setDefault(null)->setDescription($desc);
         $group = null;
         $group_uri = $this->getApplicationURI();
     } else {
         $option = $options[$key];
         $group = $option->getGroup();
         $group_uri = $this->getApplicationURI('group/' . $group->getKey() . '/');
     }
     $issue = $request->getStr('issue');
     if ($issue) {
         // If the user came here from an open setup issue, send them back.
         $done_uri = $this->getApplicationURI('issue/' . $issue . '/');
     } else {
         $done_uri = $group_uri;
     }
     // Check if the config key is already stored in the database.
     // Grab the value if it is.
     $config_entry = id(new PhabricatorConfigEntry())->loadOneWhere('configKey = %s AND namespace = %s', $key, 'default');
     if (!$config_entry) {
         $config_entry = id(new PhabricatorConfigEntry())->setConfigKey($key)->setNamespace('default')->setIsDeleted(true);
         $config_entry->setPHID($config_entry->generatePHID());
     }
     $e_value = null;
     $errors = array();
     if ($request->isFormPost() && !$option->getLocked()) {
         $result = $this->readRequest($option, $request);
         list($e_value, $value_errors, $display_value, $xaction) = $result;
         $errors = array_merge($errors, $value_errors);
         if (!$errors) {
             $editor = id(new PhabricatorConfigEditor())->setActor($viewer)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request);
             try {
                 $editor->applyTransactions($config_entry, array($xaction));
                 return id(new AphrontRedirectResponse())->setURI($done_uri);
             } catch (PhabricatorConfigValidationException $ex) {
                 $e_value = pht('Invalid');
                 $errors[] = $ex->getMessage();
             }
         }
     } else {
         if ($config_entry->getIsDeleted()) {
             $display_value = null;
         } else {
             $display_value = $this->getDisplayValue($option, $config_entry, $config_entry->getValue());
         }
     }
     $form = id(new AphrontFormView())->setEncType('multipart/form-data');
     $error_view = null;
     if ($errors) {
         $error_view = id(new PHUIInfoView())->setErrors($errors);
     }
     $status_items = array();
     if ($option->getHidden()) {
         $message = pht('This configuration is hidden and can not be edited or viewed from ' . 'the web interface.');
         $status_items[] = id(new PHUIStatusItemView())->setIcon('fa-eye-slash red')->setTarget(phutil_tag('strong', array(), pht('Configuration Hidden')))->setNote($message);
     } else {
         if ($option->getLocked()) {
             $message = $option->getLockedMessage();
             $status_items[] = id(new PHUIStatusItemView())->setIcon('fa-lock red')->setTarget(phutil_tag('strong', array(), pht('Configuration Locked')))->setNote($message);
         }
     }
     if ($status_items) {
         $doc_href = PhabricatorEnv::getDoclink('Configuration Guide: Locked and Hidden Configuration');
         $doc_link = phutil_tag('a', array('href' => $doc_href, 'target' => '_blank'), pht('Configuration Guide: Locked and Hidden Configuration'));
         $status_items[] = id(new PHUIStatusItemView())->setIcon('fa-book')->setTarget(phutil_tag('strong', array(), pht('Learn More')))->setNote($doc_link);
     }
     if ($option->getHidden() || $option->getLocked()) {
         $controls = array();
     } else {
         $controls = $this->renderControls($option, $display_value, $e_value);
     }
     $engine = new PhabricatorMarkupEngine();
     $engine->setViewer($viewer);
     $engine->addObject($option, 'description');
     $engine->process();
     $description = phutil_tag('div', array('class' => 'phabricator-remarkup'), $engine->getOutput($option, 'description'));
     $form->setUser($viewer)->addHiddenInput('issue', $request->getStr('issue'));
     if ($status_items) {
         $status_view = id(new PHUIStatusListView());
         foreach ($status_items as $status_item) {
             $status_view->addItem($status_item);
         }
         $form->appendControl(id(new AphrontFormMarkupControl())->setValue($status_view));
     }
     $description = $option->getDescription();
     if (strlen($description)) {
         $description_view = new PHUIRemarkupView($viewer, $description);
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Description'))->setValue($description_view));
     }
     if ($group) {
         $extra = $group->renderContextualDescription($option, $request);
         if ($extra !== null) {
             $form->appendChild(id(new AphrontFormMarkupControl())->setValue($extra));
         }
     }
     foreach ($controls as $control) {
         $form->appendControl($control);
     }
     if (!$option->getLocked()) {
         $form->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($done_uri)->setValue(pht('Save Config Entry')));
     }
     if (!$option->getHidden()) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Current Configuration'))->setValue($this->renderDefaults($option, $config_entry)));
     }
     $examples = $this->renderExamples($option);
     if ($examples) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Examples'))->setValue($examples));
     }
     $title = pht('Edit Option: %s', $key);
     $header_icon = 'fa-pencil';
     $short = pht('Edit');
     $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Config Option'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form);
     if ($error_view) {
         $form_box->setInfoView($error_view);
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Config'), $this->getApplicationURI());
     if ($group) {
         $crumbs->addTextCrumb($group->getName(), $group_uri);
     }
     $crumbs->addTextCrumb($key, '/config/edit/' . $key);
     $crumbs->setBorder(true);
     $timeline = $this->buildTransactionTimeline($config_entry, new PhabricatorConfigTransactionQuery());
     $timeline->setShouldTerminate(true);
     $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon($header_icon);
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter($form_box);
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }