Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / files / xaction / PhabricatorFileAltTextTransaction.php
blobdcf3c6f76f4f32fe79110e67ae39a6911b6f62a6
1 <?php
3 final class PhabricatorFileAltTextTransaction
4 extends PhabricatorFileTransactionType {
6 const TRANSACTIONTYPE = 'file:alt';
8 public function generateOldValue($object) {
9 return $object->getCustomAltText();
12 public function generateNewValue($object, $value) {
13 $value = phutil_string_cast($value);
15 if (!strlen($value)) {
16 $value = null;
19 return $value;
22 public function applyInternalEffects($object, $value) {
23 $object->setCustomAltText($value);
26 public function getTitle() {
27 $old_value = $this->getOldValue();
28 $new_value = $this->getNewValue();
30 if (!strlen($old_value)) {
31 return pht(
32 '%s set the alternate text for this file to %s.',
33 $this->renderAuthor(),
34 $this->renderNewValue());
35 } else if (!strlen($new_value)) {
36 return pht(
37 '%s removed the alternate text for this file (was %s).',
38 $this->renderAuthor(),
39 $this->renderOldValue());
40 } else {
41 return pht(
42 '%s changed the alternate text for this file from %s to %s.',
43 $this->renderAuthor(),
44 $this->renderOldValue(),
45 $this->renderNewValue());
49 public function getTitleForFeed() {
50 $old_value = $this->getOldValue();
51 $new_value = $this->getNewValue();
53 if (!strlen($old_value)) {
54 return pht(
55 '%s set the alternate text for %s to %s.',
56 $this->renderAuthor(),
57 $this->renderObject(),
58 $this->renderNewValue());
59 } else if (!strlen($new_value)) {
60 return pht(
61 '%s removed the alternate text for %s (was %s).',
62 $this->renderAuthor(),
63 $this->renderObject(),
64 $this->renderOldValue());
65 } else {
66 return pht(
67 '%s changed the alternate text for %s from %s to %s.',
68 $this->renderAuthor(),
69 $this->renderObject(),
70 $this->renderOldValue(),
71 $this->renderNewValue());
75 public function validateTransactions($object, array $xactions) {
76 $errors = array();
78 $max_length = 1024;
79 foreach ($xactions as $xaction) {
80 $new_value = $xaction->getNewValue();
82 $new_length = strlen($new_value);
83 if ($new_length > $max_length) {
84 $errors[] = $this->newInvalidError(
85 pht(
86 'File alternate text must not be longer than %s character(s).',
87 new PhutilNumber($max_length)));
91 return $errors;