Emit less E_NOTICEs and E_STRICTs

Changes of behaviour are:
  * Allow the user name, title & description \e2\80\9c0\e2\80\9d
  * Default to Port 443 if using HTTPS
  * Set $INFO['isadmin'] and $INFO['ismanager'] to \e2\80\9cfalse\e2\80\9d even if no user is
    logged in
  * Do not pass empty fragment field in the event data for event
    ACTION_SHOW_REDIRECT
  * Handle chunked encoding in HTTPClient

darcs-hash:20091104100115-e4919-5cf6397d4a457e3f98a8ca49fbdab03f2147721d.gz
This commit is contained in:
Adrian Lang 2009-11-04 11:01:15 +01:00
parent 1378fb56f6
commit c66972f2cb
17 changed files with 98 additions and 83 deletions

View File

@ -69,7 +69,8 @@ if ($conf['breadcrumbs']) breadcrumbs();
// check upstream
checkUpdateMessages();
trigger_event('DOKUWIKI_STARTED',$tmp=array());
$tmp = array(); // No event data
trigger_event('DOKUWIKI_STARTED',$tmp);
//close session
session_write_close();
@ -77,6 +78,7 @@ session_write_close();
//do the work
act_dispatch($ACT);
trigger_event('DOKUWIKI_DONE', $tmp=array());
$tmp = array(); // No event data
trigger_event('DOKUWIKI_DONE', $tmp);
// xdebug_dump_function_profile(1);

View File

