diff options
author | Andreas Gohr <andi@splitbrain.org> | 2015-07-24 08:27:55 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2015-07-24 08:27:55 +0200 |
commit | dfbeea0341741e80e32e29f4ca832f79ac21b1d8 (patch) | |
tree | 54ae6d32d32d5c2b1c25d5b6b1853e8880542d40 /inc/parser/renderer.php | |
parent | e9c4b8e690fdbc3d252801d772ce2d45309663b5 (diff) | |
parent | ac1654273a44452a833628e254ee3e172386a55e (diff) | |
download | rpg-dfbeea0341741e80e32e29f4ca832f79ac21b1d8.tar.gz rpg-dfbeea0341741e80e32e29f4ca832f79ac21b1d8.tar.bz2 |
Merge pull request #1247 from splitbrain/interwiki-fixes
Interwiki fixes
Diffstat (limited to 'inc/parser/renderer.php')
-rw-r--r-- | inc/parser/renderer.php | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 35bdd0e3f..d7a3faef8 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -806,18 +806,26 @@ class Doku_Renderer extends DokuWiki_Plugin { $url = $this->interwiki[$shortcut]; } else { // Default to Google I'm feeling lucky - $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; + $url = 'https://www.google.com/search?q={URL}&btnI=lucky'; $shortcut = 'go'; } //split into hash and url part - @list($reference, $hash) = explode('#', $reference, 2); + $hash = strrchr($reference, '#'); + if($hash) { + $reference = substr($reference, 0, -strlen($hash)); + $hash = substr($hash, 1); + } //replace placeholder if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#', $url)) { //use placeholders $url = str_replace('{URL}', rawurlencode($reference), $url); - $url = str_replace('{NAME}', $reference, $url); + //wiki names will be cleaned next, otherwise urlencode unsafe chars + $url = str_replace('{NAME}', ($url{0} === ':') ? $reference : + preg_replace_callback('/[[\\\\\]^`{|}#%]/', function($match) { + return rawurlencode($match[0]); + }, $reference), $url); $parsed = parse_url($reference); if(!$parsed['port']) $parsed['port'] = 80; $url = str_replace('{SCHEME}', $parsed['scheme'], $url); |