[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/controller/ -> DiffusionRepositoryEditEncodingController.php (source)

   1  <?php
   2  
   3  final class DiffusionRepositoryEditEncodingController
   4    extends DiffusionRepositoryEditController {
   5  
   6    public function processRequest() {
   7      $request = $this->getRequest();
   8      $user = $request->getUser();
   9      $drequest = $this->diffusionRequest;
  10      $repository = $drequest->getRepository();
  11  
  12      $repository = id(new PhabricatorRepositoryQuery())
  13        ->setViewer($user)
  14        ->requireCapabilities(
  15          array(
  16            PhabricatorPolicyCapability::CAN_VIEW,
  17            PhabricatorPolicyCapability::CAN_EDIT,
  18          ))
  19        ->withIDs(array($repository->getID()))
  20        ->executeOne();
  21  
  22      if (!$repository) {
  23        return new Aphront404Response();
  24      }
  25  
  26      $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
  27  
  28      $v_encoding = $repository->getDetail('encoding');
  29      $e_encoding = null;
  30      $errors = array();
  31  
  32      if ($request->isFormPost()) {
  33        $v_encoding = $request->getStr('encoding');
  34  
  35        if (!$errors) {
  36          $xactions = array();
  37          $template = id(new PhabricatorRepositoryTransaction());
  38  
  39          $type_encoding = PhabricatorRepositoryTransaction::TYPE_ENCODING;
  40  
  41          $xactions[] = id(clone $template)
  42            ->setTransactionType($type_encoding)
  43            ->setNewValue($v_encoding);
  44  
  45          try {
  46            id(new PhabricatorRepositoryEditor())
  47              ->setContinueOnNoEffect(true)
  48              ->setContentSourceFromRequest($request)
  49              ->setActor($user)
  50              ->applyTransactions($repository, $xactions);
  51  
  52            return id(new AphrontRedirectResponse())->setURI($edit_uri);
  53          } catch (Exception $ex) {
  54            $errors[] = $ex->getMessage();
  55          }
  56        }
  57      }
  58  
  59      $crumbs = $this->buildApplicationCrumbs();
  60      $crumbs->addTextCrumb(pht('Edit Encoding'));
  61  
  62      $title = pht('Edit %s', $repository->getName());
  63  
  64      $form = id(new AphrontFormView())
  65        ->setUser($user)
  66        ->appendRemarkupInstructions($this->getEncodingInstructions())
  67        ->appendChild(
  68          id(new AphrontFormTextControl())
  69            ->setName('encoding')
  70            ->setLabel(pht('Text Encoding'))
  71            ->setValue($v_encoding)
  72            ->setError($e_encoding))
  73        ->appendChild(
  74          id(new AphrontFormSubmitControl())
  75            ->setValue(pht('Save Encoding'))
  76            ->addCancelButton($edit_uri));
  77  
  78      $object_box = id(new PHUIObjectBoxView())
  79        ->setHeaderText($title)
  80        ->setForm($form)
  81        ->setFormErrors($errors);
  82  
  83      return $this->buildApplicationPage(
  84        array(
  85          $crumbs,
  86          $object_box,
  87        ),
  88        array(
  89          'title' => $title,
  90        ));
  91    }
  92  
  93    private function getEncodingInstructions() {
  94      return pht(<<<EOT
  95  If source code in this repository uses a character encoding other than UTF-8
  96  (for example, `ISO-8859-1`), specify it here.
  97  
  98  **Normally, you can leave this field blank.** If your source code is written in
  99  ASCII or UTF-8, everything will work correctly.
 100  
 101  Source files will be translated from the specified encoding to UTF-8 when they
 102  are read from the repository, before they are displayed in Diffusion.
 103  
 104  See [[%s | UTF-8 and Character Encoding]] for more information on how
 105  Phabricator handles text encodings.
 106  EOT
 107      ,
 108      PhabricatorEnv::getDoclink(
 109        'User Guide: UTF-8 and Character Encoding'));
 110    }
 111  
 112  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1