(bug 35565) Special:Log/patrol doesn't indicate whether patrolling was automatic
[mediawiki.git] / includes / extauth / Hardcoded.php
blobdfb4674299172986644937360a4d96766416e0e6
1 <?php
2 /**
3 * External authentication with hardcoded user names and passwords
5 * Copyright © 2009 Aryeh Gregor
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
25 /**
26 * This class supports external authentication from a literal array dumped in
27 * LocalSettings.php. It's mostly useful for testing. Example configuration:
29 * $wgExternalAuthType = 'ExternalUser_Hardcoded';
30 * $wgExternalAuthConf = array(
31 * 'Bob Smith' => array(
32 * 'password' => 'literal string',
33 * 'emailaddress' => 'bob@example.com',
34 * ),
35 * );
37 * Multiple names may be provided. The keys of the inner arrays can be either
38 * 'password', or the name of any preference.
40 * @ingroup ExternalUser
42 class ExternalUser_Hardcoded extends ExternalUser {
43 private $mName;
45 protected function initFromName( $name ) {
46 global $wgExternalAuthConf;
48 if ( isset( $wgExternalAuthConf[$name] ) ) {
49 $this->mName = $name;
50 return true;
52 return false;
55 protected function initFromId( $id ) {
56 return $this->initFromName( $id );
59 public function getId() {
60 return $this->mName;
63 public function getName() {
64 return $this->mName;
67 public function authenticate( $password ) {
68 global $wgExternalAuthConf;
70 return isset( $wgExternalAuthConf[$this->mName]['password'] )
71 && $wgExternalAuthConf[$this->mName]['password'] == $password;
74 public function getPref( $pref ) {
75 global $wgExternalAuthConf;
77 if ( isset( $wgExternalAuthConf[$this->mName][$pref] ) ) {
78 return $wgExternalAuthConf[$this->mName][$pref];
80 return null;
83 # TODO: Implement setPref() via regex on LocalSettings. (Just kidding.)