@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.

Update Phurl for modular transactions

Summary: Ref T6049. This moves Phurl to modular transactions.

Test Plan: Everything works here, add phurl, edit phurl, use phurl. Test various error states. Left a TODO on the validate dupe keys, not sure how to implement that in modular-land.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T6049

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

+303 -430
+11 -1
src/__phutil_library_map__.php
··· 3380 3380 'PhabricatorPhurlShortURLDefaultController' => 'applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php', 3381 3381 'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php', 3382 3382 'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php', 3383 + 'PhabricatorPhurlURLAliasTransaction' => 'applications/phurl/xaction/PhabricatorPhurlURLAliasTransaction.php', 3383 3384 'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php', 3384 3385 'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php', 3385 3386 'PhabricatorPhurlURLDatasource' => 'applications/phurl/typeahead/PhabricatorPhurlURLDatasource.php', 3387 + 'PhabricatorPhurlURLDescriptionTransaction' => 'applications/phurl/xaction/PhabricatorPhurlURLDescriptionTransaction.php', 3386 3388 'PhabricatorPhurlURLEditConduitAPIMethod' => 'applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php', 3387 3389 'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php', 3388 3390 'PhabricatorPhurlURLEditEngine' => 'applications/phurl/editor/PhabricatorPhurlURLEditEngine.php', 3389 3391 'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php', 3390 3392 'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php', 3393 + 'PhabricatorPhurlURLLongURLTransaction' => 'applications/phurl/xaction/PhabricatorPhurlURLLongURLTransaction.php', 3391 3394 'PhabricatorPhurlURLMailReceiver' => 'applications/phurl/mail/PhabricatorPhurlURLMailReceiver.php', 3392 3395 'PhabricatorPhurlURLNameNgrams' => 'applications/phurl/storage/PhabricatorPhurlURLNameNgrams.php', 3396 + 'PhabricatorPhurlURLNameTransaction' => 'applications/phurl/xaction/PhabricatorPhurlURLNameTransaction.php', 3393 3397 'PhabricatorPhurlURLPHIDType' => 'applications/phurl/phid/PhabricatorPhurlURLPHIDType.php', 3394 3398 'PhabricatorPhurlURLQuery' => 'applications/phurl/query/PhabricatorPhurlURLQuery.php', 3395 3399 'PhabricatorPhurlURLReplyHandler' => 'applications/phurl/mail/PhabricatorPhurlURLReplyHandler.php', ··· 3398 3402 'PhabricatorPhurlURLTransaction' => 'applications/phurl/storage/PhabricatorPhurlURLTransaction.php', 3399 3403 'PhabricatorPhurlURLTransactionComment' => 'applications/phurl/storage/PhabricatorPhurlURLTransactionComment.php', 3400 3404 'PhabricatorPhurlURLTransactionQuery' => 'applications/phurl/query/PhabricatorPhurlURLTransactionQuery.php', 3405 + 'PhabricatorPhurlURLTransactionType' => 'applications/phurl/xaction/PhabricatorPhurlURLTransactionType.php', 3401 3406 'PhabricatorPhurlURLViewController' => 'applications/phurl/controller/PhabricatorPhurlURLViewController.php', 3402 3407 'PhabricatorPinnedApplicationsSetting' => 'applications/settings/setting/PhabricatorPinnedApplicationsSetting.php', 3403 3408 'PhabricatorPirateEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorPirateEnglishTranslation.php', ··· 8545 8550 'PhabricatorNgramsInterface', 8546 8551 ), 8547 8552 'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController', 8553 + 'PhabricatorPhurlURLAliasTransaction' => 'PhabricatorPhurlURLTransactionType', 8548 8554 'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController', 8549 8555 'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability', 8550 8556 'PhabricatorPhurlURLDatasource' => 'PhabricatorTypeaheadDatasource', 8557 + 'PhabricatorPhurlURLDescriptionTransaction' => 'PhabricatorPhurlURLTransactionType', 8551 8558 'PhabricatorPhurlURLEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 8552 8559 'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController', 8553 8560 'PhabricatorPhurlURLEditEngine' => 'PhabricatorEditEngine', 8554 8561 'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor', 8555 8562 'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController', 8563 + 'PhabricatorPhurlURLLongURLTransaction' => 'PhabricatorPhurlURLTransactionType', 8556 8564 'PhabricatorPhurlURLMailReceiver' => 'PhabricatorObjectMailReceiver', 8557 8565 'PhabricatorPhurlURLNameNgrams' => 'PhabricatorSearchNgrams', 8566 + 'PhabricatorPhurlURLNameTransaction' => 'PhabricatorPhurlURLTransactionType', 8558 8567 'PhabricatorPhurlURLPHIDType' => 'PhabricatorPHIDType', 8559 8568 'PhabricatorPhurlURLQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 8560 8569 'PhabricatorPhurlURLReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 8561 8570 'PhabricatorPhurlURLSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 8562 8571 'PhabricatorPhurlURLSearchEngine' => 'PhabricatorApplicationSearchEngine', 8563 - 'PhabricatorPhurlURLTransaction' => 'PhabricatorApplicationTransaction', 8572 + 'PhabricatorPhurlURLTransaction' => 'PhabricatorModularTransaction', 8564 8573 'PhabricatorPhurlURLTransactionComment' => 'PhabricatorApplicationTransactionComment', 8565 8574 'PhabricatorPhurlURLTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 8575 + 'PhabricatorPhurlURLTransactionType' => 'PhabricatorModularTransactionType', 8566 8576 'PhabricatorPhurlURLViewController' => 'PhabricatorPhurlController', 8567 8577 'PhabricatorPinnedApplicationsSetting' => 'PhabricatorInternalSetting', 8568 8578 'PhabricatorPirateEnglishTranslation' => 'PhutilTranslation',
+14 -4
src/applications/phurl/editor/PhabricatorPhurlURLEditEngine.php
··· 21 21 return pht('Configure creation and editing forms in Phurl.'); 22 22 } 23 23 24 + public function isEngineConfigurable() { 25 + return false; 26 + } 27 + 24 28 protected function newEditableObject() { 25 29 return PhabricatorPhurlURL::initializeNewPhurlURL($this->getViewer()); 26 30 } ··· 73 77 ->setKey('name') 74 78 ->setLabel(pht('Name')) 75 79 ->setDescription(pht('URL name.')) 80 + ->setIsRequired(true) 76 81 ->setConduitTypeDescription(pht('New URL name.')) 77 - ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_NAME) 82 + ->setTransactionType( 83 + PhabricatorPhurlURLNameTransaction::TRANSACTIONTYPE) 78 84 ->setValue($object->getName()), 79 85 id(new PhabricatorTextEditField()) 80 86 ->setKey('url') ··· 83 89 ->setConduitTypeDescription(pht('New URL.')) 84 90 ->setValue($object->getLongURL()) 85 91 ->setIsRequired(true) 86 - ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_URL), 92 + ->setTransactionType( 93 + PhabricatorPhurlURLLongURLTransaction::TRANSACTIONTYPE), 87 94 id(new PhabricatorTextEditField()) 88 95 ->setKey('alias') 89 96 ->setLabel(pht('Alias')) 90 - ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_ALIAS) 97 + ->setIsRequired(true) 98 + ->setTransactionType( 99 + PhabricatorPhurlURLAliasTransaction::TRANSACTIONTYPE) 91 100 ->setDescription(pht('The alias to give the URL.')) 92 101 ->setConduitTypeDescription(pht('New alias.')) 93 102 ->setValue($object->getAlias()), ··· 96 105 ->setLabel(pht('Description')) 97 106 ->setDescription(pht('URL long description.')) 98 107 ->setConduitTypeDescription(pht('New URL description.')) 99 - ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION) 108 + ->setTransactionType( 109 + PhabricatorPhurlURLDescriptionTransaction::TRANSACTIONTYPE) 100 110 ->setValue($object->getDescription()), 101 111 ); 102 112 }
+21 -176
src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
··· 11 11 return pht('Phurl'); 12 12 } 13 13 14 + public function getCreateObjectTitle($author, $object) { 15 + return pht('%s created this URL.', $author); 16 + } 17 + 18 + public function getCreateObjectTitleForFeed($author, $object) { 19 + return pht('%s created %s.', $author, $object); 20 + } 21 + 22 + protected function supportsSearch() { 23 + return true; 24 + } 25 + 14 26 public function getTransactionTypes() { 15 27 $types = parent::getTransactionTypes(); 16 - 17 - $types[] = PhabricatorPhurlURLTransaction::TYPE_NAME; 18 - $types[] = PhabricatorPhurlURLTransaction::TYPE_URL; 19 - $types[] = PhabricatorPhurlURLTransaction::TYPE_ALIAS; 20 - $types[] = PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION; 21 - 22 28 $types[] = PhabricatorTransactions::TYPE_COMMENT; 23 29 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 24 30 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; ··· 26 32 return $types; 27 33 } 28 34 29 - protected function getCustomTransactionOldValue( 30 - PhabricatorLiskDAO $object, 31 - PhabricatorApplicationTransaction $xaction) { 32 - switch ($xaction->getTransactionType()) { 33 - case PhabricatorPhurlURLTransaction::TYPE_NAME: 34 - return $object->getName(); 35 - case PhabricatorPhurlURLTransaction::TYPE_URL: 36 - return $object->getLongURL(); 37 - case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 38 - return $object->getAlias(); 39 - case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION: 40 - return $object->getDescription(); 41 - } 42 - 43 - return parent::getCustomTransactionOldValue($object, $xaction); 44 - } 45 - 46 - protected function getCustomTransactionNewValue( 47 - PhabricatorLiskDAO $object, 48 - PhabricatorApplicationTransaction $xaction) { 49 - switch ($xaction->getTransactionType()) { 50 - case PhabricatorPhurlURLTransaction::TYPE_NAME: 51 - case PhabricatorPhurlURLTransaction::TYPE_URL: 52 - case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION: 53 - return $xaction->getNewValue(); 54 - case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 55 - if (!strlen($xaction->getNewValue())) { 56 - return null; 57 - } 58 - return $xaction->getNewValue(); 59 - } 60 - 61 - return parent::getCustomTransactionNewValue($object, $xaction); 62 - } 63 - 64 - protected function applyCustomInternalTransaction( 65 - PhabricatorLiskDAO $object, 66 - PhabricatorApplicationTransaction $xaction) { 67 - 68 - switch ($xaction->getTransactionType()) { 69 - case PhabricatorPhurlURLTransaction::TYPE_NAME: 70 - $object->setName($xaction->getNewValue()); 71 - return; 72 - case PhabricatorPhurlURLTransaction::TYPE_URL: 73 - $object->setLongURL($xaction->getNewValue()); 74 - return; 75 - case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 76 - $object->setAlias($xaction->getNewValue()); 77 - return; 78 - case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION: 79 - $object->setDescription($xaction->getNewValue()); 80 - return; 81 - } 82 - 83 - return parent::applyCustomInternalTransaction($object, $xaction); 84 - } 85 - 86 - protected function applyCustomExternalTransaction( 87 - PhabricatorLiskDAO $object, 88 - PhabricatorApplicationTransaction $xaction) { 89 - 90 - switch ($xaction->getTransactionType()) { 91 - case PhabricatorPhurlURLTransaction::TYPE_NAME: 92 - case PhabricatorPhurlURLTransaction::TYPE_URL: 93 - case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 94 - case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION: 95 - return; 96 - } 97 - 98 - return parent::applyCustomExternalTransaction($object, $xaction); 99 - } 100 - 101 - protected function validateTransaction( 102 - PhabricatorLiskDAO $object, 103 - $type, 104 - array $xactions) { 105 - 106 - $errors = parent::validateTransaction($object, $type, $xactions); 107 - 108 - switch ($type) { 109 - case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 110 - $overdrawn = $this->validateIsTextFieldTooLong( 111 - $object->getName(), 112 - $xactions, 113 - 64); 114 - 115 - if ($overdrawn) { 116 - $errors[] = new PhabricatorApplicationTransactionValidationError( 117 - $type, 118 - pht('Alias Too Long'), 119 - pht('The alias can be no longer than 64 characters.'), 120 - nonempty(last($xactions), null)); 121 - } 122 - 123 - foreach ($xactions as $xaction) { 124 - if ($xaction->getOldValue() != $xaction->getNewValue()) { 125 - $new_alias = $xaction->getNewValue(); 126 - $debug_alias = new PHUIInvisibleCharacterView($new_alias); 127 - if (!preg_match('/[a-zA-Z]/', $new_alias)) { 128 - $errors[] = new PhabricatorApplicationTransactionValidationError( 129 - $type, 130 - pht('Invalid Alias'), 131 - pht('The alias you provided (%s) must contain at least one '. 132 - 'letter.', 133 - $debug_alias), 134 - $xaction); 135 - } 136 - if (preg_match('/[^a-z0-9]/i', $new_alias)) { 137 - $errors[] = new PhabricatorApplicationTransactionValidationError( 138 - $type, 139 - pht('Invalid Alias'), 140 - pht('The alias you provided (%s) may only contain letters and '. 141 - 'numbers.', 142 - $debug_alias), 143 - $xaction); 144 - } 145 - } 146 - } 147 - 148 - break; 149 - case PhabricatorPhurlURLTransaction::TYPE_URL: 150 - $missing = $this->validateIsEmptyTextField( 151 - $object->getLongURL(), 152 - $xactions); 153 - 154 - if ($missing) { 155 - $error = new PhabricatorApplicationTransactionValidationError( 156 - $type, 157 - pht('Required'), 158 - pht('URL path is required.'), 159 - nonempty(last($xactions), null)); 160 - 161 - $error->setIsMissingFieldError(true); 162 - $errors[] = $error; 163 - } 164 - 165 - foreach ($xactions as $xaction) { 166 - if ($xaction->getOldValue() != $xaction->getNewValue()) { 167 - $protocols = PhabricatorEnv::getEnvConfig('uri.allowed-protocols'); 168 - $uri = new PhutilURI($xaction->getNewValue()); 169 - if (!isset($protocols[$uri->getProtocol()])) { 170 - $errors[] = new PhabricatorApplicationTransactionValidationError( 171 - $type, 172 - pht('Invalid URL'), 173 - pht('The protocol of the URL is invalid.'), 174 - null); 175 - } 176 - } 177 - } 178 - 179 - break; 180 - } 181 - 182 - return $errors; 183 - } 184 - 185 - protected function shouldPublishFeedStory( 35 + protected function shouldSendMail( 186 36 PhabricatorLiskDAO $object, 187 37 array $xactions) { 188 38 return true; 189 39 } 190 40 191 - protected function supportsSearch() { 192 - return true; 41 + public function getMailTagsMap() { 42 + return array( 43 + PhabricatorPhurlURLTransaction::MAILTAG_DETAILS => 44 + pht( 45 + "A URL's details change."), 46 + ); 193 47 } 194 48 195 - protected function shouldSendMail( 49 + protected function shouldPublishFeedStory( 196 50 PhabricatorLiskDAO $object, 197 51 array $xactions) { 198 52 return true; ··· 204 58 205 59 protected function getMailTo(PhabricatorLiskDAO $object) { 206 60 $phids = array(); 207 - 208 61 $phids[] = $this->getActingAsPHID(); 209 62 210 63 return $phids; 211 - } 212 - 213 - public function getMailTagsMap() { 214 - return array( 215 - PhabricatorPhurlURLTransaction::MAILTAG_DETAILS => 216 - pht( 217 - "A URL's details change."), 218 - ); 219 64 } 220 65 221 66 protected function buildMailTemplate(PhabricatorLiskDAO $object) { ··· 255 100 256 101 $errors = array(); 257 102 $errors[] = new PhabricatorApplicationTransactionValidationError( 258 - PhabricatorPhurlURLTransaction::TYPE_ALIAS, 103 + PhabricatorPhurlURLAliasTransaction::TRANSACTIONTYPE, 259 104 pht('Duplicate'), 260 105 pht('This alias is already in use.'), 261 106 null);
+13 -204
src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php
··· 1 1 <?php 2 2 3 3 final class PhabricatorPhurlURLTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_NAME = 'phurl.name'; 7 - const TYPE_URL = 'phurl.longurl'; 8 - const TYPE_ALIAS = 'phurl.alias'; 9 - const TYPE_DESCRIPTION = 'phurl.description'; 4 + extends PhabricatorModularTransaction { 10 5 11 6 const MAILTAG_DETAILS = 'phurl-details'; 12 7 ··· 22 17 return new PhabricatorPhurlURLTransactionComment(); 23 18 } 24 19 20 + public function getBaseTransactionClass() { 21 + return 'PhabricatorPhurlURLTransactionType'; 22 + } 23 + 25 24 public function getRequiredHandlePHIDs() { 26 25 $phids = parent::getRequiredHandlePHIDs(); 27 26 28 27 switch ($this->getTransactionType()) { 29 - case self::TYPE_NAME: 30 - case self::TYPE_URL: 31 - case self::TYPE_ALIAS: 32 - case self::TYPE_DESCRIPTION: 28 + case PhabricatorPhurlURLNameTransaction::TRANSACTIONTYPE: 29 + case PhabricatorPhurlURLLongURLTransaction::TRANSACTIONTYPE: 30 + case PhabricatorPhurlURLAliasTransaction::TRANSACTIONTYPE: 31 + case PhabricatorPhurlURLDescriptionTransaction::TRANSACTIONTYPE: 33 32 $phids[] = $this->getObjectPHID(); 34 33 break; 35 34 } ··· 37 36 return $phids; 38 37 } 39 38 40 - public function shouldHide() { 41 - $old = $this->getOldValue(); 42 - switch ($this->getTransactionType()) { 43 - case self::TYPE_DESCRIPTION: 44 - return ($old === null); 45 - } 46 - return parent::shouldHide(); 47 - } 48 - 49 - public function getIcon() { 50 - switch ($this->getTransactionType()) { 51 - case self::TYPE_NAME: 52 - case self::TYPE_URL: 53 - case self::TYPE_ALIAS: 54 - case self::TYPE_DESCRIPTION: 55 - return 'fa-pencil'; 56 - break; 57 - } 58 - return parent::getIcon(); 59 - } 60 - 61 - public function getTitle() { 62 - $author_phid = $this->getAuthorPHID(); 63 - $object_phid = $this->getObjectPHID(); 64 - 65 - $old = $this->getOldValue(); 66 - $new = $this->getNewValue(); 67 - 68 - $type = $this->getTransactionType(); 69 - switch ($type) { 70 - case self::TYPE_NAME: 71 - if ($old === null) { 72 - return pht( 73 - '%s created this URL.', 74 - $this->renderHandleLink($author_phid)); 75 - } else { 76 - return pht( 77 - '%s changed the name of the URL from %s to %s.', 78 - $this->renderHandleLink($author_phid), 79 - $old, 80 - $new); 81 - } 82 - case self::TYPE_URL: 83 - if ($old === null) { 84 - return pht( 85 - '%s set the destination of the URL to %s.', 86 - $this->renderHandleLink($author_phid), 87 - $new); 88 - } else { 89 - return pht( 90 - '%s changed the destination of the URL from %s to %s.', 91 - $this->renderHandleLink($author_phid), 92 - $old, 93 - $new); 94 - } 95 - case self::TYPE_ALIAS: 96 - if ($old === null) { 97 - return pht( 98 - '%s set the alias of the URL to %s.', 99 - $this->renderHandleLink($author_phid), 100 - $new); 101 - } else if ($new === null) { 102 - return pht( 103 - '%s removed the alias of the URL.', 104 - $this->renderHandleLink($author_phid)); 105 - } else { 106 - return pht( 107 - '%s changed the alias of the URL from %s to %s.', 108 - $this->renderHandleLink($author_phid), 109 - $old, 110 - $new); 111 - } 112 - case self::TYPE_DESCRIPTION: 113 - return pht( 114 - "%s updated the URL's description.", 115 - $this->renderHandleLink($author_phid)); 116 - } 117 - return parent::getTitle(); 118 - } 119 - 120 - public function getTitleForFeed() { 121 - $author_phid = $this->getAuthorPHID(); 122 - $object_phid = $this->getObjectPHID(); 123 - 124 - $old = $this->getOldValue(); 125 - $new = $this->getNewValue(); 126 - 127 - $viewer = $this->getViewer(); 128 - 129 - $type = $this->getTransactionType(); 130 - switch ($type) { 131 - case self::TYPE_NAME: 132 - if ($old === null) { 133 - return pht( 134 - '%s created %s.', 135 - $this->renderHandleLink($author_phid), 136 - $this->renderHandleLink($object_phid)); 137 - } else { 138 - return pht( 139 - '%s changed the name of %s from %s to %s.', 140 - $this->renderHandleLink($author_phid), 141 - $this->renderHandleLink($object_phid), 142 - $old, 143 - $new); 144 - } 145 - case self::TYPE_URL: 146 - if ($old === null) { 147 - return pht( 148 - '%s set the destination of %s to %s.', 149 - $this->renderHandleLink($author_phid), 150 - $this->renderHandleLink($object_phid), 151 - $new); 152 - } else { 153 - return pht( 154 - '%s changed the destination of %s from %s to %s.', 155 - $this->renderHandleLink($author_phid), 156 - $this->renderHandleLink($object_phid), 157 - $old, 158 - $new); 159 - } 160 - case self::TYPE_ALIAS: 161 - if ($old === null) { 162 - return pht( 163 - '%s set the alias of %s to %s.', 164 - $this->renderHandleLink($author_phid), 165 - $this->renderHandleLink($object_phid), 166 - $new); 167 - } else if ($new === null) { 168 - return pht( 169 - '%s removed the alias of %s.', 170 - $this->renderHandleLink($author_phid), 171 - $this->renderHandleLink($object_phid)); 172 - } else { 173 - return pht( 174 - '%s changed the alias of %s from %s to %s.', 175 - $this->renderHandleLink($author_phid), 176 - $this->renderHandleLink($object_phid), 177 - $old, 178 - $new); 179 - } 180 - case self::TYPE_DESCRIPTION: 181 - return pht( 182 - '%s updated the description of %s.', 183 - $this->renderHandleLink($author_phid), 184 - $this->renderHandleLink($object_phid)); 185 - } 186 - 187 - return parent::getTitleForFeed(); 188 - } 189 - 190 - public function getColor() { 191 - $old = $this->getOldValue(); 192 - $new = $this->getNewValue(); 193 - 194 - switch ($this->getTransactionType()) { 195 - case self::TYPE_NAME: 196 - case self::TYPE_URL: 197 - case self::TYPE_ALIAS: 198 - case self::TYPE_DESCRIPTION: 199 - return PhabricatorTransactions::COLOR_GREEN; 200 - } 201 - 202 - return parent::getColor(); 203 - } 204 - 205 - 206 - public function hasChangeDetails() { 207 - switch ($this->getTransactionType()) { 208 - case self::TYPE_DESCRIPTION: 209 - return ($this->getOldValue() !== null); 210 - } 211 - 212 - return parent::hasChangeDetails(); 213 - } 214 - 215 - public function renderChangeDetails(PhabricatorUser $viewer) { 216 - switch ($this->getTransactionType()) { 217 - case self::TYPE_DESCRIPTION: 218 - $old = $this->getOldValue(); 219 - $new = $this->getNewValue(); 220 - 221 - return $this->renderTextCorpusChangeDetails( 222 - $viewer, 223 - $old, 224 - $new); 225 - } 226 - 227 - return parent::renderChangeDetails($viewer); 228 - } 229 - 230 39 public function getMailTags() { 231 40 $tags = array(); 232 41 switch ($this->getTransactionType()) { 233 - case self::TYPE_NAME: 234 - case self::TYPE_DESCRIPTION: 235 - case self::TYPE_URL: 236 - case self::TYPE_ALIAS: 42 + case PhabricatorPhurlURLNameTransaction::TRANSACTIONTYPE: 43 + case PhabricatorPhurlURLLongURLTransaction::TRANSACTIONTYPE: 44 + case PhabricatorPhurlURLAliasTransaction::TRANSACTIONTYPE: 45 + case PhabricatorPhurlURLDescriptionTransaction::TRANSACTIONTYPE: 237 46 $tags[] = self::MAILTAG_DETAILS; 238 47 break; 239 48 }
+77
src/applications/phurl/xaction/PhabricatorPhurlURLAliasTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLAliasTransaction 4 + extends PhabricatorPhurlURLTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phurl.alias'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getAlias(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setAlias($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s changed the alias from %s to %s.', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + public function getTitleForFeed() { 25 + return pht( 26 + '%s changed the alias of %s from %s to %s.', 27 + $this->renderAuthor(), 28 + $this->renderObject(), 29 + $this->renderOldValue(), 30 + $this->renderNewValue()); 31 + } 32 + 33 + public function validateTransactions($object, array $xactions) { 34 + $errors = array(); 35 + 36 + if ($this->isEmptyTextTransaction($object->getAlias(), $xactions)) { 37 + $errors[] = $this->newRequiredError( 38 + pht('Phurls must have an alias.')); 39 + } 40 + 41 + $max_length = $object->getColumnMaximumByteLength('alias'); 42 + foreach ($xactions as $xaction) { 43 + $new_alias = $xaction->getNewValue(); 44 + 45 + // Check length 46 + $new_length = strlen($new_alias); 47 + if ($new_length > $max_length) { 48 + $errors[] = $this->newRequiredError( 49 + pht('The alias can be no longer than %d characters.', $max_length)); 50 + } 51 + 52 + // Check characters 53 + if ($xaction->getOldValue() != $xaction->getNewValue()) { 54 + $debug_alias = new PHUIInvisibleCharacterView($new_alias); 55 + if (!preg_match('/[a-zA-Z]/', $new_alias)) { 56 + $errors[] = $this->newRequiredError( 57 + pht('The alias you provided (%s) must contain at least one '. 58 + 'letter.', 59 + $debug_alias)); 60 + } 61 + if (preg_match('/[^a-z0-9]/i', $new_alias)) { 62 + $errors[] = $this->newRequiredError( 63 + pht('The alias you provided (%s) may only contain letters and '. 64 + 'numbers.', 65 + $debug_alias)); 66 + } 67 + } 68 + } 69 + 70 + return $errors; 71 + } 72 + 73 + public function getIcon() { 74 + return 'fa-compress'; 75 + } 76 + 77 + }
+60
src/applications/phurl/xaction/PhabricatorPhurlURLDescriptionTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLDescriptionTransaction 4 + extends PhabricatorPhurlURLTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phurl.description'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getDescription(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setDescription($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s updated the description.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + return pht( 24 + '%s updated the description for %s.', 25 + $this->renderAuthor(), 26 + $this->renderObject()); 27 + } 28 + 29 + public function hasChangeDetailView() { 30 + return true; 31 + } 32 + 33 + public function getMailDiffSectionHeader() { 34 + return pht('CHANGES TO PHURL DESCRIPTION'); 35 + } 36 + 37 + public function newChangeDetailView() { 38 + $viewer = $this->getViewer(); 39 + 40 + return id(new PhabricatorApplicationTransactionTextDiffDetailView()) 41 + ->setViewer($viewer) 42 + ->setOldText($this->getOldValue()) 43 + ->setNewText($this->getNewValue()); 44 + } 45 + 46 + public function newRemarkupChanges() { 47 + $changes = array(); 48 + 49 + $changes[] = $this->newRemarkupChange() 50 + ->setOldValue($this->getOldValue()) 51 + ->setNewValue($this->getNewValue()); 52 + 53 + return $changes; 54 + } 55 + 56 + public function getIcon() { 57 + return 'fa-file-text-o'; 58 + } 59 + 60 + }
+59
src/applications/phurl/xaction/PhabricatorPhurlURLLongURLTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLLongURLTransaction 4 + extends PhabricatorPhurlURLTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phurl.longurl'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getLongURL(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setLongURL($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s changed the destination URL from %s to %s.', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + public function getTitleForFeed() { 25 + return pht( 26 + '%s changed the destination URL %s from %s to %s.', 27 + $this->renderAuthor(), 28 + $this->renderObject(), 29 + $this->renderOldValue(), 30 + $this->renderNewValue()); 31 + } 32 + 33 + public function validateTransactions($object, array $xactions) { 34 + $errors = array(); 35 + 36 + if ($this->isEmptyTextTransaction($object->getLongURL(), $xactions)) { 37 + $errors[] = $this->newRequiredError( 38 + pht('URL path is required')); 39 + } 40 + 41 + foreach ($xactions as $xaction) { 42 + if ($xaction->getOldValue() != $xaction->getNewValue()) { 43 + $protocols = PhabricatorEnv::getEnvConfig('uri.allowed-protocols'); 44 + $uri = new PhutilURI($xaction->getNewValue()); 45 + if (!isset($protocols[$uri->getProtocol()])) { 46 + $errors[] = $this->newRequiredError( 47 + pht('The protocol of the URL is invalid.')); 48 + } 49 + } 50 + } 51 + 52 + return $errors; 53 + } 54 + 55 + public function getIcon() { 56 + return 'fa-external-link-square'; 57 + } 58 + 59 + }
+44
src/applications/phurl/xaction/PhabricatorPhurlURLNameTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLNameTransaction 4 + extends PhabricatorPhurlURLTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phurl.name'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getName(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setName($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s changed the name of the URL from %s to %s.', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + public function getTitleForFeed() { 25 + return pht( 26 + '%s changed the name of %s from %s to %s.', 27 + $this->renderAuthor(), 28 + $this->renderObject(), 29 + $this->renderOldValue(), 30 + $this->renderNewValue()); 31 + } 32 + 33 + public function validateTransactions($object, array $xactions) { 34 + $errors = array(); 35 + 36 + if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { 37 + $errors[] = $this->newRequiredError( 38 + pht('Phurls must have a name.')); 39 + } 40 + 41 + return $errors; 42 + } 43 + 44 + }
+4
src/applications/phurl/xaction/PhabricatorPhurlURLTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorPhurlURLTransactionType 4 + extends PhabricatorModularTransactionType {}
-45
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 2324 2324 return true; 2325 2325 } 2326 2326 2327 - /** 2328 - * Check that text field input isn't longer than a specified length. 2329 - * 2330 - * A text field input is invalid if the length of the input is longer than a 2331 - * specified length. This length can be determined by the space allotted in 2332 - * the database, or given arbitrarily. 2333 - * This method is intended to make implementing @{method:validateTransaction} 2334 - * more convenient: 2335 - * 2336 - * $overdrawn = $this->validateIsTextFieldTooLong( 2337 - * $object->getName(), 2338 - * $xactions, 2339 - * $field_length); 2340 - * 2341 - * This will return `true` if the net effect of the object and transactions 2342 - * is a field that is too long. 2343 - * 2344 - * @param wild Current field value. 2345 - * @param list<PhabricatorApplicationTransaction> Transactions editing the 2346 - * field. 2347 - * @param integer for maximum field length. 2348 - * @return bool True if the field will be too long after edits. 2349 - */ 2350 - protected function validateIsTextFieldTooLong( 2351 - $field_value, 2352 - array $xactions, 2353 - $length) { 2354 - 2355 - if ($xactions) { 2356 - $new_value_length = phutil_utf8_strlen(last($xactions)->getNewValue()); 2357 - if ($new_value_length <= $length) { 2358 - return false; 2359 - } else { 2360 - return true; 2361 - } 2362 - } 2363 - 2364 - $old_value_length = phutil_utf8_strlen($field_value); 2365 - if ($old_value_length <= $length) { 2366 - return false; 2367 - } 2368 - 2369 - return true; 2370 - } 2371 - 2372 2327 2373 2328 /* -( Implicit CCs )------------------------------------------------------- */ 2374 2329