Differential D16056 Diff 38632 src/applications/transactions/view/PhabricatorApplicationTransactionTextDiffDetailView.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/view/PhabricatorApplicationTransactionTextDiffDetailView.php
Show All 11 Lines | final class PhabricatorApplicationTransactionTextDiffDetailView | ||||
} | } | ||||
public function setOldText($old_text) { | public function setOldText($old_text) { | ||||
$this->oldText = $old_text; | $this->oldText = $old_text; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function render() { | public function render() { | ||||
$old = $this->oldText; | $diff = $this->buildDiff(); | ||||
$new = $this->newText; | |||||
// TODO: On mobile, or perhaps by default, we should switch to 1-up once | require_celerity_resource('differential-changeset-view-css'); | ||||
// that is built. | |||||
if (strlen($old)) { | $result = array(); | ||||
$old = phutil_utf8_hard_wrap($old, 80); | foreach ($diff->getParts() as $part) { | ||||
$old = implode("\n", $old)."\n"; | $type = $part['type']; | ||||
$text = $part['text']; | |||||
switch ($type) { | |||||
case '-': | |||||
$result[] = phutil_tag( | |||||
'span', | |||||
array( | |||||
'class' => 'old', | |||||
), | |||||
$text); | |||||
break; | |||||
case '+': | |||||
$result[] = phutil_tag( | |||||
'span', | |||||
array( | |||||
'class' => 'new', | |||||
), | |||||
$text); | |||||
break; | |||||
case '=': | |||||
$result[] = $text; | |||||
break; | |||||
} | } | ||||
if (strlen($new)) { | |||||
$new = phutil_utf8_hard_wrap($new, 80); | |||||
$new = implode("\n", $new)."\n"; | |||||
} | } | ||||
try { | return phutil_tag( | ||||
$engine = new PhabricatorDifferenceEngine(); | 'div', | ||||
$changeset = $engine->generateChangesetFromFileContent($old, $new); | array( | ||||
'class' => 'prose-diff', | |||||
$whitespace_mode = DifferentialChangesetParser::WHITESPACE_SHOW_ALL; | ), | ||||
$result); | |||||
$markup_engine = new PhabricatorMarkupEngine(); | } | ||||
$markup_engine->setViewer($this->getUser()); | |||||
private function buildDiff() { | |||||
$parser = new DifferentialChangesetParser(); | $engine = new PhutilProseDifferenceEngine(); | ||||
$parser->setUser($this->getUser()); | return $engine->getDiff($this->oldText, $this->newText); | ||||
$parser->setChangeset($changeset); | |||||
$parser->setMarkupEngine($markup_engine); | |||||
$parser->setWhitespaceMode($whitespace_mode); | |||||
return $parser->render(0, PHP_INT_MAX, array()); | |||||
} catch (Exception $ex) { | |||||
return $ex->getMessage(); | |||||
} | |||||
} | } | ||||
} | } |