From 99e35495224110225e33ee3192f77ba9498ab52b Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 15 Jun 2014 12:56:11 -0700 Subject: [PATCH] Support `M123/456` mock references in Remarkup Summary: Fixes T4729. This form is a little fluff, but we show it in the URI when you click an anchor on the page, and doing so seems desirable. I think it's reasonable to support this form, given that it appears in the URI. Test Plan: Wrote some stuff like `M60`, `M60/71`, `M60/72/`, `M60/73/#13` and saw it all get picked up and rendered/linked properly. Reviewers: chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T4729 Differential Revision: https://secure.phabricator.com/D9555 --- .../pholio/remarkup/PholioRemarkupRule.php | 41 ++++++++++++++++--- .../rule/PhabricatorRemarkupRuleObject.php | 6 ++- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/applications/pholio/remarkup/PholioRemarkupRule.php b/src/applications/pholio/remarkup/PholioRemarkupRule.php index 4545a23a87..998c47a55a 100644 --- a/src/applications/pholio/remarkup/PholioRemarkupRule.php +++ b/src/applications/pholio/remarkup/PholioRemarkupRule.php @@ -1,8 +1,5 @@ getURI(); + + // If the ID has a `M123/456` component, link to that specific image. + $id = explode('/', $id); + if (isset($id[1])) { + $href = $href.'/'.$id[1].'/'; + } + + return $href; + } + protected function loadObjects(array $ids) { + // Strip off any image ID components of the URI. + $map = array(); + foreach ($ids as $id) { + $map[head(explode('/', $id))][] = $id; + } + $viewer = $this->getEngine()->getConfig('viewer'); - return id(new PholioMockQuery()) + $mocks = id(new PholioMockQuery()) ->setViewer($viewer) ->needCoverFiles(true) ->needImages(true) ->needTokenCounts(true) - ->withIDs($ids) + ->withIDs(array_keys($map)) ->execute(); + + $results = array(); + foreach ($mocks as $mock) { + $ids = idx($map, $mock->getID(), array()); + foreach ($ids as $id) { + $results[$id] = $mock; + } + } + + return $results; } protected function renderObjectEmbed($object, $handle, $options) { diff --git a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleObject.php b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleObject.php index 55fd35935c..f49a1d583d 100644 --- a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleObject.php +++ b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleObject.php @@ -40,8 +40,12 @@ abstract class PhabricatorRemarkupRuleObject return $result; } + protected function getObjectHref($object, $handle, $id) { + return $handle->getURI(); + } + protected function renderObjectRef($object, $handle, $anchor, $id) { - $href = $handle->getURI(); + $href = $this->getObjectHref($object, $handle, $id); $text = $this->getObjectNamePrefix().$id; if ($anchor) {