Remove most callsites to Controller->renderHandlesForPHIDs()

Summary: Ref T7689. This moves most of the easy/testable callsites off `Controller->renderHandlesForPHIDs()`.

Test Plan:
- Viewed a file; viewed author; viewed "attached" tab.
- Viewed a mock; viewed attached tasks.
- Viewed a credential; viewed "Used By".
- Viewed a paste; viewed author; viewed forks; viewed forked from.
- Viewed a dashboard; viewed panel list.
- Viewed a dashboard panel; viewed "Appears On".
- Viewed a Phortune account; viewed "Members"; viewed payment methods.
- Viewed a Phortune merchant account; viewed "Members".
- Viewed Phortune account switcher; viewed "Accounts".
  - I just removed "Members:" here since it felt kind of out-of-place anyway.
- Viewed a Phragment fragment, viewed "Latest Version", viewed "Snapshots".
- Viewed a Phargment snapshot, viewed "Fragment".

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: hach-que, epriestley

Maniphest Tasks: T7689

Differential Revision: https://secure.phabricator.com/D12207
This commit is contained in:
epriestley
2015-03-30 06:35:32 -07:00
parent dec03cf076
commit a8271ecd40
14 changed files with 61 additions and 64 deletions

View File

@@ -165,12 +165,9 @@ final class PhabricatorDashboardManageController
pht('Editable By'), pht('Editable By'),
$descriptions[PhabricatorPolicyCapability::CAN_EDIT]); $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
$panel_phids = $dashboard->getPanelPHIDs();
$this->loadHandles($panel_phids);
$properties->addProperty( $properties->addProperty(
pht('Panels'), pht('Panels'),
$this->renderHandlesForPHIDs($panel_phids)); $viewer->renderHandleList($dashboard->getPanelPHIDs()));
return $properties; return $properties;
} }

View File

@@ -163,7 +163,6 @@ final class PhabricatorDashboardPanelViewController
$dashboard_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( $dashboard_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$panel->getPHID(), $panel->getPHID(),
PhabricatorDashboardPanelHasDashboardEdgeType::EDGECONST); PhabricatorDashboardPanelHasDashboardEdgeType::EDGECONST);
$this->loadHandles($dashboard_phids);
$does_not_appear = pht( $does_not_appear = pht(
'This panel does not appear on any dashboards.'); 'This panel does not appear on any dashboards.');
@@ -171,7 +170,7 @@ final class PhabricatorDashboardPanelViewController
$properties->addProperty( $properties->addProperty(
pht('Appears On'), pht('Appears On'),
$dashboard_phids $dashboard_phids
? $this->renderHandlesForPHIDs($dashboard_phids) ? $viewer->renderHandleList($dashboard_phids)
: phutil_tag('em', array(), $does_not_appear)); : phutil_tag('em', array(), $does_not_appear));
return $properties; return $properties;

View File

@@ -39,11 +39,6 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
$phid = $file->getPHID(); $phid = $file->getPHID();
$handle_phids = array_merge(
array($file->getAuthorPHID()),
$file->getObjectPHIDs());
$this->loadHandles($handle_phids);
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setUser($user) ->setUser($user)
->setPolicyObject($file) ->setPolicyObject($file)
@@ -185,7 +180,6 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
$properties = id(new PHUIPropertyListView()); $properties = id(new PHUIPropertyListView());
$properties->setActionList($actions); $properties->setActionList($actions);
$box->addPropertyList($properties, pht('Details')); $box->addPropertyList($properties, pht('Details'));
@@ -193,7 +187,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
if ($file->getAuthorPHID()) { if ($file->getAuthorPHID()) {
$properties->addProperty( $properties->addProperty(
pht('Author'), pht('Author'),
$this->getHandle($file->getAuthorPHID())->renderLink()); $user->renderHandle($file->getAuthorPHID()));
} }
$properties->addProperty( $properties->addProperty(
@@ -270,7 +264,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
$attached->addProperty( $attached->addProperty(
pht('Attached To'), pht('Attached To'),
$this->renderHandlesForPHIDs($phids)); $user->renderHandleList($phids));
} }

View File

