From f755f9abc6fe099a6bee2bdd4acda44baca5ea7a Mon Sep 17 00:00:00 2001 From: Christopher Smith <chris@jalakai.co.uk> Date: Sun, 7 Apr 2013 19:40:27 +0100 Subject: [PATCH] change nomenclature from 'show' to 'allow' (fn from canshow to allowed) --- inc/html.php | 2 +- inc/infoutils.php | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/inc/html.php b/inc/html.php index 09d1387bd..fb39fcb3c 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1297,7 +1297,7 @@ function html_msgarea(){ foreach($MSG as $msg){ $hash = md5($msg['msg']); if(isset($shown[$hash])) continue; // skip double messages - if(info_msg_canshow($msg)){ + if(info_msg_allowed($msg)){ print '<div class="'.$msg['lvl'].'">'; print $msg['msg']; print '</div>'; diff --git a/inc/infoutils.php b/inc/infoutils.php index da230da37..9fe5ee689 100644 --- a/inc/infoutils.php +++ b/inc/infoutils.php @@ -275,7 +275,7 @@ define('MSG_USERS_ONLY', 1); define('MSG_MANAGERS_ONLY',2); define('MSG_ADMINS_ONLY',4); -function msg($message,$lvl=0,$line='',$file='',$show=MSG_PUBLIC){ +function msg($message,$lvl=0,$line='',$file='',$allow=MSG_PUBLIC){ global $MSG, $MSG_shown; $errors[-1] = 'error'; $errors[0] = 'info'; @@ -285,7 +285,7 @@ function msg($message,$lvl=0,$line='',$file='',$show=MSG_PUBLIC){ if($line || $file) $message.=' ['.utf8_basename($file).':'.$line.']'; if(!isset($MSG)) $MSG = array(); - $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message, 'show' => $show); + $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message, 'allow' => $allow); if(isset($MSG_shown) || headers_sent()){ if(function_exists('html_msgarea')){ html_msgarea(); @@ -295,17 +295,26 @@ function msg($message,$lvl=0,$line='',$file='',$show=MSG_PUBLIC){ unset($GLOBALS['MSG']); } } - -function info_msg_canshow($msg){ +/** + * Determine whether the current user is allowed to view the message + * in the $msg data structure + * + * @param $msg array dokuwiki msg structure + * msg => string, the message + * lvl => int, level of the message (see msg() function) + * allow => int, flag used to determine who is allowed to see the message + * see MSG_* constants + */ +function info_msg_allowed($msg){ global $INFO, $auth; // is the message public? - everyone and anyone can see it - if (empty($msg['show']) || ($msg['show'] == MSG_PUBLIC)) return true; + if (empty($msg['allow']) || ($msg['allow'] == MSG_PUBLIC)) return true; // restricted msg, but no authentication if (empty($auth)) return false; - switch ($msg['show']){ + switch ($msg['allow']){ case MSG_USERS_ONLY: return !empty($INFO['userinfo']); @@ -316,7 +325,7 @@ function info_msg_canshow($msg){ return $INFO['isadmin']; default: - trigger_error('invalid msg show restriction. msg="'.$msg['msg'].'" show='.$msg['show'].'"', E_USER_WARNING); + trigger_error('invalid msg allow restriction. msg="'.$msg['msg'].'" allow='.$msg['allow'].'"', E_USER_WARNING); return $INFO['isadmin']; } -- GitLab