Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2709945
D25083.1735325094.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
3 KB
Referenced Files
None
Subscribers
None
D25083.1735325094.diff
View Options
diff --git a/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php b/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php
--- a/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php
+++ b/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php
@@ -76,7 +76,19 @@
return $name;
}
- $same_window = $engine->getConfig('uri.same-window', false);
+ $same_window = $engine->getConfig('uri.same-window', null);
+
+ if ($same_window === null) {
+ // TODO:
+ // Instead of assuming every link as external,
+ // assume that only external links should be opened
+ // externally. This still probably creates lot of
+ // external links than needed, but less than before.
+ // https://we.phorge.it/T15161
+// $same_window = $this->isInternalGenericURI($link);
+ $same_window = false;
+ }
+
if ($same_window) {
$target = null;
} else {
diff --git a/src/infrastructure/markup/markuprule/PhutilRemarkupHyperlinkRule.php b/src/infrastructure/markup/markuprule/PhutilRemarkupHyperlinkRule.php
--- a/src/infrastructure/markup/markuprule/PhutilRemarkupHyperlinkRule.php
+++ b/src/infrastructure/markup/markuprule/PhutilRemarkupHyperlinkRule.php
@@ -116,7 +116,19 @@
$engine = $this->getEngine();
- $same_window = $engine->getConfig('uri.same-window', false);
+ $same_window = $engine->getConfig('uri.same-window', null);
+
+ if ($same_window === null) {
+ // TODO:
+ // Instead of assuming every link as external,
+ // assume that only external links should be opened
+ // externally. This still probably creates lot of
+ // external links than needed, but less than before.
+ // https://we.phorge.it/T15161
+// $same_window = $this->isInternalAbsoluteURI($link);
+ $same_window = false;
+ }
+
if ($same_window) {
$target = null;
} else {
diff --git a/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php b/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
--- a/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
+++ b/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
@@ -130,4 +130,54 @@
return strncmp($uri, '/', 1) == 0;
}
+ /**
+ * Check if a generic URI points to an internal destination
+ *
+ * The URI can be relative or absolute
+ *
+ * @param string $uri Example '/bar/' or 'http://example.com/bar/'
+ * @return bool
+ */
+ protected function isInternalGenericURI($uri) {
+ return $this->isURIAnchor($uri)
+ || $this->isURIRelativePath($uri)
+ || $this->isInternalAbsoluteURI($uri);
+ }
+
+ /**
+ * Check if an absolute URI points to Phorge/Phabricator itself
+ *
+ * @param string $uri Example 'http://example.com/bar/'
+ * @return bool
+ */
+ protected function isInternalAbsoluteURI($uri) {
+
+ // Get the Base URI - full URI with protocol and ending with '/'
+ // It's difficult to imagine a case where this config is not defined,
+ // but better to be nice here
+ $base_uri =
+ PhabricatorEnv::getEnvConfigIfExists('phabricator.base-uri', null);
+
+ // Assume a safe default
+ if (!$base_uri) {
+ return false;
+ }
+
+ return $this->isURIStartingWith($uri, $base_uri);
+ }
+
+ /**
+ * Check whenever an URI starts with a specific prefix
+ *
+ * @param $uri string Example 'http://example.com/bar/'
+ * @param $prefix string Example 'http://example.com/'
+ * @return bool True if the first is contained in the second
+ */
+ private function isURIStartingWith($uri, $prefix) {
+ // I know that PHP 8 has 'str_starts_with()'
+ // but that is not the minimum version
+ // https://stackoverflow.com/a/2790919
+ return substr($uri, 0, strlen($prefix)) === $prefix;
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 27, 18:44 (8 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1035360
Default Alt Text
D25083.1735325094.diff (3 KB)
Attached To
Mode
D25083: Remarkup: simplify the way "internal links" could be identified
Attached
Detach File
Event Timeline
Log In to Comment