@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
at upstream/main 95 lines 2.9 kB view raw
1<?php 2 3final class PhabricatorApplicationTransactionCommentRemoveController 4 extends PhabricatorApplicationTransactionController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $this->getViewer(); 8 $phid = $request->getURIData('phid'); 9 10 $xaction = id(new PhabricatorObjectQuery()) 11 ->withPHIDs(array($phid)) 12 ->setViewer($viewer) 13 ->executeOne(); 14 if (!$xaction) { 15 return new Aphront404Response(); 16 } 17 18 if (!$xaction->getComment()) { 19 return new Aphront404Response(); 20 } 21 22 if ($xaction->getComment()->getIsRemoved()) { 23 // You can't remove an already-removed comment. 24 return new Aphront400Response(); 25 } 26 27 $obj_phid = $xaction->getObjectPHID(); 28 $obj_handle = id(new PhabricatorHandleQuery()) 29 ->setViewer($viewer) 30 ->withPHIDs(array($obj_phid)) 31 ->executeOne(); 32 33 $done_uri = $obj_handle->getURI(); 34 35 // We allow administrative removal of comments even if an object is locked, 36 // so you can lock a flamewar and then go clean it up. Locked threads may 37 // not otherwise be edited, and non-administrators can not remove comments 38 // from locked threads. 39 40 $object = $xaction->getObject(); 41 $can_interact = PhabricatorPolicyFilter::canInteract( 42 $viewer, 43 $object); 44 if (!$can_interact && !$viewer->getIsAdmin()) { 45 return $this->newDialog() 46 ->setTitle(pht('Conversation Locked')) 47 ->appendParagraph( 48 pht( 49 'You can not remove this comment because the conversation is '. 50 'locked.')) 51 ->addCancelButton($done_uri); 52 } 53 54 if ($request->isFormOrHisecPost()) { 55 $comment = $xaction->getApplicationTransactionCommentObject() 56 ->setContent('') 57 ->setIsRemoved(true); 58 59 $editor = id(new PhabricatorApplicationTransactionCommentEditor()) 60 ->setActor($viewer) 61 ->setRequest($request) 62 ->setCancelURI($done_uri) 63 ->setContentSource(PhabricatorContentSource::newFromRequest($request)) 64 ->applyEdit($xaction, $comment); 65 66 if ($request->isAjax()) { 67 return id(new AphrontAjaxResponse())->setContent(array()); 68 } else { 69 return id(new AphrontReloadResponse())->setURI($done_uri); 70 } 71 } 72 73 $form = id(new AphrontFormView()) 74 ->setUser($viewer); 75 76 $dialog = $this->newDialog() 77 ->setTitle(pht('Remove Comment')); 78 79 $dialog 80 ->appendParagraph( 81 pht( 82 "Removing a comment prevents anyone (including you) from reading ". 83 "it. Removing a comment also hides the comment's edit history ". 84 "and prevents it from being edited.")) 85 ->appendParagraph( 86 pht('Really remove this comment?')); 87 88 $dialog 89 ->addSubmitButton(pht('Remove Comment')) 90 ->addCancelButton($done_uri); 91 92 return $dialog; 93 } 94 95}