diff --git a/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php b/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php --- a/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php +++ b/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php @@ -12,6 +12,15 @@ private $htmlSections = array(); private $attachments = array(); + private $viewer; + + public function getViewer() { + return $this->viewer; + } + + public function setViewer($viewer) { + $this->viewer = $viewer; + } /* -( Composition )-------------------------------------------------------- */ @@ -33,6 +42,23 @@ return $this; } + public function addRemarkupSection($text) { + $engine = PhabricatorMarkupEngine::newMarkupEngine(array()); + $engine->setConfig('viewer', $this->getViewer()); + $engine->setMode(PhutilRemarkupEngine::MODE_TEXT); + $styled_text = $engine->markupText($text); + $this->sections[] = $styled_text; + + $mail_engine = PhabricatorMarkupEngine::newMarkupEngine(array()); + $mail_engine->setConfig('viewer', $this->getViewer()); + $mail_engine->setMode(PhutilRemarkupEngine::MODE_HTML_MAIL); + $mail_engine->setConfig('uri.base', PhabricatorEnv::getProductionURI('/')); + $html = $mail_engine->markupText($text); + $this->htmlSections[] = $html; + + return $this; + } + public function addRawPlaintextSection($text) { if (strlen($text)) { $text = rtrim($text); diff --git a/src/applications/people/markup/PhabricatorMentionRemarkupRule.php b/src/applications/people/markup/PhabricatorMentionRemarkupRule.php --- a/src/applications/people/markup/PhabricatorMentionRemarkupRule.php +++ b/src/applications/people/markup/PhabricatorMentionRemarkupRule.php @@ -100,11 +100,17 @@ $user = $actual_users[$username]; Javelin::initBehavior('phabricator-hovercards'); + $user_href = '/p/'.$user->getUserName().'/'; + + if ($engine->isHTMLMailMode()) { + $user_href = PhabricatorEnv::getProductionURI($user_href); + } + $tag = id(new PHUITagView()) ->setType(PHUITagView::TYPE_PERSON) ->setPHID($user->getPHID()) ->setName('@'.$user->getUserName()) - ->setHref('/p/'.$user->getUserName().'/'); + ->setHref($user_href); if (!$user->isUserActivated()) { $tag->setDotColor(PHUITagView::COLOR_GREY); diff --git a/src/applications/phriction/markup/PhrictionRemarkupRule.php b/src/applications/phriction/markup/PhrictionRemarkupRule.php --- a/src/applications/phriction/markup/PhrictionRemarkupRule.php +++ b/src/applications/phriction/markup/PhrictionRemarkupRule.php @@ -29,9 +29,12 @@ $slug = PhrictionDocument::getSlugURI($slug); $href = (string)id(new PhutilURI($slug))->setFragment($fragment); + $text_mode = $this->getEngine()->isTextMode(); + $mail_mode = $this->getEngine()->isHTMLMailMode(); + if ($this->getEngine()->getState('toc')) { $text = $name; - } else if ($this->getEngine()->isTextMode()) { + } else if ($text_mode || $mail_mode) { return PhabricatorEnv::getProductionURI($href); } else { $text = $this->newTag( diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -2159,10 +2159,11 @@ } $body = new PhabricatorMetaMTAMailBody(); + $body->setViewer($this->requireActor()); $body->addRawSection(implode("\n", $headers)); foreach ($comments as $comment) { - $body->addRawSection($comment); + $body->addRemarkupSection($comment); } if ($object instanceof PhabricatorCustomFieldInterface) { diff --git a/src/infrastructure/markup/rule/PhabricatorObjectRemarkupRule.php b/src/infrastructure/markup/rule/PhabricatorObjectRemarkupRule.php --- a/src/infrastructure/markup/rule/PhabricatorObjectRemarkupRule.php +++ b/src/infrastructure/markup/rule/PhabricatorObjectRemarkupRule.php @@ -44,7 +44,11 @@ return $handle->getURI(); } - protected function renderObjectRef($object, $handle, $anchor, $id) { + protected function renderObjectRefForAnyMedia ( + $object, + $handle, + $anchor, + $id) { $href = $this->getObjectHref($object, $handle, $id); $text = $this->getObjectNamePrefix().$id; @@ -55,10 +59,25 @@ if ($this->getEngine()->isTextMode()) { return PhabricatorEnv::getProductionURI($href); + } else if ($this->getEngine()->isHTMLMailMode()) { + $href = PhabricatorEnv::getProductionURI($href); + return $this->renderObjectTagForMail($text, $href, $handle); } + return $this->renderObjectRef($object, $handle, $anchor, $id); + + } + + protected function renderObjectRef($object, $handle, $anchor, $id) { + $href = $this->getObjectHref($object, $handle, $id); + $text = $this->getObjectNamePrefix().$id; $status_closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; + if ($anchor) { + $href = $href.'#'.$anchor; + $text = $text.'#'.$anchor; + } + $attr = array( 'phid' => $handle->getPHID(), 'closed' => ($handle->getStatus() == $status_closed), @@ -67,15 +86,24 @@ return $this->renderHovertag($text, $href, $attr); } - protected function renderObjectEmbed($object, $handle, $options) { + protected function renderObjectEmbedForAnyMedia($object, $handle, $options) { $name = $handle->getFullName(); $href = $handle->getURI(); - $status_closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; if ($this->getEngine()->isTextMode()) { return $name.' <'.PhabricatorEnv::getProductionURI($href).'>'; + } else if ($this->getEngine()->isHTMLMailMode()) { + $href = PhabricatorEnv::getProductionURI($href); + return $this->renderObjectTagForMail($name, $href, $handle); } + return $this->renderObjectEmbed($object, $handle, $options); + } + + protected function renderObjectEmbed($object, $handle, $options) { + $name = $handle->getFullName(); + $href = $handle->getURI(); + $status_closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; $attr = array( 'phid' => $handle->getPHID(), 'closed' => ($handle->getStatus() == $status_closed), @@ -84,6 +112,31 @@ return $this->renderHovertag($name, $href, $attr); } + protected function renderObjectTagForMail( + $text, + $href, + $handle) { + + $status_closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; + $strikethrough = $handle->getStatus() == $status_closed ? + 'text-decoration: line-through;' : + 'text-decoration: none;'; + + return phutil_tag( + 'a', + array( + 'href' => $href, + 'style' => 'background-color: #e7e7e7; + border-color: #e7e7e7; + border-radius: 3px; + padding: 0 4px; + font-weight: bold; + color: black;' + .$strikethrough, + ), + $text); + } + protected function renderHovertag($name, $href, array $attr = array()) { return id(new PHUITagView()) ->setName($name) @@ -282,7 +335,8 @@ $object = $objects[$spec['id']]; switch ($spec['type']) { case 'ref': - $view = $this->renderObjectRef( + + $view = $this->renderObjectRefForAnyMedia( $object, $handle, $spec['anchor'], @@ -290,7 +344,10 @@ break; case 'embed': $spec['options'] = $this->assertFlatText($spec['options']); - $view = $this->renderObjectEmbed($object, $handle, $spec['options']); + $view = $this->renderObjectEmbedForAnyMedia( + $object, + $handle, + $spec['options']); break; } $engine->overwriteStoredText($spec['token'], $view); diff --git a/src/infrastructure/markup/rule/PhabricatorYoutubeRemarkupRule.php b/src/infrastructure/markup/rule/PhabricatorYoutubeRemarkupRule.php --- a/src/infrastructure/markup/rule/PhabricatorYoutubeRemarkupRule.php +++ b/src/infrastructure/markup/rule/PhabricatorYoutubeRemarkupRule.php @@ -20,8 +20,10 @@ public function markupYoutubeLink() { $v = idx($this->uri->getQueryParams(), 'v'); + $text_mode = $this->getEngine()->isTextMode(); + $mail_mode = $this->getEngine()->isHTMLMailMode(); - if ($this->getEngine()->isTextMode()) { + if ($text_mode || $mail_mode) { return $this->getEngine()->storeText('http://youtu.be/'.$v); }