Differential D8361 Diff 19878 src/applications/differential/controller/DifferentialRevisionViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/controller/DifferentialRevisionViewController.php
| Show All 35 Lines | $diffs = id(new DifferentialDiffQuery()) | ||||
| ->execute(); | ->execute(); | ||||
| $diffs = array_reverse($diffs, $preserve_keys = true); | $diffs = array_reverse($diffs, $preserve_keys = true); | ||||
| if (!$diffs) { | if (!$diffs) { | ||||
| throw new Exception( | throw new Exception( | ||||
| "This revision has no diffs. Something has gone quite wrong."); | "This revision has no diffs. Something has gone quite wrong."); | ||||
| } | } | ||||
| $revision->attachActiveDiff(last($diffs)); | |||||
| $diff_vs = $request->getInt('vs'); | $diff_vs = $request->getInt('vs'); | ||||
| $target_id = $request->getInt('id'); | $target_id = $request->getInt('id'); | ||||
| $target = idx($diffs, $target_id, end($diffs)); | $target = idx($diffs, $target_id, end($diffs)); | ||||
| $target_manual = $target; | $target_manual = $target; | ||||
| if (!$target_id) { | if (!$target_id) { | ||||
| foreach ($diffs as $diff) { | foreach ($diffs as $diff) { | ||||
| Show All 25 Lines | if ($request->getExists('download')) { | ||||
| $repository); | $repository); | ||||
| } | } | ||||
| $props = id(new DifferentialDiffProperty())->loadAllWhere( | $props = id(new DifferentialDiffProperty())->loadAllWhere( | ||||
| 'diffID = %d', | 'diffID = %d', | ||||
| $target_manual->getID()); | $target_manual->getID()); | ||||
| $props = mpull($props, 'getData', 'getName'); | $props = mpull($props, 'getData', 'getName'); | ||||
| $aux_fields = $this->loadAuxiliaryFields($revision); | |||||
| $comments = $revision->loadComments(); | $comments = $revision->loadComments(); | ||||
| $all_changesets = $changesets; | $all_changesets = $changesets; | ||||
| $inlines = $this->loadInlineComments( | $inlines = $this->loadInlineComments( | ||||
| $revision, | $revision, | ||||
| $all_changesets); | $all_changesets); | ||||
| $object_phids = array_merge( | $object_phids = array_merge( | ||||
| Show All 13 Lines | public function processRequest() { | ||||
| } | } | ||||
| foreach ($revision->getAttached() as $type => $phids) { | foreach ($revision->getAttached() as $type => $phids) { | ||||
| foreach ($phids as $phid => $info) { | foreach ($phids as $phid => $info) { | ||||
| $object_phids[] = $phid; | $object_phids[] = $phid; | ||||
| } | } | ||||
| } | } | ||||
| $aux_phids = array(); | |||||
| foreach ($aux_fields as $key => $aux_field) { | |||||
| $aux_field->setDiff($target); | |||||
| $aux_field->setManualDiff($target_manual); | |||||
| $aux_field->setDiffProperties($props); | |||||
| $aux_phids[$key] = $aux_field->getRequiredHandlePHIDsForRevisionView(); | |||||
| } | |||||
| $object_phids = array_merge($object_phids, array_mergev($aux_phids)); | |||||
| $object_phids = array_unique($object_phids); | |||||
| $handles = $this->loadViewerHandles($object_phids); | $handles = $this->loadViewerHandles($object_phids); | ||||
| foreach ($aux_fields as $key => $aux_field) { | |||||
| // Make sure each field only has access to handles it specifically | |||||
| // requested, not all handles. Otherwise you can get a field which works | |||||
| // only in the presence of other fields. | |||||
| $aux_field->setHandles(array_select_keys($handles, $aux_phids[$key])); | |||||
| } | |||||
| $request_uri = $request->getRequestURI(); | $request_uri = $request->getRequestURI(); | ||||
| $limit = 100; | $limit = 100; | ||||
| $large = $request->getStr('large'); | $large = $request->getStr('large'); | ||||
| if (count($changesets) > $limit && !$large) { | if (count($changesets) > $limit && !$large) { | ||||
| $count = count($changesets); | $count = count($changesets); | ||||
| $warning = new AphrontErrorView(); | $warning = new AphrontErrorView(); | ||||
| $warning->setTitle('Very Large Diff'); | $warning->setTitle('Very Large Diff'); | ||||
| Show All 36 Lines | if (count($changesets) > $limit && !$large) { | ||||
| } | } | ||||
| } | } | ||||
| } else { | } else { | ||||
| $warning = null; | $warning = null; | ||||
| $visible_changesets = $changesets; | $visible_changesets = $changesets; | ||||
| } | } | ||||
| $field_list = PhabricatorCustomField::getObjectFields( | |||||
| $revision, | |||||
| PhabricatorCustomField::ROLE_VIEW); | |||||
| $field_list->setViewer($user); | |||||
| $field_list->readFieldsFromStorage($revision); | |||||
| $revision_detail = id(new DifferentialRevisionDetailView()) | $revision_detail = id(new DifferentialRevisionDetailView()) | ||||
| ->setUser($user) | ->setUser($user) | ||||
| ->setRevision($revision) | ->setRevision($revision) | ||||
| ->setDiff(end($diffs)) | ->setDiff(end($diffs)) | ||||
| ->setAuxiliaryFields($aux_fields) | ->setCustomFields($field_list) | ||||
| ->setURI($request->getRequestURI()); | ->setURI($request->getRequestURI()); | ||||
| $actions = $this->getRevisionActions($revision); | $actions = $this->getRevisionActions($revision); | ||||
| $custom_renderer_class = PhabricatorEnv::getEnvConfig( | |||||
| 'differential.revision-custom-detail-renderer'); | |||||
| if ($custom_renderer_class) { | |||||
| // TODO: build a better version of the action links and deprecate the | |||||
| // whole DifferentialRevisionDetailRenderer class. | |||||
| $custom_renderer = newv($custom_renderer_class, array()); | |||||
| $custom_renderer->setUser($user); | |||||
| $custom_renderer->setDiff($target); | |||||
| if ($diff_vs) { | |||||
| $custom_renderer->setVSDiff($diffs[$diff_vs]); | |||||
| } | |||||
| $actions = array_merge( | |||||
| $actions, | |||||
| $custom_renderer->generateActionLinks($revision, $target_manual)); | |||||
| } | |||||
| $whitespace = $request->getStr( | $whitespace = $request->getStr( | ||||
| 'whitespace', | 'whitespace', | ||||
| DifferentialChangesetParser::WHITESPACE_IGNORE_ALL); | DifferentialChangesetParser::WHITESPACE_IGNORE_ALL); | ||||
| if ($arc_project) { | if ($arc_project) { | ||||
| list($symbol_indexes, $project_phids) = $this->buildSymbolIndexes( | list($symbol_indexes, $project_phids) = $this->buildSymbolIndexes( | ||||
| $arc_project, | $arc_project, | ||||
| $visible_changesets); | $visible_changesets); | ||||
| ▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | if (!$viewer_is_anonymous) { | ||||
| $handles = $this->loadViewerHandles(array_merge($reviewers, $ccs)); | $handles = $this->loadViewerHandles(array_merge($reviewers, $ccs)); | ||||
| $reviewers = array_select_keys($handles, $reviewers); | $reviewers = array_select_keys($handles, $reviewers); | ||||
| $ccs = array_select_keys($handles, $ccs); | $ccs = array_select_keys($handles, $ccs); | ||||
| } | } | ||||
| } | } | ||||
| $comment_form = new DifferentialAddCommentView(); | $comment_form = new DifferentialAddCommentView(); | ||||
| $comment_form->setRevision($revision); | $comment_form->setRevision($revision); | ||||
| $comment_form->setAuxFields($aux_fields); | |||||
| // TODO: Restore the ability for fields to add accept warnings. | |||||
| $comment_form->setActions($this->getRevisionCommentActions($revision)); | $comment_form->setActions($this->getRevisionCommentActions($revision)); | ||||
| $action_uri = '/differential/comment/save/'; | $action_uri = '/differential/comment/save/'; | ||||
| if (false) { | if (false) { | ||||
| // TODO: Temporary for testing the new comment workflow. | // TODO: Temporary for testing the new comment workflow. | ||||
| $action_uri = $this->getApplicationURI( | $action_uri = $this->getApplicationURI( | ||||
| 'comment/savepro/'.$revision->getID().'/'); | 'comment/savepro/'.$revision->getID().'/'); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | private function getRevisionActions(DifferentialRevision $revision) { | ||||
| $revision_id = $revision->getID(); | $revision_id = $revision->getID(); | ||||
| $revision_phid = $revision->getPHID(); | $revision_phid = $revision->getPHID(); | ||||
| $can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
| $viewer, | $viewer, | ||||
| $revision, | $revision, | ||||
| PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
| $links = array(); | $actions = array(); | ||||
| $links[] = array( | $actions[] = id(new PhabricatorActionView()) | ||||
| 'icon' => 'edit', | ->setIcon('edit') | ||||
| 'href' => "/differential/revision/edit/{$revision_id}/", | ->setHref("/differential/revision/edit/{$revision_id}/") | ||||
| 'name' => pht('Edit Revision'), | ->setName(pht('Edit Revision')) | ||||
| 'disabled' => !$can_edit, | ->setDisabled(!$can_edit) | ||||
| 'sigil' => $can_edit ? null : 'workflow', | ->setWorkflow(!$can_edit); | ||||
| ); | |||||
| $this->requireResource('phabricator-object-selector-css'); | $this->requireResource('phabricator-object-selector-css'); | ||||
| $this->requireResource('javelin-behavior-phabricator-object-selector'); | $this->requireResource('javelin-behavior-phabricator-object-selector'); | ||||
| $links[] = array( | $actions[] = id(new PhabricatorActionView()) | ||||
| 'icon' => 'link', | ->setIcon('link') | ||||
| 'name' => pht('Edit Dependencies'), | ->setName(pht('Edit Dependencies')) | ||||
| 'href' => "/search/attach/{$revision_phid}/DREV/dependencies/", | ->setHref("/search/attach/{$revision_phid}/DREV/dependencies/") | ||||
| 'sigil' => 'workflow', | ->setWorkflow(true) | ||||
| 'disabled' => !$can_edit, | ->setDisabled(!$can_edit); | ||||
| ); | |||||
| $maniphest = 'PhabricatorApplicationManiphest'; | $maniphest = 'PhabricatorApplicationManiphest'; | ||||
| if (PhabricatorApplication::isClassInstalled($maniphest)) { | if (PhabricatorApplication::isClassInstalled($maniphest)) { | ||||
| $links[] = array( | $actions[] = id(new PhabricatorActionView()) | ||||
| 'icon' => 'attach', | ->setIcon('attach') | ||||
| 'name' => pht('Edit Maniphest Tasks'), | ->setName(pht('Edit Maniphest Tasks')) | ||||
| 'href' => "/search/attach/{$revision_phid}/TASK/", | ->setHref("/search/attach/{$revision_phid}/TASK/") | ||||
| 'sigil' => 'workflow', | ->setWorkflow(true) | ||||
| 'disabled' => !$can_edit, | ->setDisabled(!$can_edit); | ||||
| ); | |||||
| } | } | ||||
| $request_uri = $this->getRequest()->getRequestURI(); | $request_uri = $this->getRequest()->getRequestURI(); | ||||
| $links[] = array( | $actions[] = id(new PhabricatorActionView()) | ||||
| 'icon' => 'download', | ->setIcon('download') | ||||
| 'name' => pht('Download Raw Diff'), | ->setName(pht('Download Raw Diff')) | ||||
| 'href' => $request_uri->alter('download', 'true') | ->setHref($request_uri->alter('download', 'true')); | ||||
| ); | |||||
| return $links; | return $actions; | ||||
| } | } | ||||
| private function getRevisionCommentActions(DifferentialRevision $revision) { | private function getRevisionCommentActions(DifferentialRevision $revision) { | ||||
| $actions = array( | $actions = array( | ||||
| DifferentialAction::ACTION_COMMENT => true, | DifferentialAction::ACTION_COMMENT => true, | ||||
| ); | ); | ||||
| ▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | if ($diff_vs) { | ||||
| } | } | ||||
| } | } | ||||
| $changesets = msort($changesets, 'getSortKey'); | $changesets = msort($changesets, 'getSortKey'); | ||||
| return array($changesets, $vs_map, $vs_changesets, $refs); | return array($changesets, $vs_map, $vs_changesets, $refs); | ||||
| } | } | ||||
| private function loadAuxiliaryFields(DifferentialRevision $revision) { | |||||
| $aux_fields = DifferentialFieldSelector::newSelector() | |||||
| ->getFieldSpecifications(); | |||||
| foreach ($aux_fields as $key => $aux_field) { | |||||
| if (!$aux_field->shouldAppearOnRevisionView()) { | |||||
| unset($aux_fields[$key]); | |||||
| } else { | |||||
| $aux_field->setUser($this->getRequest()->getUser()); | |||||
| } | |||||
| } | |||||
| $aux_fields = DifferentialAuxiliaryField::loadFromStorage( | |||||
| $revision, | |||||
| $aux_fields); | |||||
| return $aux_fields; | |||||
| } | |||||
| private function buildSymbolIndexes( | private function buildSymbolIndexes( | ||||
| PhabricatorRepositoryArcanistProject $arc_project, | PhabricatorRepositoryArcanistProject $arc_project, | ||||
| array $visible_changesets) { | array $visible_changesets) { | ||||
| assert_instances_of($visible_changesets, 'DifferentialChangeset'); | assert_instances_of($visible_changesets, 'DifferentialChangeset'); | ||||
| $engine = PhabricatorSyntaxHighlighter::newEngine(); | $engine = PhabricatorSyntaxHighlighter::newEngine(); | ||||
| $langs = $arc_project->getSymbolIndexLanguages(); | $langs = $arc_project->getSymbolIndexLanguages(); | ||||
| ▲ Show 20 Lines • Show All 235 Lines • Show Last 20 Lines | |||||