@@ -189,10 +189,9 @@ final class PassphraseCredentialViewController extends PassphraseController {
PhabricatorCredentialsUsedByObjectEdgeType::EDGECONST); PhabricatorCredentialsUsedByObjectEdgeType::EDGECONST);
if ($used_by_phids) { if ($used_by_phids) {
$this->loadHandles($used_by_phids);
$properties->addProperty( $properties->addProperty(
pht('Used By'), pht('Used By'),
$this->renderHandlesForPHIDs($used_by_phids)); $viewer->renderHandleList($used_by_phids));
} }
$description = $credential->getDescription(); $description = $credential->getDescription();

View File

@@ -176,35 +176,35 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
PhabricatorPaste $paste, PhabricatorPaste $paste,
array $child_phids, array $child_phids,
PhabricatorActionListView $actions) { PhabricatorActionListView $actions) {
$viewer = $this->getViewer();
$user = $this->getRequest()->getUser();
$properties = id(new PHUIPropertyListView()) $properties = id(new PHUIPropertyListView())
->setUser($user) ->setUser($viewer)
->setObject($paste) ->setObject($paste)
->setActionList($actions); ->setActionList($actions);
$properties->addProperty( $properties->addProperty(
pht('Author'), pht('Author'),
$this->getHandle($paste->getAuthorPHID())->renderLink()); $viewer->renderHandle($paste->getAuthorPHID()));
$properties->addProperty( $properties->addProperty(
pht('Created'), pht('Created'),
phabricator_datetime($paste->getDateCreated(), $user)); phabricator_datetime($paste->getDateCreated(), $viewer));
if ($paste->getParentPHID()) { if ($paste->getParentPHID()) {
$properties->addProperty( $properties->addProperty(
pht('Forked From'), pht('Forked From'),
$this->getHandle($paste->getParentPHID())->renderLink()); $viewer->renderHandle($paste->getParentPHID()));
} }
if ($child_phids) { if ($child_phids) {
$properties->addProperty( $properties->addProperty(
pht('Forks'), pht('Forks'),
$this->renderHandlesForPHIDs($child_phids)); $viewer->renderHandleList($child_phids));
} }
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
$user, $viewer,
$paste); $paste);
return $properties; return $properties;

View File

