Skip to content
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
merged 26 commits into from Mar 16, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
60a396c
wrap userlink building with event.
Klap-in Feb 3, 2014
8a7e0ee
update $username as well, when read from _SERVER
Klap-in Feb 3, 2014
62c8004
change default arg value of userinfo in null instead false
Klap-in Feb 14, 2014
7c2f8ee
handle interwiki without slashes as pageids. Added user interwiki
Klap-in Feb 14, 2014
b3d353e
wikilink needs wiki target as well
Klap-in Feb 14, 2014
7f08182
Extend showuseras config with username_link
Klap-in Feb 14, 2014
2d6df79
added tests for Doku_Renderer::_resolveInterWiki
Klap-in Feb 14, 2014
2345e87
wikilink creating refactored to _resolveinterwiki().
Klap-in Feb 15, 2014
5a9ce44
code reformatting
Klap-in Feb 15, 2014
4485a89
Fix double slash in coral interwikilink
Klap-in Feb 15, 2014
ddb55c7
Use DOKU_BASE in resolveinterwiki unittest
Klap-in Feb 15, 2014
6496c33
interwiki : prefixed configurls handled as wikilinks
Klap-in Feb 15, 2014
f379edc
fix comment in _resolveInterWiki
Klap-in Feb 15, 2014
6198904
generalised link colour in header, making interwiki links blue as wel…
selfthinker Feb 16, 2014
2a2a43c
change default userspace to :user:<username> and add interwiki class
Klap-in Feb 16, 2014
118e005
update unittest with interwiki.conf change as well
Klap-in Feb 16, 2014
6384941
added user.png for interwiki links
Klap-in Mar 10, 2014
f97db66
Merge remote-tracking branch 'origin/master' into userlink
Klap-in Mar 10, 2014
30f6ec4
update usage in userlink
Klap-in Mar 10, 2014
533772e
declare more clear, before used as ref
Klap-in Mar 10, 2014
15f3bc4
enable editorinfo and userinfo to return plain text names
Klap-in Mar 14, 2014
c18baa7
override user link icon in header
splitbrain Mar 15, 2014
c095302
improve phpdocs editorinfo()
Klap-in Mar 16, 2014
898f93a
Merge remote-tracking branch 'origin/userlink' into userlink
Klap-in Mar 16, 2014
cd4635e
Rename userinfo() to userlink()
Klap-in Mar 16, 2014
4d5fc92
use more consistent names
Klap-in Mar 16, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
109 changes: 85 additions & 24 deletions inc/common.php
Expand Up @@ -1418,34 +1418,95 @@ function shorten($keep, $short, $max, $min = 9, $char = '…') {
* @author Andy Webber <dokuwiki AT andywebber DOT com>
*/
function editorinfo($username) {
global $conf;
return userinfo($username);
}

/**
* Returns users realname w/o link
*
* @param string|bool $username or false when currently logged-in user should be used
* @return string html of formatted user name
*
* @triggers COMMON_USER_LINK
*/
function userinfo($username = false) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think null or maybe an empty string would make slightly more sense as a default.

global $conf, $INFO;
/** @var DokuWiki_Auth_Plugin $auth */
global $auth;

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' => ''
),
'userinfo' => ''
);
if($username === false) {
$data['username'] = $username = $_SERVER['REMOTE_USER'];
$data['name'] = '<bdi>'.hsc($INFO['userinfo']['name']).'</bdi> (<bdi>'.hsc($_SERVER['REMOTE_USER']).'</bdi>)';
}

$evt = new Doku_Event('COMMON_USER_LINK', $data);
if($evt->advise_before(true)) {
if(empty($data['name'])) {
if($conf['showuseras'] == 'loginname') {
$data['name'] = hsc($data['username']);
} else {
if($auth) $info = $auth->getUserData($username);
if(isset($info) && $info) {
switch($conf['showuseras']) {
case 'username':
$data['name'] = hsc($info['name']);
break;
case 'email':
case 'email_link':
$data['name'] = obfuscate($info['mail']);
break;
}
}
}
}
if($data['link'] !== false && empty($data['link']['url'])){
if($conf['showuseras'] == 'email_link') {
if(!isset($info)) {
if($auth) $info = $auth->getUserData($username);
}
if(isset($info) && $info) {
$data['link']['url'] = 'mailto:'.obfuscate($info['mail']);
} else {
$data['link'] = false;
}

} else {
$data['link'] = false;
}
}

if($data['link'] === false) {
$data['userinfo'] = $data['name'];
} else{
$data['link']['name'] = $data['name'];
/** @var Doku_Renderer_xhtml $xhtml_renderer */
static $xhtml_renderer = null;
if(is_null($xhtml_renderer)){
$xhtml_renderer = p_get_renderer('xhtml');
}
$data['userinfo'] = $xhtml_renderer->_formatLink($data['link']);
}
} else {
return hsc($username);
}
$evt->advise_after();
unset($evt);

return $data['userinfo'];
}

/**
Expand Down
3 changes: 1 addition & 2 deletions inc/template.php
Expand Up @@ -885,9 +885,8 @@ function tpl_youarehere($sep = ' » ') {
*/
function tpl_userinfo() {
global $lang;
global $INFO;
if(isset($_SERVER['REMOTE_USER'])) {
print $lang['loggedinas'].': <bdi>'.hsc($INFO['userinfo']['name']).'</bdi> (<bdi>'.hsc($_SERVER['REMOTE_USER']).'</bdi>)';
print $lang['loggedinas'].': '.userinfo();
return true;
}
return false;
Expand Down