public function handleProtocols(PhabricatorRepository $repository)
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $type = $repository->getVersionControlSystem();
     $is_svn = $type == PhabricatorRepositoryType::REPOSITORY_TYPE_SVN;
     $v_http_mode = $repository->getDetail('serve-over-http', PhabricatorRepository::SERVE_OFF);
     $v_ssh_mode = $repository->getDetail('serve-over-ssh', PhabricatorRepository::SERVE_OFF);
     $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
     $prev_uri = $this->getRepositoryControllerURI($repository, 'edit/hosting/');
     if ($request->isFormPost()) {
         $v_http_mode = $request->getStr('http');
         $v_ssh_mode = $request->getStr('ssh');
         $xactions = array();
         $template = id(new PhabricatorRepositoryTransaction());
         $type_http = PhabricatorRepositoryTransaction::TYPE_PROTOCOL_HTTP;
         $type_ssh = PhabricatorRepositoryTransaction::TYPE_PROTOCOL_SSH;
         if (!$is_svn) {
             $xactions[] = id(clone $template)->setTransactionType($type_http)->setNewValue($v_http_mode);
         }
         $xactions[] = id(clone $template)->setTransactionType($type_ssh)->setNewValue($v_ssh_mode);
         id(new PhabricatorRepositoryEditor())->setContinueOnNoEffect(true)->setContentSourceFromRequest($request)->setActor($user)->applyTransactions($repository, $xactions);
         return id(new AphrontRedirectResponse())->setURI($edit_uri);
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Edit Protocols'));
     $title = pht('Edit Protocols (%s)', $repository->getName());
     $rw_message = pht('Phabricator will serve a read-write copy of this repository.');
     if (!$repository->isHosted()) {
         $rw_message = array($rw_message, phutil_tag('br'), phutil_tag('br'), pht('%s: This repository is hosted elsewhere, so Phabricator can not ' . 'perform writes. This mode will act like "Read Only" for ' . 'repositories hosted elsewhere.', phutil_tag('strong', array(), 'WARNING')));
     }
     $ssh_control = id(new AphrontFormRadioButtonControl())->setName('ssh')->setLabel(pht('SSH'))->setValue($v_ssh_mode)->addButton(PhabricatorRepository::SERVE_OFF, PhabricatorRepository::getProtocolAvailabilityName(PhabricatorRepository::SERVE_OFF), pht('Phabricator will not serve this repository over SSH.'))->addButton(PhabricatorRepository::SERVE_READONLY, PhabricatorRepository::getProtocolAvailabilityName(PhabricatorRepository::SERVE_READONLY), pht('Phabricator will serve a read-only copy of this repository ' . 'over SSH.'))->addButton(PhabricatorRepository::SERVE_READWRITE, PhabricatorRepository::getProtocolAvailabilityName(PhabricatorRepository::SERVE_READWRITE), $rw_message);
     $http_control = id(new AphrontFormRadioButtonControl())->setName('http')->setLabel(pht('HTTP'))->setValue($v_http_mode)->addButton(PhabricatorRepository::SERVE_OFF, PhabricatorRepository::getProtocolAvailabilityName(PhabricatorRepository::SERVE_OFF), pht('Phabricator will not serve this repository over HTTP.'))->addButton(PhabricatorRepository::SERVE_READONLY, PhabricatorRepository::getProtocolAvailabilityName(PhabricatorRepository::SERVE_READONLY), pht('Phabricator will serve a read-only copy of this repository ' . 'over HTTP.'))->addButton(PhabricatorRepository::SERVE_READWRITE, PhabricatorRepository::getProtocolAvailabilityName(PhabricatorRepository::SERVE_READWRITE), $rw_message);
     if ($is_svn) {
         $http_control = id(new AphrontFormMarkupControl())->setLabel(pht('HTTP'))->setValue(phutil_tag('em', array(), pht('Phabricator does not currently support HTTP access to ' . 'Subversion repositories.')));
     }
     $form = id(new AphrontFormView())->setUser($user)->appendRemarkupInstructions(pht('Phabricator can serve repositories over various protocols. You can ' . 'configure server protocols here.'))->appendChild($ssh_control);
     if (!PhabricatorEnv::getEnvConfig('diffusion.allow-http-auth')) {
         $form->appendRemarkupInstructions(pht('NOTE: The configuration setting [[ %s | %s ]] is currently ' . 'disabled. You must enable it to activate authenticated access ' . 'to repositories over HTTP.', '/config/edit/diffusion.allow-http-auth/', 'diffusion.allow-http-auth'));
     }
     $form->appendChild($http_control)->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save Changes'))->addCancelButton($prev_uri, pht('Back')));
     $object_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setForm($form);
     return $this->buildApplicationPage(array($crumbs, $object_box), array('title' => $title));
 }
 private function buildHostingProperties(PhabricatorRepository $repository, PhabricatorActionListView $actions)
 {
     $user = $this->getRequest()->getUser();
     $view = id(new PHUIPropertyListView())->setUser($user)->setActionList($actions);
     $hosting = $repository->isHosted() ? pht('Hosted on Phabricator') : pht('Hosted Elsewhere');
     $view->addProperty(pht('Hosting'), phutil_tag('em', array(), $hosting));
     $view->addProperty(pht('Serve over HTTP'), phutil_tag('em', array(), PhabricatorRepository::getProtocolAvailabilityName($repository->getServeOverHTTP())));
     $view->addProperty(pht('Serve over SSH'), phutil_tag('em', array(), PhabricatorRepository::getProtocolAvailabilityName($repository->getServeOverSSH())));
     if ($repository->canAllowDangerousChanges()) {
         if ($repository->shouldAllowDangerousChanges()) {
             $description = pht('Allowed');
         } else {
             $description = pht('Not Allowed');
         }
         $view->addProperty(pht('Dangerous Changes'), $description);
     }
     return $view;
 }
 public function getTitle()
 {
     $author_phid = $this->getAuthorPHID();
     $old = $this->getOldValue();
     $new = $this->getNewValue();
     switch ($this->getTransactionType()) {
         case self::TYPE_VCS:
             return pht('%s created this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_ACTIVATE:
             if ($new) {
                 return pht('%s activated this repository.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s deactivated this repository.', $this->renderHandleLink($author_phid));
             }
         case self::TYPE_NAME:
             return pht('%s renamed this repository from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
         case self::TYPE_DESCRIPTION:
             return pht('%s updated the description of this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_ENCODING:
             if (strlen($old) && !strlen($new)) {
                 return pht('%s removed the "%s" encoding configured for this repository.', $this->renderHandleLink($author_phid), $old);
             } else {
                 if (strlen($new) && !strlen($old)) {
                     return pht('%s set the encoding for this repository to "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the repository encoding from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
         case self::TYPE_DEFAULT_BRANCH:
             if (!strlen($new)) {
                 return pht('%s removed "%s" as the default branch.', $this->renderHandleLink($author_phid), $old);
             } else {
                 if (!strlen($old)) {
                     return pht('%s set the default branch to "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the default branch from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
             break;
         case self::TYPE_TRACK_ONLY:
             if (!$new) {
                 return pht('%s set this repository to track all branches.', $this->renderHandleLink($author_phid));
             } else {
                 if (!$old) {
                     return pht('%s set this repository to track branches: %s.', $this->renderHandleLink($author_phid), implode(', ', $new));
                 } else {
                     return pht('%s changed track branches from "%s" to "%s".', $this->renderHandleLink($author_phid), implode(', ', $old), implode(', ', $new));
                 }
             }
             break;
         case self::TYPE_AUTOCLOSE_ONLY:
             if (!$new) {
                 return pht('%s set this repository to autoclose on all branches.', $this->renderHandleLink($author_phid));
             } else {
                 if (!$old) {
                     return pht('%s set this repository to autoclose on branches: %s.', $this->renderHandleLink($author_phid), implode(', ', $new));
                 } else {
                     return pht('%s changed autoclose branches from "%s" to "%s".', $this->renderHandleLink($author_phid), implode(', ', $old), implode(', ', $new));
                 }
             }
             break;
         case self::TYPE_UUID:
             if (!strlen($new)) {
                 return pht('%s removed "%s" as the repository UUID.', $this->renderHandleLink($author_phid), $old);
             } else {
                 if (!strlen($old)) {
                     return pht('%s set the repository UUID to "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the repository UUID from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
             break;
         case self::TYPE_SVN_SUBPATH:
             if (!strlen($new)) {
                 return pht('%s removed "%s" as the Import Only path.', $this->renderHandleLink($author_phid), $old);
             } else {
                 if (!strlen($old)) {
                     return pht('%s set the repository to import only "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the import path from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
             break;
         case self::TYPE_NOTIFY:
             if ($new) {
                 return pht('%s enabled notifications and publishing for this repository.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s disabled notifications and publishing for this repository.', $this->renderHandleLink($author_phid));
             }
             break;
         case self::TYPE_AUTOCLOSE:
             if ($new) {
                 return pht('%s enabled autoclose for this repository.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s disabled autoclose for this repository.', $this->renderHandleLink($author_phid));
             }
             break;
         case self::TYPE_REMOTE_URI:
             if (!strlen($old)) {
                 return pht('%s set the remote URI for this repository to "%s".', $this->renderHandleLink($author_phid), $new);
             } else {
                 if (!strlen($new)) {
                     return pht('%s removed the remote URI for this repository.', $this->renderHandleLink($author_phid));
                 } else {
                     return pht('%s changed the remote URI for this repository from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
             break;
         case self::TYPE_SSH_LOGIN:
             return pht('%s updated the SSH login for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_SSH_KEY:
             return pht('%s updated the SSH key for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_SSH_KEYFILE:
             return pht('%s updated the SSH keyfile for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_HTTP_LOGIN:
             return pht('%s updated the HTTP login for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_HTTP_PASS:
             return pht('%s updated the HTTP password for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_LOCAL_PATH:
             return pht('%s changed the local path from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
         case self::TYPE_HOSTING:
             if ($new) {
                 return pht('%s changed this repository to be hosted on Phabricator.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s changed this repository to track a remote elsewhere.', $this->renderHandleLink($author_phid));
             }
         case self::TYPE_PROTOCOL_HTTP:
             return pht('%s changed the availability of this repository over HTTP from ' . '"%s" to "%s".', $this->renderHandleLink($author_phid), PhabricatorRepository::getProtocolAvailabilityName($old), PhabricatorRepository::getProtocolAvailabilityName($new));
         case self::TYPE_PROTOCOL_SSH:
             return pht('%s changed the availability of this repository over SSH from ' . '"%s" to "%s".', $this->renderHandleLink($author_phid), PhabricatorRepository::getProtocolAvailabilityName($old), PhabricatorRepository::getProtocolAvailabilityName($new));
         case self::TYPE_PUSH_POLICY:
             return pht('%s changed the push policy of this repository from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->renderPolicyName($old, 'old'), $this->renderPolicyName($new, 'new'));
         case self::TYPE_DANGEROUS:
             if ($new) {
                 return pht('%s disabled protection against dangerous changes.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s enabled protection against dangerous changes.', $this->renderHandleLink($author_phid));
             }
         case self::TYPE_SLUG:
             if (strlen($old) && !strlen($new)) {
                 return pht('%s removed the short name of this repository.', $this->renderHandleLink($author_phid));
             } else {
                 if (strlen($new) && !strlen($old)) {
                     return pht('%s set the short name of this repository to "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the short name of this repository from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
         case self::TYPE_SERVICE:
             if (strlen($old) && !strlen($new)) {
                 return pht('%s moved storage for this repository from %s to local.', $this->renderHandleLink($author_phid), $this->renderHandleLink($old));
             } else {
                 if (!strlen($old) && strlen($new)) {
                     // TODO: Possibly, we should distinguish between automatic assignment
                     // on creation vs explicit adjustment.
                     return pht('%s set storage for this repository to %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($new));
                 } else {
                     return pht('%s moved storage for this repository from %s to %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($old), $this->renderHandleLink($new));
                 }
             }
         case self::TYPE_SYMBOLS_SOURCES:
             return pht('%s changed symbol sources from %s to %s.', $this->renderHandleLink($author_phid), empty($old) ? pht('None') : $this->renderHandleList($old), empty($new) ? pht('None') : $this->renderHandleList($new));
         case self::TYPE_SYMBOLS_LANGUAGE:
             return pht('%s changed indexed languages from %s to %s.', $this->renderHandleLink($author_phid), $old ? implode(', ', $old) : pht('Any'), $new ? implode(', ', $new) : pht('Any'));
         case self::TYPE_STAGING_URI:
             if (!$old) {
                 return pht('%s set "%s" as the staging area for this repository.', $this->renderHandleLink($author_phid), $new);
             } else {
                 if (!$new) {
                     return pht('%s removed "%s" as the staging area for this repository.', $this->renderHandleLink($author_phid), $old);
                 } else {
                     return pht('%s changed the staging area for this repository from ' . '"%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
         case self::TYPE_AUTOMATION_BLUEPRINTS:
             $add = array_diff($new, $old);
             $rem = array_diff($old, $new);
             if ($add && $rem) {
                 return pht('%s changed %s automation blueprint(s), ' . 'added %s: %s; removed %s: %s.', $this->renderHandleLink($author_phid), new PhutilNumber(count($add) + count($rem)), new PhutilNumber(count($add)), $this->renderHandleList($add), new PhutilNumber(count($rem)), $this->renderHandleList($rem));
             } else {
                 if ($add) {
                     return pht('%s added %s automation blueprint(s): %s.', $this->renderHandleLink($author_phid), new PhutilNumber(count($add)), $this->renderHandleList($add));
                 } else {
                     return pht('%s removed %s automation blueprint(s): %s.', $this->renderHandleLink($author_phid), new PhutilNumber(count($rem)), $this->renderHandleList($rem));
                 }
             }
     }
     return parent::getTitle();
 }
 public function getTitle()
 {
     $author_phid = $this->getAuthorPHID();
     $old = $this->getOldValue();
     $new = $this->getNewValue();
     switch ($this->getTransactionType()) {
         case self::TYPE_VCS:
             return pht('%s created this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_ACTIVATE:
             if ($new) {
                 return pht('%s activated this repository.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s deactivated this repository.', $this->renderHandleLink($author_phid));
             }
         case self::TYPE_NAME:
             return pht('%s renamed this repository from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
         case self::TYPE_DESCRIPTION:
             return pht('%s updated the description of this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_ENCODING:
             if (strlen($old) && !strlen($new)) {
                 return pht('%s removed the "%s" encoding configured for this repository.', $this->renderHandleLink($author_phid), $old);
             } else {
                 if (strlen($new) && !strlen($old)) {
                     return pht('%s set the encoding for this repository to "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the repository encoding from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
         case self::TYPE_DEFAULT_BRANCH:
             if (!strlen($new)) {
                 return pht('%s removed "%s" as the default branch.', $this->renderHandleLink($author_phid), $old);
             } else {
                 if (!strlen($old)) {
                     return pht('%s set the default branch to "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the default branch from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
             break;
         case self::TYPE_TRACK_ONLY:
             if (!$new) {
                 return pht('%s set this repository to track all branches.', $this->renderHandleLink($author_phid));
             } else {
                 if (!$old) {
                     return pht('%s set this repository to track branches: %s.', $this->renderHandleLink($author_phid), implode(', ', $new));
                 } else {
                     return pht('%s changed track branches from "%s" to "%s".', $this->renderHandleLink($author_phid), implode(', ', $old), implode(', ', $new));
                 }
             }
             break;
         case self::TYPE_AUTOCLOSE_ONLY:
             if (!$new) {
                 return pht('%s set this repository to autoclose on all branches.', $this->renderHandleLink($author_phid));
             } else {
                 if (!$old) {
                     return pht('%s set this repository to autoclose on branches: %s.', $this->renderHandleLink($author_phid), implode(', ', $new));
                 } else {
                     return pht('%s changed autoclose branches from "%s" to "%s".', $this->renderHandleLink($author_phid), implode(', ', $old), implode(', ', $new));
                 }
             }
             break;
         case self::TYPE_UUID:
             if (!strlen($new)) {
                 return pht('%s removed "%s" as the repository UUID.', $this->renderHandleLink($author_phid), $old);
             } else {
                 if (!strlen($old)) {
                     return pht('%s set the repository UUID to "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the repository UUID from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
             break;
         case self::TYPE_SVN_SUBPATH:
             if (!strlen($new)) {
                 return pht('%s removed "%s" as the Import Only path.', $this->renderHandleLink($author_phid), $old);
             } else {
                 if (!strlen($old)) {
                     return pht('%s set the repository to import only "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the import path from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
             break;
         case self::TYPE_NOTIFY:
             if ($new) {
                 return pht('%s enabled notifications and publishing for this repository.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s disabled notifications and publishing for this repository.', $this->renderHandleLink($author_phid));
             }
             break;
         case self::TYPE_AUTOCLOSE:
             if ($new) {
                 return pht('%s enabled autoclose for this repository.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s disabled autoclose for this repository.', $this->renderHandleLink($author_phid));
             }
             break;
         case self::TYPE_REMOTE_URI:
             if (!strlen($old)) {
                 return pht('%s set the remote URI for this repository to "%s".', $this->renderHandleLink($author_phid), $new);
             } else {
                 if (!strlen($new)) {
                     return pht('%s removed the remote URI for this repository.', $this->renderHandleLink($author_phid));
                 } else {
                     return pht('%s changed the remote URI for this repository from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
             break;
         case self::TYPE_SSH_LOGIN:
             return pht('%s updated the SSH login for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_SSH_KEY:
             return pht('%s updated the SSH key for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_SSH_KEYFILE:
             return pht('%s updated the SSH keyfile for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_HTTP_LOGIN:
             return pht('%s updated the HTTP login for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_HTTP_PASS:
             return pht('%s updated the HTTP password for this repository.', $this->renderHandleLink($author_phid));
         case self::TYPE_LOCAL_PATH:
             return pht('%s changed the local path from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
         case self::TYPE_HOSTING:
             if ($new) {
                 return pht('%s changed this repository to be hosted on Phabricator.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s changed this repository to track a remote elsewhere.', $this->renderHandleLink($author_phid));
             }
         case self::TYPE_PROTOCOL_HTTP:
             return pht('%s changed the availability of this repository over HTTP from ' . '"%s" to "%s".', $this->renderHandleLink($author_phid), PhabricatorRepository::getProtocolAvailabilityName($old), PhabricatorRepository::getProtocolAvailabilityName($new));
         case self::TYPE_PROTOCOL_SSH:
             return pht('%s changed the availability of this repository over SSH from ' . '"%s" to "%s".', $this->renderHandleLink($author_phid), PhabricatorRepository::getProtocolAvailabilityName($old), PhabricatorRepository::getProtocolAvailabilityName($new));
         case self::TYPE_PUSH_POLICY:
             return pht('%s changed the push policy of this repository from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->renderPolicyName($old, 'old'), $this->renderPolicyName($new, 'new'));
         case self::TYPE_DANGEROUS:
             if ($new) {
                 return pht('%s disabled protection against dangerous changes.', $this->renderHandleLink($author_phid));
             } else {
                 return pht('%s enabled protection against dangerous changes.', $this->renderHandleLink($author_phid));
             }
         case self::TYPE_CLONE_NAME:
             if (strlen($old) && !strlen($new)) {
                 return pht('%s removed the clone name of this repository.', $this->renderHandleLink($author_phid));
             } else {
                 if (strlen($new) && !strlen($old)) {
                     return pht('%s set the clone name of this repository to "%s".', $this->renderHandleLink($author_phid), $new);
                 } else {
                     return pht('%s changed the clone name of this repository from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new);
                 }
             }
     }
     return parent::getTitle();
 }