mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-28 09:42:41 +01:00
85bc05be25
Summary: Ref T4119. - Trim newlines off the quoted text before quoting it; otherwise we can end up with a staircase of ">" at the end of a quote. - Allow image macros to have leading whitespace, so multiple consecuitive quoted macros work properly. Test Plan: I QUOTED MACROS A LOT OF TIMES Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T4119 Differential Revision: https://secure.phabricator.com/D8983
68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
final class PhabricatorApplicationTransactionCommentQuoteController
|
|
extends PhabricatorApplicationTransactionController {
|
|
|
|
private $phid;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->phid = $data['phid'];
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$viewer = $request->getUser();
|
|
|
|
$xaction = id(new PhabricatorObjectQuery())
|
|
->withPHIDs(array($this->phid))
|
|
->setViewer($viewer)
|
|
->executeOne();
|
|
if (!$xaction) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
if (!$xaction->getComment()) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
if ($xaction->getComment()->getIsRemoved()) {
|
|
return new Aphront400Response();
|
|
}
|
|
|
|
if (!$xaction->hasComment()) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$content = $xaction->getComment()->getContent();
|
|
$content = rtrim($content, "\r\n");
|
|
$content = phutil_split_lines($content, true);
|
|
foreach ($content as $key => $line) {
|
|
if (strlen($line) && ($line[0] != '>')) {
|
|
$content[$key] = '> '.$line;
|
|
} else {
|
|
$content[$key] = '>'.$line;
|
|
}
|
|
}
|
|
$content = implode('', $content);
|
|
|
|
$author = id(new PhabricatorHandleQuery())
|
|
->setViewer($viewer)
|
|
->withPHIDs(array($xaction->getComment()->getAuthorPHID()))
|
|
->executeOne();
|
|
|
|
$ref = $request->getStr('ref');
|
|
if (strlen($ref)) {
|
|
$quote = pht('In %s, %s wrote:', $ref, '@'.$author->getName());
|
|
} else {
|
|
$quote = pht('%s wrote:', '@'.$author->getName());
|
|
}
|
|
|
|
$content = ">>! {$quote}\n{$content}";
|
|
|
|
return id(new AphrontAjaxResponse())->setContent(
|
|
array(
|
|
'quoteText' => $content,
|
|
));
|
|
}
|
|
|
|
}
|