Skip to content

Commit

Permalink
Merge pull request #588 from splitbrain/purge_E_ALL
Browse files Browse the repository at this point in the history
Purge error log messages to support use of E_ALL
  • Loading branch information
splitbrain committed Mar 8, 2014
2 parents 9b50ec5 + 49f299d commit d27c0c1
Show file tree
Hide file tree
Showing 28 changed files with 313 additions and 162 deletions.
3 changes: 3 additions & 0 deletions _test/core/DokuWikiTest.php
Expand Up @@ -115,5 +115,8 @@ public function setUp() {
// reload language
$local = $conf['lang'];
trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true);

global $INPUT;
$INPUT = new Input();
}
}
18 changes: 18 additions & 0 deletions inc/Input.class.php
Expand Up @@ -15,6 +15,8 @@ class Input {
public $post;
/** @var GetInput Access $_GET parameters */
public $get;
/** @var ServerInput Access $_SERVER parameters */
public $server;

protected $access;

Expand All @@ -25,6 +27,7 @@ function __construct() {
$this->access = &$_REQUEST;
$this->post = new PostInput();
$this->get = new GetInput();
$this->server = new ServerInput();
}

/**
Expand Down Expand Up @@ -260,3 +263,18 @@ public function set($name, $value) {
$_REQUEST[$name] = $value;
}
}

/**
* Internal class used for $_SERVER access in Input class
*/
class ServerInput extends Input {
protected $access;

/**
* Initialize the $access array, remove subclass members
*/
function __construct() {
$this->access = &$_SERVER;
}

}
3 changes: 2 additions & 1 deletion inc/JpegMeta.php
Expand Up @@ -2929,7 +2929,8 @@ function & _getFixedString(&$data, $pos, $length = -1) {
$length = strlen($data) - $pos;
}

return substr($data, $pos, $length);
$rv = substr($data, $pos, $length);
return $rv;
}

