aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPhy <git@phy25.com>2019-06-17 20:23:24 -0400
committerPhy <git@phy25.com>2019-10-20 15:49:21 -0400
commitabde598049eec6f3cef64248e410e3f96bf797eb (patch)
tree4d0246ed8c6d4ca6c5c7407cb0619caedaa8b1b8
parent2b5dd8f4d74e2c8c88f8fd64695d9bc21367e6fa (diff)
downloaddokuwiki-abde598049eec6f3cef64248e410e3f96bf797eb.tar.gz
dokuwiki-abde598049eec6f3cef64248e410e3f96bf797eb.zip
Remove Google Lucky for non-existing interwiki links
For compatibility renderer will return string '' of $shortcut and $url instead of NULL when seeing a non-existing interwiki link. In the meantime, media and link output in xhtml renderer is adjusted, to show title text instead when src/href is null. In interwiki case, the title will be the "reference" part of the interwiki link. This makes it possible to also support no URL cases in `interwiki.conf`. Before it will output a URL as `rawurlencode($reference)`, which doesn't make too much sense since it's encoded. However, I am not sure the use case under the current behavior (no URL, but text as `$reference`). Docs needs to be added to warn renderer plugin developers of this situation. This fixes #2588.
-rw-r--r--_test/tests/inc/parser/renderer_resolveinterwiki.test.php4
-rw-r--r--inc/parser/renderer.php11
-rw-r--r--inc/parser/xhtml.php14
3 files changed, 20 insertions, 9 deletions
diff --git a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php
index 2cd23dfaa..8ace02fab 100644
--- a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php
+++ b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php
@@ -47,9 +47,9 @@ class Test_resolveInterwiki extends DokuWikiTest {
$shortcut = 'nonexisting';
$reference = 'foo @+%/';
$url = $Renderer->_resolveInterWiki($shortcut, $reference);
- $expected = 'https://www.google.com/search?q=foo%20%40%2B%25%2F&amp;btnI=lucky';
- $this->assertEquals($expected, $url);
+ $this->assertEquals('', $url);
+ $this->assertEquals('', $shortcut);
}
}
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index 6a76d4861..fe4eb7908 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -846,9 +846,9 @@ abstract class Doku_Renderer extends Plugin {
if(isset($this->interwiki[$shortcut])) {
$url = $this->interwiki[$shortcut];
} else {
- // Default to Google I'm feeling lucky
- $url = 'https://www.google.com/search?q={URL}&amp;btnI=lucky';
- $shortcut = 'go';
+ // not parsable interwiki outputs '' to make sure string manipluation works
+ $shortcut = '';
+ $url = '';
}
//split into hash and url part
@@ -880,8 +880,9 @@ abstract class Doku_Renderer extends Plugin {
'{PATH}' => $parsed['path'],
'{QUERY}' => $parsed['query'] ,
]);
- } else {
- //default
+ } else if($url != '') {
+ // make sure when no url is defined, we keep it null
+ // default
$url = $url.rawurlencode($reference);
}
//handle as wiki links
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 388e1b7ad..f448d8a25 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -1062,11 +1062,13 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['url'] = $url;
$link['title'] = htmlspecialchars($link['url']);
- //output formatted
+ // output formatted
if($returnonly) {
+ if($url == '') return $link['name'];
return $this->_formatLink($link);
} else {
- $this->doc .= $this->_formatLink($link);
+ if($url == '') $this->doc .= $link['name'];
+ else $this->doc .= $this->_formatLink($link);
}
}
@@ -1248,9 +1250,17 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
list($shortcut, $reference) = explode('>', $src, 2);
$exists = null;
$src = $this->_resolveInterWiki($shortcut, $reference, $exists);
+ if($src == '' && empty($title)){
+ // make sure at least something will be shown in this case
+ $title = $reference;
+ }
}
list($src, $hash) = explode('#', $src, 2);
$noLink = false;
+ if($src == '') {
+ // only output plaintext without link if there is no src
+ $noLink = true;
+ }
$render = ($linking == 'linkonly') ? false : true;
$link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);