@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<?php
2
3final class PhabricatorRepositoryEncodingTransaction
4 extends PhabricatorRepositoryTransactionType {
5
6 const TRANSACTIONTYPE = 'repo:encoding';
7
8 public function generateOldValue($object) {
9 return $object->getDetail('encoding');
10 }
11
12 public function applyInternalEffects($object, $value) {
13 $object->setDetail('encoding', $value);
14 }
15
16 public function getTitle() {
17 $old = $this->getOldValue();
18 $new = $this->getNewValue();
19
20 if ($old !== null && $new === null) {
21 return pht(
22 '%s removed the %s encoding configured for this repository.',
23 $this->renderAuthor(),
24 $this->renderOldValue());
25 } else if ($new !== null && $old === null) {
26 return pht(
27 '%s set the encoding for this repository to %s.',
28 $this->renderAuthor(),
29 $this->renderNewValue());
30 } else {
31 return pht(
32 '%s changed the repository encoding from %s to %s.',
33 $this->renderAuthor(),
34 $this->renderOldValue(),
35 $this->renderNewValue());
36 }
37 }
38
39 public function validateTransactions($object, array $xactions) {
40 $errors = array();
41
42 foreach ($xactions as $xaction) {
43 // Make sure the encoding is valid by converting to UTF-8. This tests
44 // that the user has mbstring installed, and also that they didn't
45 // type a garbage encoding name. Note that we're converting from
46 // UTF-8 to the target encoding, because mbstring is fine with
47 // converting from a nonsense encoding.
48 $encoding = $xaction->getNewValue();
49 if (!strlen($encoding)) {
50 continue;
51 }
52
53 try {
54 phutil_utf8_convert('.', $encoding, 'UTF-8');
55 } catch (Exception $ex) {
56 $errors[] = $this->newInvalidError(
57 pht(
58 'Repository encoding "%s" is not valid: %s',
59 $encoding,
60 $ex->getMessage()),
61 $xaction);
62 }
63 }
64
65 return $errors;
66 }
67
68}