forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorFileAltTextTransaction.php
94 lines (78 loc) · 2.47 KB
/
PhabricatorFileAltTextTransaction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
final class PhabricatorFileAltTextTransaction
extends PhabricatorFileTransactionType {
const TRANSACTIONTYPE = 'file:alt';
public function generateOldValue($object) {
return $object->getCustomAltText();
}
public function generateNewValue($object, $value) {
$value = phutil_string_cast($value);
if (!strlen($value)) {
$value = null;
}
return $value;
}
public function applyInternalEffects($object, $value) {
$object->setCustomAltText($value);
}
public function getTitle() {
$old_value = $this->getOldValue();
$new_value = $this->getNewValue();
if ($old_value == null || !strlen($old_value)) {
return pht(
'%s set the alternate text for this file to %s.',
$this->renderAuthor(),
$this->renderNewValue());
} else if ($new_value === null || !strlen($new_value)) {
return pht(
'%s removed the alternate text for this file (was %s).',
$this->renderAuthor(),
$this->renderOldValue());
} else {
return pht(
'%s changed the alternate text for this file from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
}
public function getTitleForFeed() {
$old_value = $this->getOldValue();
$new_value = $this->getNewValue();
if ($old_value === null || !strlen($old_value)) {
return pht(
'%s set the alternate text for %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderNewValue());
} else if ($new_value === null || !strlen($new_value)) {
return pht(
'%s removed the alternate text for %s (was %s).',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue());
} else {
return pht(
'%s changed the alternate text for %s from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
$this->renderNewValue());
}
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$max_length = 1024;
foreach ($xactions as $xaction) {
$new_value = $xaction->getNewValue();
$new_length = strlen($new_value);
if ($new_length > $max_length) {
$errors[] = $this->newInvalidError(
pht(
'File alternate text must not be longer than %s character(s).',
new PhutilNumber($max_length)));
}
}
return $errors;
}
}