1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

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
This commit is contained in:
epriestley 2021-07-26 11:28:56 -07:00
parent c7550dbee9
commit 8daaf5ef21
2 changed files with 21 additions and 14 deletions

View file

@ -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);

View file

@ -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();
}