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

Support relative links in Phriction

Summary:
Resolves T7691. This turned out more complex than I really wanted, mainly because I needed to feed the slug information through to both the document renderer and the preview window that appears in the edit controller.

After this change, you can now create relative links in Phriction by doing `[[ ./../some/relative/path ]]`. Relative paths aren't handled anywhere else (they'll still render, but the dots are turned into a literal 'dot' as per existing behaviour).

Test Plan: Created some Phriction documents with relative links, saw them all link correctly.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

Maniphest Tasks: T7691

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

+67 -3
+2
src/__phutil_library_map__.php
··· 3905 3905 'PhrictionHistoryController' => 'applications/phriction/controller/PhrictionHistoryController.php', 3906 3906 'PhrictionInfoConduitAPIMethod' => 'applications/phriction/conduit/PhrictionInfoConduitAPIMethod.php', 3907 3907 'PhrictionListController' => 'applications/phriction/controller/PhrictionListController.php', 3908 + 'PhrictionMarkupPreviewController' => 'applications/phriction/controller/PhrictionMarkupPreviewController.php', 3908 3909 'PhrictionMoveController' => 'applications/phriction/controller/PhrictionMoveController.php', 3909 3910 'PhrictionNewController' => 'applications/phriction/controller/PhrictionNewController.php', 3910 3911 'PhrictionRemarkupRule' => 'applications/phriction/markup/PhrictionRemarkupRule.php', ··· 8702 8703 'PhrictionHistoryController' => 'PhrictionController', 8703 8704 'PhrictionInfoConduitAPIMethod' => 'PhrictionConduitAPIMethod', 8704 8705 'PhrictionListController' => 'PhrictionController', 8706 + 'PhrictionMarkupPreviewController' => 'PhabricatorController', 8705 8707 'PhrictionMoveController' => 'PhrictionController', 8706 8708 'PhrictionNewController' => 'PhrictionController', 8707 8709 'PhrictionRemarkupRule' => 'PhutilRemarkupRule',
+1 -1
src/applications/phriction/application/PhabricatorPhrictionApplication.php
··· 59 59 'new/' => 'PhrictionNewController', 60 60 'move/(?P<id>[1-9]\d*)/' => 'PhrictionMoveController', 61 61 62 - 'preview/' => 'PhabricatorMarkupPreviewController', 62 + 'preview/(?P<slug>.+/)' => 'PhrictionMarkupPreviewController', 63 63 'diff/(?P<id>[1-9]\d*)/' => 'PhrictionDiffController', 64 64 ), 65 65 );
+1 -1
src/applications/phriction/controller/PhrictionEditController.php
··· 272 272 273 273 $preview = id(new PHUIRemarkupPreviewPanel()) 274 274 ->setHeader($content->getTitle()) 275 - ->setPreviewURI('/phriction/preview/') 275 + ->setPreviewURI('/phriction/preview/'.$document->getSlug()) 276 276 ->setControlID('document-textarea') 277 277 ->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT); 278 278
+28
src/applications/phriction/controller/PhrictionMarkupPreviewController.php
··· 1 + <?php 2 + 3 + final class PhrictionMarkupPreviewController 4 + extends PhabricatorController { 5 + 6 + public function processRequest() { 7 + $request = $this->getRequest(); 8 + $viewer = $request->getUser(); 9 + 10 + $text = $request->getStr('text'); 11 + $slug = $request->getURIData('slug'); 12 + 13 + $output = PhabricatorMarkupEngine::renderOneObject( 14 + id(new PhabricatorMarkupOneOff()) 15 + ->setPreserveLinebreaks(true) 16 + ->setDisableCache(true) 17 + ->setContent($text), 18 + 'default', 19 + $viewer, 20 + array( 21 + 'phriction.isPreview' => true, 22 + 'phriction.slug' => $slug, 23 + )); 24 + 25 + return id(new AphrontAjaxResponse()) 26 + ->setContent($output); 27 + } 28 + }
+33
src/applications/phriction/markup/PhrictionRemarkupRule.php
··· 15 15 16 16 public function markupDocumentLink(array $matches) { 17 17 $link = trim($matches[1]); 18 + 19 + // Handle relative links. 20 + if (substr($link, 0, 2) === './') { 21 + $base = null; 22 + $context = $this->getEngine()->getConfig('contextObject'); 23 + if ($context !== null && $context instanceof PhrictionContent) { 24 + // Handle content when it's being rendered in document view. 25 + $base = $context->getSlug(); 26 + } 27 + if ($context !== null && is_array($context) && 28 + idx($context, 'phriction.isPreview')) { 29 + // Handle content when it's a preview for the Phriction editor. 30 + $base = idx($context, 'phriction.slug'); 31 + } 32 + if ($base !== null) { 33 + $base_parts = explode('/', rtrim($base, '/')); 34 + $rel_parts = explode('/', substr(rtrim($link, '/'), 2)); 35 + foreach ($rel_parts as $part) { 36 + if ($part === '.') { 37 + // Consume standalone dots in a relative path, and do 38 + // nothing with them. 39 + } else if ($part === '..') { 40 + if (count($base_parts) > 0) { 41 + array_pop($base_parts); 42 + } 43 + } else { 44 + array_push($base_parts, $part); 45 + } 46 + } 47 + $link = implode('/', $base_parts).'/'; 48 + } 49 + } 50 + 18 51 $name = trim(idx($matches, 2, $link)); 19 52 if (empty($matches[2])) { 20 53 $name = explode('/', trim($name, '/'));
+2 -1
src/applications/phriction/storage/PhrictionContent.php
··· 27 27 return PhabricatorMarkupEngine::renderOneObject( 28 28 $this, 29 29 self::MARKUP_FIELD_BODY, 30 - $viewer); 30 + $viewer, 31 + $this); 31 32 } 32 33 33 34 protected function getConfiguration() {