New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linked and formatted user names #527
Merged
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
60a396c
wrap userlink building with event.
Klap-in 8a7e0ee
update $username as well, when read from _SERVER
Klap-in 62c8004
change default arg value of userinfo in null instead false
Klap-in 7c2f8ee
handle interwiki without slashes as pageids. Added user interwiki
Klap-in b3d353e
wikilink needs wiki target as well
Klap-in 7f08182
Extend showuseras config with username_link
Klap-in 2d6df79
added tests for Doku_Renderer::_resolveInterWiki
Klap-in 2345e87
wikilink creating refactored to _resolveinterwiki().
Klap-in 5a9ce44
code reformatting
Klap-in 4485a89
Fix double slash in coral interwikilink
Klap-in ddb55c7
Use DOKU_BASE in resolveinterwiki unittest
Klap-in 6496c33
interwiki : prefixed configurls handled as wikilinks
Klap-in f379edc
fix comment in _resolveInterWiki
Klap-in 6198904
generalised link colour in header, making interwiki links blue as wel…
selfthinker 2a2a43c
change default userspace to :user:<username> and add interwiki class
Klap-in 118e005
update unittest with interwiki.conf change as well
Klap-in 6384941
added user.png for interwiki links
Klap-in f97db66
Merge remote-tracking branch 'origin/master' into userlink
Klap-in 30f6ec4
update usage in userlink
Klap-in 533772e
declare more clear, before used as ref
Klap-in 15f3bc4
enable editorinfo and userinfo to return plain text names
Klap-in c18baa7
override user link icon in header
splitbrain c095302
improve phpdocs editorinfo()
Klap-in 898f93a
Merge remote-tracking branch 'origin/userlink' into userlink
Klap-in cd4635e
Rename userinfo() to userlink()
Klap-in 4d5fc92
use more consistent names
Klap-in File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
require_once DOKU_INC . 'inc/parser/renderer.php'; | ||
|
||
/** | ||
* Tests for Doku_Renderer::_resolveInterWiki() | ||
*/ | ||
class Test_resolveInterwiki extends PHPUnit_Framework_TestCase { | ||
|
||
function testDefaults() { | ||
$Renderer = new Doku_Renderer(); | ||
$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'; | ||
|
||
$tests = array( | ||
// shortcut, reference and expected | ||
array('wp', 'foo @+%/#txt', 'http://en.wikipedia.org/wiki/foo @+%/#txt'), | ||
array('amazon', 'foo @+%/#txt', 'http://www.amazon.com/exec/obidos/ASIN/foo%20%40%2B%25%2F/splitbrain-20/#txt'), | ||
array('doku', 'foo @+%/#txt', 'http://www.dokuwiki.org/foo%20%40%2B%25%2F#txt'), | ||
array('coral', 'http://example.com:83/path/naar/?query=foo%20%40%2B%25%2F', 'http://example.com.83.nyud.net:8090/path/naar/?query=foo%20%40%2B%25%2F'), | ||
array('scheme', 'ftp://foo @+%/#txt', 'ftp://example.com#txt'), | ||
//relative url | ||
array('withslash', 'foo @+%/#txt', '/testfoo%20%40%2B%25%2F#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') | ||
); | ||
|
||
foreach($tests as $test) { | ||
$url = $Renderer->_resolveInterWiki($test[0], $test[1]); | ||
|
||
$this->assertEquals($test[2], $url); | ||
} | ||
} | ||
|
||
function testNonexisting() { | ||
$Renderer = new Doku_Renderer(); | ||
$Renderer->interwiki = getInterwiki(); | ||
|
||
$shortcut = 'nonexisting'; | ||
$reference = 'foo @+%/'; | ||
$url = $Renderer->_resolveInterWiki($shortcut, $reference); | ||
$expected = 'http://www.google.com/search?q=foo%20%40%2B%25%2F&btnI=lucky'; | ||
|
||
$this->assertEquals($expected, $url); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,17 +273,17 @@ function tablecell_close(){} | |
* | ||
* @author Andreas Gohr <andi@splitbrain.org> | ||
*/ | ||
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 @@ function _simpleTitle($name){ | |
/** | ||
* 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,25 +303,30 @@ function _resolveInterWiki(&$shortcut,$reference){ | |
} | ||
|
||
//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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the current behavior anymore. |
||
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn. I forgot about this usecase. this will break with your change. You no longer can create a shortcut to have special protocol links like skype:, mailto: or javascript:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could use a (pseudo) full link syntax instead?
But users would expect these to work too then:
which doesn't really make sense. Maybe we can do something like in mime.conf and prefix things that should be resolved as page name with a !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FS#2713 suggests using
_shortcut
or.shortcut
for internal links, you added!shortcut
as well.Which variant do we like?