Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/controller/PhabricatorFileInfoController.php
<?php | <?php | ||||
final class PhabricatorFileInfoController extends PhabricatorFileController { | final class PhabricatorFileInfoController extends PhabricatorFileController { | ||||
private $phid; | |||||
private $id; | |||||
public function shouldAllowPublic() { | public function shouldAllowPublic() { | ||||
return true; | return true; | ||||
} | } | ||||
public function willProcessRequest(array $data) { | public function handleRequest(AphrontRequest $request) { | ||||
$this->phid = idx($data, 'phid'); | $viewer = $request->getViewer(); | ||||
$this->id = idx($data, 'id'); | $id = $request->getURIData('id'); | ||||
} | $phid = $request->getURIData('phid'); | ||||
public function processRequest() { | if ($phid) { | ||||
$request = $this->getRequest(); | |||||
$user = $request->getUser(); | |||||
if ($this->phid) { | |||||
$file = id(new PhabricatorFileQuery()) | $file = id(new PhabricatorFileQuery()) | ||||
->setViewer($user) | ->setViewer($viewer) | ||||
->withPHIDs(array($this->phid)) | ->withPHIDs(array($phid)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$file) { | if (!$file) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
return id(new AphrontRedirectResponse())->setURI($file->getInfoURI()); | return id(new AphrontRedirectResponse())->setURI($file->getInfoURI()); | ||||
} | } | ||||
$file = id(new PhabricatorFileQuery()) | $file = id(new PhabricatorFileQuery()) | ||||
->setViewer($user) | ->setViewer($viewer) | ||||
->withIDs(array($this->id)) | ->withIDs(array($id)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$file) { | if (!$file) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$phid = $file->getPHID(); | $phid = $file->getPHID(); | ||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->setPolicyObject($file) | ->setPolicyObject($file) | ||||
->setHeader($file->getName()); | ->setHeader($file->getName()); | ||||
$ttl = $file->getTTL(); | $ttl = $file->getTTL(); | ||||
if ($ttl !== null) { | if ($ttl !== null) { | ||||
$ttl_tag = id(new PHUITagView()) | $ttl_tag = id(new PHUITagView()) | ||||
->setType(PHUITagView::TYPE_STATE) | ->setType(PHUITagView::TYPE_STATE) | ||||
->setBackgroundColor(PHUITagView::COLOR_YELLOW) | ->setBackgroundColor(PHUITagView::COLOR_YELLOW) | ||||
Show All 30 Lines | return $this->buildApplicationPage( | ||||
), | ), | ||||
array( | array( | ||||
'title' => $file->getName(), | 'title' => $file->getName(), | ||||
'pageObjects' => array($file->getPHID()), | 'pageObjects' => array($file->getPHID()), | ||||
)); | )); | ||||
} | } | ||||
private function buildTransactionView(PhabricatorFile $file) { | private function buildTransactionView(PhabricatorFile $file) { | ||||
$user = $this->getRequest()->getUser(); | $viewer = $this->getViewer(); | ||||
epriestley: Or `$this->getViewer()`. | |||||
$timeline = $this->buildTransactionTimeline( | $timeline = $this->buildTransactionTimeline( | ||||
$file, | $file, | ||||
new PhabricatorFileTransactionQuery()); | new PhabricatorFileTransactionQuery()); | ||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); | $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); | ||||
$add_comment_header = $is_serious | $add_comment_header = $is_serious | ||||
? pht('Add Comment') | ? pht('Add Comment') | ||||
: pht('Question File Integrity'); | : pht('Question File Integrity'); | ||||
$draft = PhabricatorDraft::newFromUserAndKey($user, $file->getPHID()); | $draft = PhabricatorDraft::newFromUserAndKey($viewer, $file->getPHID()); | ||||
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) | $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->setObjectPHID($file->getPHID()) | ->setObjectPHID($file->getPHID()) | ||||
->setDraft($draft) | ->setDraft($draft) | ||||
->setHeaderText($add_comment_header) | ->setHeaderText($add_comment_header) | ||||
->setAction($this->getApplicationURI('/comment/'.$file->getID().'/')) | ->setAction($this->getApplicationURI('/comment/'.$file->getID().'/')) | ||||
->setSubmitButtonName(pht('Add Comment')); | ->setSubmitButtonName(pht('Add Comment')); | ||||
return array( | return array( | ||||
$timeline, | $timeline, | ||||
$add_comment_form, | $add_comment_form, | ||||
); | ); | ||||
} | } | ||||
private function buildActionView(PhabricatorFile $file) { | private function buildActionView(PhabricatorFile $file) { | ||||
$request = $this->getRequest(); | $viewer = $this->getViewer(); | ||||
$viewer = $request->getUser(); | |||||
$id = $file->getID(); | $id = $file->getID(); | ||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
$viewer, | $viewer, | ||||
$file, | $file, | ||||
PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | private function buildActionView(PhabricatorFile $file) { | ||||
return $view; | return $view; | ||||
} | } | ||||
private function buildPropertyViews( | private function buildPropertyViews( | ||||
PHUIObjectBoxView $box, | PHUIObjectBoxView $box, | ||||
PhabricatorFile $file, | PhabricatorFile $file, | ||||
PhabricatorActionListView $actions) { | PhabricatorActionListView $actions) { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $viewer = $request->getUser(); | ||||
Done Inline ActionsOr $this->getViewer(). epriestley: Or `$this->getViewer()`. | |||||
$properties = id(new PHUIPropertyListView()); | $properties = id(new PHUIPropertyListView()); | ||||
$properties->setActionList($actions); | $properties->setActionList($actions); | ||||
$box->addPropertyList($properties, pht('Details')); | $box->addPropertyList($properties, pht('Details')); | ||||
if ($file->getAuthorPHID()) { | if ($file->getAuthorPHID()) { | ||||
$properties->addProperty( | $properties->addProperty( | ||||
pht('Author'), | pht('Author'), | ||||
$user->renderHandle($file->getAuthorPHID())); | $viewer->renderHandle($file->getAuthorPHID())); | ||||
} | } | ||||
$properties->addProperty( | $properties->addProperty( | ||||
pht('Created'), | pht('Created'), | ||||
phabricator_datetime($file->getDateCreated(), $user)); | phabricator_datetime($file->getDateCreated(), $viewer)); | ||||
$finfo = id(new PHUIPropertyListView()); | $finfo = id(new PHUIPropertyListView()); | ||||
$box->addPropertyList($finfo, pht('File Info')); | $box->addPropertyList($finfo, pht('File Info')); | ||||
$finfo->addProperty( | $finfo->addProperty( | ||||
pht('Size'), | pht('Size'), | ||||
phutil_format_bytes($file->getByteSize())); | phutil_format_bytes($file->getByteSize())); | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | private function buildPropertyViews( | ||||
$phids = $file->getObjectPHIDs(); | $phids = $file->getObjectPHIDs(); | ||||
if ($phids) { | if ($phids) { | ||||
$attached = new PHUIPropertyListView(); | $attached = new PHUIPropertyListView(); | ||||
$box->addPropertyList($attached, pht('Attached')); | $box->addPropertyList($attached, pht('Attached')); | ||||
$attached->addProperty( | $attached->addProperty( | ||||
pht('Attached To'), | pht('Attached To'), | ||||
$user->renderHandleList($phids)); | $viewer->renderHandleList($phids)); | ||||
} | } | ||||
if ($file->isViewableImage()) { | if ($file->isViewableImage()) { | ||||
$image = phutil_tag( | $image = phutil_tag( | ||||
'img', | 'img', | ||||
array( | array( | ||||
'src' => $file->getViewURI(), | 'src' => $file->getViewURI(), | ||||
'class' => 'phui-property-list-image', | 'class' => 'phui-property-list-image', | ||||
Show All 37 Lines | private function buildPropertyViews( | ||||
} | } | ||||
if ($engine) { | if ($engine) { | ||||
if ($engine->isChunkEngine()) { | if ($engine->isChunkEngine()) { | ||||
$chunkinfo = new PHUIPropertyListView(); | $chunkinfo = new PHUIPropertyListView(); | ||||
$box->addPropertyList($chunkinfo, pht('Chunks')); | $box->addPropertyList($chunkinfo, pht('Chunks')); | ||||
$chunks = id(new PhabricatorFileChunkQuery()) | $chunks = id(new PhabricatorFileChunkQuery()) | ||||
->setViewer($user) | ->setViewer($viewer) | ||||
->withChunkHandles(array($file->getStorageHandle())) | ->withChunkHandles(array($file->getStorageHandle())) | ||||
->execute(); | ->execute(); | ||||
$chunks = msort($chunks, 'getByteStart'); | $chunks = msort($chunks, 'getByteStart'); | ||||
$rows = array(); | $rows = array(); | ||||
$completed = array(); | $completed = array(); | ||||
foreach ($chunks as $chunk) { | foreach ($chunks as $chunk) { | ||||
$is_complete = $chunk->getDataFilePHID(); | $is_complete = $chunk->getDataFilePHID(); | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |
Or $this->getViewer().