From 60a396c8ac50f17c2e3f43a9533af86cf6976976 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 4 Feb 2014 00:34:12 +0100 Subject: wrap userlink building with event. Implements an event which can modify the link below usernames, and the displayed user name. When no name supplied, the name of currently logged-in user is used. --- inc/common.php | 109 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 24 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 32771285b..053776a41 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1418,34 +1418,95 @@ function shorten($keep, $short, $max, $min = 9, $char = '…') { * @author Andy Webber */ 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) { + 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 ''.$mail.''; - 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'] = $_SERVER['REMOTE_USER']; + $data['name'] = ''.hsc($INFO['userinfo']['name']).' ('.hsc($_SERVER['REMOTE_USER']).')'; + } + + $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']; } /** -- cgit v1.2.3 From 8a7e0ee6403bb358edf90c2419af066dd79cb2ce Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 4 Feb 2014 00:59:45 +0100 Subject: update $username as well, when read from _SERVER --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 053776a41..297c36355 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1451,7 +1451,7 @@ function userinfo($username = false) { 'userinfo' => '' ); if($username === false) { - $data['username'] = $_SERVER['REMOTE_USER']; + $data['username'] = $username = $_SERVER['REMOTE_USER']; $data['name'] = ''.hsc($INFO['userinfo']['name']).' ('.hsc($_SERVER['REMOTE_USER']).')'; } -- cgit v1.2.3 From 62c8004ec7c360471b96b4faa6128cd207f89bf2 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Fri, 14 Feb 2014 14:36:54 +0100 Subject: change default arg value of userinfo in null instead false --- inc/common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 297c36355..c18f43668 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1429,7 +1429,7 @@ function editorinfo($username) { * * @triggers COMMON_USER_LINK */ -function userinfo($username = false) { +function userinfo($username = null) { global $conf, $INFO; /** @var DokuWiki_Auth_Plugin $auth */ global $auth; @@ -1450,7 +1450,7 @@ function userinfo($username = false) { ), 'userinfo' => '' ); - if($username === false) { + if($username === null) { $data['username'] = $username = $_SERVER['REMOTE_USER']; $data['name'] = ''.hsc($INFO['userinfo']['name']).' ('.hsc($_SERVER['REMOTE_USER']).')'; } -- cgit v1.2.3 From 7f081821c51e704c2720b993ca5364fa5e7e3663 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 15 Feb 2014 00:42:05 +0100 Subject: Extend showuseras config with username_link uses the user interwiki link as profile link --- inc/common.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index c18f43668..22e57b2c5 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1465,6 +1465,7 @@ function userinfo($username = null) { if(isset($info) && $info) { switch($conf['showuseras']) { case 'username': + case 'username_link': $data['name'] = hsc($info['name']); break; case 'email': @@ -1475,13 +1476,31 @@ function userinfo($username = null) { } } } + + /** @var Doku_Renderer_xhtml $xhtml_renderer */ + static $xhtml_renderer = null; + if($data['link'] !== false && empty($data['link']['url'])){ - if($conf['showuseras'] == 'email_link') { + + if(in_array($conf['showuseras'], array('email_link', 'username_link'))) { if(!isset($info)) { if($auth) $info = $auth->getUserData($username); } if(isset($info) && $info) { - $data['link']['url'] = 'mailto:'.obfuscate($info['mail']); + 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'; + $url = $xhtml_renderer->_resolveInterWiki($shortcut, $username); + list($url, $urlparam) = explode('?', $url, 2); + $data['link']['url'] = wl($url, $urlparam); + } } else { $data['link'] = false; } @@ -1495,8 +1514,6 @@ function userinfo($username = null) { $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'); } -- 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/common.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 22e57b2c5..e991375f5 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1497,9 +1497,7 @@ function userinfo($username = null) { $xhtml_renderer->interwiki = getInterwiki(); } $shortcut = 'user'; - $url = $xhtml_renderer->_resolveInterWiki($shortcut, $username); - list($url, $urlparam) = explode('?', $url, 2); - $data['link']['url'] = wl($url, $urlparam); + $data['link']['url'] = $xhtml_renderer->_resolveInterWiki($shortcut, $username); } } else { $data['link'] = false; -- 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/common.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index e991375f5..cd3c053a3 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1438,21 +1438,21 @@ function userinfo($username = null) { $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' => '' + 'link' => array( //setting 'link' to false disables linking + 'target' => '', + 'pre' => '', + 'suf' => '', + 'style' => '', + 'more' => '', + 'url' => '', + 'title' => '', + 'class' => '' ), 'userinfo' => '' ); if($username === null) { $data['username'] = $username = $_SERVER['REMOTE_USER']; - $data['name'] = ''.hsc($INFO['userinfo']['name']).' ('.hsc($_SERVER['REMOTE_USER']).')'; + $data['name'] = '' . hsc($INFO['userinfo']['name']) . ' (' . hsc($_SERVER['REMOTE_USER']) . ')'; } $evt = new Doku_Event('COMMON_USER_LINK', $data); @@ -1480,7 +1480,7 @@ function userinfo($username = null) { /** @var Doku_Renderer_xhtml $xhtml_renderer */ static $xhtml_renderer = null; - if($data['link'] !== false && empty($data['link']['url'])){ + if($data['link'] !== false && empty($data['link']['url'])) { if(in_array($conf['showuseras'], array('email_link', 'username_link'))) { if(!isset($info)) { @@ -1488,9 +1488,9 @@ function userinfo($username = null) { } if(isset($info) && $info) { if($conf['showuseras'] == 'email_link') { - $data['link']['url'] = 'mailto:'.obfuscate($info['mail']); + $data['link']['url'] = 'mailto:' . obfuscate($info['mail']); } else { - if(is_null($xhtml_renderer)){ + if(is_null($xhtml_renderer)) { $xhtml_renderer = p_get_renderer('xhtml'); } if(empty($xhtml_renderer->interwiki)) { @@ -1510,9 +1510,9 @@ function userinfo($username = null) { if($data['link'] === false) { $data['userinfo'] = $data['name']; - } else{ + } else { $data['link']['name'] = $data['name']; - if(is_null($xhtml_renderer)){ + if(is_null($xhtml_renderer)) { $xhtml_renderer = p_get_renderer('xhtml'); } $data['userinfo'] = $xhtml_renderer->_formatLink($data['link']); -- 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/common.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'inc/common.php') 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; -- cgit v1.2.3 From 2a2a43c4fa64079215d205d1faf50ab8a59caaab Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Mon, 17 Feb 2014 00:37:28 +0100 Subject: change default userspace to :user: and add interwiki class --- inc/common.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index aa59a8c11..4a5ead6b8 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1498,6 +1498,7 @@ function userinfo($username = null) { } $shortcut = 'user'; $data['link']['url'] = $xhtml_renderer->_resolveInterWiki($shortcut, $username, $exists); + $data['link']['class'] .= ' interwiki iw_user'; if($exists !== null) { if($exists) { $data['link']['class'] .= ' wikilink1'; -- cgit v1.2.3 From 74160ca1dea24b237ff3e956d19a420a1593b957 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 20 Feb 2014 14:10:24 +0100 Subject: PHPDocs missing breaks, removed unused var in common.php --- inc/common.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 32771285b..4682bedf9 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1140,7 +1140,6 @@ function saveWikiText($id, $text, $summary, $minor = false) { * @author Andreas Gohr */ function saveOldRevision($id) { - global $conf; $oldf = wikiFN($id); if(!@file_exists($oldf)) return ''; $date = filemtime($oldf); @@ -1230,8 +1229,9 @@ function getGoogleQuery() { /** * Return the human readable size of a file * - * @param int $size A file size - * @param int $dec A number of decimal places + * @param int $size A file size + * @param int $dec A number of decimal places + * @return string human readable size * @author Martin Benjamin * @author Aidan Lister * @version 1.0.0 @@ -1362,12 +1362,16 @@ function php_to_byte($v) { $l = substr($v, -1); $ret = substr($v, 0, -1); switch(strtoupper($l)) { + /** @noinspection PhpMissingBreakStatementInspection */ case 'P': $ret *= 1024; + /** @noinspection PhpMissingBreakStatementInspection */ case 'T': $ret *= 1024; + /** @noinspection PhpMissingBreakStatementInspection */ case 'G': $ret *= 1024; + /** @noinspection PhpMissingBreakStatementInspection */ case 'M': $ret *= 1024; case 'K': -- cgit v1.2.3 From 01c9a118dacc1e2c07f2b0ddee84c514022e5927 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 23 Feb 2014 09:54:47 +0100 Subject: have most current revision always available in $INFO fixes fix for FS#2853 --- inc/common.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 32771285b..bbc0a6e68 100644 --- a/inc/common.php +++ b/inc/common.php @@ -155,12 +155,13 @@ function pageinfo() { $info['subscribed'] = false; } - $info['locked'] = checklock($ID); - $info['filepath'] = fullpath(wikiFN($ID)); - $info['exists'] = @file_exists($info['filepath']); + $info['locked'] = checklock($ID); + $info['filepath'] = fullpath(wikiFN($ID)); + $info['exists'] = @file_exists($info['filepath']); + $info['currentrev'] = @filemtime($info['filepath']); if($REV) { //check if current revision was meant - if($info['exists'] && (@filemtime($info['filepath']) == $REV)) { + if($info['exists'] && ($info['currentrev'] == $REV)) { $REV = ''; } elseif($RANGE) { //section editing does not work with old revisions! -- cgit v1.2.3 From 0e80bb5e347ff00c6f81627d8e39dafaaa923bc5 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Wed, 5 Mar 2014 21:58:46 +0000 Subject: use empty() where array values might not be set --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 9a53ee526..36bd32c4f 100644 --- a/inc/common.php +++ b/inc/common.php @@ -191,7 +191,7 @@ function pageinfo() { if($REV) { $revinfo = getRevisionInfo($ID, $REV, 1024); } else { - if(is_array($info['meta']['last_change'])) { + if(!empty($info['meta']['last_change']) && is_array($info['meta']['last_change'])) { $revinfo = $info['meta']['last_change']; } else { $revinfo = getRevisionInfo($ID, $info['lastmod'], 1024); -- cgit v1.2.3 From 6d2af55dde922ac10a288b4195b1bf338e7bc5a9 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Wed, 5 Mar 2014 22:01:20 +0000 Subject: suppress errors where list() may not fill all vars --- inc/common.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 36bd32c4f..6aad42bd1 100644 --- a/inc/common.php +++ b/inc/common.php @@ -773,7 +773,7 @@ function checklock($id) { } //my own lock - list($ip, $session) = explode("\n", io_readFile($lock)); + @list($ip, $session) = explode("\n", io_readFile($lock)); if($ip == $_SERVER['REMOTE_USER'] || $ip == clientIP() || $session == session_id()) { return false; } @@ -811,7 +811,7 @@ function lock($id) { function unlock($id) { $lock = wikiLockFN($id); if(@file_exists($lock)) { - list($ip, $session) = explode("\n", io_readFile($lock)); + @list($ip, $session) = explode("\n", io_readFile($lock)); if($ip == $_SERVER['REMOTE_USER'] || $ip == clientIP() || $session == session_id()) { @unlink($lock); return true; @@ -1536,7 +1536,7 @@ function send_redirect($url) { // work around IE bug // http://www.ianhoar.com/2008/11/16/internet-explorer-6-and-redirected-anchor-links/ - list($url, $hash) = explode('#', $url); + @list($url, $hash) = explode('#', $url); if($hash) { if(strpos($url, '?')) { $url = $url.'&#'.$hash; -- cgit v1.2.3 From 585bf44e2b756eac2e1cfce7035ef237bc02a788 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 6 Mar 2014 19:55:56 +0000 Subject: amend $_SERVER to $INPUT->server --- inc/common.php | 102 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 31 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 6aad42bd1..9fbebde94 100644 --- a/inc/common.php +++ b/inc/common.php @@ -56,15 +56,18 @@ function stripctl($string) { * @return string */ function getSecurityToken() { - return PassHash::hmac('md5', session_id().$_SERVER['REMOTE_USER'], auth_cookiesalt()); + /** @var Input $INPUT */ + global $INPUT; + return PassHash::hmac('md5', session_id().$INPUT->server->str('REMOTE_USER'), auth_cookiesalt()); } /** * Check the secret CSRF token */ function checkSecurityToken($token = null) { + /** @var Input $INPUT */ global $INPUT; - if(empty($_SERVER['REMOTE_USER'])) return true; // no logged in user, no need for a check + if(!$INPUT->server->str('REMOTE_USER')) return true; // no logged in user, no need for a check if(is_null($token)) $token = $INPUT->str('sectok'); if(getSecurityToken() != $token) { @@ -93,14 +96,16 @@ function formSecurityToken($print = true) { */ function basicinfo($id, $htmlClient=true){ global $USERINFO; + /* @var Input $INPUT */ + global $INPUT; // set info about manager/admin status. $info['isadmin'] = false; $info['ismanager'] = false; - if(isset($_SERVER['REMOTE_USER'])) { + if($INPUT->server->has('REMOTE_USER')) { $info['userinfo'] = $USERINFO; $info['perm'] = auth_quickaclcheck($id); - $info['client'] = $_SERVER['REMOTE_USER']; + $info['client'] = $INPUT->server->str('REMOTE_USER'); if($info['perm'] == AUTH_ADMIN) { $info['isadmin'] = true; @@ -111,7 +116,7 @@ function basicinfo($id, $htmlClient=true){ // if some outside auth were used only REMOTE_USER is set if(!$info['userinfo']['name']) { - $info['userinfo']['name'] = $_SERVER['REMOTE_USER']; + $info['userinfo']['name'] = $INPUT->server->str('REMOTE_USER'); } } else { @@ -140,6 +145,8 @@ function pageinfo() { global $REV; global $RANGE; global $lang; + /* @var Input $INPUT */ + global $INPUT; $info = basicinfo($ID); @@ -148,7 +155,7 @@ function pageinfo() { $info['id'] = $ID; $info['rev'] = $REV; - if(isset($_SERVER['REMOTE_USER'])) { + if($INPUT->server->has('REMOTE_USER')) { $sub = new Subscription(); $info['subscribed'] = $sub->user_subscription(); } else { @@ -356,11 +363,14 @@ function breadcrumbs() { */ function idfilter($id, $ue = true) { global $conf; + /* @var Input $INPUT */ + global $INPUT; + if($conf['useslash'] && $conf['userewrite']) { $id = strtr($id, ':', '/'); } elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && $conf['userewrite'] && - strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') === false + strpos($INPUT->server->str('SERVER_SOFTWARE'), 'Microsoft-IIS') === false ) { $id = strtr($id, ':', ';'); } @@ -588,6 +598,8 @@ function checkwordblock($text = '') { global $SUM; global $conf; global $INFO; + /* @var Input $INPUT */ + global $INPUT; if(!$conf['usewordblock']) return false; @@ -620,9 +632,9 @@ function checkwordblock($text = '') { if(count($re) && preg_match('#('.join('|', $re).')#si', $text, $matches)) { // prepare event data $data['matches'] = $matches; - $data['userinfo']['ip'] = $_SERVER['REMOTE_ADDR']; - if($_SERVER['REMOTE_USER']) { - $data['userinfo']['user'] = $_SERVER['REMOTE_USER']; + $data['userinfo']['ip'] = $INPUT->server->str('REMOTE_ADDR'); + if($INPUT->server->str('REMOTE_USER')) { + $data['userinfo']['user'] = $INPUT->server->str('REMOTE_USER'); $data['userinfo']['name'] = $INFO['userinfo']['name']; $data['userinfo']['mail'] = $INFO['userinfo']['mail']; } @@ -648,12 +660,17 @@ function checkwordblock($text = '') { * @return string */ function clientIP($single = false) { + /* @var Input $INPUT */ + global $INPUT; + $ip = array(); - $ip[] = $_SERVER['REMOTE_ADDR']; - if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) - $ip = array_merge($ip, explode(',', str_replace(' ', '', $_SERVER['HTTP_X_FORWARDED_FOR']))); - if(!empty($_SERVER['HTTP_X_REAL_IP'])) - $ip = array_merge($ip, explode(',', str_replace(' ', '', $_SERVER['HTTP_X_REAL_IP']))); + $ip[] = $INPUT->server->str('REMOTE_ADDR'); + if($INPUT->server->str('HTTP_X_FORWARDED_FOR')) { + $ip = array_merge($ip, explode(',', str_replace(' ', '', $INPUT->server->str('HTTP_X_FORWARDED_FOR')))); + } + if($INPUT->server->str('HTTP_X_REAL_IP')) { + $ip = array_merge($ip, explode(',', str_replace(' ', '', $INPUT->server->str('HTTP_X_REAL_IP')))); + } // some IPv4/v6 regexps borrowed from Feyd // see: http://forums.devnetwork.net/viewtopic.php?f=38&t=53479 @@ -712,16 +729,18 @@ function clientIP($single = false) { * @link http://www.brainhandles.com/2007/10/15/detecting-mobile-browsers/#code */ function clientismobile() { + /* @var Input $INPUT */ + global $INPUT; - if(isset($_SERVER['HTTP_X_WAP_PROFILE'])) return true; + if($INPUT->server->has('HTTP_X_WAP_PROFILE')) return true; - if(preg_match('/wap\.|\.wap/i', $_SERVER['HTTP_ACCEPT'])) return true; + if(preg_match('/wap\.|\.wap/i', $INPUT->server->str('HTTP_ACCEPT'))) return true; - if(!isset($_SERVER['HTTP_USER_AGENT'])) return false; + if(!$INPUT->server->has('HTTP_USER_AGENT')) return false; $uamatches = 'midp|j2me|avantg|docomo|novarra|palmos|palmsource|240x320|opwv|chtml|pda|windows ce|mmp\/|blackberry|mib\/|symbian|wireless|nokia|hand|mobi|phone|cdm|up\.b|audio|SIE\-|SEC\-|samsung|HTC|mot\-|mitsu|sagem|sony|alcatel|lg|erics|vx|NEC|philips|mmm|xx|panasonic|sharp|wap|sch|rover|pocket|benq|java|pt|pg|vox|amoi|bird|compal|kg|voda|sany|kdd|dbt|sendo|sgh|gradi|jb|\d\d\di|moto'; - if(preg_match("/$uamatches/i", $_SERVER['HTTP_USER_AGENT'])) return true; + if(preg_match("/$uamatches/i", $INPUT->server->str('HTTP_USER_AGENT'))) return true; return false; } @@ -761,6 +780,9 @@ function gethostsbyaddrs($ips) { */ function checklock($id) { global $conf; + /* @var Input $INPUT */ + global $INPUT; + $lock = wikiLockFN($id); //no lockfile @@ -774,7 +796,7 @@ function checklock($id) { //my own lock @list($ip, $session) = explode("\n", io_readFile($lock)); - if($ip == $_SERVER['REMOTE_USER'] || $ip == clientIP() || $session == session_id()) { + if($ip == $INPUT->server->str('REMOTE_USER') || $ip == clientIP() || $session == session_id()) { return false; } @@ -788,14 +810,16 @@ function checklock($id) { */ function lock($id) { global $conf; + /* @var Input $INPUT */ + global $INPUT; if($conf['locktime'] == 0) { return; } $lock = wikiLockFN($id); - if($_SERVER['REMOTE_USER']) { - io_saveFile($lock, $_SERVER['REMOTE_USER']); + if($INPUT->server->str('REMOTE_USER')) { + io_saveFile($lock, $INPUT->server->str('REMOTE_USER')); } else { io_saveFile($lock, clientIP()."\n".session_id()); } @@ -809,10 +833,13 @@ function lock($id) { * @return bool true if a lock was removed */ function unlock($id) { + /* @var Input $INPUT */ + global $INPUT; + $lock = wikiLockFN($id); if(@file_exists($lock)) { @list($ip, $session) = explode("\n", io_readFile($lock)); - if($ip == $_SERVER['REMOTE_USER'] || $ip == clientIP() || $session == session_id()) { + if($ip == $INPUT->server->str('REMOTE_USER') || $ip == clientIP() || $session == session_id()) { @unlink($lock); return true; } @@ -938,6 +965,8 @@ function parsePageTemplate(&$data) { global $USERINFO; global $conf; + /* @var Input $INPUT */ + global $INPUT; // replace placeholders $file = noNS($id); @@ -969,7 +998,7 @@ function parsePageTemplate(&$data) { utf8_ucfirst($page), utf8_ucwords($page), utf8_strtoupper($page), - $_SERVER['REMOTE_USER'], + $INPUT->server->str('REMOTE_USER'), $USERINFO['name'], $USERINFO['mail'], $conf['dformat'], @@ -1050,6 +1079,9 @@ function saveWikiText($id, $text, $summary, $minor = false) { global $conf; global $lang; global $REV; + /* @var Input $INPUT */ + global $INPUT; + // ignore if no changes were made if($text == rawWiki($id, '')) { return; @@ -1112,7 +1144,7 @@ function saveWikiText($id, $text, $summary, $minor = false) { $type = DOKU_CHANGE_TYPE_CREATE; } else if($wasRemoved) { $type = DOKU_CHANGE_TYPE_DELETE; - } else if($minor && $conf['useacl'] && $_SERVER['REMOTE_USER']) { + } else if($minor && $conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { $type = DOKU_CHANGE_TYPE_MINOR_EDIT; } //minor edits only for logged in users @@ -1164,6 +1196,8 @@ function saveOldRevision($id) { */ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = array()) { global $conf; + /* @var Input $INPUT */ + global $INPUT; // decide if there is something to do, eg. whom to mail if($who == 'admin') { @@ -1172,7 +1206,7 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = $to = $conf['notify']; } elseif($who == 'subscribers') { if(!actionOK('subscribe')) return false; //subscribers enabled? - if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) return false; //skip minors + if($conf['useacl'] && $INPUT->server->str('REMOTE_USER') && $minor) return false; //skip minors $data = array('id' => $id, 'addresslist' => '', 'self' => false); trigger_event( 'COMMON_NOTIFY_ADDRESSLIST', $data, @@ -1197,10 +1231,13 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = * @author Todd Augsburger */ function getGoogleQuery() { - if(!isset($_SERVER['HTTP_REFERER'])) { + /* @var Input $INPUT */ + global $INPUT; + + if(!$INPUT->server->has('HTTP_REFERER')) { return ''; } - $url = parse_url($_SERVER['HTTP_REFERER']); + $url = parse_url($INPUT->server->str('HTTP_REFERER')); // only handle common SEs if(!preg_match('/(google|bing|yahoo|ask|duckduckgo|babylon|aol|yandex)/',$url['host'])) return ''; @@ -1523,6 +1560,9 @@ function is_mem_available($mem, $bytes = 1048576) { * @author Andreas Gohr */ function send_redirect($url) { + /* @var Input $INPUT */ + global $INPUT; + //are there any undisplayed messages? keep them in session for display global $MSG; if(isset($MSG) && count($MSG) && !defined('NOSESSION')) { @@ -1546,9 +1586,9 @@ function send_redirect($url) { } // check if running on IIS < 6 with CGI-PHP - if(isset($_SERVER['SERVER_SOFTWARE']) && isset($_SERVER['GATEWAY_INTERFACE']) && - (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) && - (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) && + if($INPUT->server->has('SERVER_SOFTWARE') && $INPUT->server->has('GATEWAY_INTERFACE') && + (strpos($INPUT->server->str('GATEWAY_INTERFACE'), 'CGI') !== false) && + (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($INPUT->server->str('SERVER_SOFTWARE')), $matches)) && $matches[1] < 6 ) { header('Refresh: 0;url='.$url); -- cgit v1.2.3 From 30f6ec4bf42de282d69f87494819f0599a1fae82 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Mon, 10 Mar 2014 23:58:18 +0100 Subject: update usage in userlink --- inc/common.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 143ad8923..d971986df 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1475,6 +1475,8 @@ function userinfo($username = null) { global $conf, $INFO; /** @var DokuWiki_Auth_Plugin $auth */ global $auth; + /** @var Input $INPUT */ + global $INPUT; // prepare initial event data $data = array( @@ -1493,8 +1495,8 @@ function userinfo($username = null) { 'userinfo' => '' ); if($username === null) { - $data['username'] = $username = $_SERVER['REMOTE_USER']; - $data['name'] = '' . hsc($INFO['userinfo']['name']) . ' (' . hsc($_SERVER['REMOTE_USER']) . ')'; + $data['username'] = $username = $INPUT->server->str('REMOTE_USER'); + $data['name'] = '' . hsc($INFO['userinfo']['name']) . ' (' . hsc($INPUT->server->str('REMOTE_USER')) . ')'; } $evt = new Doku_Event('COMMON_USER_LINK', $data); -- cgit v1.2.3 From 533772e1d092bc1b1326f7fe5a31091b58bf9030 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 11 Mar 2014 00:00:50 +0100 Subject: declare more clear, before used as ref --- inc/common.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index d971986df..6e7142f0e 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1541,6 +1541,7 @@ function userinfo($username = null) { $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) { -- cgit v1.2.3 From 15f3bc49ed925ccb7c04299e9f614b0a1b739b13 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Fri, 14 Mar 2014 18:42:25 +0100 Subject: enable editorinfo and userinfo to return plain text names --- inc/common.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 6e7142f0e..f0c935c0c 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1457,21 +1457,26 @@ 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 text of formatted user name + * * @author Andy Webber */ -function editorinfo($username) { - return userinfo($username); +function editorinfo($username, $textonly = false) { + return userinfo($username, $textonly); } /** * 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 + * @param bool $textonly true returns only plain text, true allows returning html + * @return string html or text of formatted user name * * @triggers COMMON_USER_LINK */ -function userinfo($username = null) { +function userinfo($username = null, $textonly = false) { global $conf, $INFO; /** @var DokuWiki_Auth_Plugin $auth */ global $auth; @@ -1492,25 +1497,30 @@ function userinfo($username = null) { 'title' => '', 'class' => '' ), - 'userinfo' => '' + 'userinfo' => '', // formatted user name as will be returned + 'textonly' => $textonly ); if($username === null) { $data['username'] = $username = $INPUT->server->str('REMOTE_USER'); - $data['name'] = '' . hsc($INFO['userinfo']['name']) . ' (' . hsc($INPUT->server->str('REMOTE_USER')) . ')'; + if($textonly){ + $data['name'] = $INFO['userinfo']['name']. ' (' . $INPUT->server->str('REMOTE_USER') . ')'; + }else { + $data['name'] = '' . hsc($INFO['userinfo']['name']) . ' (' . hsc($INPUT->server->str('REMOTE_USER')) . ')'; + } } $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']); + $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'] = hsc($info['name']); + $data['name'] = $textonly ? $info['name'] : hsc($info['name']); break; case 'email': case 'email_link': @@ -1524,7 +1534,7 @@ function userinfo($username = null) { /** @var Doku_Renderer_xhtml $xhtml_renderer */ static $xhtml_renderer = null; - if($data['link'] !== false && empty($data['link']['url'])) { + if(!$data['textonly'] && empty($data['link']['url'])) { if(in_array($conf['showuseras'], array('email_link', 'username_link'))) { if(!isset($info)) { @@ -1554,15 +1564,15 @@ function userinfo($username = null) { } } } else { - $data['link'] = false; + $data['textonly'] = true; } } else { - $data['link'] = false; + $data['textonly'] = true; } } - if($data['link'] === false) { + if($data['textonly']) { $data['userinfo'] = $data['name']; } else { $data['link']['name'] = $data['name']; -- cgit v1.2.3 From f8fb2d1811251304687b805a60b489f63cb5c4fb Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 15 Mar 2014 21:29:33 +0100 Subject: strip sourcemaps in CSS and JS #601 source maps are invalid for our dispatched sources and may even cause problems. this makes sure any sourcemap declarations are stripped from the output --- inc/common.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 9fbebde94..5aacf6355 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1675,4 +1675,13 @@ function set_doku_pref($pref, $val) { } } +/** + * Strips source mapping declarations from given text #601 + * + * @param &string $text reference to the CSS or JavaScript code to clean + */ +function stripsourcemaps(&$text){ + $text = preg_replace('/^(\/\/|\/\*)[@#]\s+sourceMappingURL=.*?(\*\/)?$/im', '\\1\\2', $text); +} + //Setup VIM: ex: et ts=2 : -- cgit v1.2.3 From c0953023fdf442f13e6c27b7bd70dcde61243e88 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sun, 16 Mar 2014 21:00:06 +0100 Subject: improve phpdocs editorinfo() --- inc/common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index f0c935c0c..14d4a9d79 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1459,7 +1459,7 @@ function shorten($keep, $short, $max, $min = 9, $char = '…') { * * @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 text of formatted user name + * @return string html or plain text(not escaped) of formatted user name * * @author Andy Webber */ @@ -1472,7 +1472,7 @@ function editorinfo($username, $textonly = false) { * * @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 text of formatted user name + * @return string html or plain text(not escaped) of formatted user name * * @triggers COMMON_USER_LINK */ -- cgit v1.2.3 From cd4635ee7f07ae17e1b2a58d8d9e6620ddb077ef Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sun, 16 Mar 2014 21:10:43 +0100 Subject: Rename userinfo() to userlink() --- inc/common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 14d4a9d79..eef160122 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1464,7 +1464,7 @@ function shorten($keep, $short, $max, $min = 9, $char = '…') { * @author Andy Webber */ function editorinfo($username, $textonly = false) { - return userinfo($username, $textonly); + return userlink($username, $textonly); } /** @@ -1476,7 +1476,7 @@ function editorinfo($username, $textonly = false) { * * @triggers COMMON_USER_LINK */ -function userinfo($username = null, $textonly = false) { +function userlink($username = null, $textonly = false) { global $conf, $INFO; /** @var DokuWiki_Auth_Plugin $auth */ global $auth; -- cgit v1.2.3 From 4d5fc927eace8f4208895cd309d23fc9025dbb6b Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sun, 16 Mar 2014 21:13:27 +0100 Subject: use more consistent names --- inc/common.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index eef160122..5164d4ac0 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1497,7 +1497,7 @@ function userlink($username = null, $textonly = false) { 'title' => '', 'class' => '' ), - 'userinfo' => '', // formatted user name as will be returned + 'userlink' => '', // formatted user name as will be returned 'textonly' => $textonly ); if($username === null) { @@ -1573,19 +1573,19 @@ function userlink($username = null, $textonly = false) { } if($data['textonly']) { - $data['userinfo'] = $data['name']; + $data['userlink'] = $data['name']; } else { $data['link']['name'] = $data['name']; if(is_null($xhtml_renderer)) { $xhtml_renderer = p_get_renderer('xhtml'); } - $data['userinfo'] = $xhtml_renderer->_formatLink($data['link']); + $data['userlink'] = $xhtml_renderer->_formatLink($data['link']); } } $evt->advise_after(); unset($evt); - return $data['userinfo']; + return $data['userlink']; } /** -- cgit v1.2.3