@@ -2,6 +2,7 @@
/** /**
* @task factors Multi-Factor Authentication * @task factors Multi-Factor Authentication
* @task handles Managing Handles
*/ */
final class PhabricatorUser final class PhabricatorUser
extends PhabricatorUserDAO extends PhabricatorUserDAO
@@ -801,7 +802,7 @@ EOBODY;
} }
/* -( Handles )------------------------------------------------------------ */ /* -( Managing Handles )--------------------------------------------------- */
/** /**
@@ -810,6 +811,7 @@ EOBODY;
* *
* @param list<phid> List of PHIDs to load. * @param list<phid> List of PHIDs to load.
* @return PhabricatorHandleList Handle list object. * @return PhabricatorHandleList Handle list object.
* @task handle
*/ */
public function loadHandles(array $phids) { public function loadHandles(array $phids) {
if ($this->handlePool === null) { if ($this->handlePool === null) {
@@ -821,6 +823,34 @@ EOBODY;
} }
/**
* Get a @{class:PHUIHandleView} for a single handle.
*
* This benefits from the viewer's internal handle pool.
*
* @param phid PHID to render a handle for.
* @return PHUIHandleView View of the handle.
* @task handle
*/
public function renderHandle($phid) {
return $this->loadHandles(array($phid))->renderHandle($phid);
}
/**
* Get a @{class:PHUIHandleListView} for a list of handles.
*
* This benefits from the viewer's internal handle pool.
*
* @param list<phid> List of PHIDs to render.
* @return PHUIHandleListView View of the handles.
* @task handle
*/
public function renderHandleList(array $phids) {
return $this->loadHandles($phids)->renderList();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */

View File

@@ -42,8 +42,6 @@ final class PholioMockViewController extends PholioController {
$mock->getPHID(), $mock->getPHID(),
PholioMockHasTaskEdgeType::EDGECONST); PholioMockHasTaskEdgeType::EDGECONST);
$this->setManiphestTaskPHIDs($phids); $this->setManiphestTaskPHIDs($phids);
$phids[] = $mock->getAuthorPHID();
$this->loadHandles($phids);
$engine = id(new PhabricatorMarkupEngine()) $engine = id(new PhabricatorMarkupEngine())
->setViewer($user); ->setViewer($user);
@@ -167,7 +165,7 @@ final class PholioMockViewController extends PholioController {
$properties->addProperty( $properties->addProperty(
pht('Author'), pht('Author'),
$this->getHandle($mock->getAuthorPHID())->renderLink()); $user->renderHandle($mock->getAuthorPHID()));
$properties->addProperty( $properties->addProperty(
pht('Created'), pht('Created'),
@@ -176,7 +174,7 @@ final class PholioMockViewController extends PholioController {
if ($this->getManiphestTaskPHIDs()) { if ($this->getManiphestTaskPHIDs()) {
$properties->addProperty( $properties->addProperty(
pht('Maniphest Tasks'), pht('Maniphest Tasks'),
$this->renderHandlesForPHIDs($this->getManiphestTaskPHIDs())); $user->renderHandleList($this->getManiphestTaskPHIDs()));
} }
$properties->invokeWillRenderEvent(); $properties->invokeWillRenderEvent();

View File

@@ -36,12 +36,10 @@ final class PhortuneAccountListController extends PhortuneController {
foreach ($accounts as $account) { foreach ($accounts as $account) {
$this->loadHandles($account->getMemberPHIDs()); $this->loadHandles($account->getMemberPHIDs());
$members = $this->renderHandlesForPHIDs($account->getMemberPHIDs(), ',');
$item = id(new PHUIObjectItemView()) $item = id(new PHUIObjectItemView())
->setObjectName(pht('Account %d', $account->getID())) ->setObjectName(pht('Account %d', $account->getID()))
->setHeader($account->getName()) ->setHeader($account->getName())
->setHref($this->getApplicationURI($account->getID().'/')) ->setHref($this->getApplicationURI($account->getID().'/'))
->addAttribute(pht('Members: %s', $members))
->setObject($account); ->setObject($account);
$payment_list->addItem($item); $payment_list->addItem($item);

View File

@@ -57,11 +57,9 @@ final class PhortuneAccountViewController extends PhortuneController {
->setObject($account) ->setObject($account)
->setUser($viewer); ->setUser($viewer);
$this->loadHandles($account->getMemberPHIDs());
$properties->addProperty( $properties->addProperty(
pht('Members'), pht('Members'),
$this->renderHandlesForPHIDs($account->getMemberPHIDs())); $viewer->renderHandleList($account->getMemberPHIDs()));
$status_items = $this->getStatusItemsForAccount($account, $invoices); $status_items = $this->getStatusItemsForAccount($account, $invoices);
$status_view = new PHUIStatusListView(); $status_view = new PHUIStatusListView();
@@ -137,10 +135,6 @@ final class PhortuneAccountViewController extends PhortuneController {
->withAccountPHIDs(array($account->getPHID())) ->withAccountPHIDs(array($account->getPHID()))
->execute(); ->execute();
if ($methods) {
$this->loadHandles(mpull($methods, 'getAuthorPHID'));
}
foreach ($methods as $method) { foreach ($methods as $method) {
$id = $method->getID(); $id = $method->getID();

View File

@@ -135,11 +135,9 @@ final class PhortuneMerchantViewController
$view->addProperty(pht('Status'), $status_view); $view->addProperty(pht('Status'), $status_view);
$this->loadHandles($merchant->getMemberPHIDs());
$view->addProperty( $view->addProperty(
pht('Members'), pht('Members'),
$this->renderHandlesForPHIDs($merchant->getMemberPHIDs())); $viewer->renderHandleList($merchant->getMemberPHIDs()));
$view->invokeWillRenderEvent(); $view->invokeWillRenderEvent();

View File

@@ -57,21 +57,15 @@ abstract class PhragmentController extends PhabricatorController {
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
$phids = array();
$phids[] = $fragment->getLatestVersionPHID();
$snapshot_phids = array(); $snapshot_phids = array();
$snapshots = id(new PhragmentSnapshotQuery()) $snapshots = id(new PhragmentSnapshotQuery())
->setViewer($viewer) ->setViewer($viewer)
->withPrimaryFragmentPHIDs(array($fragment->getPHID())) ->withPrimaryFragmentPHIDs(array($fragment->getPHID()))
->execute(); ->execute();
foreach ($snapshots as $snapshot) { foreach ($snapshots as $snapshot) {
$phids[] = $snapshot->getPHID();
$snapshot_phids[] = $snapshot->getPHID(); $snapshot_phids[] = $snapshot->getPHID();
} }
$this->loadHandles($phids);
$file = null; $file = null;
$file_uri = null; $file_uri = null;
if (!$fragment->isDirectory()) { if (!$fragment->isDirectory()) {
@@ -183,7 +177,7 @@ abstract class PhragmentController extends PhabricatorController {
} }
$properties->addProperty( $properties->addProperty(
pht('Latest Version'), pht('Latest Version'),
$this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID()))); $viewer->renderHandle($fragment->getLatestVersionPHID()));
} else { } else {
$properties->addProperty( $properties->addProperty(
pht('Type'), pht('Type'),
@@ -193,7 +187,7 @@ abstract class PhragmentController extends PhabricatorController {
if (count($snapshot_phids) > 0) { if (count($snapshot_phids) > 0) {
$properties->addProperty( $properties->addProperty(
pht('Snapshots'), pht('Snapshots'),
$this->renderHandlesForPHIDs($snapshot_phids)); $viewer->renderHandleList($snapshot_phids));
} }
return id(new PHUIObjectBoxView()) return id(new PHUIObjectBoxView())

View File

@@ -43,8 +43,11 @@ final class PhragmentCreateController extends PhragmentController {
$errors[] = pht('The fragment name can not contain \'/\'.'); $errors[] = pht('The fragment name can not contain \'/\'.');
} }
$file = id(new PhabricatorFile())->load($v_fileid); $file = id(new PhabricatorFileQuery())
if ($file === null) { ->setViewer($viewer)
->withIDs(array($v_fileid))
->executeOne();
if (!$file) {
$errors[] = pht('The specified file doesn\'t exist.'); $errors[] = pht('The specified file doesn\'t exist.');
} }
@@ -115,9 +118,12 @@ final class PhragmentCreateController extends PhragmentController {
$box = id(new PHUIObjectBoxView()) $box = id(new PHUIObjectBoxView())
->setHeaderText('Create Fragment') ->setHeaderText('Create Fragment')
->setValidationException(null)
->setForm($form); ->setForm($form);
if ($error_view) {
$box->setInfoView($error_view);
}
return $this->buildApplicationPage( return $this->buildApplicationPage(
array( array(
$crumbs, $crumbs,

View File

@@ -90,11 +90,6 @@ final class PhragmentSnapshotViewController extends PhragmentController {
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
$phids = array();
$phids[] = $snapshot->getPrimaryFragmentPHID();
$this->loadHandles($phids);
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setHeader(pht('"%s" Snapshot', $snapshot->getName())) ->setHeader(pht('"%s" Snapshot', $snapshot->getName()))
->setPolicyObject($snapshot) ->setPolicyObject($snapshot)
@@ -146,7 +141,7 @@ final class PhragmentSnapshotViewController extends PhragmentController {
$snapshot->getName()); $snapshot->getName());
$properties->addProperty( $properties->addProperty(
pht('Fragment'), pht('Fragment'),
$this->renderHandlesForPHIDs(array($snapshot->getPrimaryFragmentPHID()))); $viewer->renderHandle($snapshot->getPrimaryFragmentPHID()));
return id(new PHUIObjectBoxView()) return id(new PHUIObjectBoxView())
->setHeader($header) ->setHeader($header)

View File

@@ -33,11 +33,6 @@ final class PhragmentVersionController extends PhragmentController {
$crumbs = $this->buildApplicationCrumbsWithPath($parents); $crumbs = $this->buildApplicationCrumbsWithPath($parents);
$crumbs->addTextCrumb(pht('View Version %d', $version->getSequence())); $crumbs->addTextCrumb(pht('View Version %d', $version->getSequence()));
$phids = array();
$phids[] = $version->getFilePHID();
$this->loadHandles($phids);
$file = id(new PhabricatorFileQuery()) $file = id(new PhabricatorFileQuery())
->setViewer($viewer) ->setViewer($viewer)
->withPHIDs(array($version->getFilePHID())) ->withPHIDs(array($version->getFilePHID()))
@@ -71,7 +66,7 @@ final class PhragmentVersionController extends PhragmentController {
->setActionList($actions); ->setActionList($actions);
$properties->addProperty( $properties->addProperty(
pht('File'), pht('File'),
$this->renderHandlesForPHIDs(array($version->getFilePHID()))); $viewer->renderHandle($version->getFilePHID()));
$box = id(new PHUIObjectBoxView()) $box = id(new PHUIObjectBoxView())
->setHeader($header) ->setHeader($header)