Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / phurl / controller / PhabricatorPhurlURLViewController.php
blob578e3ed9f8012ea02abe6060fd7036866b5caab9
1 <?php
3 final class PhabricatorPhurlURLViewController
4 extends PhabricatorPhurlController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
12 $id = $request->getURIData('id');
14 $timeline = null;
16 $url = id(new PhabricatorPhurlURLQuery())
17 ->setViewer($viewer)
18 ->withIDs(array($id))
19 ->executeOne();
20 if (!$url) {
21 return new Aphront404Response();
24 $title = $url->getMonogram();
25 $page_title = $title.' '.$url->getName();
26 $crumbs = $this->buildApplicationCrumbs();
27 $crumbs->addTextCrumb($title);
28 $crumbs->setBorder(true);
30 $timeline = $this->buildTransactionTimeline(
31 $url,
32 new PhabricatorPhurlURLTransactionQuery());
33 $timeline->setQuoteRef($url->getMonogram());
35 $header = $this->buildHeaderView($url);
36 $curtain = $this->buildCurtain($url);
37 $details = $this->buildPropertySectionView($url);
39 $url_error = id(new PHUIInfoView())
40 ->setErrors(array(pht('This URL is invalid due to a bad protocol.')))
41 ->setIsHidden($url->isValid());
43 $add_comment_form = $this->buildCommentForm($url, $timeline);
45 $view = id(new PHUITwoColumnView())
46 ->setHeader($header)
47 ->setCurtain($curtain)
48 ->setMainColumn(array(
49 $url_error,
50 $details,
51 $timeline,
52 $add_comment_form,
53 ));
55 return $this->newPage()
56 ->setTitle($page_title)
57 ->setCrumbs($crumbs)
58 ->setPageObjectPHIDs(array($url->getPHID()))
59 ->appendChild(
60 array(
61 $view,
62 ));
65 private function buildCommentForm(PhabricatorPhurlURL $url, $timeline) {
66 $viewer = $this->getViewer();
67 $box = id(new PhabricatorPhurlURLEditEngine())
68 ->setViewer($viewer)
69 ->buildEditEngineCommentView($url)
70 ->setTransactionTimeline($timeline);
72 return $box;
75 private function buildHeaderView(PhabricatorPhurlURL $url) {
76 $viewer = $this->getViewer();
77 $icon = 'fa-check';
78 $color = 'bluegrey';
79 $status = pht('Active');
80 $id = $url->getID();
82 $visit = id(new PHUIButtonView())
83 ->setTag('a')
84 ->setText(pht('Visit URL'))
85 ->setIcon('fa-external-link')
86 ->setHref($url->getRedirectURI())
87 ->setDisabled(!$url->isValid());
89 $header = id(new PHUIHeaderView())
90 ->setUser($viewer)
91 ->setHeader($url->getDisplayName())
92 ->setStatus($icon, $color, $status)
93 ->setPolicyObject($url)
94 ->setHeaderIcon('fa-compress')
95 ->addActionLink($visit);
97 return $header;
100 private function buildCurtain(PhabricatorPhurlURL $url) {
101 $viewer = $this->getViewer();
102 $id = $url->getID();
104 $curtain = $this->newCurtainView($url);
106 $can_edit = PhabricatorPolicyFilter::hasCapability(
107 $viewer,
108 $url,
109 PhabricatorPolicyCapability::CAN_EDIT);
111 $curtain
112 ->addAction(
113 id(new PhabricatorActionView())
114 ->setName(pht('Edit Phurl'))
115 ->setIcon('fa-pencil')
116 ->setHref($this->getApplicationURI("url/edit/{$id}/"))
117 ->setDisabled(!$can_edit)
118 ->setWorkflow(!$can_edit));
120 return $curtain;
123 private function buildPropertySectionView(PhabricatorPhurlURL $url) {
124 $viewer = $this->getViewer();
126 $properties = id(new PHUIPropertyListView())
127 ->setUser($viewer);
129 $properties->addProperty(
130 pht('Short URL'),
131 $url->getRedirectURI());
133 $properties->addProperty(
134 pht('Original URL'),
135 $url->getLongURL());
137 $properties->addProperty(
138 pht('Alias'),
139 $url->getAlias());
141 $description = $url->getDescription();
142 if (strlen($description)) {
143 $description = new PHUIRemarkupView($viewer, $description);
144 $properties->addSectionHeader(pht('Description'));
145 $properties->addTextContent($description);
148 return id(new PHUIObjectBoxView())
149 ->setHeaderText(pht('Details'))
150 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
151 ->appendChild($properties);