mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
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
This commit is contained in:
parent
d96b6506d7
commit
dd1023e5a8
6 changed files with 67 additions and 3 deletions
|
@ -3905,6 +3905,7 @@ phutil_register_library_map(array(
|
|||
'PhrictionHistoryController' => 'applications/phriction/controller/PhrictionHistoryController.php',
|
||||
'PhrictionInfoConduitAPIMethod' => 'applications/phriction/conduit/PhrictionInfoConduitAPIMethod.php',
|
||||
'PhrictionListController' => 'applications/phriction/controller/PhrictionListController.php',
|
||||
'PhrictionMarkupPreviewController' => 'applications/phriction/controller/PhrictionMarkupPreviewController.php',
|
||||
'PhrictionMoveController' => 'applications/phriction/controller/PhrictionMoveController.php',
|
||||
'PhrictionNewController' => 'applications/phriction/controller/PhrictionNewController.php',
|
||||
'PhrictionRemarkupRule' => 'applications/phriction/markup/PhrictionRemarkupRule.php',
|
||||
|
@ -8702,6 +8703,7 @@ phutil_register_library_map(array(
|
|||
'PhrictionHistoryController' => 'PhrictionController',
|
||||
'PhrictionInfoConduitAPIMethod' => 'PhrictionConduitAPIMethod',
|
||||
'PhrictionListController' => 'PhrictionController',
|
||||
'PhrictionMarkupPreviewController' => 'PhabricatorController',
|
||||
'PhrictionMoveController' => 'PhrictionController',
|
||||
'PhrictionNewController' => 'PhrictionController',
|
||||
'PhrictionRemarkupRule' => 'PhutilRemarkupRule',
|
||||
|
|
|
@ -59,7 +59,7 @@ final class PhabricatorPhrictionApplication extends PhabricatorApplication {
|
|||
'new/' => 'PhrictionNewController',
|
||||
'move/(?P<id>[1-9]\d*)/' => 'PhrictionMoveController',
|
||||
|
||||
'preview/' => 'PhabricatorMarkupPreviewController',
|
||||
'preview/(?P<slug>.+/)' => 'PhrictionMarkupPreviewController',
|
||||
'diff/(?P<id>[1-9]\d*)/' => 'PhrictionDiffController',
|
||||
),
|
||||
);
|
||||
|
|
|
@ -272,7 +272,7 @@ final class PhrictionEditController
|
|||
|
||||
$preview = id(new PHUIRemarkupPreviewPanel())
|
||||
->setHeader($content->getTitle())
|
||||
->setPreviewURI('/phriction/preview/')
|
||||
->setPreviewURI('/phriction/preview/'.$document->getSlug())
|
||||
->setControlID('document-textarea')
|
||||
->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT);
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
final class PhrictionMarkupPreviewController
|
||||
extends PhabricatorController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$text = $request->getStr('text');
|
||||
$slug = $request->getURIData('slug');
|
||||
|
||||
$output = PhabricatorMarkupEngine::renderOneObject(
|
||||
id(new PhabricatorMarkupOneOff())
|
||||
->setPreserveLinebreaks(true)
|
||||
->setDisableCache(true)
|
||||
->setContent($text),
|
||||
'default',
|
||||
$viewer,
|
||||
array(
|
||||
'phriction.isPreview' => true,
|
||||
'phriction.slug' => $slug,
|
||||
));
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($output);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,39 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule {
|
|||
|
||||
public function markupDocumentLink(array $matches) {
|
||||
$link = trim($matches[1]);
|
||||
|
||||
// Handle relative links.
|
||||
if (substr($link, 0, 2) === './') {
|
||||
$base = null;
|
||||
$context = $this->getEngine()->getConfig('contextObject');
|
||||
if ($context !== null && $context instanceof PhrictionContent) {
|
||||
// Handle content when it's being rendered in document view.
|
||||
$base = $context->getSlug();
|
||||
}
|
||||
if ($context !== null && is_array($context) &&
|
||||
idx($context, 'phriction.isPreview')) {
|
||||
// Handle content when it's a preview for the Phriction editor.
|
||||
$base = idx($context, 'phriction.slug');
|
||||
}
|
||||
if ($base !== null) {
|
||||
$base_parts = explode('/', rtrim($base, '/'));
|
||||
$rel_parts = explode('/', substr(rtrim($link, '/'), 2));
|
||||
foreach ($rel_parts as $part) {
|
||||
if ($part === '.') {
|
||||
// Consume standalone dots in a relative path, and do
|
||||
// nothing with them.
|
||||
} else if ($part === '..') {
|
||||
if (count($base_parts) > 0) {
|
||||
array_pop($base_parts);
|
||||
}
|
||||
} else {
|
||||
array_push($base_parts, $part);
|
||||
}
|
||||
}
|
||||
$link = implode('/', $base_parts).'/';
|
||||
}
|
||||
}
|
||||
|
||||
$name = trim(idx($matches, 2, $link));
|
||||
if (empty($matches[2])) {
|
||||
$name = explode('/', trim($name, '/'));
|
||||
|
|
|
@ -27,7 +27,8 @@ final class PhrictionContent extends PhrictionDAO
|
|||
return PhabricatorMarkupEngine::renderOneObject(
|
||||
$this,
|
||||
self::MARKUP_FIELD_BODY,
|
||||
$viewer);
|
||||
$viewer,
|
||||
$this);
|
||||
}
|
||||
|
||||
protected function getConfiguration() {
|
||||
|
|
Loading…
Reference in a new issue