mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
Provide context objects for remarkup mail rendering, fixing Phriction relative URIs in initial email
Summary: Fixes T10969. Ref T13077. When you create a Phriction document with a relative link (`[[ ./path/to/page ]]`) the initial email currently points to the wrong place. This is because the context object (the page) isn't passed to the markup engine. Without this context, the relative link is rendered as though it appeared somewhere else (like a task or revision) where relative links don't make sense. Test Plan: Created a new Phriction document with a relative link to `[[ ./porcupine_facts/starmap ]]`, saw a usable link in the resulting email. Maniphest Tasks: T13077, T10969 Differential Revision: https://secure.phabricator.com/D19105
This commit is contained in:
parent
f713e1dfc1
commit
bfdc9411f7
3 changed files with 63 additions and 22 deletions
|
@ -13,6 +13,7 @@ final class PhabricatorMetaMTAMailBody extends Phobject {
|
||||||
private $attachments = array();
|
private $attachments = array();
|
||||||
|
|
||||||
private $viewer;
|
private $viewer;
|
||||||
|
private $contextObject;
|
||||||
|
|
||||||
public function getViewer() {
|
public function getViewer() {
|
||||||
return $this->viewer;
|
return $this->viewer;
|
||||||
|
@ -23,6 +24,16 @@ final class PhabricatorMetaMTAMailBody extends Phobject {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setContextObject($context_object) {
|
||||||
|
$this->contextObject = $context_object;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContextObject() {
|
||||||
|
return $this->contextObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Composition )-------------------------------------------------------- */
|
/* -( Composition )-------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,9 +56,9 @@ final class PhabricatorMetaMTAMailBody extends Phobject {
|
||||||
|
|
||||||
public function addRemarkupSection($header, $text) {
|
public function addRemarkupSection($header, $text) {
|
||||||
try {
|
try {
|
||||||
$engine = PhabricatorMarkupEngine::newMarkupEngine(array());
|
$engine = $this->newMarkupEngine()
|
||||||
$engine->setConfig('viewer', $this->getViewer());
|
->setMode(PhutilRemarkupEngine::MODE_TEXT);
|
||||||
$engine->setMode(PhutilRemarkupEngine::MODE_TEXT);
|
|
||||||
$styled_text = $engine->markupText($text);
|
$styled_text = $engine->markupText($text);
|
||||||
$this->addPlaintextSection($header, $styled_text);
|
$this->addPlaintextSection($header, $styled_text);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
@ -56,12 +67,9 @@ final class PhabricatorMetaMTAMailBody extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$mail_engine = PhabricatorMarkupEngine::newMarkupEngine(array());
|
$mail_engine = $this->newMarkupEngine()
|
||||||
$mail_engine->setConfig('viewer', $this->getViewer());
|
->setMode(PhutilRemarkupEngine::MODE_HTML_MAIL);
|
||||||
$mail_engine->setMode(PhutilRemarkupEngine::MODE_HTML_MAIL);
|
|
||||||
$mail_engine->setConfig(
|
|
||||||
'uri.base',
|
|
||||||
PhabricatorEnv::getProductionURI('/'));
|
|
||||||
$html = $mail_engine->markupText($text);
|
$html = $mail_engine->markupText($text);
|
||||||
$this->addHTMLSection($header, $html);
|
$this->addHTMLSection($header, $html);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
@ -215,4 +223,19 @@ final class PhabricatorMetaMTAMailBody extends Phobject {
|
||||||
private function indent($text) {
|
private function indent($text) {
|
||||||
return rtrim(" ".str_replace("\n", "\n ", $text));
|
return rtrim(" ".str_replace("\n", "\n ", $text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function newMarkupEngine() {
|
||||||
|
$engine = PhabricatorMarkupEngine::newMarkupEngine(array())
|
||||||
|
->setConfig('viewer', $this->getViewer())
|
||||||
|
->setConfig('uri.base', PhabricatorEnv::getProductionURI('/'));
|
||||||
|
|
||||||
|
$context = $this->getContextObject();
|
||||||
|
if ($context) {
|
||||||
|
$engine->setConfig('contextObject', $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $engine;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,17 +28,7 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule {
|
||||||
|
|
||||||
// Handle relative links.
|
// Handle relative links.
|
||||||
if ((substr($link, 0, 2) === './') || (substr($link, 0, 3) === '../')) {
|
if ((substr($link, 0, 2) === './') || (substr($link, 0, 3) === '../')) {
|
||||||
$base = null;
|
$base = $this->getRelativeBaseURI();
|
||||||
$context = $this->getEngine()->getConfig('contextObject');
|
|
||||||
if ($context !== null && $context instanceof PhrictionContent) {
|
|
||||||
// Handle content when it's being rendered in document view.
|
|
||||||
$base = $context->getSlug();
|
|
||||||
}
|
|
||||||
if ($context !== null && is_array($context) &&
|
|
||||||
idx($context, 'phriction.isPreview')) {
|
|
||||||
// Handle content when it's a preview for the Phriction editor.
|
|
||||||
$base = idx($context, 'phriction.slug');
|
|
||||||
}
|
|
||||||
if ($base !== null) {
|
if ($base !== null) {
|
||||||
$base_parts = explode('/', rtrim($base, '/'));
|
$base_parts = explode('/', rtrim($base, '/'));
|
||||||
$rel_parts = explode('/', rtrim($link, '/'));
|
$rel_parts = explode('/', rtrim($link, '/'));
|
||||||
|
@ -195,4 +185,30 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getRelativeBaseURI() {
|
||||||
|
$context = $this->getEngine()->getConfig('contextObject');
|
||||||
|
|
||||||
|
if (!$context) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle content when it's a preview for the Phriction editor.
|
||||||
|
if (is_array($context)) {
|
||||||
|
if (idx($context, 'phriction.isPreview')) {
|
||||||
|
return idx($context, 'phriction.slug');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($context instanceof PhrictionContent) {
|
||||||
|
return $context->getSlug();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($context instanceof PhrictionDocument) {
|
||||||
|
return $context->getSlug();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2880,11 +2880,13 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
PhabricatorLiskDAO $object,
|
PhabricatorLiskDAO $object,
|
||||||
array $xactions) {
|
array $xactions) {
|
||||||
|
|
||||||
$body = new PhabricatorMetaMTAMailBody();
|
$body = id(new PhabricatorMetaMTAMailBody())
|
||||||
$body->setViewer($this->requireActor());
|
->setViewer($this->requireActor())
|
||||||
|
->setContextObject($object);
|
||||||
|
|
||||||
$this->addHeadersAndCommentsToMailBody($body, $xactions);
|
$this->addHeadersAndCommentsToMailBody($body, $xactions);
|
||||||
$this->addCustomFieldsToMailBody($body, $object, $xactions);
|
$this->addCustomFieldsToMailBody($body, $object, $xactions);
|
||||||
|
|
||||||
return $body;
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue