@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add an alias to Phurl URL's

Summary: Ref T8992, Add an alias to Phurl URL's that can be used to redirect to link.

Test Plan: Add an alias to Phurl object, and navigate to `local.install.com/u/<newalias>`. This should redirect to the Phurl's URL.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: joshuaspence, Korvin

Maniphest Tasks: T8992

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

+103 -5
+1
src/applications/phurl/application/PhabricatorPhurlApplication.php
··· 30 30 return array( 31 31 '/U(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLViewController', 32 32 '/u/(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLAccessController', 33 + '/u/(?P<alias>[^/]+)' => 'PhabricatorPhurlURLAccessController', 33 34 '/phurl/' => array( 34 35 '(?:query/(?P<queryKey>[^/]+)/)?' 35 36 => 'PhabricatorPhurlURLListController',
+12 -4
src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
··· 6 6 public function handleRequest(AphrontRequest $request) { 7 7 $viewer = $this->getViewer(); 8 8 $id = $request->getURIData('id'); 9 + $alias = $request->getURIData('alias'); 9 10 10 - $url = id(new PhabricatorPhurlURLQuery()) 11 - ->setViewer($viewer) 12 - ->withIDs(array($id)) 13 - ->executeOne(); 11 + if ($id) { 12 + $url = id(new PhabricatorPhurlURLQuery()) 13 + ->setViewer($viewer) 14 + ->withIDs(array($id)) 15 + ->executeOne(); 16 + } else if ($alias) { 17 + $url = id(new PhabricatorPhurlURLQuery()) 18 + ->setViewer($viewer) 19 + ->withAliases(array($alias)) 20 + ->executeOne(); 21 + } 14 22 15 23 if (!$url) { 16 24 return new Aphront404Response();
+18 -1
src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
··· 7 7 $id = $request->getURIData('id'); 8 8 $is_create = !$id; 9 9 10 - $viewer = $request->getViewer(); 10 + $viewer = $this->getViewer(); 11 11 $user_phid = $viewer->getPHID(); 12 12 $error_name = true; 13 13 $error_long_url = true; 14 + $error_alias = null; 14 15 $validation_exception = null; 15 16 16 17 $next_workflow = $request->getStr('next'); ··· 58 59 59 60 $name = $url->getName(); 60 61 $long_url = $url->getLongURL(); 62 + $alias = $url->getAlias(); 61 63 $description = $url->getDescription(); 62 64 $edit_policy = $url->getEditPolicy(); 63 65 $view_policy = $url->getViewPolicy(); ··· 67 69 $xactions = array(); 68 70 $name = $request->getStr('name'); 69 71 $long_url = $request->getStr('longURL'); 72 + $alias = $request->getStr('alias'); 70 73 $projects = $request->getArr('projects'); 71 74 $description = $request->getStr('description'); 72 75 $subscribers = $request->getArr('subscribers'); ··· 83 86 ->setTransactionType( 84 87 PhabricatorPhurlURLTransaction::TYPE_URL) 85 88 ->setNewValue($long_url); 89 + 90 + $xactions[] = id(new PhabricatorPhurlURLTransaction()) 91 + ->setTransactionType( 92 + PhabricatorPhurlURLTransaction::TYPE_ALIAS) 93 + ->setNewValue($alias); 86 94 87 95 $xactions[] = id(new PhabricatorPhurlURLTransaction()) 88 96 ->setTransactionType( ··· 127 135 PhabricatorPhurlURLTransaction::TYPE_NAME); 128 136 $error_long_url = $ex->getShortMessage( 129 137 PhabricatorPhurlURLTransaction::TYPE_URL); 138 + $error_alias = $ex->getShortMessage( 139 + PhabricatorPhurlURLTransaction::TYPE_ALIAS); 130 140 } 131 141 } 132 142 ··· 146 156 ->setName('longURL') 147 157 ->setValue($long_url) 148 158 ->setError($error_long_url); 159 + 160 + $alias = id(new AphrontFormTextControl()) 161 + ->setLabel(pht('Alias')) 162 + ->setName('alias') 163 + ->setValue($alias) 164 + ->setError($error_alias); 149 165 150 166 $projects = id(new AphrontFormTokenizerControl()) 151 167 ->setLabel(pht('Projects')) ··· 187 203 ->setUser($viewer) 188 204 ->appendChild($name) 189 205 ->appendChild($long_url) 206 + ->appendChild($alias) 190 207 ->appendControl($view_policies) 191 208 ->appendControl($edit_policies) 192 209 ->appendControl($subscribers)
+4
src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
··· 129 129 pht('Original URL'), 130 130 $url->getLongURL()); 131 131 132 + $properties->addProperty( 133 + pht('Alias'), 134 + $url->getAlias()); 135 + 132 136 $properties->invokeWillRenderEvent(); 133 137 134 138 if (strlen($url->getDescription())) {
+30
src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
··· 16 16 17 17 $types[] = PhabricatorPhurlURLTransaction::TYPE_NAME; 18 18 $types[] = PhabricatorPhurlURLTransaction::TYPE_URL; 19 + $types[] = PhabricatorPhurlURLTransaction::TYPE_ALIAS; 19 20 $types[] = PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION; 20 21 21 22 $types[] = PhabricatorTransactions::TYPE_COMMENT; ··· 33 34 return $object->getName(); 34 35 case PhabricatorPhurlURLTransaction::TYPE_URL: 35 36 return $object->getLongURL(); 37 + case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 38 + return $object->getAlias(); 36 39 case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION: 37 40 return $object->getDescription(); 38 41 } ··· 46 49 switch ($xaction->getTransactionType()) { 47 50 case PhabricatorPhurlURLTransaction::TYPE_NAME: 48 51 case PhabricatorPhurlURLTransaction::TYPE_URL: 52 + case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 49 53 case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION: 50 54 return $xaction->getNewValue(); 51 55 } ··· 64 68 case PhabricatorPhurlURLTransaction::TYPE_URL: 65 69 $object->setLongURL($xaction->getNewValue()); 66 70 return; 71 + case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 72 + $object->setAlias($xaction->getNewValue()); 73 + return; 67 74 case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION: 68 75 $object->setDescription($xaction->getNewValue()); 69 76 return; ··· 79 86 switch ($xaction->getTransactionType()) { 80 87 case PhabricatorPhurlURLTransaction::TYPE_NAME: 81 88 case PhabricatorPhurlURLTransaction::TYPE_URL: 89 + case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 82 90 case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION: 83 91 return; 84 92 } ··· 109 117 $error->setIsMissingFieldError(true); 110 118 $errors[] = $error; 111 119 } 120 + break; 121 + case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 122 + foreach ($xactions as $xaction) { 123 + if ($xaction->getOldValue() != $xaction->getNewValue()) { 124 + $new_alias = $xaction->getNewValue(); 125 + if (!preg_match('/[a-zA-Z]/', $new_alias)) { 126 + $errors[] = new PhabricatorApplicationTransactionValidationError( 127 + $type, 128 + pht('Invalid Alias'), 129 + pht('The alias must contain at least one letter.'), 130 + $xaction); 131 + } 132 + if (preg_match('/[^a-z0-9]/i', $new_alias)) { 133 + $errors[] = new PhabricatorApplicationTransactionValidationError( 134 + $type, 135 + pht('Invalid Alias'), 136 + pht('The alias may only contain letters and numbers.'), 137 + $xaction); 138 + } 139 + } 140 + } 141 + 112 142 break; 113 143 case PhabricatorPhurlURLTransaction::TYPE_URL: 114 144 $missing = $this->validateIsEmptyTextField(
+13
src/applications/phurl/query/PhabricatorPhurlURLQuery.php
··· 7 7 private $phids; 8 8 private $names; 9 9 private $longURLs; 10 + private $aliases; 10 11 private $authorPHIDs; 11 12 12 13 public function newResultObject() { ··· 30 31 31 32 public function withLongURLs(array $long_urls) { 32 33 $this->longURLs = $long_urls; 34 + return $this; 35 + } 36 + 37 + public function withAliases(array $aliases) { 38 + $this->aliases = $aliases; 33 39 return $this; 34 40 } 35 41 ··· 85 91 $conn, 86 92 'url.longURL IN (%Ls)', 87 93 $this->longURLs); 94 + } 95 + 96 + if ($this->aliases !== null) { 97 + $where[] = qsprintf( 98 + $conn, 99 + 'url.alias IN (%Ls)', 100 + $this->aliases); 88 101 } 89 102 90 103 return $where;
+25
src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php
··· 5 5 6 6 const TYPE_NAME = 'phurl.name'; 7 7 const TYPE_URL = 'phurl.longurl'; 8 + const TYPE_ALIAS = 'phurl.alias'; 8 9 const TYPE_DESCRIPTION = 'phurl.description'; 9 10 10 11 const MAILTAG_CONTENT = 'phurl:content'; ··· 28 29 switch ($this->getTransactionType()) { 29 30 case self::TYPE_NAME: 30 31 case self::TYPE_URL: 32 + case self::TYPE_ALIAS: 31 33 case self::TYPE_DESCRIPTION: 32 34 $phids[] = $this->getObjectPHID(); 33 35 break; ··· 49 51 switch ($this->getTransactionType()) { 50 52 case self::TYPE_NAME: 51 53 case self::TYPE_URL: 54 + case self::TYPE_ALIAS: 52 55 case self::TYPE_DESCRIPTION: 53 56 return 'fa-pencil'; 54 57 break; ··· 83 86 $this->renderHandleLink($author_phid), 84 87 $old, 85 88 $new); 89 + case self::TYPE_ALIAS: 90 + return pht( 91 + '%s changed the alias of the URL from %s to %s.', 92 + $this->renderHandleLink($author_phid), 93 + $old, 94 + $new); 86 95 case self::TYPE_DESCRIPTION: 87 96 return pht( 88 97 "%s updated the URL's description.", ··· 130 139 $old, 131 140 $new); 132 141 } 142 + case self::TYPE_ALIAS: 143 + if ($old === null) { 144 + return pht( 145 + '%s created %s.', 146 + $this->renderHandleLink($author_phid), 147 + $this->renderHandleLink($object_phid)); 148 + } else { 149 + return pht( 150 + '%s changed the alias of %s from %s to %s', 151 + $this->renderHandleLink($author_phid), 152 + $this->renderHandleLink($object_phid), 153 + $old, 154 + $new); 155 + } 133 156 case self::TYPE_DESCRIPTION: 134 157 return pht( 135 158 '%s updated the description of %s.', ··· 147 170 switch ($this->getTransactionType()) { 148 171 case self::TYPE_NAME: 149 172 case self::TYPE_URL: 173 + case self::TYPE_ALIAS: 150 174 case self::TYPE_DESCRIPTION: 151 175 return PhabricatorTransactions::COLOR_GREEN; 152 176 } ··· 185 209 case self::TYPE_NAME: 186 210 case self::TYPE_DESCRIPTION: 187 211 case self::TYPE_URL: 212 + case self::TYPE_ALIAS: 188 213 $tags[] = self::MAILTAG_CONTENT; 189 214 break; 190 215 }