@ -198,8 +198,8 @@ class HTTPClient {
if(empty($path)) $path = '/';
if(!empty($uri['query'])) $path .= '?'.$uri['query'];
$port = $uri['port'];
if($uri['user']) $this->user = $uri['user'];
if($uri['pass']) $this->pass = $uri['pass'];
if(isset($uri['user'])) $this->user = $uri['user'];
if(isset($uri['pass'])) $this->pass = $uri['pass'];
// proxy setup
if($this->proxy_host){
@ -366,7 +366,7 @@ class HTTPClient {
//read body (with chunked encoding if needed)
$r_body = '';
if(preg_match('/transfer\-(en)?coding:\s*chunked\r\n/i',$r_header)){
if(preg_match('/transfer\-(en)?coding:\s*chunked\r\n/i',$r_headers)){
do {
unset($chunk_size);
do {
@ -416,7 +416,8 @@ class HTTPClient {
else
break;
}
if($this->resp_headers['content-length'] && !$this->resp_headers['transfer-encoding'] &&
if(isset($this->resp_headers['content-length']) &&
!isset($this->resp_headers['transfer-encoding']) &&
$this->resp_headers['content-length'] == $r_size){
// we read the content-length, finish here
break;
@ -429,7 +430,9 @@ class HTTPClient {
fclose($socket);
// decode gzip if needed
if($this->resp_headers['content-encoding'] == 'gzip' && strlen($r_body) > 10 && substr($r_body,0,3)=="\x1f\x8b\x08"){
if(isset($this->resp_headers['content-encoding']) &&
$this->resp_headers['content-encoding'] == 'gzip' &&
strlen($r_body) > 10 && substr($r_body,0,3)=="\x1f\x8b\x08"){
$this->resp_body = @gzinflate(substr($r_body, 10));
}else{
$this->resp_body = $r_body;
@ -513,12 +516,12 @@ class HTTPClient {
* @author Andreas Goetz <cpuidle@gmx.de>
*/
function _getCookies(){
$headers = '';
foreach ($this->cookies as $key => $val){
if ($headers) $headers .= '; ';
$headers .= $key.'='.$val;
$headers .= "$key=$val; ";
}
if ($headers) $headers = "Cookie: $headers".HTTP_NL;
$headers = substr($headers, 0, -2);
if ($headers !== '') $headers = "Cookie: $headers".HTTP_NL;
return $headers;
}

View File

@ -387,23 +387,22 @@ function act_redirect($id,$preact){
session_write_close();
}
//get section name when coming from section edit
if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){
$check = false;
$title = sectionID($match[0],$check);
}
$opts = array(
'id' => $id,
'fragment' => $title,
'preact' => $preact
);
//get section name when coming from section edit
if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){
$check = false; //Byref
$opts['fragment'] = sectionID($match[0], $check);
}
trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute');
}
function act_redirect_execute($opts){
$go = wl($opts['id'],'',true);
if($opts['fragment']) $go .= '#'.$opts['fragment'];
if(isset($opts['fragment'])) $go .= '#'.$opts['fragment'];
//show it
send_redirect($go);
@ -419,7 +418,7 @@ function act_auth($act){
global $INFO;
//already logged in?
if($_SERVER['REMOTE_USER'] && $act=='login'){
if(isset($_SERVER['REMOTE_USER']) && $act=='login'){
return 'show';
}

View File

@ -74,7 +74,7 @@ if($conf['useacl']){
$_REQUEST['http_credentials'] = true;
}
if($_REQUEST['authtok']){
if(isset($_REQUEST['authtok'])){
// when an authentication token is given, trust the session
auth_validateToken($_REQUEST['authtok']);
}elseif(!is_null($auth) && $auth->canDo('external')){
@ -336,7 +336,13 @@ function auth_ismanager($user=null,$groups=null,$adminonly=false){
global $USERINFO;
if(!$conf['useacl']) return false;
if(is_null($user)) $user = $_SERVER['REMOTE_USER'];
if(is_null($user)) {
if (!isset($_SERVER['REMOTE_USER'])) {
return false;
} else {
$user = $_SERVER['REMOTE_USER'];
}
}
if(is_null($groups)) $groups = (array) $USERINFO['grps'];
$user = auth_nameencode($user);
@ -1019,7 +1025,7 @@ function auth_setCookie($user,$pass,$sticky) {
// set cookie
$cookie = base64_encode($user).'|'.((int) $sticky).'|'.base64_encode($pass);
if($sticky) $time = time()+60*60*24*365; //one year
$time = $sticky ? (time()+60*60*24*365) : 0; //one year
if (version_compare(PHP_VERSION, '5.2.0', '>')) {
setcookie(DOKU_COOKIE,$cookie,$time,DOKU_REL,'',($conf['securecookie'] && is_ssl()),true);
}else{
@ -1039,6 +1045,9 @@ function auth_setCookie($user,$pass,$sticky) {
* @returns array
*/
function auth_getCookie(){
if (!isset($_COOKIE[DOKU_COOKIE])) {
return array(null, null, null);
}
list($user,$sticky,$pass) = explode('|',$_COOKIE[DOKU_COOKIE],3);
$sticky = (bool) $sticky;
$pass = base64_decode($pass);

View File

@ -278,7 +278,7 @@ class cache_instructions extends cache_parser {
parent::cache_parser($id, $file, 'i');
}
function retrieveCache() {
function retrieveCache($clean=true) {
$contents = io_readFile($this->cache, false);
return !empty($contents) ? unserialize($contents) : array();
}

View File

@ -382,7 +382,7 @@ function getRevisionInfo($id, $rev, $chunk_size=8192) {
*
* For efficiency, the log lines are parsed and cached for later
* calls to getRevisionInfo. Large changelog files are read
* backwards in chunks untill the requested number of changelog
* backwards in chunks until the requested number of changelog
* lines are recieved.
*
* @author Ben Coburn <btcoburn@silicodon.net>

View File

@ -111,16 +111,16 @@ function pageinfo(){
$info['id'] = $ID;
$info['rev'] = $REV;
if($_SERVER['REMOTE_USER']){
// set info about manager/admin status.
$info['isadmin'] = false;
$info['ismanager'] = false;
if(isset($_SERVER['REMOTE_USER'])){
$info['userinfo'] = $USERINFO;
$info['perm'] = auth_quickaclcheck($ID);
$info['subscribed'] = is_subscribed($ID,$_SERVER['REMOTE_USER'],false);
$info['subscribedns'] = is_subscribed($ID,$_SERVER['REMOTE_USER'],true);
$info['client'] = $_SERVER['REMOTE_USER'];
// set info about manager/admin status
$info['isadmin'] = false;
$info['ismanager'] = false;
if($info['perm'] == AUTH_ADMIN){
$info['isadmin'] = true;
$info['ismanager'] = true;
@ -275,12 +275,9 @@ function breadcrumbs(){
global $ID;
global $ACT;
global $conf;
$crumbs = $_SESSION[DOKU_COOKIE]['bc'];
//first visit?
if (!is_array($crumbs)){
$crumbs = array();
}
$crumbs = isset($_SESSION[DOKU_COOKIE]['bc']) ? $_SESSION[DOKU_COOKIE]['bc'] : array();
//we only save on show and existing wiki documents
$file = wikiFN($ID);
if($ACT != 'show' || !@file_exists($file)){
@ -1130,11 +1127,14 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
* @author Todd Augsburger <todd@rollerorgans.com>
*/
function getGoogleQuery(){
if (!isset($_SERVER['HTTP_REFERER'])) {
return '';
}
$url = parse_url($_SERVER['HTTP_REFERER']);
if(!$url) return '';
$query = array();
parse_str($url['query'],$query);
$q = '';
if(isset($query['q']))
$q = $query['q']; // google, live/msn, aol, ask, altavista, alltheweb, gigablast
elseif(isset($query['p']))
@ -1144,7 +1144,7 @@ function getGoogleQuery(){
elseif(preg_match("#a9\.com#i",$url['host'])) // a9
$q = urldecode(ltrim($url['path'],'/'));
if(!$q) return '';
if($q === '') return '';
$q = preg_split('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$q,-1,PREG_SPLIT_NO_EMPTY);
return $q;
}
@ -1403,7 +1403,7 @@ function preg_quote_cb($string){
/**
* Shorten a given string by removing data from the middle
*
* You can give the string in two parts, teh first part $keep
* You can give the string in two parts, the first part $keep
* will never be shortened. The second part $short will be cut
* in the middle to shorten but only if at least $min chars are
* left to display it. Otherwise it will be left off.

View File

@ -1481,7 +1481,7 @@ function html_TOC($toc){
* Callback for html_buildlist
*/
function html_list_toc($item){
if($item['hid']){
if(isset($item['hid'])){
$link = '#'.$item['hid'];
}else{
$link = $item['link'];

View File

@ -56,7 +56,7 @@ function http_conditionalRequest($timestamp){
header('HTTP/1.0 304 Not Modified');
// don't produce output, even if compression is on
ob_end_clean();
@ob_end_clean();
exit;
}

View File

@ -74,7 +74,7 @@ function idx_saveIndex($pre, $wlen, &$idx){
fwrite($fh,$line);
}
fclose($fh);
if($conf['fperm']) chmod($fn.'.tmp', $conf['fperm']);
if(isset($conf['fperm'])) chmod($fn.'.tmp', $conf['fperm']);
io_rename($fn.'.tmp', $fn.'.idx');
return true;
}
@ -574,12 +574,16 @@ function idx_lookup($words){
// merge found pages into final result array
$final = array();
foreach(array_keys($result) as $word){
foreach($result as $word => $res){
$final[$word] = array();
foreach($result[$word] as $wid){
foreach($res as $wid){
$hits = &$docs[$wid];
foreach ($hits as $hitkey => $hitcnt) {
$final[$word][$hitkey] = $hitcnt + $final[$word][$hitkey];
if (!isset($final[$word][$hitkey])) {
$final[$word][$hitkey] = $hitcnt;
} else {
$final[$word][$hitkey] += $hitcnt;
}
}
}
}

View File

@ -219,7 +219,7 @@ if (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
$_REQUEST = array_merge($_GET,$_POST);
// we don't want a purge URL to be digged
if($_REQUEST['purge'] && $_SERVER['HTTP_REFERER']) unset($_REQUEST['purge']);
if(isset($_REQUEST['purge']) && $_SERVER['HTTP_REFERER']) unset($_REQUEST['purge']);
// disable gzip if not available
if($conf['compression'] == 'bz2' && !function_exists('bzopen')){
@ -413,8 +413,8 @@ function getBaseURL($abs=null){
$dir = str_replace('\\','/',$dir); // bugfix for weird WIN behaviour
$dir = preg_replace('#//+#','/',"/$dir/"); // ensure leading and trailing slashes
//handle script in lib/exe dir
$dir = preg_replace('!lib/exe/$!','',$dir);
//handle script in lib/exe dir
$dir = preg_replace('!lib/exe/$!','',$dir);
//handle script in lib/plugins dir
$dir = preg_replace('!lib/plugins/.*$!','',$dir);
@ -426,23 +426,27 @@ function getBaseURL($abs=null){
if($conf['baseurl']) return rtrim($conf['baseurl'],'/').$dir;
//split hostheader into host and port
list($host,$port) = explode(':',$_SERVER['HTTP_HOST']);
if(!$port) $port = $_SERVER['SERVER_PORT'];
if(!$port) $port = 80;
$addr = explode(':',$_SERVER['HTTP_HOST']);
$host = $addr[0];
$port = '';
if (isset($addr[1])) {
$port = $addr[1];
} elseif (isset($_SERVER['SERVER_PORT'])) {
$port = $_SERVER['SERVER_PORT'];
}
if(!is_ssl()){
$proto = 'http://';
if ($port == '80') {
$port='';
$port = '';
}
}else{
$proto = 'https://';
if ($port == '443') {
$port='';
$port = '';
}
}
if($port) $port = ':'.$port;
if($port !== '') $port = ':'.$port;
return $proto.$host.$port.$dir;
}
@ -456,7 +460,8 @@ function getBaseURL($abs=null){
* @returns bool true when SSL is active
*/
function is_ssl(){
if (preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){
if (!isset($_SERVER['HTTPS']) ||
preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){
return false;
}else{
return true;

View File

@ -58,7 +58,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
// store internal info in metadata (notoc,nocache)
$this->meta['internal'] = $this->info;
if (!$this->meta['description']['abstract']){
if (!isset($this->meta['description']['abstract'])){
// cut off too long abstracts
$this->doc = trim($this->doc);
if (strlen($this->doc) > 500)
@ -91,7 +91,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
}
function header($text, $level, $pos) {
if (!$this->meta['title']) $this->meta['title'] = $text;
if (!isset($this->meta['title'])) $this->meta['title'] = $text;
// add the header to the TOC
$hid = $this->_headerToLink($text,'true');
@ -227,7 +227,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
if ($this->capture) $this->doc .= $text;
}
function file($text){
function file($text, $lang = null, $file = null){
if ($this->capture){
$this->doc .= DOKU_LF.$text;
if (strlen($this->doc) > 250) $this->capture = false;
@ -247,7 +247,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
}
}
function code($text, $language = NULL){
function code($text, $language = NULL, $file = null){
if ($this->capture){
$this->doc .= DOKU_LF.$text;
if (strlen($this->doc) > 250) $this->capture = false;

View File

@ -80,7 +80,7 @@ function tpl_content_core(){
html_search();
break;
case 'revisions':
$first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
$first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
html_revisions($first);
break;
case 'diff':
@ -517,7 +517,7 @@ function tpl_button($type,$return=false){
break;
case 'login':
if($conf['useacl'] && $auth){
if($_SERVER['REMOTE_USER']){
if(isset($_SERVER['REMOTE_USER'])){
$out .= html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken()));
}else{
$out .= html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken()));
@ -567,7 +567,7 @@ function tpl_button($type,$return=false){
$out .= html_btn('backlink',$ID,'',array('do' => 'backlink'));
break;
case 'profile':
if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $auth &&
if($conf['useacl'] && isset($_SERVER['REMOTE_USER']) && $auth &&
$auth->canDo('Profile') && ($ACT!='profile')){
$out .= html_btn('profile',$ID,'',array('do' => 'profile'));
}
@ -927,7 +927,7 @@ function tpl_youarehere($sep=' &raquo; '){
function tpl_userinfo(){
global $lang;
global $INFO;
if($_SERVER['REMOTE_USER']){
if(isset($_SERVER['REMOTE_USER'])){
print $lang['loggedinas'].': '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')';
return true;
}
@ -1103,7 +1103,7 @@ function tpl_img($maxwidth=0,$maxheight=0){
/**
* This function inserts a 1x1 pixel gif which in reality
* is the inexer function.
* is the indexer function.
*
* Should be called somewhere at the very end of the main.php
* template
@ -1375,7 +1375,7 @@ function tpl_license($img='badge',$imgonly=false,$return=false){
if(!$imgonly) {
$out .= $lang['license'];
$out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"';
if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"';
$out .= '>'.$lic['name'].'</a>';
}
$out .= '</div>';

View File

@ -485,7 +485,7 @@ function langsel(){
}
/**
* Print gloabl error array
* Print global error array
*
* @author Andreas Gohr <andi@splitbrain.org>
*/

View File

@ -32,15 +32,10 @@ if(!defined('SIMPLE_TEST')){
function css_out(){
global $conf;
global $lang;
switch ($_REQUEST['s']) {
case 'all':
case 'print':
case 'feed':
$style = $_REQUEST['s'];
break;
default:
$style = '';
break;
$style = '';
if (isset($_REQUEST['s']) &&
in_array($_REQUEST['s'], array('all', 'print', 'feed'))) {
$style = $_REQUEST['s'];
}
$tpl = trim(preg_replace('/[^\w-]+/','',$_REQUEST['t']));
@ -152,7 +147,7 @@ function css_out(){
function css_cacheok($cache,$files,$tplinc){
global $config_cascade;
if($_REQUEST['purge']) return false; //support purge request
if(isset($_REQUEST['purge'])) return false; //support purge request
$ctime = @filemtime($cache);
if(!$ctime) return false; //There is no cache

View File

@ -20,20 +20,18 @@ define('INDEXER_VERSION', 2);
@ignore_user_abort(true);
// check if user abort worked, if yes send output early
if(@ignore_user_abort() && !$conf['broken_iua']){
$defer = !@ignore_user_abort() || $conf['broken_iua'];
if(!$defer){
sendGIF(); // send gif
$defer = false;
}else{
$defer = true;
}
$ID = cleanID($_REQUEST['id']);
// Catch any possible output (e.g. errors)
if(!$_REQUEST['debug']) ob_start();
if(!isset($_REQUEST['debug'])) ob_start();
// run one of the jobs
$tmp = array();
$tmp = array(); // No event data
$evt = new Doku_Event('INDEXER_TASKS_RUN', $tmp);
if ($evt->advise_before()) {
runIndexer() or
@ -45,7 +43,7 @@ if ($evt->advise_before()) {
}
if($defer) sendGIF();
if(!$_REQUEST['debug']) ob_end_clean();
if(!isset($_REQUEST['debug'])) ob_end_clean();
exit;
// --------------------------------------------------------------------
@ -358,7 +356,7 @@ function date_iso8601($int_date) {
* @author Harry Fuecks <fuecks@gmail.com>
*/
function sendGIF(){
if($_REQUEST['debug']){
if(isset($_REQUEST['debug'])){
header('Content-Type: text/plain');
return;
}

View File

@ -179,7 +179,7 @@ function js_load($file){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function js_cacheok($cache,$files){
if($_REQUEST['purge']) return false; //support purge request
if(isset($_REQUEST['purge'])) return false; //support purge request
$ctime = @filemtime($cache);
if(!$ctime) return false; //There is no cache