summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerrit Uitslag <klapinklapin@gmail.com>2014-03-16 21:52:10 +0100
committerGerrit Uitslag <klapinklapin@gmail.com>2014-03-16 21:52:10 +0100
commit02fdb912950b25bafecfc3f3f4d2b4be5352453b (patch)
treef1c67d720c96065ec343492dd6b301ba0060869a
parente9ac0877f6c7eb3536f8f2b6b2a431c00de8fe4f (diff)
parent4d5fc927eace8f4208895cd309d23fc9025dbb6b (diff)
downloadrpg-02fdb912950b25bafecfc3f3f4d2b4be5352453b.tar.gz
rpg-02fdb912950b25bafecfc3f3f4d2b4be5352453b.tar.bz2
Merge pull request #527 from splitbrain/userlink
Linked and formatted user names
-rw-r--r--_test/tests/inc/parser/renderer_resolveinterwiki.test.php53
-rw-r--r--conf/interwiki.conf3
-rw-r--r--inc/common.php148
-rw-r--r--inc/parser/renderer.php48
-rw-r--r--inc/parser/xhtml.php19
-rw-r--r--inc/template.php3
-rw-r--r--lib/images/interwiki/user.pngbin0 -> 741 bytes
-rw-r--r--lib/plugins/config/lang/en/lang.php9
-rw-r--r--lib/plugins/config/settings/config.metadata.php2
-rw-r--r--lib/tpl/dokuwiki/css/design.less15
10 files changed, 235 insertions, 65 deletions
diff --git a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php
new file mode 100644
index 000000000..7b43b6d62
--- /dev/null
+++ b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php
@@ -0,0 +1,53 @@
+<?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'),
+ array('skype', 'foo @+%/#txt', 'skype:foo @+%/#txt'),
+ //dokuwiki id's
+ array('onlytext', 'foo @+%#txt', DOKU_BASE.'doku.php?id=onlytextfoo#txt'),
+ array('user', 'foo @+%#txt', DOKU_BASE.'doku.php?id=user:foo#txt'),
+ array('withquery', 'foo @+%#txt', DOKU_BASE.'doku.php?id=anyns:foo&amp;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&amp;btnI=lucky';
+
+ $this->assertEquals($expected, $url);
+ }
+
+} \ No newline at end of file
diff --git a/conf/interwiki.conf b/conf/interwiki.conf
index 28561a4ae..d961912e5 100644
--- a/conf/interwiki.conf
+++ b/conf/interwiki.conf
@@ -24,12 +24,13 @@ amazon.de http://www.amazon.de/exec/obidos/ASIN/{URL}/splitbrain-21/
amazon.uk http://www.amazon.co.uk/exec/obidos/ASIN/
paypal https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=
phpfn http://www.php.net/{NAME}
-coral http://{HOST}.{PORT}.nyud.net:8090/{PATH}?{QUERY}
+coral http://{HOST}.{PORT}.nyud.net:8090{PATH}?{QUERY}
freecache http://freecache.org/{NAME}
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}&amp;btnI=lucky
+user :user:{NAME}
# To support VoIP/SIP links
callto callto://{NAME}
diff --git a/inc/common.php b/inc/common.php
index 268a61fe6..5960d414e 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -1459,37 +1459,135 @@ function shorten($keep, $short, $max, $min = 9, $char = '…') {
* Return the users realname or e-mail address for use
* in page footer and recent changes pages
*
+ * @param string|bool $username or false when currently logged-in user should be used
+ * @param bool $textonly true returns only plain text, true allows returning html
+ * @return string html or plain text(not escaped) of formatted user name
+ *
* @author Andy Webber <dokuwiki AT andywebber DOT com>
*/
-function editorinfo($username) {
- global $conf;
+function editorinfo($username, $textonly = false) {
+ return userlink($username, $textonly);
+}
+
+/**
+ * Returns users realname w/o link
+ *
+ * @param string|bool $username or false when currently logged-in user should be used
+ * @param bool $textonly true returns only plain text, true allows returning html
+ * @return string html or plain text(not escaped) of formatted user name
+ *
+ * @triggers COMMON_USER_LINK
+ */
+function userlink($username = null, $textonly = false) {
+ global $conf, $INFO;
+ /** @var DokuWiki_Auth_Plugin $auth */
global $auth;
+ /** @var Input $INPUT */
+ global $INPUT;
- switch($conf['showuseras']) {
- case 'username':
- case 'email':
- case 'email_link':
- if($auth) $info = $auth->getUserData($username);
- break;
- default:
- return hsc($username);
- }
-
- if(isset($info) && $info) {
- switch($conf['showuseras']) {
- case 'username':
- return hsc($info['name']);
- case 'email':
- return obfuscate($info['mail']);
- case 'email_link':
- $mail = obfuscate($info['mail']);
- return '<a href="mailto:'.$mail.'">'.$mail.'</a>';
- default:
- return hsc($username);
+ // prepare initial event data
+ $data = array(
+ 'username' => $username, // the unique user name
+ 'name' => '',
+ 'link' => array( //setting 'link' to false disables linking
+ 'target' => '',
+ 'pre' => '',
+ 'suf' => '',
+ 'style' => '',
+ 'more' => '',
+ 'url' => '',
+ 'title' => '',
+ 'class' => ''
+ ),
+ 'userlink' => '', // formatted user name as will be returned
+ 'textonly' => $textonly
+ );
+ if($username === null) {
+ $data['username'] = $username = $INPUT->server->str('REMOTE_USER');
+ if($textonly){
+ $data['name'] = $INFO['userinfo']['name']. ' (' . $INPUT->server->str('REMOTE_USER') . ')';
+ }else {
+ $data['name'] = '<bdi>' . hsc($INFO['userinfo']['name']) . '</bdi> (<bdi>' . hsc($INPUT->server->str('REMOTE_USER')) . '</bdi>)';
}
- } else {
- return hsc($username);
}
+
+ $evt = new Doku_Event('COMMON_USER_LINK', $data);
+ if($evt->advise_before(true)) {
+ if(empty($data['name'])) {
+ if($conf['showuseras'] == 'loginname') {
+ $data['name'] = $textonly ? $data['username'] : hsc($data['username']);
+ } else {
+ if($auth) $info = $auth->getUserData($username);
+ if(isset($info) && $info) {
+ switch($conf['showuseras']) {
+ case 'username':
+ case 'username_link':
+ $data['name'] = $textonly ? $info['name'] : hsc($info['name']);
+ break;
+ case 'email':
+ case 'email_link':
+ $data['name'] = obfuscate($info['mail']);
+ break;
+ }
+ }
+ }
+ }
+
+ /** @var Doku_Renderer_xhtml $xhtml_renderer */
+ static $xhtml_renderer = null;
+
+ if(!$data['textonly'] && empty($data['link']['url'])) {
+
+ if(in_array($conf['showuseras'], array('email_link', 'username_link'))) {
+ if(!isset($info)) {
+ if($auth) $info = $auth->getUserData($username);
+ }
+ if(isset($info) && $info) {
+ if($conf['showuseras'] == 'email_link') {
+ $data['link']['url'] = 'mailto:' . obfuscate($info['mail']);
+ } else {
+ if(is_null($xhtml_renderer)) {
+ $xhtml_renderer = p_get_renderer('xhtml');
+ }
+ if(empty($xhtml_renderer->interwiki)) {
+ $xhtml_renderer->interwiki = getInterwiki();
+ }
+ $shortcut = 'user';
+ $exists = null;
+ $data['link']['url'] = $xhtml_renderer->_resolveInterWiki($shortcut, $username, $exists);
+ $data['link']['class'] .= ' interwiki iw_user';
+ if($exists !== null) {
+ if($exists) {
+ $data['link']['class'] .= ' wikilink1';
+ } else {
+ $data['link']['class'] .= ' wikilink2';
+ $data['link']['rel'] = 'nofollow';
+ }
+ }
+ }
+ } else {
+ $data['textonly'] = true;
+ }
+
+ } else {
+ $data['textonly'] = true;
+ }
+ }
+
+ if($data['textonly']) {
+ $data['userlink'] = $data['name'];
+ } else {
+ $data['link']['name'] = $data['name'];
+ if(is_null($xhtml_renderer)) {
+ $xhtml_renderer = p_get_renderer('xhtml');
+ }
+ $data['userlink'] = $xhtml_renderer->_formatLink($data['link']);
+ }
+ }
+ $evt->advise_after();
+ unset($evt);
+
+ return $data['userlink'];
}
/**
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index e748c36d8..0c3c56c56 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -271,17 +271,17 @@ class Doku_Renderer extends DokuWiki_Plugin {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- function _simpleTitle($name){
+ function _simpleTitle($name) {
global $conf;
- //if there is a hash we use the anchor name only
- @list($name,$hash) = explode('#',$name,2);
+ //if there is a hash we use the ancor name only
+ @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);
@@ -290,9 +290,9 @@ 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]) ) {
+ if(isset($this->interwiki[$shortcut])) {
$url = $this->interwiki[$shortcut];
} else {
// Default to Google I'm feeling lucky
@@ -301,25 +301,31 @@ 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);
+ }
+ //handle as wiki links
+ if($url{0} === ':') {
+ list($id, $urlparam) = explode('?', $url, 2);
+ $url = wl(cleanID($id), $urlparam);
+ $exists = page_exists($id);
}
- 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 4966f103a..e3f9a4187 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -688,7 +688,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
/**
- */
+ */
function interwikilink($match, $name = null, $wikiName, $wikiUri) {
global $conf;
@@ -700,19 +700,28 @@ 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);
+ 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 ){
+ 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']);
diff --git a/inc/template.php b/inc/template.php
index 4b1188c95..8bd3234cc 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -914,12 +914,11 @@ function tpl_youarehere($sep = ' » ') {
*/
function tpl_userinfo() {
global $lang;
- global $INFO;
/** @var Input $INPUT */
global $INPUT;
if($INPUT->server->str('REMOTE_USER')) {
- print $lang['loggedinas'].': <bdi>'.hsc($INFO['userinfo']['name']).'</bdi> (<bdi>'.hsc($INPUT->server->str('REMOTE_USER')).'</bdi>)';
+ print $lang['loggedinas'].': '.userlink();
return true;
}
return false;
diff --git a/lib/images/interwiki/user.png b/lib/images/interwiki/user.png
new file mode 100644
index 000000000..79f35ccbd
--- /dev/null
+++ b/lib/images/interwiki/user.png
Binary files differ
diff --git a/lib/plugins/config/lang/en/lang.php b/lib/plugins/config/lang/en/lang.php
index cdef85a85..66d4dc356 100644
--- a/lib/plugins/config/lang/en/lang.php
+++ b/lib/plugins/config/lang/en/lang.php
@@ -245,10 +245,11 @@ $lang['xsendfile_o_2'] = 'Standard X-Sendfile header';
$lang['xsendfile_o_3'] = 'Proprietary Nginx X-Accel-Redirect header';
/* Display user info */
-$lang['showuseras_o_loginname'] = 'Login name';
-$lang['showuseras_o_username'] = "User's full name";
-$lang['showuseras_o_email'] = "User's e-mail addresss (obfuscated according to mailguard setting)";
-$lang['showuseras_o_email_link'] = "User's e-mail addresss as a mailto: link";
+$lang['showuseras_o_loginname'] = 'Login name';
+$lang['showuseras_o_username'] = "User's full name";
+$lang['showuseras_o_username_link'] = "User's full name as interwiki user link";
+$lang['showuseras_o_email'] = "User's e-mail addresss (obfuscated according to mailguard setting)";
+$lang['showuseras_o_email_link'] = "User's e-mail addresss as a mailto: link";
/* useheading options */
$lang['useheading_o_0'] = 'Never';
diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php
index f9dabfeb0..69cc0df01 100644
--- a/lib/plugins/config/settings/config.metadata.php
+++ b/lib/plugins/config/settings/config.metadata.php
@@ -116,7 +116,7 @@ $meta['fullpath'] = array('onoff','_caution' => 'security');
$meta['typography'] = array('multichoice','_choices' => array(0,1,2));
$meta['dformat'] = array('string');
$meta['signature'] = array('string');
-$meta['showuseras'] = array('multichoice','_choices' => array('loginname','username','email','email_link'));
+$meta['showuseras'] = array('multichoice','_choices' => array('loginname','username','username_link','email','email_link'));
$meta['toptoclevel'] = array('multichoice','_choices' => array(1,2,3,4,5)); // 5 toc levels
$meta['tocminheads'] = array('multichoice','_choices' => array(0,1,2,3,4,5,10,15,20));
$meta['maxtoclevel'] = array('multichoice','_choices' => array(0,1,2,3,4,5));
diff --git a/lib/tpl/dokuwiki/css/design.less b/lib/tpl/dokuwiki/css/design.less
index 46b4a045b..66607b5e9 100644
--- a/lib/tpl/dokuwiki/css/design.less
+++ b/lib/tpl/dokuwiki/css/design.less
@@ -48,6 +48,12 @@
margin-bottom: 0;
font-size: 0.875em;
}
+
+ /* make all links in header (including breadcrumb and interwiki) same colour as the rest */
+ a {
+ color: @ini_link;
+ background-color: inherit;
+ }
}
[dir=rtl] #dokuwiki__header h1 img {
@@ -100,7 +106,8 @@
margin-left: 0;
}
-#dokuwiki__usertools a.action {
+#dokuwiki__usertools a.action,
+#dokuwiki__usertools a.iw_user {
padding-left: 20px;
background: transparent url(images/usertools.png) no-repeat 0 0;
}
@@ -137,6 +144,7 @@
background-position: left 0;
}
+ a.iw_user,
a.action.profile {
background-position: left -32px;
}
@@ -260,11 +268,6 @@ form.search {
border-bottom: 1px solid @ini_border;
}
- a {
- color: @ini_link;
- background-color: inherit;
- }
-
.bcsep {
font-size: 0.75em;
}