diff options
Diffstat (limited to 'lib/plugins/authplain/auth.php')
-rw-r--r-- | lib/plugins/authplain/auth.php | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/lib/plugins/authplain/auth.php b/lib/plugins/authplain/auth.php index e0c1b9291..370e6cfa0 100644 --- a/lib/plugins/authplain/auth.php +++ b/lib/plugins/authplain/auth.php @@ -1,5 +1,6 @@ <?php +use dokuwiki\Extension\AuthPlugin; use dokuwiki\Logger; use dokuwiki\Utf8\Sort; @@ -11,13 +12,13 @@ use dokuwiki\Utf8\Sort; * @author Chris Smith <chris@jalakai.co.uk> * @author Jan Schumann <js@schumann-it.com> */ -class auth_plugin_authplain extends DokuWiki_Auth_Plugin +class auth_plugin_authplain extends AuthPlugin { /** @var array user cache */ - protected $users = null; + protected $users; /** @var array filter pattern */ - protected $pattern = array(); + protected $pattern = []; /** @var bool safe version of preg_split */ protected $pregsplit_safe = false; @@ -90,7 +91,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin public function getUserData($user, $requireGroups = true) { if ($this->users === null) $this->loadUserData(); - return isset($this->users[$user]) ? $this->users[$user] : false; + return $this->users[$user] ?? false; } /** @@ -107,11 +108,11 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin */ protected function createUserLine($user, $pass, $name, $mail, $grps) { - $groups = join(',', $grps); - $userline = array($user, $pass, $name, $mail, $groups); + $groups = implode(',', $grps); + $userline = [$user, $pass, $name, $mail, $groups]; $userline = str_replace('\\', '\\\\', $userline); // escape \ as \\ $userline = str_replace(':', '\\:', $userline); // escape : as \: - $userline = join(':', $userline)."\n"; + $userline = implode(':', $userline) . "\n"; return $userline; } @@ -148,7 +149,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin $pass = auth_cryptPassword($pwd); // set default group if no groups specified - if (!is_array($grps)) $grps = array($conf['defaultgroup']); + if (!is_array($grps)) $grps = [$conf['defaultgroup']]; // prepare user line $userline = $this->createUserLine($user, $pass, $name, $mail, $grps); @@ -158,7 +159,12 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin return null; } - $this->users[$user] = compact('pass', 'name', 'mail', 'grps'); + $this->users[$user] = [ + 'pass' => $pass, + 'name' => $name, + 'mail' => $mail, + 'grps' => $grps + ]; return $pwd; } @@ -187,7 +193,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin return false; } - if (!is_array($changes) || !count($changes)) return true; + if (!is_array($changes) || $changes === []) return true; // update userinfo with new data, remembering to encrypt any password $newuser = $user; @@ -208,14 +214,14 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin $userinfo['grps'] ); - if (!io_replaceInFile($config_cascade['plainauth.users']['default'], '/^'.$user.':/', $userline, true)) { + if (!io_replaceInFile($config_cascade['plainauth.users']['default'], '/^' . $user . ':/', $userline, true)) { msg('There was an error modifying your user data. You may need to register again.', -1); // FIXME, io functions should be fail-safe so existing data isn't lost $ACT = 'register'; return false; } - if(isset($this->users[$user])) unset($this->users[$user]); + if (isset($this->users[$user])) unset($this->users[$user]); $this->users[$newuser] = $userinfo; return true; } @@ -231,11 +237,11 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { global $config_cascade; - if (!is_array($users) || empty($users)) return 0; + if (!is_array($users) || $users === []) return 0; if ($this->users === null) $this->loadUserData(); - $deleted = array(); + $deleted = []; foreach ($users as $user) { // don't delete protected users if (!empty($this->users[$user]['protected'])) { @@ -245,9 +251,9 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin if (isset($this->users[$user])) $deleted[] = preg_quote($user, '/'); } - if (empty($deleted)) return 0; + if ($deleted === []) return 0; - $pattern = '/^('.join('|', $deleted).'):/'; + $pattern = '/^(' . implode('|', $deleted) . '):/'; if (!io_deleteFromFile($config_cascade['plainauth.users']['default'], $pattern, true)) { msg($this->getLang('writefail'), -1); return 0; @@ -268,12 +274,12 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin * @param array $filter * @return int */ - public function getUserCount($filter = array()) + public function getUserCount($filter = []) { if ($this->users === null) $this->loadUserData(); - if (!count($filter)) return count($this->users); + if ($filter === []) return count($this->users); $count = 0; $this->constructPattern($filter); @@ -295,7 +301,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin * @param array $filter array of field/pattern pairs * @return array userinfo (refer getUserData for internal userinfo details) */ - public function retrieveUsers($start = 0, $limit = 0, $filter = array()) + public function retrieveUsers($start = 0, $limit = 0, $filter = []) { if ($this->users === null) $this->loadUserData(); @@ -304,7 +310,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin $i = 0; $count = 0; - $out = array(); + $out = []; $this->constructPattern($filter); foreach ($this->users as $user => $info) { @@ -334,12 +340,12 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin $groups = []; if ($this->users === null) $this->loadUserData(); - foreach($this->users as $user => $info) { + foreach ($this->users as $info) { $groups = array_merge($groups, array_diff($info['grps'], $groups)); } Sort::ksort($groups); - if($limit > 0) { + if ($limit > 0) { return array_splice($groups, $start, $limit); } return array_splice($groups, $start); @@ -404,7 +410,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin */ protected function readUserFile($file) { - $users = array(); + $users = []; if (!file_exists($file)) return $users; $lines = file($file); @@ -436,7 +442,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin protected function splitUserData($line) { $data = preg_split('/(?<![^\\\\]\\\\)\:/', $line, 5); // allow for : escaped as \: - if(count($data) < 5) { + if (count($data) < 5) { $data = array_pad($data, 5, ''); Logger::error('User line with less than 5 fields. Possibly corruption in your user file', $data); } @@ -459,8 +465,8 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin if (!preg_match($pattern, $user)) return false; } elseif ($item == 'grps') { if (!count(preg_grep($pattern, $info['grps']))) return false; - } else { - if (!preg_match($pattern, $info[$item])) return false; + } elseif (!preg_match($pattern, $info[$item])) { + return false; } } return true; @@ -473,9 +479,9 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin */ protected function constructPattern($filter) { - $this->pattern = array(); + $this->pattern = []; foreach ($filter as $item => $pattern) { - $this->pattern[$item] = '/'.str_replace('/', '\/', $pattern).'/i'; // allow regex characters + $this->pattern[$item] = '/' . str_replace('/', '\/', $pattern) . '/i'; // allow regex characters } } } |