From 8daaf5ef214597ca1a87268510743be283cca1bf Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 26 Jul 2021 11:28:56 -0700 Subject: [PATCH] Pass a real context object to Phriction previews, fixing mentions Summary: Fixes T13662. Phriction currently passes a map as a "context object", but this code is ancient and predates the modern meaning of a "context object". In modern code, context objects should be real objects. Provide a real object as a context object. We do this by either loading the actual document or constructing a synthetic version of it. Test Plan: - Edited an existing document, observing the preview: - Used a mention rule, saw a preview. - Used `[[ a ]]` and `[[ ./a ]]` absolute and relative reference rules, saw accurate previews. - Edited a new document, observing the preview: - Used a mention rule, saw a preview. - Used absolute/relative references, saw accurate previews. - Grepped for other references to the removed properties (`phriction.isPreview` and `phriction.slug`), found none remaining. Reviewers: 0 Reviewed By: 0 Maniphest Tasks: T13662 Differential Revision: https://secure.phabricator.com/D21709 --- .../PhrictionMarkupPreviewController.php | 28 ++++++++++++++----- .../markup/PhrictionRemarkupRule.php | 7 ----- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/applications/phriction/controller/PhrictionMarkupPreviewController.php b/src/applications/phriction/controller/PhrictionMarkupPreviewController.php index 7e56436dbb..a0964c53c4 100644 --- a/src/applications/phriction/controller/PhrictionMarkupPreviewController.php +++ b/src/applications/phriction/controller/PhrictionMarkupPreviewController.php @@ -3,13 +3,30 @@ final class PhrictionMarkupPreviewController extends PhabricatorController { - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); $text = $request->getStr('text'); $slug = $request->getStr('slug'); + $document = id(new PhrictionDocumentQuery()) + ->setViewer($viewer) + ->withSlugs(array($slug)) + ->needContent(true) + ->executeOne(); + if (!$document) { + $document = PhrictionDocument::initializeNewDocument( + $viewer, + $slug); + + $content = id(new PhrictionContent()) + ->setSlug($slug); + + $document + ->setPHID($document->generatePHID()) + ->attachContent($content); + } + $output = PhabricatorMarkupEngine::renderOneObject( id(new PhabricatorMarkupOneOff()) ->setPreserveLinebreaks(true) @@ -17,10 +34,7 @@ final class PhrictionMarkupPreviewController ->setContent($text), 'default', $viewer, - array( - 'phriction.isPreview' => true, - 'phriction.slug' => $slug, - )); + $document); return id(new AphrontAjaxResponse()) ->setContent($output); diff --git a/src/applications/phriction/markup/PhrictionRemarkupRule.php b/src/applications/phriction/markup/PhrictionRemarkupRule.php index 11994e0aa5..8394b23218 100644 --- a/src/applications/phriction/markup/PhrictionRemarkupRule.php +++ b/src/applications/phriction/markup/PhrictionRemarkupRule.php @@ -273,13 +273,6 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule { 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(); }