From 7c2f8eec8f8dbd26e20f8afc516e38d5c6f1cc02 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Fri, 14 Feb 2014 23:54:54 +0100 Subject: handle interwiki without slashes as pageids. Added user interwiki * allowed urlparams * added `wiki:users:` as default user profile link --- inc/parser/xhtml.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 80701cd2e..fbdd8ada6 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -699,6 +699,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { //get interwiki URL $url = $this->_resolveInterWiki($wikiName,$wikiUri); + if(strpos($url,'/') === false) { + list($url, $urlparam) = explode('?', $url, 2); + $url = wl($url, $urlparam); + } + if ( !$isImage ) { $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); $link['class'] = "interwiki iw_$class"; -- cgit v1.2.3 From b3d353e634614780173506006921f7545ca81305 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 15 Feb 2014 00:00:24 +0100 Subject: wikilink needs wiki target as well --- inc/parser/xhtml.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index fbdd8ada6..957dd992b 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -702,6 +702,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(strpos($url,'/') === false) { list($url, $urlparam) = explode('?', $url, 2); $url = wl($url, $urlparam); + $link['target'] = $conf['target']['wiki']; } if ( !$isImage ) { -- cgit v1.2.3 From 2345e871e407dbece52f3181cd8b077f07cbb0c1 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 15 Feb 2014 11:11:15 +0100 Subject: wikilink creating refactored to _resolveinterwiki(). Added DOKU_BASE for local target --- inc/parser/renderer.php | 5 +++++ inc/parser/xhtml.php | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index e3401fd48..66a106b11 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -321,6 +321,11 @@ class Doku_Renderer extends DokuWiki_Plugin { //default $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($hash) $url .= '#'.rawurlencode($hash); return $url; diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 957dd992b..f0a507721 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -699,12 +699,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer { //get interwiki URL $url = $this->_resolveInterWiki($wikiName,$wikiUri); - if(strpos($url,'/') === false) { - list($url, $urlparam) = explode('?', $url, 2); - $url = wl($url, $urlparam); - $link['target'] = $conf['target']['wiki']; - } - if ( !$isImage ) { $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); $link['class'] = "interwiki iw_$class"; @@ -713,7 +707,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } //do we stay at the same server? Use local target - if( strpos($url,DOKU_URL) === 0 ){ + if( strpos($url,DOKU_URL) === 0 OR strpos($url,DOKU_BASE) === 0){ $link['target'] = $conf['target']['wiki']; } -- cgit v1.2.3 From 5a9ce44695f44ecc76f356c1fc26f0a1846231b7 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 15 Feb 2014 11:17:09 +0100 Subject: code reformatting --- inc/parser/renderer.php | 42 +++++++++++++++++++++--------------------- inc/parser/xhtml.php | 10 +++++----- 2 files changed, 26 insertions(+), 26 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 66a106b11..d01fc3899 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -273,17 +273,17 @@ class Doku_Renderer extends DokuWiki_Plugin { * * @author Andreas Gohr */ - function _simpleTitle($name){ + function _simpleTitle($name) { global $conf; //if there is a hash we use the ancor name only - list($name,$hash) = explode('#',$name,2); + list($name, $hash) = explode('#', $name, 2); if($hash) return $hash; - if($conf['useslash']){ - $name = strtr($name,';/',';:'); - }else{ - $name = strtr($name,';',':'); + if($conf['useslash']) { + $name = strtr($name, ';/', ';:'); + } else { + $name = strtr($name, ';', ':'); } return noNSorNS($name); @@ -292,9 +292,9 @@ class Doku_Renderer extends DokuWiki_Plugin { /** * Resolve an interwikilink */ - function _resolveInterWiki(&$shortcut,$reference){ + function _resolveInterWiki(&$shortcut, $reference) { //get interwiki URL - if ( isset($this->interwiki[$shortcut]) ) { + if(isset($this->interwiki[$shortcut])) { $url = $this->interwiki[$shortcut]; } else { // Default to Google I'm feeling lucky @@ -303,30 +303,30 @@ class Doku_Renderer extends DokuWiki_Plugin { } //split into hash and url part - list($reference,$hash) = explode('#',$reference,2); + list($reference, $hash) = explode('#', $reference, 2); //replace placeholder - if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ + 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); + $url = str_replace('{URL}', rawurlencode($reference), $url); + $url = str_replace('{NAME}', $reference, $url); $parsed = parse_url($reference); if(!$parsed['port']) $parsed['port'] = 80; - $url = str_replace('{SCHEME}',$parsed['scheme'],$url); - $url = str_replace('{HOST}',$parsed['host'],$url); - $url = str_replace('{PORT}',$parsed['port'],$url); - $url = str_replace('{PATH}',$parsed['path'],$url); - $url = str_replace('{QUERY}',$parsed['query'],$url); - }else{ + $url = str_replace('{SCHEME}', $parsed['scheme'], $url); + $url = str_replace('{HOST}', $parsed['host'], $url); + $url = str_replace('{PORT}', $parsed['port'], $url); + $url = str_replace('{PATH}', $parsed['path'], $url); + $url = str_replace('{QUERY}', $parsed['query'], $url); + } else { //default - $url = $url.rawurlencode($reference); + $url = $url . rawurlencode($reference); } //url without slashes is handled as a pageid - if(strpos($url,'/') === false) { + if(strpos($url, '/') === false) { list($url, $urlparam) = explode('?', $url, 2); $url = wl($url, $urlparam); } - if($hash) $url .= '#'.rawurlencode($hash); + if($hash) $url .= '#' . rawurlencode($hash); return $url; } diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index f0a507721..20cd8e9d6 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -685,7 +685,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } /** - */ + */ function interwikilink($match, $name = null, $wikiName, $wikiUri) { global $conf; @@ -697,17 +697,17 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); //get interwiki URL - $url = $this->_resolveInterWiki($wikiName,$wikiUri); + $url = $this->_resolveInterWiki($wikiName, $wikiUri); - if ( !$isImage ) { - $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); + if(!$isImage) { + $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName); $link['class'] = "interwiki iw_$class"; } else { $link['class'] = 'media'; } //do we stay at the same server? Use local target - if( strpos($url,DOKU_URL) === 0 OR strpos($url,DOKU_BASE) === 0){ + if(strpos($url, DOKU_URL) === 0 OR strpos($url, DOKU_BASE) === 0) { $link['target'] = $conf['target']['wiki']; } -- cgit v1.2.3 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 --- inc/parser/renderer.php | 9 +++++---- inc/parser/xhtml.php | 11 ++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'inc/parser') 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 From f379edc2c80eee8cab2b94a4374113a0100f3929 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 15 Feb 2014 16:51:48 +0100 Subject: fix comment in _resolveInterWiki --- inc/parser/renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index fa70c299e..01a1fbfec 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -321,7 +321,7 @@ class Doku_Renderer extends DokuWiki_Plugin { //default $url = $url . rawurlencode($reference); } - //url without slashes is handled as a pageid + //handle as wiki links if($url{0} === ':') { list($id, $urlparam) = explode('?', $url, 2); $url = wl(cleanID($id), $urlparam); -- cgit v1.2.3