@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.

Fix possible recursive embeds in Dashboard text panels

Summary:
We currently detect tab panels embedding themselves, but do not detect text panels embedding themselves with `{Wxx}`.

Detect these self-embedding panels.

I had to add a bit of a hack to pass the parent panel PHIDs to the rule. Generally, I got the Markup API kind of wrong and want to update it, I'll file a followup with details about how I'd like to move forward.

Test Plan:
Created a text panel embedding itself, a tab panel embedding a text panel embedding itself, a tab panel embedding a text panel embedding the tab panel, etc.

Rendered all panels standalone and as `{Wxx}` from a different context.

{F761158}

{F761159}

{F761160}

{F761161}

{F761162}

Reviewers: chad, jbeta

Reviewed By: chad, jbeta

Differential Revision: https://secure.phabricator.com/D13999

+37 -6
+18 -4
src/applications/dashboard/paneltype/PhabricatorDashboardTextPanelType.php
··· 37 37 PhabricatorDashboardPanelRenderingEngine $engine) { 38 38 39 39 $text = $panel->getProperty('text', ''); 40 + $oneoff = id(new PhabricatorMarkupOneOff())->setContent($text); 41 + $field = 'default'; 40 42 41 - $text_content = PhabricatorMarkupEngine::renderOneObject( 42 - id(new PhabricatorMarkupOneOff())->setContent($text), 43 - 'default', 44 - $viewer); 43 + // NOTE: We're taking extra steps here to prevent creation of a text panel 44 + // which embeds itself using `{Wnnn}`, recursing indefinitely. 45 + 46 + $parent_key = PhabricatorDashboardRemarkupRule::KEY_PARENT_PANEL_PHIDS; 47 + $parent_phids = $engine->getParentPanelPHIDs(); 48 + $parent_phids[] = $panel->getPHID(); 49 + 50 + $markup_engine = id(new PhabricatorMarkupEngine()) 51 + ->setViewer($viewer) 52 + ->setContextObject($panel) 53 + ->setAuxiliaryConfig($parent_key, $parent_phids); 54 + 55 + $text_content = $markup_engine 56 + ->addObject($oneoff, $field) 57 + ->process() 58 + ->getOutput($oneoff, $field); 45 59 46 60 return id(new PHUIPropertyListView()) 47 61 ->addTextContent($text_content);
+8 -2
src/applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php
··· 3 3 final class PhabricatorDashboardRemarkupRule 4 4 extends PhabricatorObjectRemarkupRule { 5 5 6 + const KEY_PARENT_PANEL_PHIDS = 'dashboard.parentPanelPHIDs'; 7 + 6 8 protected function getObjectNamePrefix() { 7 9 return 'W'; 8 10 } ··· 21 23 PhabricatorObjectHandle $handle, 22 24 $options) { 23 25 24 - $viewer = $this->getEngine()->getConfig('viewer'); 26 + $engine = $this->getEngine(); 27 + $viewer = $engine->getConfig('viewer'); 28 + 29 + $parent_key = self::KEY_PARENT_PANEL_PHIDS; 30 + $parent_phids = $engine->getConfig($parent_key, array()); 25 31 26 32 return id(new PhabricatorDashboardPanelRenderingEngine()) 27 33 ->setViewer($viewer) 28 34 ->setPanel($object) 29 - ->setParentPanelPHIDs(array()) 35 + ->setParentPanelPHIDs($parent_phids) 30 36 ->renderPanel(); 31 37 32 38 }
+11
src/infrastructure/markup/PhabricatorMarkupEngine.php
··· 44 44 private $contextObject; 45 45 private $version = 15; 46 46 private $engineCaches = array(); 47 + private $auxiliaryConfig = array(); 47 48 48 49 49 50 /* -( Markup Pipeline )---------------------------------------------------- */ ··· 122 123 $engines[$key] = $info['object']->newMarkupEngine($info['field']); 123 124 $engines[$key]->setConfig('viewer', $this->viewer); 124 125 $engines[$key]->setConfig('contextObject', $this->contextObject); 126 + 127 + foreach ($this->auxiliaryConfig as $aux_key => $aux_value) { 128 + $engines[$key]->setConfig($aux_key, $aux_value); 129 + } 125 130 } 126 131 127 132 // Load or build the preprocessor caches. ··· 307 312 */ 308 313 public function setContextObject($object) { 309 314 $this->contextObject = $object; 315 + return $this; 316 + } 317 + 318 + public function setAuxiliaryConfig($key, $value) { 319 + // TODO: This is gross and should be removed. Avoid use. 320 + $this->auxiliaryConfig[$key] = $value; 310 321 return $this; 311 322 } 312 323