From 0e40b3c5b2a7e25525d09a2e069444d051ae82ff Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 31 Aug 2011 13:42:52 -0700 Subject: [PATCH] Allow Phriction [[links]] to link to non-Phriction URIs Summary: If the link text is a URI, just treat it as a nameable (and possibly relative) URI link. See tasks. Test Plan: Copy/pasted the doc example into Phriction, links worked. Reviewers: skrul, hunterbridges, jungejason, tuomaspelkonen, aran Reviewed By: jungejason CC: aran, jungejason Differential Revision: 882 --- src/docs/userguide/remarkup.diviner | 6 ++++++ .../PhabricatorRemarkupRulePhriction.php | 20 ++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/docs/userguide/remarkup.diviner b/src/docs/userguide/remarkup.diviner index b9358a7b9a..d924a13997 100644 --- a/src/docs/userguide/remarkup.diviner +++ b/src/docs/userguide/remarkup.diviner @@ -187,3 +187,9 @@ With a pipe (##|##), you can retitle the link. Use this to mislead your opponents: Check out these [[legal/boring_documents/ | exciting legal documents]]! + +You can also use this as an explicit syntax for other web links, either within +Phabricator or on the internet at large: + + [[/herald/transcript/ | Herald Transcripts]] + [[http://www.boring-legal-documents.com/ | exciting legal documents]] \ No newline at end of file diff --git a/src/infrastructure/markup/remarkup/markuprule/phriction/PhabricatorRemarkupRulePhriction.php b/src/infrastructure/markup/remarkup/markuprule/phriction/PhabricatorRemarkupRulePhriction.php index 66259dbafa..7bcc188a8f 100644 --- a/src/infrastructure/markup/remarkup/markuprule/phriction/PhabricatorRemarkupRulePhriction.php +++ b/src/infrastructure/markup/remarkup/markuprule/phriction/PhabricatorRemarkupRulePhriction.php @@ -33,18 +33,28 @@ class PhabricatorRemarkupRulePhriction $slug = trim($matches[1]); $name = trim(idx($matches, 2, $slug)); - $name = explode('/', $name); - $name = end($name); - $slug = PhrictionDocument::normalizeSlug($slug); - $uri = PhrictionDocument::getSlugURI($slug); + // If whatever is being linked to begins with "/" or has "://", treat it + // as a URI instead of a wiki page. + $is_uri = preg_match('@(^/)|(://)@', $slug); + if ($is_uri) { + $uri = $slug; + // Leave the name unchanged, i.e. link the whole URI if there's no + // explicit name. + } else { + $name = explode('/', trim($name, '/')); + $name = end($name); + + $slug = PhrictionDocument::normalizeSlug($slug); + $uri = PhrictionDocument::getSlugURI($slug); + } return $this->getEngine()->storeText( phutil_render_tag( 'a', array( 'href' => $uri, - 'class' => 'phriction-link', + 'class' => $is_uri ? null : 'phriction-link', ), phutil_escape_html($name))); }