@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

Update Phurl to use EditEngine

Summary: Fixes T10673. Set up Phurl to use Edit Engine. There's no way this is all I needed to do to get it working, so I'll be making another pass at it and testing more thoroughly...

Test Plan: Ran through the Phurl URL creation/edit/deletion process.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley, yelirekim

Maniphest Tasks: T10673

Differential Revision: https://secure.phabricator.com/D16573

Josh Cox 0817eb14 9329e6a1

+113 -272
+2
src/__phutil_library_map__.php
··· 3184 3184 'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php', 3185 3185 'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php', 3186 3186 'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php', 3187 + 'PhabricatorPhurlURLEditEngine' => 'applications/phurl/editor/PhabricatorPhurlURLEditEngine.php', 3187 3188 'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php', 3188 3189 'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php', 3189 3190 'PhabricatorPhurlURLMailReceiver' => 'applications/phurl/mail/PhabricatorPhurlURLMailReceiver.php', ··· 8097 8098 'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController', 8098 8099 'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability', 8099 8100 'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController', 8101 + 'PhabricatorPhurlURLEditEngine' => 'PhabricatorEditEngine', 8100 8102 'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor', 8101 8103 'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController', 8102 8104 'PhabricatorPhurlURLMailReceiver' => 'PhabricatorObjectMailReceiver',
-1
src/applications/paste/application/PhabricatorPasteApplication.php
··· 38 38 => 'PhabricatorPasteViewController', 39 39 '/paste/' => array( 40 40 '(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController', 41 - 'create/' => 'PhabricatorPasteEditController', 42 41 $this->getEditRoutePattern('edit/') => 'PhabricatorPasteEditController', 43 42 'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController', 44 43 'archive/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteArchiveController',
+1 -3
src/applications/phurl/application/PhabricatorPhurlApplication.php
··· 46 46 '(?:query/(?P<queryKey>[^/]+)/)?' 47 47 => 'PhabricatorPhurlURLListController', 48 48 'url/' => array( 49 - 'create/' 50 - => 'PhabricatorPhurlURLEditController', 51 - 'edit/(?P<id>[1-9]\d*)/' 49 + $this->getEditRoutePattern('edit/') 52 50 => 'PhabricatorPhurlURLEditController', 53 51 'comment/(?P<id>[1-9]\d*)/' 54 52 => 'PhabricatorPhurlURLCommentController',
+3 -10
src/applications/phurl/controller/PhabricatorPhurlController.php
··· 3 3 abstract class PhabricatorPhurlController extends PhabricatorController { 4 4 5 5 protected function buildApplicationCrumbs() { 6 - $can_create = $this->hasApplicationCapability( 7 - PhabricatorPhurlURLCreateCapability::CAPABILITY); 8 - 9 6 $crumbs = parent::buildApplicationCrumbs(); 10 - $crumbs->addAction( 11 - id(new PHUIListItemView()) 12 - ->setName(pht('Shorten URL')) 13 - ->setHref($this->getApplicationURI().'url/create/') 14 - ->setIcon('fa-plus-square') 15 - ->setDisabled(!$can_create) 16 - ->setWorkflow(!$can_create)); 7 + id(new PhabricatorPhurlURLEditEngine()) 8 + ->setViewer($this->getViewer()) 9 + ->addActionToCrumbs($crumbs); 17 10 18 11 return $crumbs; 19 12 }
+3 -258
src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
··· 4 4 extends PhabricatorPhurlController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 - $id = $request->getURIData('id'); 8 - $is_create = !$id; 9 - 10 - $viewer = $this->getViewer(); 11 - $user_phid = $viewer->getPHID(); 12 - $error_long_url = true; 13 - $error_alias = null; 14 - $validation_exception = null; 15 - 16 - $next_workflow = $request->getStr('next'); 17 - $uri_query = $request->getStr('query'); 18 - 19 - if ($is_create) { 20 - $this->requireApplicationCapability( 21 - PhabricatorPhurlURLCreateCapability::CAPABILITY); 22 - 23 - $url = PhabricatorPhurlURL::initializeNewPhurlURL( 24 - $viewer); 25 - $submit_label = pht('Create'); 26 - $page_title = pht('Shorten URL'); 27 - $header_icon = 'fa-plus-square'; 28 - $subscribers = array(); 29 - $cancel_uri = $this->getApplicationURI(); 30 - } else { 31 - $url = id(new PhabricatorPhurlURLQuery()) 32 - ->setViewer($viewer) 33 - ->withIDs(array($id)) 34 - ->requireCapabilities( 35 - array( 36 - PhabricatorPolicyCapability::CAN_VIEW, 37 - PhabricatorPolicyCapability::CAN_EDIT, 38 - )) 39 - ->executeOne(); 40 - 41 - if (!$url) { 42 - return new Aphront404Response(); 43 - } 44 - 45 - $submit_label = pht('Update'); 46 - $page_title = pht('Edit URL: %s', $url->getName()); 47 - $header_icon = 'fa-pencil'; 48 - 49 - $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( 50 - $url->getPHID()); 51 - 52 - $cancel_uri = '/U'.$url->getID(); 53 - } 54 - 55 - if ($is_create) { 56 - $projects = array(); 57 - } else { 58 - $projects = PhabricatorEdgeQuery::loadDestinationPHIDs( 59 - $url->getPHID(), 60 - PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 61 - $projects = array_reverse($projects); 62 - } 63 - 64 - $name = $url->getName(); 65 - $long_url = $url->getLongURL(); 66 - $alias = $url->getAlias(); 67 - $description = $url->getDescription(); 68 - $edit_policy = $url->getEditPolicy(); 69 - $view_policy = $url->getViewPolicy(); 70 - $space = $url->getSpacePHID(); 71 - 72 - if ($request->isFormPost()) { 73 - $xactions = array(); 74 - $name = $request->getStr('name'); 75 - $long_url = $request->getStr('longURL'); 76 - $alias = $request->getStr('alias'); 77 - $projects = $request->getArr('projects'); 78 - $description = $request->getStr('description'); 79 - $subscribers = $request->getArr('subscribers'); 80 - $edit_policy = $request->getStr('editPolicy'); 81 - $view_policy = $request->getStr('viewPolicy'); 82 - $space = $request->getStr('spacePHID'); 83 - 84 - $xactions[] = id(new PhabricatorPhurlURLTransaction()) 85 - ->setTransactionType( 86 - PhabricatorPhurlURLTransaction::TYPE_NAME) 87 - ->setNewValue($name); 88 - 89 - $xactions[] = id(new PhabricatorPhurlURLTransaction()) 90 - ->setTransactionType( 91 - PhabricatorPhurlURLTransaction::TYPE_URL) 92 - ->setNewValue($long_url); 93 - 94 - $xactions[] = id(new PhabricatorPhurlURLTransaction()) 95 - ->setTransactionType( 96 - PhabricatorPhurlURLTransaction::TYPE_ALIAS) 97 - ->setNewValue($alias); 98 - 99 - $xactions[] = id(new PhabricatorPhurlURLTransaction()) 100 - ->setTransactionType( 101 - PhabricatorTransactions::TYPE_SUBSCRIBERS) 102 - ->setNewValue(array('=' => array_fuse($subscribers))); 103 - 104 - $xactions[] = id(new PhabricatorPhurlURLTransaction()) 105 - ->setTransactionType( 106 - PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION) 107 - ->setNewValue($description); 108 - 109 - $xactions[] = id(new PhabricatorPhurlURLTransaction()) 110 - ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 111 - ->setNewValue($view_policy); 112 - 113 - $xactions[] = id(new PhabricatorPhurlURLTransaction()) 114 - ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) 115 - ->setNewValue($edit_policy); 116 - 117 - $xactions[] = id(new PhabricatorPhurlURLTransaction()) 118 - ->setTransactionType(PhabricatorTransactions::TYPE_SPACE) 119 - ->setNewValue($space); 120 - 121 - $editor = id(new PhabricatorPhurlURLEditor()) 122 - ->setActor($viewer) 123 - ->setContentSourceFromRequest($request) 124 - ->setContinueOnNoEffect(true); 125 - 126 - try { 127 - $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 128 - $xactions[] = id(new PhabricatorPhurlURLTransaction()) 129 - ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 130 - ->setMetadataValue('edge:type', $proj_edge_type) 131 - ->setNewValue(array('=' => array_fuse($projects))); 132 - 133 - $xactions = $editor->applyTransactions($url, $xactions); 134 - return id(new AphrontRedirectResponse()) 135 - ->setURI($url->getURI()); 136 - } catch (PhabricatorApplicationTransactionValidationException $ex) { 137 - $validation_exception = $ex; 138 - $error_long_url = $ex->getShortMessage( 139 - PhabricatorPhurlURLTransaction::TYPE_URL); 140 - $error_alias = $ex->getShortMessage( 141 - PhabricatorPhurlURLTransaction::TYPE_ALIAS); 142 - } 143 - } 144 - 145 - $current_policies = id(new PhabricatorPolicyQuery()) 146 - ->setViewer($viewer) 147 - ->setObject($url) 148 - ->execute(); 149 - 150 - $name = id(new AphrontFormTextControl()) 151 - ->setLabel(pht('Name')) 152 - ->setName('name') 153 - ->setValue($name); 154 - 155 - $long_url = id(new AphrontFormTextControl()) 156 - ->setLabel(pht('URL')) 157 - ->setName('longURL') 158 - ->setValue($long_url) 159 - ->setError($error_long_url); 160 - 161 - $alias = id(new AphrontFormTextControl()) 162 - ->setLabel(pht('Alias')) 163 - ->setName('alias') 164 - ->setValue($alias) 165 - ->setError($error_alias); 166 - 167 - $projects = id(new AphrontFormTokenizerControl()) 168 - ->setLabel(pht('Tags')) 169 - ->setName('projects') 170 - ->setValue($projects) 171 - ->setUser($viewer) 172 - ->setDatasource(new PhabricatorProjectDatasource()); 173 - 174 - $description = id(new PhabricatorRemarkupControl()) 175 - ->setLabel(pht('Description')) 176 - ->setName('description') 177 - ->setValue($description) 178 - ->setUser($viewer); 179 - 180 - $view_policies = id(new AphrontFormPolicyControl()) 181 - ->setUser($viewer) 182 - ->setValue($view_policy) 183 - ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) 184 - ->setPolicyObject($url) 185 - ->setPolicies($current_policies) 186 - ->setSpacePHID($space) 187 - ->setName('viewPolicy'); 188 - $edit_policies = id(new AphrontFormPolicyControl()) 189 - ->setUser($viewer) 190 - ->setValue($edit_policy) 191 - ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 192 - ->setPolicyObject($url) 193 - ->setPolicies($current_policies) 194 - ->setName('editPolicy'); 195 - 196 - $subscribers = id(new AphrontFormTokenizerControl()) 197 - ->setLabel(pht('Subscribers')) 198 - ->setName('subscribers') 199 - ->setValue($subscribers) 200 - ->setUser($viewer) 201 - ->setDatasource(new PhabricatorMetaMTAMailableDatasource()); 202 - 203 - $form = id(new AphrontFormView()) 204 - ->setUser($viewer) 205 - ->appendChild($name) 206 - ->appendChild($long_url) 207 - ->appendChild($alias) 208 - ->appendControl($view_policies) 209 - ->appendControl($edit_policies) 210 - ->appendControl($subscribers) 211 - ->appendChild($projects) 212 - ->appendChild($description); 213 - 214 - 215 - if ($request->isAjax()) { 216 - return $this->newDialog() 217 - ->setTitle($page_title) 218 - ->setWidth(AphrontDialogView::WIDTH_FULL) 219 - ->appendForm($form) 220 - ->addCancelButton($cancel_uri) 221 - ->addSubmitButton($submit_label); 222 - } 223 - 224 - $submit = id(new AphrontFormSubmitControl()) 225 - ->addCancelButton($cancel_uri) 226 - ->setValue($submit_label); 227 - 228 - $form->appendChild($submit); 229 - 230 - $form_box = id(new PHUIObjectBoxView()) 231 - ->setHeaderText($page_title) 232 - ->setForm($form); 233 - 234 - $crumbs = $this->buildApplicationCrumbs(); 235 - 236 - if (!$is_create) { 237 - $crumbs->addTextCrumb($url->getMonogram(), $url->getURI()); 238 - } else { 239 - $crumbs->addTextCrumb(pht('Create URL')); 240 - } 241 - 242 - $crumbs->addTextCrumb($page_title); 243 - $crumbs->setBorder(true); 244 - 245 - $object_box = id(new PHUIObjectBoxView()) 246 - ->setHeaderText(pht('URL')) 247 - ->setValidationException($validation_exception) 248 - ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 249 - ->appendChild($form); 250 - 251 - $header = id(new PHUIHeaderView()) 252 - ->setHeader($page_title) 253 - ->setHeaderIcon($header_icon); 254 - 255 - $view = id(new PHUITwoColumnView()) 256 - ->setHeader($header) 257 - ->setFooter(array( 258 - $object_box, 259 - )); 260 - 261 - return $this->newPage() 262 - ->setTitle($page_title) 263 - ->setCrumbs($crumbs) 264 - ->appendChild($view); 7 + return id(new PhabricatorPhurlURLEditEngine()) 8 + ->setController($this) 9 + ->buildResponse(); 265 10 } 266 11 }
+104
src/applications/phurl/editor/PhabricatorPhurlURLEditEngine.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLEditEngine 4 + extends PhabricatorEditEngine { 5 + 6 + const ENGINECONST = 'phurl.url'; 7 + 8 + public function getEngineName() { 9 + return pht('Phurl'); 10 + } 11 + 12 + public function getEngineApplicationClass() { 13 + return 'PhabricatorPhurlApplication'; 14 + } 15 + 16 + public function getSummaryHeader() { 17 + return pht('Configure Phurl Forms'); 18 + } 19 + 20 + public function getSummaryText() { 21 + return pht('Configure creation and editing forms in Phurl.'); 22 + } 23 + 24 + protected function newEditableObject() { 25 + return PhabricatorPhurlURL::initializeNewPhurlURL($this->getViewer()); 26 + } 27 + 28 + protected function newObjectQuery() { 29 + return new PhabricatorPhurlURLQuery(); 30 + } 31 + 32 + protected function getObjectCreateTitleText($object) { 33 + return pht('Create New URL'); 34 + } 35 + 36 + protected function getObjectEditTitleText($object) { 37 + return pht('Edit URL: %s', $object->getName()); 38 + } 39 + 40 + protected function getObjectEditShortText($object) { 41 + return $object->getName(); 42 + } 43 + 44 + protected function getObjectCreateShortText() { 45 + return pht('Create URL'); 46 + } 47 + 48 + protected function getObjectName() { 49 + return pht('URL'); 50 + } 51 + 52 + protected function getObjectCreateCancelURI($object) { 53 + return $this->getApplication()->getApplicationURI('/'); 54 + } 55 + 56 + protected function getEditorURI() { 57 + return $this->getApplication()->getApplicationURI('url/edit/'); 58 + } 59 + 60 + protected function getObjectViewURI($object) { 61 + return $object->getURI(); 62 + } 63 + 64 + protected function getCreateNewObjectPolicy() { 65 + return $this->getApplication()->getPolicy( 66 + PhabricatorPhurlURLCreateCapability::CAPABILITY); 67 + } 68 + 69 + protected function buildCustomEditFields($object) { 70 + 71 + return array( 72 + id(new PhabricatorTextEditField()) 73 + ->setKey('name') 74 + ->setLabel(pht('Name')) 75 + ->setDescription(pht('URL name.')) 76 + ->setConduitTypeDescription(pht('New URL name.')) 77 + ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_NAME) 78 + ->setValue($object->getName()), 79 + id(new PhabricatorTextEditField()) 80 + ->setKey('url') 81 + ->setLabel(pht('URL')) 82 + ->setDescription(pht('The URL to shorten.')) 83 + ->setConduitTypeDescription(pht('New URL.')) 84 + ->setValue($object->getLongURL()) 85 + ->setIsRequired(true) 86 + ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_URL), 87 + id(new PhabricatorTextEditField()) 88 + ->setKey('alias') 89 + ->setLabel(pht('Alias')) 90 + ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_ALIAS) 91 + ->setDescription(pht('The alias to give the URL.')) 92 + ->setConduitTypeDescription(pht('New alias.')) 93 + ->setValue($object->getAlias()), 94 + id(new PhabricatorRemarkupEditField()) 95 + ->setKey('description') 96 + ->setLabel(pht('Description')) 97 + ->setDescription(pht('URL long description.')) 98 + ->setConduitTypeDescription(pht('New URL description.')) 99 + ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION) 100 + ->setValue($object->getDescription()), 101 + ); 102 + } 103 + 104 + }