@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 219 lines 7.8 kB view raw
1<?php 2 3final class DiffusionURIEditEngine 4 extends PhabricatorEditEngine { 5 6 const ENGINECONST = 'diffusion.uri'; 7 8 private $repository; 9 10 public function setRepository(PhabricatorRepository $repository) { 11 $this->repository = $repository; 12 return $this; 13 } 14 15 public function getRepository() { 16 return $this->repository; 17 } 18 19 public function isEngineConfigurable() { 20 return false; 21 } 22 23 public function getEngineName() { 24 return pht('Repository URIs'); 25 } 26 27 public function getSummaryHeader() { 28 return pht('Edit Repository URI'); 29 } 30 31 public function getSummaryText() { 32 return pht('Creates and edits repository URIs.'); 33 } 34 35 public function getEngineApplicationClass() { 36 return PhabricatorDiffusionApplication::class; 37 } 38 39 protected function newEditableObject() { 40 $uri = PhabricatorRepositoryURI::initializeNewURI(); 41 42 $repository = $this->getRepository(); 43 if ($repository) { 44 $uri->setRepositoryPHID($repository->getPHID()); 45 $uri->attachRepository($repository); 46 } 47 48 return $uri; 49 } 50 51 protected function newObjectQuery() { 52 return new PhabricatorRepositoryURIQuery(); 53 } 54 55 protected function getObjectCreateTitleText($object) { 56 return pht('Create Repository URI'); 57 } 58 59 protected function getObjectCreateButtonText($object) { 60 return pht('Create Repository URI'); 61 } 62 63 protected function getObjectEditTitleText($object) { 64 return pht('Edit Repository URI %d', $object->getID()); 65 } 66 67 protected function getObjectEditShortText($object) { 68 return pht('URI %d', $object->getID()); 69 } 70 71 protected function getObjectCreateShortText() { 72 return pht('Create Repository URI'); 73 } 74 75 protected function getObjectName() { 76 return pht('Repository URI'); 77 } 78 79 protected function getObjectViewURI($object) { 80 return $object->getViewURI(); 81 } 82 83 protected function buildCustomEditFields($object) { 84 $viewer = $this->getViewer(); 85 86 $uri_instructions = null; 87 if ($object->isBuiltin()) { 88 $is_builtin = true; 89 $uri_value = (string)$object->getDisplayURI(); 90 91 switch ($object->getBuiltinProtocol()) { 92 case PhabricatorRepositoryURI::BUILTIN_PROTOCOL_SSH: 93 $uri_instructions = pht( 94 " - Configure [[ %s | %s ]] to change the SSH username.\n". 95 " - Configure [[ %s | %s ]] to change the SSH host.\n". 96 " - Configure [[ %s | %s ]] to change the SSH port.", 97 '/config/edit/diffusion.ssh-user/', 98 'diffusion.ssh-user', 99 '/config/edit/diffusion.ssh-host/', 100 'diffusion.ssh-host', 101 '/config/edit/diffusion.ssh-port/', 102 'diffusion.ssh-port'); 103 break; 104 } 105 } else { 106 $is_builtin = false; 107 $uri_value = $object->getURI(); 108 109 if ($object->getRepositoryPHID()) { 110 $repository = $object->getRepository(); 111 if ($repository->isGit()) { 112 $uri_instructions = pht( 113 "Provide the URI of a Git repository. It should usually look ". 114 "like one of these examples:\n". 115 "\n". 116 "| Example Git URIs\n". 117 "| -----------------------\n". 118 "| `git@github.com:example/example.git`\n". 119 "| `ssh://user@host.com/git/example.git`\n". 120 "| `https://example.com/repository.git`"); 121 } else if ($repository->isHg()) { 122 $uri_instructions = pht( 123 "Provide the URI of a Mercurial repository. It should usually ". 124 "look like one of these examples:\n". 125 "\n". 126 "| Example Mercurial URIs\n". 127 "|-----------------------\n". 128 "| `ssh://hg@bitbucket.org/example/repository`\n". 129 "| `https://bitbucket.org/example/repository`"); 130 } else if ($repository->isSVN()) { 131 $uri_instructions = pht( 132 "Provide the **Repository Root** of a Subversion repository. ". 133 "You can identify this by running `svn info` in a working ". 134 "copy. It should usually look like one of these examples:\n". 135 "\n". 136 "| Example Subversion URIs\n". 137 "|-----------------------\n". 138 "| `http://svn.example.org/svnroot/`\n". 139 "| `svn+ssh://svn.example.com/svnroot/`\n". 140 "| `svn://svn.example.net/svnroot/`\n\n". 141 "You **MUST** specify the root of the repository, not a ". 142 "subdirectory."); 143 } 144 } 145 } 146 147 return array( 148 id(new PhabricatorHandlesEditField()) 149 ->setKey('repository') 150 ->setAliases(array('repositoryPHID')) 151 ->setLabel(pht('Repository')) 152 ->setIsRequired(true) 153 ->setIsFormField(false) 154 ->setTransactionType( 155 PhabricatorRepositoryURITransaction::TYPE_REPOSITORY) 156 ->setDescription(pht('The repository this URI is associated with.')) 157 ->setConduitDescription( 158 pht( 159 'Create a URI in a given repository. This transaction type '. 160 'must be present when creating a new URI and must not be '. 161 'present when editing an existing URI.')) 162 ->setConduitTypeDescription( 163 pht('Repository PHID to create a new URI for.')) 164 ->setSingleValue($object->getRepositoryPHID()), 165 id(new PhabricatorTextEditField()) 166 ->setKey('uri') 167 ->setLabel(pht('URI')) 168 ->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_URI) 169 ->setDescription(pht('The repository URI.')) 170 ->setConduitDescription(pht('Change the repository URI.')) 171 ->setConduitTypeDescription(pht('New repository URI.')) 172 ->setIsRequired(!$is_builtin) 173 ->setIsLocked($is_builtin) 174 ->setValue($uri_value) 175 ->setControlInstructions($uri_instructions), 176 id(new PhabricatorSelectEditField()) 177 ->setKey('io') 178 ->setLabel(pht('I/O Type')) 179 ->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_IO) 180 ->setDescription(pht('URI I/O behavior.')) 181 ->setConduitDescription(pht('Adjust I/O behavior.')) 182 ->setConduitTypeDescription(pht('New I/O behavior.')) 183 ->setValue($object->getIOType()) 184 ->setOptions($object->getAvailableIOTypeOptions()), 185 id(new PhabricatorSelectEditField()) 186 ->setKey('display') 187 ->setLabel(pht('Display Type')) 188 ->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_DISPLAY) 189 ->setDescription(pht('URI display behavior.')) 190 ->setConduitDescription(pht('Change display behavior.')) 191 ->setConduitTypeDescription(pht('New display behavior.')) 192 ->setValue($object->getDisplayType()) 193 ->setOptions($object->getAvailableDisplayTypeOptions()), 194 id(new PhabricatorHandlesEditField()) 195 ->setKey('credential') 196 ->setAliases(array('credentialPHID')) 197 ->setLabel(pht('Credential')) 198 ->setIsFormField(false) 199 ->setTransactionType( 200 PhabricatorRepositoryURITransaction::TYPE_CREDENTIAL) 201 ->setDescription( 202 pht('The credential to use when interacting with this URI.')) 203 ->setConduitDescription(pht('Change the credential for this URI.')) 204 ->setConduitTypeDescription(pht('New credential PHID, or null.')) 205 ->setSingleValue($object->getCredentialPHID()), 206 id(new PhabricatorBoolEditField()) 207 ->setKey('disable') 208 ->setLabel(pht('Disabled')) 209 ->setIsFormField(false) 210 ->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_DISABLE) 211 ->setDescription(pht('Active status of the URI.')) 212 ->setConduitDescription(pht('Disable or activate the URI.')) 213 ->setConduitTypeDescription(pht('True to disable the URI.')) 214 ->setOptions(pht('Enable'), pht('Disable')) 215 ->setValue($object->getIsDisabled()), 216 ); 217 } 218 219}