Path: blob/master/src/applications/diffusion/editor/DiffusionURIEditEngine.php
12242 views
<?php12final class DiffusionURIEditEngine3extends PhabricatorEditEngine {45const ENGINECONST = 'diffusion.uri';67private $repository;89public function setRepository(PhabricatorRepository $repository) {10$this->repository = $repository;11return $this;12}1314public function getRepository() {15return $this->repository;16}1718public function isEngineConfigurable() {19return false;20}2122public function getEngineName() {23return pht('Repository URIs');24}2526public function getSummaryHeader() {27return pht('Edit Repository URI');28}2930public function getSummaryText() {31return pht('Creates and edits repository URIs.');32}3334public function getEngineApplicationClass() {35return 'PhabricatorDiffusionApplication';36}3738protected function newEditableObject() {39$uri = PhabricatorRepositoryURI::initializeNewURI();4041$repository = $this->getRepository();42if ($repository) {43$uri->setRepositoryPHID($repository->getPHID());44$uri->attachRepository($repository);45}4647return $uri;48}4950protected function newObjectQuery() {51return new PhabricatorRepositoryURIQuery();52}5354protected function getObjectCreateTitleText($object) {55return pht('Create Repository URI');56}5758protected function getObjectCreateButtonText($object) {59return pht('Create Repository URI');60}6162protected function getObjectEditTitleText($object) {63return pht('Edit Repository URI %d', $object->getID());64}6566protected function getObjectEditShortText($object) {67return pht('URI %d', $object->getID());68}6970protected function getObjectCreateShortText() {71return pht('Create Repository URI');72}7374protected function getObjectName() {75return pht('Repository URI');76}7778protected function getObjectViewURI($object) {79return $object->getViewURI();80}8182protected function buildCustomEditFields($object) {83$viewer = $this->getViewer();8485$uri_instructions = null;86if ($object->isBuiltin()) {87$is_builtin = true;88$uri_value = (string)$object->getDisplayURI();8990switch ($object->getBuiltinProtocol()) {91case PhabricatorRepositoryURI::BUILTIN_PROTOCOL_SSH:92$uri_instructions = pht(93" - Configure [[ %s | %s ]] to change the SSH username.\n".94" - Configure [[ %s | %s ]] to change the SSH host.\n".95" - Configure [[ %s | %s ]] to change the SSH port.",96'/config/edit/diffusion.ssh-user/',97'diffusion.ssh-user',98'/config/edit/diffusion.ssh-host/',99'diffusion.ssh-host',100'/config/edit/diffusion.ssh-port/',101'diffusion.ssh-port');102break;103}104} else {105$is_builtin = false;106$uri_value = $object->getURI();107108if ($object->getRepositoryPHID()) {109$repository = $object->getRepository();110if ($repository->isGit()) {111$uri_instructions = pht(112"Provide the URI of a Git repository. It should usually look ".113"like one of these examples:\n".114"\n".115"| Example Git URIs\n".116"| -----------------------\n".117"| `[email protected]:example/example.git`\n".118"| `ssh://[email protected]/git/example.git`\n".119"| `https://example.com/repository.git`");120} else if ($repository->isHg()) {121$uri_instructions = pht(122"Provide the URI of a Mercurial repository. It should usually ".123"look like one of these examples:\n".124"\n".125"| Example Mercurial URIs\n".126"|-----------------------\n".127"| `ssh://[email protected]/example/repository`\n".128"| `https://bitbucket.org/example/repository`");129} else if ($repository->isSVN()) {130$uri_instructions = pht(131"Provide the **Repository Root** of a Subversion repository. ".132"You can identify this by running `svn info` in a working ".133"copy. It should usually look like one of these examples:\n".134"\n".135"| Example Subversion URIs\n".136"|-----------------------\n".137"| `http://svn.example.org/svnroot/`\n".138"| `svn+ssh://svn.example.com/svnroot/`\n".139"| `svn://svn.example.net/svnroot/`\n\n".140"You **MUST** specify the root of the repository, not a ".141"subdirectory.");142}143}144}145146return array(147id(new PhabricatorHandlesEditField())148->setKey('repository')149->setAliases(array('repositoryPHID'))150->setLabel(pht('Repository'))151->setIsRequired(true)152->setIsFormField(false)153->setTransactionType(154PhabricatorRepositoryURITransaction::TYPE_REPOSITORY)155->setDescription(pht('The repository this URI is associated with.'))156->setConduitDescription(157pht(158'Create a URI in a given repository. This transaction type '.159'must be present when creating a new URI and must not be '.160'present when editing an existing URI.'))161->setConduitTypeDescription(162pht('Repository PHID to create a new URI for.'))163->setSingleValue($object->getRepositoryPHID()),164id(new PhabricatorTextEditField())165->setKey('uri')166->setLabel(pht('URI'))167->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_URI)168->setDescription(pht('The repository URI.'))169->setConduitDescription(pht('Change the repository URI.'))170->setConduitTypeDescription(pht('New repository URI.'))171->setIsRequired(!$is_builtin)172->setIsLocked($is_builtin)173->setValue($uri_value)174->setControlInstructions($uri_instructions),175id(new PhabricatorSelectEditField())176->setKey('io')177->setLabel(pht('I/O Type'))178->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_IO)179->setDescription(pht('URI I/O behavior.'))180->setConduitDescription(pht('Adjust I/O behavior.'))181->setConduitTypeDescription(pht('New I/O behavior.'))182->setValue($object->getIOType())183->setOptions($object->getAvailableIOTypeOptions()),184id(new PhabricatorSelectEditField())185->setKey('display')186->setLabel(pht('Display Type'))187->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_DISPLAY)188->setDescription(pht('URI display behavior.'))189->setConduitDescription(pht('Change display behavior.'))190->setConduitTypeDescription(pht('New display behavior.'))191->setValue($object->getDisplayType())192->setOptions($object->getAvailableDisplayTypeOptions()),193id(new PhabricatorHandlesEditField())194->setKey('credential')195->setAliases(array('credentialPHID'))196->setLabel(pht('Credential'))197->setIsFormField(false)198->setTransactionType(199PhabricatorRepositoryURITransaction::TYPE_CREDENTIAL)200->setDescription(201pht('The credential to use when interacting with this URI.'))202->setConduitDescription(pht('Change the credential for this URI.'))203->setConduitTypeDescription(pht('New credential PHID, or null.'))204->setSingleValue($object->getCredentialPHID()),205id(new PhabricatorBoolEditField())206->setKey('disable')207->setLabel(pht('Disabled'))208->setIsFormField(false)209->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_DISABLE)210->setDescription(pht('Active status of the URI.'))211->setConduitDescription(pht('Disable or activate the URI.'))212->setConduitTypeDescription(pht('True to disable the URI.'))213->setOptions(pht('Enable'), pht('Disable'))214->setValue($object->getIsDisabled()),215);216}217218}219220221