Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / editor / DiffusionCommitEditEngine.php
blob60a2667c95dd7a924656b067b2481c46a491ef61
1 <?php
3 final class DiffusionCommitEditEngine
4 extends PhabricatorEditEngine {
6 const ENGINECONST = 'diffusion.commit';
8 const ACTIONGROUP_AUDIT = 'audit';
9 const ACTIONGROUP_COMMIT = 'commit';
11 public function isEngineConfigurable() {
12 return false;
15 public function getEngineName() {
16 return pht('Commits');
19 public function getSummaryHeader() {
20 return pht('Edit Commits');
23 public function getSummaryText() {
24 return pht('Edit commits.');
27 public function getEngineApplicationClass() {
28 return 'PhabricatorDiffusionApplication';
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.
36 $repository = new PhabricatorRepository();
37 $data = new PhabricatorRepositoryCommitData();
39 return id(new PhabricatorRepositoryCommit())
40 ->attachRepository($repository)
41 ->attachCommitData($data)
42 ->attachAudits(array());
45 protected function newObjectQuery() {
46 $viewer = $this->getViewer();
48 return id(new DiffusionCommitQuery())
49 ->needCommitData(true)
50 ->needAuditRequests(true)
51 ->needAuditAuthority(array($viewer))
52 ->needIdentities(true);
55 protected function getEditorURI() {
56 return $this->getApplication()->getApplicationURI('commit/edit/');
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')),
70 protected function getObjectCreateTitleText($object) {
71 return pht('Create Commit');
74 protected function getObjectCreateShortText() {
75 return pht('Create Commit');
78 protected function getObjectEditTitleText($object) {
79 return pht('Edit Commit: %s', $object->getDisplayName());
82 protected function getObjectEditShortText($object) {
83 return $object->getDisplayName();
86 protected function getObjectName() {
87 return pht('Commit');
90 protected function getObjectViewURI($object) {
91 return $object->getURI();
94 protected function getCreateNewObjectPolicy() {
95 return PhabricatorPolicies::POLICY_NOONE;
98 protected function buildCustomEditFields($object) {
99 $viewer = $this->getViewer();
100 $data = $object->getCommitData();
102 $fields = array();
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());
117 $actions = DiffusionCommitActionTransaction::loadAllActions();
118 $actions = msortv($actions, 'getCommitActionOrderVector');
120 foreach ($actions as $key => $action) {
121 $fields[] = $action->newEditField($object, $viewer);
124 return $fields;
127 protected function newAutomaticCommentTransactions($object) {
128 $viewer = $this->getViewer();
130 $editor = $object->getApplicationTransactionEditor()
131 ->setActor($viewer);
133 $xactions = $editor->newAutomaticInlineTransactions(
134 $object,
135 PhabricatorAuditActionConstants::INLINE,
136 new DiffusionDiffInlineCommentQuery());
138 return $xactions;
141 protected function newCommentPreviewContent($object, array $xactions) {
142 $viewer = $this->getViewer();
143 $type_inline = PhabricatorAuditActionConstants::INLINE;
145 $inlines = array();
146 foreach ($xactions as $xaction) {
147 if ($xaction->getTransactionType() === $type_inline) {
148 $inlines[] = $xaction->getComment();
152 $content = array();
154 if ($inlines) {
155 $inline_preview = id(new PHUIDiffInlineCommentPreviewListView())
156 ->setViewer($viewer)
157 ->setInlineComments($inlines);
159 $content[] = phutil_tag(
160 'div',
161 array(
162 'id' => 'inline-comment-preview',
164 $inline_preview);
167 return $content;