@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+63 -22
+32 -9
src/applications/metamta/view/PhabricatorMetaMTAMailBody.php
··· 13 13 private $attachments = array(); 14 14 15 15 private $viewer; 16 + private $contextObject; 16 17 17 18 public function getViewer() { 18 19 return $this->viewer; ··· 22 23 $this->viewer = $viewer; 23 24 return $this; 24 25 } 26 + 27 + public function setContextObject($context_object) { 28 + $this->contextObject = $context_object; 29 + return $this; 30 + } 31 + 32 + public function getContextObject() { 33 + return $this->contextObject; 34 + } 35 + 25 36 26 37 /* -( Composition )-------------------------------------------------------- */ 27 38 ··· 45 56 46 57 public function addRemarkupSection($header, $text) { 47 58 try { 48 - $engine = PhabricatorMarkupEngine::newMarkupEngine(array()); 49 - $engine->setConfig('viewer', $this->getViewer()); 50 - $engine->setMode(PhutilRemarkupEngine::MODE_TEXT); 59 + $engine = $this->newMarkupEngine() 60 + ->setMode(PhutilRemarkupEngine::MODE_TEXT); 61 + 51 62 $styled_text = $engine->markupText($text); 52 63 $this->addPlaintextSection($header, $styled_text); 53 64 } catch (Exception $ex) { ··· 56 67 } 57 68 58 69 try { 59 - $mail_engine = PhabricatorMarkupEngine::newMarkupEngine(array()); 60 - $mail_engine->setConfig('viewer', $this->getViewer()); 61 - $mail_engine->setMode(PhutilRemarkupEngine::MODE_HTML_MAIL); 62 - $mail_engine->setConfig( 63 - 'uri.base', 64 - PhabricatorEnv::getProductionURI('/')); 70 + $mail_engine = $this->newMarkupEngine() 71 + ->setMode(PhutilRemarkupEngine::MODE_HTML_MAIL); 72 + 65 73 $html = $mail_engine->markupText($text); 66 74 $this->addHTMLSection($header, $html); 67 75 } catch (Exception $ex) { ··· 215 223 private function indent($text) { 216 224 return rtrim(" ".str_replace("\n", "\n ", $text)); 217 225 } 226 + 227 + 228 + private function newMarkupEngine() { 229 + $engine = PhabricatorMarkupEngine::newMarkupEngine(array()) 230 + ->setConfig('viewer', $this->getViewer()) 231 + ->setConfig('uri.base', PhabricatorEnv::getProductionURI('/')); 232 + 233 + $context = $this->getContextObject(); 234 + if ($context) { 235 + $engine->setConfig('contextObject', $context); 236 + } 237 + 238 + return $engine; 239 + } 240 + 218 241 }
+27 -11
src/applications/phriction/markup/PhrictionRemarkupRule.php
··· 28 28 29 29 // Handle relative links. 30 30 if ((substr($link, 0, 2) === './') || (substr($link, 0, 3) === '../')) { 31 - $base = null; 32 - $context = $this->getEngine()->getConfig('contextObject'); 33 - if ($context !== null && $context instanceof PhrictionContent) { 34 - // Handle content when it's being rendered in document view. 35 - $base = $context->getSlug(); 36 - } 37 - if ($context !== null && is_array($context) && 38 - idx($context, 'phriction.isPreview')) { 39 - // Handle content when it's a preview for the Phriction editor. 40 - $base = idx($context, 'phriction.slug'); 41 - } 31 + $base = $this->getRelativeBaseURI(); 42 32 if ($base !== null) { 43 33 $base_parts = explode('/', rtrim($base, '/')); 44 34 $rel_parts = explode('/', rtrim($link, '/')); ··· 194 184 $this->getEngine()->overwriteStoredText($spec['token'], $text); 195 185 } 196 186 } 187 + 188 + private function getRelativeBaseURI() { 189 + $context = $this->getEngine()->getConfig('contextObject'); 190 + 191 + if (!$context) { 192 + return null; 193 + } 194 + 195 + // Handle content when it's a preview for the Phriction editor. 196 + if (is_array($context)) { 197 + if (idx($context, 'phriction.isPreview')) { 198 + return idx($context, 'phriction.slug'); 199 + } 200 + } 201 + 202 + if ($context instanceof PhrictionContent) { 203 + return $context->getSlug(); 204 + } 205 + 206 + if ($context instanceof PhrictionDocument) { 207 + return $context->getSlug(); 208 + } 209 + 210 + return null; 211 + } 212 + 197 213 198 214 }
+4 -2
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 2880 2880 PhabricatorLiskDAO $object, 2881 2881 array $xactions) { 2882 2882 2883 - $body = new PhabricatorMetaMTAMailBody(); 2884 - $body->setViewer($this->requireActor()); 2883 + $body = id(new PhabricatorMetaMTAMailBody()) 2884 + ->setViewer($this->requireActor()) 2885 + ->setContextObject($object); 2885 2886 2886 2887 $this->addHeadersAndCommentsToMailBody($body, $xactions); 2887 2888 $this->addCustomFieldsToMailBody($body, $object, $xactions); 2889 + 2888 2890 return $body; 2889 2891 } 2890 2892