@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 154 lines 4.1 kB view raw
1<?php 2 3final class PhabricatorPhurlURLViewController 4 extends PhabricatorPhurlController { 5 6 public function shouldAllowPublic() { 7 return true; 8 } 9 10 public function handleRequest(AphrontRequest $request) { 11 $viewer = $request->getViewer(); 12 $id = $request->getURIData('id'); 13 14 $timeline = null; 15 16 $url = id(new PhabricatorPhurlURLQuery()) 17 ->setViewer($viewer) 18 ->withIDs(array($id)) 19 ->executeOne(); 20 if (!$url) { 21 return new Aphront404Response(); 22 } 23 24 $title = $url->getMonogram(); 25 $page_title = $title.' '.$url->getName(); 26 $crumbs = $this->buildApplicationCrumbs(); 27 $crumbs->addTextCrumb($title); 28 $crumbs->setBorder(true); 29 30 $timeline = $this->buildTransactionTimeline( 31 $url, 32 new PhabricatorPhurlURLTransactionQuery()); 33 $timeline->setQuoteRef($url->getMonogram()); 34 35 $header = $this->buildHeaderView($url); 36 $curtain = $this->buildCurtain($url); 37 $details = $this->buildPropertySectionView($url); 38 39 $url_error = id(new PHUIInfoView()) 40 ->setErrors(array(pht('This URL is invalid due to a bad protocol.'))) 41 ->setIsHidden($url->isValid()); 42 43 $add_comment_form = $this->buildCommentForm($url, $timeline); 44 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 )); 54 55 return $this->newPage() 56 ->setTitle($page_title) 57 ->setCrumbs($crumbs) 58 ->setPageObjectPHIDs(array($url->getPHID())) 59 ->appendChild( 60 array( 61 $view, 62 )); 63 } 64 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); 71 72 return $box; 73 } 74 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(); 81 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()); 88 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); 96 97 return $header; 98 } 99 100 private function buildCurtain(PhabricatorPhurlURL $url) { 101 $viewer = $this->getViewer(); 102 $id = $url->getID(); 103 104 $curtain = $this->newCurtainView($url); 105 106 $can_edit = PhabricatorPolicyFilter::hasCapability( 107 $viewer, 108 $url, 109 PhabricatorPolicyCapability::CAN_EDIT); 110 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)); 119 120 return $curtain; 121 } 122 123 private function buildPropertySectionView(PhabricatorPhurlURL $url) { 124 $viewer = $this->getViewer(); 125 126 $properties = id(new PHUIPropertyListView()) 127 ->setUser($viewer); 128 129 $properties->addProperty( 130 pht('Short URL'), 131 $url->getRedirectURI()); 132 133 $properties->addProperty( 134 pht('Original URL'), 135 $url->getLongURL()); 136 137 $properties->addProperty( 138 pht('Alias'), 139 $url->getAlias()); 140 141 $description = $url->getDescription(); 142 if (strlen($description)) { 143 $description = new PHUIRemarkupView($viewer, $description); 144 $properties->addSectionHeader(pht('Description')); 145 $properties->addTextContent($description); 146 } 147 148 return id(new PHUIObjectBoxView()) 149 ->setHeaderText(pht('Details')) 150 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 151 ->appendChild($properties); 152 } 153 154}