2013-12-08 02:14:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhragmentVersionController extends PhragmentController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
2013-12-13 04:42:12 +01:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-08 02:14:34 +01:00
|
|
|
public function willProcessRequest(array $data) {
|
2014-06-09 20:36:49 +02:00
|
|
|
$this->id = idx($data, 'id', 0);
|
2013-12-08 02:14:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$version = id(new PhragmentFragmentVersionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
if ($version === null) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$parents = $this->loadParentFragments($version->getFragment()->getPath());
|
|
|
|
if ($parents === null) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
$current = idx($parents, count($parents) - 1, null);
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbsWithPath($parents);
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('View Version %d', $version->getSequence()));
|
2013-12-08 02:14:34 +01:00
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
$phids[] = $version->getFilePHID();
|
|
|
|
|
|
|
|
$this->loadHandles($phids);
|
|
|
|
|
|
|
|
$file = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($version->getFilePHID()))
|
|
|
|
->executeOne();
|
|
|
|
if ($file !== null) {
|
2013-12-13 04:42:12 +01:00
|
|
|
$file_uri = $file->getDownloadURI();
|
2013-12-08 02:14:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht(
|
2014-06-09 20:36:49 +02:00
|
|
|
'%s at version %d',
|
2013-12-08 02:14:34 +01:00
|
|
|
$version->getFragment()->getName(),
|
|
|
|
$version->getSequence()))
|
|
|
|
->setPolicyObject($version)
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($version)
|
|
|
|
->setObjectURI($version->getURI());
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Download Version'))
|
2013-12-13 04:42:12 +01:00
|
|
|
->setDisabled($file === null || !$this->isCorrectlyConfigured())
|
|
|
|
->setHref($this->isCorrectlyConfigured() ? $file_uri : null)
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-download'));
|
2013-12-08 02:14:34 +01:00
|
|
|
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($version)
|
|
|
|
->setActionList($actions);
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('File'),
|
|
|
|
$this->renderHandlesForPHIDs(array($version->getFilePHID())));
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addPropertyList($properties);
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-12-13 04:42:12 +01:00
|
|
|
$this->renderConfigurationWarningIfRequired(),
|
2013-12-08 02:14:34 +01:00
|
|
|
$box,
|
|
|
|
$this->renderPreviousVersionList($version)),
|
|
|
|
array(
|
|
|
|
'title' => pht('View Version'),
|
|
|
|
'device' => true));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderPreviousVersionList(
|
|
|
|
PhragmentFragmentVersion $version) {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$previous_versions = id(new PhragmentFragmentVersionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withFragmentPHIDs(array($version->getFragmentPHID()))
|
|
|
|
->withSequenceBefore($version->getSequence())
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$list = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
foreach ($previous_versions as $previous_version) {
|
|
|
|
$item = id(new PHUIObjectItemView());
|
|
|
|
$item->setHeader('Version '.$previous_version->getSequence());
|
|
|
|
$item->setHref($previous_version->getURI());
|
|
|
|
$item->addAttribute(phabricator_datetime(
|
|
|
|
$previous_version->getDateCreated(),
|
|
|
|
$viewer));
|
2013-12-13 04:42:12 +01:00
|
|
|
$patch_uri = $this->getApplicationURI(
|
|
|
|
'patch/'.$previous_version->getID().'/'.$version->getID());
|
2013-12-08 02:14:34 +01:00
|
|
|
$item->addAction(id(new PHUIListItemView())
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-file-o')
|
2014-06-09 20:36:49 +02:00
|
|
|
->setName(pht('Get Patch'))
|
2013-12-13 04:42:12 +01:00
|
|
|
->setHref($this->isCorrectlyConfigured() ? $patch_uri : null)
|
|
|
|
->setDisabled(!$this->isCorrectlyConfigured()));
|
2013-12-08 02:14:34 +01:00
|
|
|
$list->addItem($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
$item = id(new PHUIObjectItemView());
|
|
|
|
$item->setHeader('Prior to Version 0');
|
|
|
|
$item->addAttribute('Prior to any content (empty file)');
|
|
|
|
$item->addAction(id(new PHUIListItemView())
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-file-o')
|
2014-06-09 20:36:49 +02:00
|
|
|
->setName(pht('Get Patch'))
|
2013-12-08 02:14:34 +01:00
|
|
|
->setHref($this->getApplicationURI(
|
|
|
|
'patch/x/'.$version->getID())));
|
|
|
|
$list->addItem($item);
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|