diff options
author | Andreas Gohr <andi@splitbrain.org> | 2020-03-04 15:52:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-04 15:52:14 +0100 |
commit | 728db97892a8bea808bd1c8179e4a1c932be3497 (patch) | |
tree | d00616a4aa9536777b62d103fd8afa8c45bd4b29 | |
parent | bcb9e6dfd943e82f5d13f08551c0364d59243342 (diff) | |
parent | 768be5a379b67ee2adf4b56b980421f77ad7447c (diff) | |
download | dokuwiki-728db97892a8bea808bd1c8179e4a1c932be3497.tar.gz dokuwiki-728db97892a8bea808bd1c8179e4a1c932be3497.zip |
Merge pull request #2802 from splitbrain/interwiki-remove-golucky
Remove Google Lucky for non-existing interwiki links
-rw-r--r-- | _test/tests/inc/parser/renderer_resolveinterwiki.test.php | 18 | ||||
-rw-r--r-- | inc/parser/renderer.php | 16 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 16 |
3 files changed, 39 insertions, 11 deletions
diff --git a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php index 2cd23dfaa..ae23280cf 100644 --- a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php +++ b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php @@ -43,13 +43,27 @@ class Test_resolveInterwiki extends DokuWikiTest { function testNonexisting() { $Renderer = new Doku_Renderer(); $Renderer->interwiki = getInterwiki(); + unset($Renderer->interwiki['default']); $shortcut = 'nonexisting'; $reference = 'foo @+%/'; $url = $Renderer->_resolveInterWiki($shortcut, $reference); - $expected = 'https://www.google.com/search?q=foo%20%40%2B%25%2F&btnI=lucky'; - $this->assertEquals($expected, $url); + $this->assertEquals('', $url); + $this->assertEquals('', $shortcut); + } + + function testNonexistingWithDefault() { + $Renderer = new Doku_Renderer(); + $Renderer->interwiki = getInterwiki(); + $Renderer->interwiki['default'] = 'https://en.wikipedia.org/wiki/{NAME}'; + + $shortcut = 'nonexisting'; + $reference = 'foo'; + $url = $Renderer->_resolveInterWiki($shortcut, $reference); + + $this->assertEquals('https://en.wikipedia.org/wiki/foo', $url); + $this->assertEquals('default', $shortcut); } } diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 6aba6506c..a03b84c8e 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -845,10 +845,13 @@ abstract class Doku_Renderer extends Plugin { //get interwiki URL 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}&btnI=lucky'; - $shortcut = 'go'; + }elseif(isset($this->interwiki['default'])) { + $shortcut = 'default'; + $url = $this->interwiki[$shortcut]; + }else{ + // not parsable interwiki outputs '' to make sure string manipluation works + $shortcut = ''; + $url = ''; } //split into hash and url part @@ -880,8 +883,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 662883416..169f4f9f4 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); @@ -1637,7 +1647,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(!$render) { // if the picture is not supposed to be rendered // return the title of the picture - if(!$title) { + if($title === null || $title === "") { // just show the sourcename $title = $this->_xmlEntities(\dokuwiki\Utf8\PhpString::basename(noNS($src))); } |