use $auth instanceof AuthPlugin instead of not null check

This commit is contained in:
Gerrit Uitslag 2023-09-01 01:10:48 +02:00
parent 4dc42f7f53
commit 6547cfc745
11 changed files with 44 additions and 33 deletions

View File

@ -448,7 +448,7 @@ function rss_buildItems(&$rss, &$data, $opt)
$item->authorEmail = $user . '@undisclosed.example.com';
// get real user name if configured
if ($conf['useacl'] && $auth) {
if ($conf['useacl'] && $auth instanceof AuthPlugin) {
$userInfo = $auth->getUserData($user);
if ($userInfo) {
switch ($conf['showuseras']) {

View File

@ -3,6 +3,7 @@
namespace dokuwiki\Action;
use dokuwiki\Action\Exception\ActionAclRequiredException;
use dokuwiki\Extension\AuthPlugin;
/**
* Class AbstractAclAction
@ -20,6 +21,6 @@ abstract class AbstractAclAction extends AbstractAction
global $conf;
global $auth;
if (!$conf['useacl']) throw new ActionAclRequiredException();
if (!$auth) throw new ActionAclRequiredException();
if (!$auth instanceof AuthPlugin) throw new ActionAclRequiredException();
}
}

View File

@ -1063,7 +1063,7 @@ class ApiCore
global $auth;
if (!$conf['useacl']) return 0;
if (!$auth) return 0;
if (!$auth instanceof AuthPlugin) return 0;
@session_start(); // reopen session for login
$ok = null;
@ -1094,7 +1094,7 @@ class ApiCore
global $conf;
global $auth;
if (!$conf['useacl']) return 0;
if (!$auth) return 0;
if (!$auth instanceof AuthPlugin) return 0;
auth_logoff();

View File

@ -53,8 +53,8 @@ function auth_setup()
}
}
if (!isset($auth) || !$auth) {
msg($lang['authtempfail'], -1);
if (!$auth instanceof AuthPlugin) {
msg($lang['authtempfail'].'ss', -1);
return false;
}
@ -92,7 +92,7 @@ function auth_setup()
}
$ok = null;
if (!is_null($auth) && $auth->canDo('external')) {
if ($auth instanceof AuthPlugin && $auth->canDo('external')) {
$ok = $auth->trustExternal($INPUT->str('u'), $INPUT->str('p'), $INPUT->bool('r'));
}
@ -222,7 +222,7 @@ function auth_login($user, $pass, $sticky = false, $silent = false)
/* @var Input $INPUT */
global $INPUT;
if (!$auth) return false;
if (!$auth instanceof AuthPlugin) return false;
if (!empty($user)) {
//usual login
@ -455,7 +455,9 @@ function auth_logoff($keepbc = false)
'samesite' => $conf['samesitecookie'] ?: null, // null means browser default
]);
if ($auth) $auth->logOff();
if ($auth instanceof AuthPlugin) {
$auth->logOff();
}
}
/**
@ -485,7 +487,7 @@ function auth_ismanager($user = null, $groups = null, $adminonly = false, $recac
global $INPUT;
if (!$auth) return false;
if (!$auth instanceof AuthPlugin) return false;
if (is_null($user)) {
if (!$INPUT->server->has('REMOTE_USER')) {
return false;
@ -556,7 +558,7 @@ function auth_isMember($memberlist, $user, array $groups)
{
/* @var AuthPlugin $auth */
global $auth;
if (!$auth) return false;
if (!$auth instanceof AuthPlugin) return false;
// clean user and groups
if (!$auth->isCaseSensitive()) {
@ -655,7 +657,7 @@ function auth_aclcheck_cb($data)
// if no ACL is used always return upload rights
if (!$conf['useacl']) return AUTH_UPLOAD;
if (!$auth) return AUTH_NONE;
if (!$auth instanceof AuthPlugin) return AUTH_NONE;
if (!is_array($AUTH_ACL)) return AUTH_NONE;
//make sure groups is an array
@ -870,7 +872,7 @@ function auth_sendPassword($user, $password)
global $lang;
/* @var AuthPlugin $auth */
global $auth;
if (!$auth) return false;
if (!$auth instanceof AuthPlugin) return false;
$user = $auth->cleanUser($user);
$userinfo = $auth->getUserData($user, false);
@ -1293,7 +1295,7 @@ function auth_setCookie($user, $pass, $sticky)
global $auth;
global $USERINFO;
if (!$auth) return false;
if (!$auth instanceof AuthPlugin) return false;
$USERINFO = $auth->getUserData($user);
// set cookie

View File

@ -1694,7 +1694,9 @@ function userlink($username = null, $textonly = false)
$evt = new Event('COMMON_USER_LINK', $data);
if ($evt->advise_before(true)) {
if (empty($data['name'])) {
if ($auth) $info = $auth->getUserData($username);
if ($auth instanceof AuthPlugin) {
$info = $auth->getUserData($username);
}
if ($conf['showuseras'] != 'loginname' && isset($info) && $info) {
switch ($conf['showuseras']) {
case 'username':
@ -1716,8 +1718,8 @@ function userlink($username = null, $textonly = false)
if (!$data['textonly'] && empty($data['link']['url'])) {
if (in_array($conf['showuseras'], ['email_link', 'username_link'])) {
if (!isset($info)) {
if ($auth) $info = $auth->getUserData($username);
if (!isset($info) && $auth instanceof AuthPlugin) {
$info = $auth->getUserData($username);
}
if (isset($info) && $info) {
if ($conf['showuseras'] == 'email_link') {

View File

@ -368,25 +368,25 @@ function actionOK($action)
// prepare disabled actions array and handle legacy options
$disabled = explode(',', $conf['disableactions']);
$disabled = array_map('trim', $disabled);
if ((isset($conf['openregister']) && !$conf['openregister']) || is_null($auth) || !$auth->canDo('addUser')) {
if ((isset($conf['openregister']) && !$conf['openregister']) || !$auth instanceof AuthPlugin || !$auth->canDo('addUser')) {
$disabled[] = 'register';
}
if ((isset($conf['resendpasswd']) && !$conf['resendpasswd']) || is_null($auth) || !$auth->canDo('modPass')) {
if ((isset($conf['resendpasswd']) && !$conf['resendpasswd']) || !$auth instanceof AuthPlugin || !$auth->canDo('modPass')) {
$disabled[] = 'resendpwd';
}
if ((isset($conf['subscribers']) && !$conf['subscribers']) || is_null($auth)) {
if ((isset($conf['subscribers']) && !$conf['subscribers']) || !$auth instanceof AuthPlugin) {
$disabled[] = 'subscribe';
}
if (is_null($auth) || !$auth->canDo('Profile')) {
if (!$auth instanceof AuthPlugin || !$auth->canDo('Profile')) {
$disabled[] = 'profile';
}
if (is_null($auth) || !$auth->canDo('delUser')) {
if (!$auth instanceof AuthPlugin || !$auth->canDo('delUser')) {
$disabled[] = 'profile_delete';
}
if (is_null($auth)) {
if (!$auth instanceof AuthPlugin) {
$disabled[] = 'login';
}
if (is_null($auth) || !$auth->canDo('logout')) {
if (!$auth instanceof AuthPlugin || !$auth->canDo('logout')) {
$disabled[] = 'logout';
}
$disabled = array_unique($disabled);

View File

@ -771,7 +771,7 @@ function html_debug()
echo $lang['encoding'];
echo '</pre>';
if ($auth) {
if ($auth instanceof AuthPlugin) {
echo '<b>Auth backend capabilities:</b><pre>';
foreach ($auth->getCapabilities() as $cando) {
echo ' ' . str_pad($cando, 16) . ' => ' . (int)$auth->canDo($cando) . DOKU_LF;

View File

@ -7,6 +7,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
use dokuwiki\Extension\AuthPlugin;
use dokuwiki\Extension\Event;
use dokuwiki\Utf8\PhpString;
use dokuwiki\Debug\DebugHelper;
@ -424,7 +425,7 @@ function info_msg_allowed($msg)
if (empty($msg['allow']) || ($msg['allow'] == MSG_PUBLIC)) return true;
// restricted msg, but no authentication
if (empty($auth)) return false;
if (!$auth instanceof AuthPlugin) return false;
switch ($msg['allow']) {
case MSG_USERS_ONLY:

View File

@ -1,5 +1,6 @@
<?php
use dokuwiki\Extension\AuthPlugin;
use dokuwiki\HTTP\DokuHTTPClient;
use dokuwiki\Extension\Event;
@ -217,7 +218,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
unset($list);
// user count
if ($auth && $auth->canDo('getUserCount')) {
if ($auth instanceof AuthPlugin && $auth->canDo('getUserCount')) {
$data['user_count'] = $auth->getUserCount();
}

View File

@ -46,7 +46,7 @@ class admin_plugin_usermanager extends AdminPlugin
$this->setupLocale();
if (!isset($auth)) {
if (!$auth instanceof AuthPlugin) {
$this->disabled = $this->lang['noauth'];
} elseif (!$auth->canDo('getUsers')) {
$this->disabled = $this->lang['nosupport'];
@ -358,7 +358,7 @@ class admin_plugin_usermanager extends AdminPlugin
{
/** @var AuthPlugin $auth */
global $auth;
if (!$auth || !$auth->canDo('getUsers')) {
if (!$auth instanceof AuthPlugin || !$auth->canDo('getUsers')) {
return false;
}
@ -912,13 +912,17 @@ class admin_plugin_usermanager extends AdminPlugin
$user[2] = $INPUT->str('username');
$user[3] = $INPUT->str('usermail');
$user[4] = explode(',', $INPUT->str('usergroups'));
$user[5] = $INPUT->str('userpass2'); // repeated password for confirmation
$user[5] = $INPUT->str('userpass2'); // repeated password for confirmation
$user[4] = array_map('trim', $user[4]);
if ($clean) $user[4] = array_map([$auth, 'cleanGroup'], $user[4]);
if ($clean) {
$user[4] = array_map([$auth, 'cleanGroup'], $user[4]);
}
$user[4] = array_filter($user[4]);
$user[4] = array_unique($user[4]);
if ($user[4] === []) $user[4] = null;
if ($user[4] === []) {
$user[4] = null;
}
return $user;
}

View File

@ -63,7 +63,7 @@ class cli_plugin_usermanager extends CLIPlugin
/** @var AuthPlugin $auth */
global $auth;
if (!isset($auth)) {
if (!$auth instanceof AuthPlugin) {
$this->error($this->getLang('noauth'));
return 1;
}