@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 recaptime-dev/main 62 lines 1.6 kB view raw
1<?php 2 3final class PhabricatorApplicationTransactionCommentQuoteController 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 return new Aphront400Response(); 24 } 25 26 if (!$xaction->hasComment()) { 27 return new Aphront404Response(); 28 } 29 30 $content = $xaction->getComment()->getContent(); 31 $content = rtrim($content, "\r\n"); 32 $content = phutil_split_lines($content, true); 33 foreach ($content as $key => $line) { 34 if (strlen($line) && ($line[0] != '>')) { 35 $content[$key] = '> '.$line; 36 } else { 37 $content[$key] = '>'.$line; 38 } 39 } 40 $content = implode('', $content); 41 42 $author = id(new PhabricatorHandleQuery()) 43 ->setViewer($viewer) 44 ->withPHIDs(array($xaction->getComment()->getAuthorPHID())) 45 ->executeOne(); 46 47 $ref = $request->getStr('ref'); 48 if (strlen($ref)) { 49 $quote = pht('In %s, %s wrote:', $ref, '@'.$author->getName()); 50 } else { 51 $quote = pht('%s wrote:', '@'.$author->getName()); 52 } 53 54 $content = ">>! {$quote}\n{$content}"; 55 56 return id(new AphrontAjaxResponse())->setContent( 57 array( 58 'quoteText' => $content, 59 )); 60 } 61 62}