Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/editor/DiffusionCommitEditEngine.php
12242 views
1
<?php
2
3
final class DiffusionCommitEditEngine
4
extends PhabricatorEditEngine {
5
6
const ENGINECONST = 'diffusion.commit';
7
8
const ACTIONGROUP_AUDIT = 'audit';
9
const ACTIONGROUP_COMMIT = 'commit';
10
11
public function isEngineConfigurable() {
12
return false;
13
}
14
15
public function getEngineName() {
16
return pht('Commits');
17
}
18
19
public function getSummaryHeader() {
20
return pht('Edit Commits');
21
}
22
23
public function getSummaryText() {
24
return pht('Edit commits.');
25
}
26
27
public function getEngineApplicationClass() {
28
return 'PhabricatorDiffusionApplication';
29
}
30
31
protected function newEditableObject() {
32
// NOTE: We must return a valid object here so that things like Conduit
33
// documentation generation work. You can't actually create commits via
34
// EditEngine. This is enforced with a "No One" creation policy.
35
36
$repository = new PhabricatorRepository();
37
$data = new PhabricatorRepositoryCommitData();
38
39
return id(new PhabricatorRepositoryCommit())
40
->attachRepository($repository)
41
->attachCommitData($data)
42
->attachAudits(array());
43
}
44
45
protected function newObjectQuery() {
46
$viewer = $this->getViewer();
47
48
return id(new DiffusionCommitQuery())
49
->needCommitData(true)
50
->needAuditRequests(true)
51
->needAuditAuthority(array($viewer))
52
->needIdentities(true);
53
}
54
55
protected function getEditorURI() {
56
return $this->getApplication()->getApplicationURI('commit/edit/');
57
}
58
59
protected function newCommentActionGroups() {
60
return array(
61
id(new PhabricatorEditEngineCommentActionGroup())
62
->setKey(self::ACTIONGROUP_AUDIT)
63
->setLabel(pht('Audit Actions')),
64
id(new PhabricatorEditEngineCommentActionGroup())
65
->setKey(self::ACTIONGROUP_COMMIT)
66
->setLabel(pht('Commit Actions')),
67
);
68
}
69
70
protected function getObjectCreateTitleText($object) {
71
return pht('Create Commit');
72
}
73
74
protected function getObjectCreateShortText() {
75
return pht('Create Commit');
76
}
77
78
protected function getObjectEditTitleText($object) {
79
return pht('Edit Commit: %s', $object->getDisplayName());
80
}
81
82
protected function getObjectEditShortText($object) {
83
return $object->getDisplayName();
84
}
85
86
protected function getObjectName() {
87
return pht('Commit');
88
}
89
90
protected function getObjectViewURI($object) {
91
return $object->getURI();
92
}
93
94
protected function getCreateNewObjectPolicy() {
95
return PhabricatorPolicies::POLICY_NOONE;
96
}
97
98
protected function buildCustomEditFields($object) {
99
$viewer = $this->getViewer();
100
$data = $object->getCommitData();
101
102
$fields = array();
103
104
$fields[] = id(new PhabricatorDatasourceEditField())
105
->setKey('auditors')
106
->setLabel(pht('Auditors'))
107
->setDatasource(new DiffusionAuditorDatasource())
108
->setUseEdgeTransactions(true)
109
->setTransactionType(
110
DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE)
111
->setCommentActionLabel(pht('Change Auditors'))
112
->setDescription(pht('Auditors for this commit.'))
113
->setConduitDescription(pht('Change the auditors for this commit.'))
114
->setConduitTypeDescription(pht('New auditors.'))
115
->setValue($object->getAuditorPHIDsForEdit());
116
117
$actions = DiffusionCommitActionTransaction::loadAllActions();
118
$actions = msortv($actions, 'getCommitActionOrderVector');
119
120
foreach ($actions as $key => $action) {
121
$fields[] = $action->newEditField($object, $viewer);
122
}
123
124
return $fields;
125
}
126
127
protected function newAutomaticCommentTransactions($object) {
128
$viewer = $this->getViewer();
129
130
$editor = $object->getApplicationTransactionEditor()
131
->setActor($viewer);
132
133
$xactions = $editor->newAutomaticInlineTransactions(
134
$object,
135
PhabricatorAuditActionConstants::INLINE,
136
new DiffusionDiffInlineCommentQuery());
137
138
return $xactions;
139
}
140
141
protected function newCommentPreviewContent($object, array $xactions) {
142
$viewer = $this->getViewer();
143
$type_inline = PhabricatorAuditActionConstants::INLINE;
144
145
$inlines = array();
146
foreach ($xactions as $xaction) {
147
if ($xaction->getTransactionType() === $type_inline) {
148
$inlines[] = $xaction->getComment();
149
}
150
}
151
152
$content = array();
153
154
if ($inlines) {
155
$inline_preview = id(new PHUIDiffInlineCommentPreviewListView())
156
->setViewer($viewer)
157
->setInlineComments($inlines);
158
159
$content[] = phutil_tag(
160
'div',
161
array(
162
'id' => 'inline-comment-preview',
163
),
164
$inline_preview);
165
}
166
167
return $content;
168
}
169
}
170
171