@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 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::class;
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 // remove "Change Auditors" from "Add Action" dropdown etc
104 // if Audit is disabled
105 if (id(new PhabricatorAuditApplication())->isInstalled()) {
106 $fields[] = id(new PhabricatorDatasourceEditField())
107 ->setKey('auditors')
108 ->setLabel(pht('Auditors'))
109 ->setDatasource(new DiffusionAuditorDatasource())
110 ->setUseEdgeTransactions(true)
111 ->setTransactionType(
112 DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE)
113 ->setCommentActionLabel(pht('Change Auditors'))
114 ->setDescription(pht('Auditors for this commit.'))
115 ->setConduitDescription(pht('Change the auditors for this commit.'))
116 ->setConduitTypeDescription(pht('New auditors.'))
117 ->setValue($object->getAuditorPHIDsForEdit());
118 }
119
120 $actions = DiffusionCommitActionTransaction::loadAllActions();
121 $actions = msortv($actions, 'getCommitActionOrderVector');
122
123 foreach ($actions as $key => $action) {
124 $fields[] = $action->newEditField($object, $viewer);
125 }
126
127 return $fields;
128 }
129
130 protected function newAutomaticCommentTransactions($object) {
131 $viewer = $this->getViewer();
132
133 $editor = $object->getApplicationTransactionEditor()
134 ->setActor($viewer);
135
136 $xactions = $editor->newAutomaticInlineTransactions(
137 $object,
138 PhabricatorAuditActionConstants::INLINE,
139 new DiffusionDiffInlineCommentQuery());
140
141 return $xactions;
142 }
143
144 protected function newCommentPreviewContent($object, array $xactions) {
145 $viewer = $this->getViewer();
146 $type_inline = PhabricatorAuditActionConstants::INLINE;
147
148 $inlines = array();
149 foreach ($xactions as $xaction) {
150 if ($xaction->getTransactionType() === $type_inline) {
151 $inlines[] = $xaction->getComment();
152 }
153 }
154
155 $content = array();
156
157 if ($inlines) {
158 $inline_preview = id(new PHUIDiffInlineCommentPreviewListView())
159 ->setViewer($viewer)
160 ->setInlineComments($inlines);
161
162 $content[] = phutil_tag(
163 'div',
164 array(
165 'id' => 'inline-comment-preview',
166 ),
167 $inline_preview);
168 }
169
170 return $content;
171 }
172}