From 6496c33fc8e98f6e3acaaa5db0234d9c07bec4fe Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 15 Feb 2014 14:34:26 +0100 Subject: interwiki : prefixed configurls handled as wikilinks --- _test/tests/inc/parser/renderer_resolveinterwiki.test.php | 11 ++++++----- conf/interwiki.conf | 2 +- inc/common.php | 10 +++++++++- inc/parser/renderer.php | 9 +++++---- inc/parser/xhtml.php | 11 ++++++++++- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php index a71895b34..e78930934 100644 --- a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php +++ b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php @@ -12,8 +12,8 @@ class Test_resolveInterwiki extends PHPUnit_Framework_TestCase { $Renderer->interwiki = getInterwiki(); $Renderer->interwiki['scheme'] = '{SCHEME}://example.com'; $Renderer->interwiki['withslash'] = '/test'; - $Renderer->interwiki['onlytext'] = 'onlytext{NAME}'; //with {URL} double urlencoded - $Renderer->interwiki['withquery'] = 'anyns:{NAME}?do=edit'; + $Renderer->interwiki['onlytext'] = ':onlytext{NAME}'; //with {URL} double urlencoded + $Renderer->interwiki['withquery'] = ':anyns:{NAME}?do=edit'; $tests = array( // shortcut, reference and expected @@ -24,10 +24,11 @@ class Test_resolveInterwiki extends PHPUnit_Framework_TestCase { array('scheme', 'ftp://foo @+%/#txt', 'ftp://example.com#txt'), //relative url array('withslash', 'foo @+%/#txt', '/testfoo%20%40%2B%25%2F#txt'), + array('skype', 'foo @+%/#txt', 'skype:foo @+%/#txt'), //dokuwiki id's - array('onlytext', 'foo @+%#txt', DOKU_BASE.'doku.php?id=onlytextfoo%20%40%2B%25#txt'), - array('user', 'foo @+%#txt', DOKU_BASE.'doku.php?id=wiki:users:foo%20%40%2B%25#txt'), - array('withquery', 'foo @+%#txt', DOKU_BASE.'doku.php?id=anyns:foo%20%40%2B%25&do=edit#txt') + array('onlytext', 'foo @+%#txt', DOKU_BASE.'doku.php?id=onlytextfoo#txt'), + array('user', 'foo @+%#txt', DOKU_BASE.'doku.php?id=wiki:users:foo#txt'), + array('withquery', 'foo @+%#txt', DOKU_BASE.'doku.php?id=anyns:foo&do=edit#txt') ); foreach($tests as $test) { diff --git a/conf/interwiki.conf b/conf/interwiki.conf index 999462170..0643f764b 100644 --- a/conf/interwiki.conf +++ b/conf/interwiki.conf @@ -30,7 +30,7 @@ sb http://www.splitbrain.org/go/ skype skype:{NAME} google.de http://www.google.de/search?q= go http://www.google.com/search?q={URL}&btnI=lucky -user wiki:users:{NAME} +user :wiki:users:{NAME} # To support VoIP/SIP links callto callto://{NAME} diff --git a/inc/common.php b/inc/common.php index cd3c053a3..aa59a8c11 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1497,7 +1497,15 @@ function userinfo($username = null) { $xhtml_renderer->interwiki = getInterwiki(); } $shortcut = 'user'; - $data['link']['url'] = $xhtml_renderer->_resolveInterWiki($shortcut, $username); + $data['link']['url'] = $xhtml_renderer->_resolveInterWiki($shortcut, $username, $exists); + if($exists !== null) { + if($exists) { + $data['link']['class'] .= ' wikilink1'; + } else { + $data['link']['class'] .= ' wikilink2'; + $data['link']['rel'] = 'nofollow'; + } + } } } else { $data['link'] = false; diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index d01fc3899..fa70c299e 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -292,7 +292,7 @@ class Doku_Renderer extends DokuWiki_Plugin { /** * Resolve an interwikilink */ - function _resolveInterWiki(&$shortcut, $reference) { + function _resolveInterWiki(&$shortcut, $reference, &$exists=null) { //get interwiki URL if(isset($this->interwiki[$shortcut])) { $url = $this->interwiki[$shortcut]; @@ -322,9 +322,10 @@ class Doku_Renderer extends DokuWiki_Plugin { $url = $url . rawurlencode($reference); } //url without slashes is handled as a pageid - if(strpos($url, '/') === false) { - list($url, $urlparam) = explode('?', $url, 2); - $url = wl($url, $urlparam); + if($url{0} === ':') { + list($id, $urlparam) = explode('?', $url, 2); + $url = wl(cleanID($id), $urlparam); + $exists = page_exists($id); } if($hash) $url .= '#' . rawurlencode($hash); diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 20cd8e9d6..53a4dbcad 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -697,7 +697,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); //get interwiki URL - $url = $this->_resolveInterWiki($wikiName, $wikiUri); + $exists = null; + $url = $this->_resolveInterWiki($wikiName, $wikiUri, $exists); if(!$isImage) { $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName); @@ -710,6 +711,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(strpos($url, DOKU_URL) === 0 OR strpos($url, DOKU_BASE) === 0) { $link['target'] = $conf['target']['wiki']; } + if($exists !== null && !$isImage) { + if($exists) { + $link['class'] .= ' wikilink1'; + } else { + $link['class'] .= ' wikilink2'; + $link['rel'] = 'nofollow'; + } + } $link['url'] = $url; $link['title'] = htmlspecialchars($link['url']); -- cgit v1.2.3