/*************************************************************/
Expand Down
15 changes: 10 additions & 5 deletions inc/Mailer.class.php
Expand Up @@ -39,6 +39,8 @@ class Mailer {
*/
public function __construct() {
global $conf;
/* @var Input $INPUT */
global $INPUT;

$server = parse_url(DOKU_URL, PHP_URL_HOST);
if(strpos($server,'.') === false) $server = $server.'.localhost';
Expand All @@ -53,7 +55,7 @@ public function __construct() {

// add some default headers for mailfiltering FS#2247
$this->setHeader('X-Mailer', 'DokuWiki');
$this->setHeader('X-DokuWiki-User', $_SERVER['REMOTE_USER']);
$this->setHeader('X-DokuWiki-User', $INPUT->server->str('REMOTE_USER'));
$this->setHeader('X-DokuWiki-Title', $conf['title']);
$this->setHeader('X-DokuWiki-Server', $server);
$this->setHeader('X-Auto-Response-Suppress', 'OOF');
Expand Down Expand Up @@ -181,6 +183,9 @@ public function setParameters($param) {
public function setBody($text, $textrep = null, $htmlrep = null, $html = null, $wrap = true) {
global $INFO;
global $conf;
/* @var Input $INPUT */
global $INPUT;

$htmlrep = (array)$htmlrep;
$textrep = (array)$textrep;

Expand Down Expand Up @@ -218,24 +223,24 @@ public function setBody($text, $textrep = null, $htmlrep = null, $html = null, $
$cip = gethostsbyaddrs($ip);
$trep = array(
'DATE' => dformat(),
'BROWSER' => $_SERVER['HTTP_USER_AGENT'],
'BROWSER' => $INPUT->server->str('HTTP_USER_AGENT'),
'IPADDRESS' => $ip,
'HOSTNAME' => $cip,
'TITLE' => $conf['title'],
'DOKUWIKIURL' => DOKU_URL,
'USER' => $_SERVER['REMOTE_USER'],
'USER' => $INPUT->server->str('REMOTE_USER'),
'NAME' => $INFO['userinfo']['name'],
'MAIL' => $INFO['userinfo']['mail'],
);
$trep = array_merge($trep, (array)$textrep);
$hrep = array(
'DATE' => '<i>'.hsc(dformat()).'</i>',
'BROWSER' => hsc($_SERVER['HTTP_USER_AGENT']),
'BROWSER' => hsc($INPUT->server->str('HTTP_USER_AGENT')),
'IPADDRESS' => '<code>'.hsc($ip).'</code>',
'HOSTNAME' => '<code>'.hsc($cip).'</code>',
'TITLE' => hsc($conf['title']),
'DOKUWIKIURL' => '<a href="'.DOKU_URL.'">'.DOKU_URL.'</a>',
'USER' => hsc($_SERVER['REMOTE_USER']),
'USER' => hsc($INPUT->server->str('REMOTE_USER')),
'NAME' => hsc($INFO['userinfo']['name']),
'MAIL' => '<a href="mailto:"'.hsc($INFO['userinfo']['mail']).'">'.
hsc($INFO['userinfo']['mail']).'</a>',
Expand Down
29 changes: 19 additions & 10 deletions inc/actions.php
Expand Up @@ -20,6 +20,7 @@ function act_dispatch(){
global $ID;
global $INFO;
global $QUERY;
/* @var Input $INPUT */
global $INPUT;
global $lang;
global $conf;
Expand Down Expand Up @@ -94,7 +95,7 @@ function act_dispatch(){

// user profile changes
if (in_array($ACT, array('profile','profile_delete'))) {
if(!$_SERVER['REMOTE_USER']) {
if(!$INPUT->server->str('REMOTE_USER')) {
$ACT = 'login';
} else {
switch ($ACT) {
Expand Down Expand Up @@ -190,7 +191,7 @@ function act_dispatch(){
unset($evt);

// when action 'show', the intial not 'show' and POST, do a redirect
if($ACT == 'show' && $preact != 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
if($ACT == 'show' && $preact != 'show' && strtolower($INPUT->server->str('REQUEST_METHOD')) == 'post'){
act_redirect($ID,$preact);
}

Expand Down Expand Up @@ -414,6 +415,8 @@ function act_revert($act){
global $ID;
global $REV;
global $lang;
/* @var Input $INPUT */
global $INPUT;
// FIXME $INFO['writable'] currently refers to the attic version
// global $INFO;
// if (!$INFO['writable']) {
Expand Down Expand Up @@ -445,7 +448,7 @@ function act_revert($act){
session_write_close();

// when done, show current page
$_SERVER['REQUEST_METHOD'] = 'post'; //should force a redirect
$INPUT->server->set('REQUEST_METHOD','post'); //should force a redirect
$REV = '';
return 'show';
}
Expand Down Expand Up @@ -493,17 +496,20 @@ function act_redirect_execute($opts){
function act_auth($act){
global $ID;
global $INFO;
/* @var Input $INPUT */
global $INPUT;

//already logged in?
if(isset($_SERVER['REMOTE_USER']) && $act=='login'){
if($INPUT->server->has('REMOTE_USER') && $act=='login'){
return 'show';
}

//handle logout
if($act=='logout'){
$lockedby = checklock($ID); //page still locked?
if($lockedby == $_SERVER['REMOTE_USER'])
if($lockedby == $INPUT->server->str('REMOTE_USER')){
unlock($ID); //try to unlock
}

// do the logout stuff
auth_logoff();
Expand Down Expand Up @@ -719,10 +725,11 @@ function act_subscription($act){
global $lang;
global $INFO;
global $ID;
/* @var Input $INPUT */
global $INPUT;

// subcriptions work for logged in users only
if(!$_SERVER['REMOTE_USER']) return 'show';
if(!$INPUT->server->str('REMOTE_USER')) return 'show';

// get and preprocess data.
$params = array();
Expand All @@ -733,7 +740,7 @@ function act_subscription($act){
}

// any action given? if not just return and show the subscription page
if(!$params['action'] || !checkSecurityToken()) return $act;
if(empty($params['action']) || !checkSecurityToken()) return $act;

// Handle POST data, may throw exception.
trigger_event('ACTION_HANDLE_SUBSCRIBE', $params, 'subscription_handle_post');
Expand All @@ -745,9 +752,9 @@ function act_subscription($act){
// Perform action.
$sub = new Subscription();
if($action == 'unsubscribe'){
$ok = $sub->remove($target, $_SERVER['REMOTE_USER'], $style);
$ok = $sub->remove($target, $INPUT->server->str('REMOTE_USER'), $style);
}else{
$ok = $sub->add($target, $_SERVER['REMOTE_USER'], $style);
$ok = $sub->add($target, $INPUT->server->str('REMOTE_USER'), $style);
}

if($ok) {
Expand Down Expand Up @@ -776,6 +783,8 @@ function act_subscription($act){
function subscription_handle_post(&$params) {
global $INFO;
global $lang;
/* @var Input $INPUT */
global $INPUT;

// Get and validate parameters.
if (!isset($params['target'])) {
Expand Down Expand Up @@ -806,7 +815,7 @@ function subscription_handle_post(&$params) {
}
if ($is === false) {
throw new Exception(sprintf($lang['subscr_not_subscribed'],
$_SERVER['REMOTE_USER'],
$INPUT->server->str('REMOTE_USER'),
prettyprint_id($target)));
}
// subscription_set deletes a subscription if style = null.
Expand Down
54 changes: 35 additions & 19 deletions inc/auth.php
Expand Up @@ -131,6 +131,8 @@ function auth_setup() {
function auth_loadACL() {
global $config_cascade;
global $USERINFO;
/* @var Input $INPUT */
global $INPUT;

if(!is_readable($config_cascade['acl']['default'])) return array();

Expand All @@ -145,10 +147,10 @@ function auth_loadACL() {
// substitute user wildcard first (its 1:1)
if(strstr($line, '%USER%')){
// if user is not logged in, this ACL line is meaningless - skip it
if (!isset($_SERVER['REMOTE_USER'])) continue;
if (!$INPUT->server->has('REMOTE_USER')) continue;

$id = str_replace('%USER%',cleanID($_SERVER['REMOTE_USER']),$id);
$rest = str_replace('%USER%',auth_nameencode($_SERVER['REMOTE_USER']),$rest);
$id = str_replace('%USER%',cleanID($INPUT->server->str('REMOTE_USER')),$id);
$rest = str_replace('%USER%',auth_nameencode($INPUT->server->str('REMOTE_USER')),$rest);
}

// substitute group wildcard (its 1:m)
Expand Down Expand Up @@ -217,6 +219,8 @@ function auth_login($user, $pass, $sticky = false, $silent = false) {
global $lang;
/* @var DokuWiki_Auth_Plugin $auth */
global $auth;
/* @var Input $INPUT */
global $INPUT;

$sticky ? $sticky = true : $sticky = false; //sanity check

Expand All @@ -226,7 +230,7 @@ function auth_login($user, $pass, $sticky = false, $silent = false) {
//usual login
if($auth->checkPass($user, $pass)) {
// make logininfo globally available
$_SERVER['REMOTE_USER'] = $user;
$INPUT->server->set('REMOTE_USER', $user);
$secret = auth_cookiesalt(!$sticky, true); //bind non-sticky to session
auth_setCookie($user, auth_encrypt($pass, $secret), $sticky);
return true;
Expand All @@ -253,7 +257,7 @@ function auth_login($user, $pass, $sticky = false, $silent = false) {
) {

// he has session, cookie and browser right - let him in
$_SERVER['REMOTE_USER'] = $user;
$INPUT->server->set('REMOTE_USER', $user);
$USERINFO = $session['info']; //FIXME move all references to session
return true;
}
Expand Down Expand Up @@ -288,7 +292,10 @@ function auth_validateToken($token) {
}
// still here? trust the session data
global $USERINFO;
$_SERVER['REMOTE_USER'] = $_SESSION[DOKU_COOKIE]['auth']['user'];
/* @var Input $INPUT */
global $INPUT;

$INPUT->server->set('REMOTE_USER',$_SESSION[DOKU_COOKIE]['auth']['user']);
$USERINFO = $_SESSION[DOKU_COOKIE]['auth']['info'];
return true;
}
Expand Down Expand Up @@ -321,11 +328,14 @@ function auth_createToken() {
* @return string a MD5 sum of various browser headers
*/
function auth_browseruid() {
/* @var Input $INPUT */
global $INPUT;

$ip = clientIP(true);
$uid = '';
$uid .= $_SERVER['HTTP_USER_AGENT'];
$uid .= $_SERVER['HTTP_ACCEPT_ENCODING'];
$uid .= $_SERVER['HTTP_ACCEPT_CHARSET'];
$uid .= $INPUT->server->str('HTTP_USER_AGENT');
$uid .= $INPUT->server->str('HTTP_ACCEPT_ENCODING');
$uid .= $INPUT->server->str('HTTP_ACCEPT_CHARSET');
$uid .= substr($ip, 0, strpos($ip, '.'));
$uid = strtolower($uid);
return md5($uid);
Expand Down Expand Up @@ -511,6 +521,8 @@ function auth_logoff($keepbc = false) {
global $USERINFO;
/* @var DokuWiki_Auth_Plugin $auth */
global $auth;
/* @var Input $INPUT */
global $INPUT;

// make sure the session is writable (it usually is)
@session_start();
Expand All @@ -523,8 +535,7 @@ function auth_logoff($keepbc = false) {
unset($_SESSION[DOKU_COOKIE]['auth']['info']);
if(!$keepbc && isset($_SESSION[DOKU_COOKIE]['bc']))
unset($_SESSION[DOKU_COOKIE]['bc']);
if(isset($_SERVER['REMOTE_USER']))
unset($_SERVER['REMOTE_USER']);
$INPUT->server->remove('REMOTE_USER');
$USERINFO = null; //FIXME

$cookieDir = empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'];
Expand Down Expand Up @@ -553,13 +564,16 @@ function auth_ismanager($user = null, $groups = null, $adminonly = false) {
global $USERINFO;
/* @var DokuWiki_Auth_Plugin $auth */
global $auth;
/* @var Input $INPUT */
global $INPUT;


if(!$auth) return false;
if(is_null($user)) {
if(!isset($_SERVER['REMOTE_USER'])) {
if(!$INPUT->server->has('REMOTE_USER')) {
return false;
} else {
$user = $_SERVER['REMOTE_USER'];
$user = $INPUT->server->str('REMOTE_USER');
}
}
if(is_null($groups)) {
Expand Down Expand Up @@ -651,9 +665,11 @@ function auth_isMember($memberlist, $user, array $groups) {
function auth_quickaclcheck($id) {
global $conf;
global $USERINFO;
/* @var Input $INPUT */
global $INPUT;
# if no ACL is used always return upload rights
if(!$conf['useacl']) return AUTH_UPLOAD;
return auth_aclcheck($id, $_SERVER['REMOTE_USER'], $USERINFO['grps']);
return auth_aclcheck($id, $INPUT->server->str('REMOTE_USER'), $USERINFO['grps']);
}

/**
Expand Down Expand Up @@ -1058,18 +1074,18 @@ function updateprofile() {
}

if($conf['profileconfirm']) {
if(!$auth->checkPass($_SERVER['REMOTE_USER'], $INPUT->post->str('oldpass'))) {
if(!$auth->checkPass($INPUT->server->str('REMOTE_USER'), $INPUT->post->str('oldpass'))) {
msg($lang['badpassconfirm'], -1);
return false;
}
}

if($result = $auth->triggerUserMod('modify', array($_SERVER['REMOTE_USER'], $changes))) {
if($result = $auth->triggerUserMod('modify', array($INPUT->server->str('REMOTE_USER'), $changes))) {
// update cookie and session with the changed data
if($changes['pass']) {
list( /*user*/, $sticky, /*pass*/) = auth_getCookie();
$pass = auth_encrypt($changes['pass'], auth_cookiesalt(!$sticky, true));
auth_setCookie($_SERVER['REMOTE_USER'], $pass, (bool) $sticky);
auth_setCookie($INPUT->server->str('REMOTE_USER'), $pass, (bool) $sticky);
}
return true;
}
Expand Down Expand Up @@ -1105,13 +1121,13 @@ function auth_deleteprofile(){
}

if($conf['profileconfirm']) {
if(!$auth->checkPass($_SERVER['REMOTE_USER'], $INPUT->post->str('oldpass'))) {
if(!$auth->checkPass($INPUT->server->str('REMOTE_USER'), $INPUT->post->str('oldpass'))) {
msg($lang['badpassconfirm'], -1);
return false;
}
}

$deleted[] = $_SERVER['REMOTE_USER'];
$deleted[] = $INPUT->server->str('REMOTE_USER');
if($auth->triggerUserMod('delete', array($deleted))) {
// force and immediate logout including removing the sticky cookie
auth_logoff();
Expand Down

0 comments on commit d27c0c1

Please sign in to comment.