Whitelist the <wbr> element.
[mediawiki.git] / includes / AuthPlugin.php
blob84cf3d5ecee4ccdf03d4959e25df00386c55f918
1 <?php
2 /**
3 * Authentication plugin interface
5 * Copyright © 2004 Brion Vibber <brion@pobox.com>
6 * http://www.mediawiki.org/
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
23 * @file
26 /**
27 * Authentication plugin interface. Instantiate a subclass of AuthPlugin
28 * and set $wgAuth to it to authenticate against some external tool.
30 * The default behavior is not to do anything, and use the local user
31 * database for all authentication. A subclass can require that all
32 * accounts authenticate externally, or use it only as a fallback; also
33 * you can transparently create internal wiki accounts the first time
34 * someone logs in who can be authenticated externally.
36 class AuthPlugin {
38 /**
39 * @var string
41 protected $domain;
43 /**
44 * Check whether there exists a user account with the given name.
45 * The name will be normalized to MediaWiki's requirements, so
46 * you might need to munge it (for instance, for lowercase initial
47 * letters).
49 * @param string $username username.
50 * @return bool
52 public function userExists( $username ) {
53 # Override this!
54 return false;
57 /**
58 * Check if a username+password pair is a valid login.
59 * The name will be normalized to MediaWiki's requirements, so
60 * you might need to munge it (for instance, for lowercase initial
61 * letters).
63 * @param string $username username.
64 * @param string $password user password.
65 * @return bool
67 public function authenticate( $username, $password ) {
68 # Override this!
69 return false;
72 /**
73 * Modify options in the login template.
75 * @param $template UserLoginTemplate object.
76 * @param string $type 'signup' or 'login'. Added in 1.16.
78 public function modifyUITemplate( &$template, &$type ) {
79 # Override this!
80 $template->set( 'usedomain', false );
83 /**
84 * Set the domain this plugin is supposed to use when authenticating.
86 * @param string $domain authentication domain.
88 public function setDomain( $domain ) {
89 $this->domain = $domain;
92 /**
93 * Get the user's domain
95 * @return string
97 public function getDomain() {
98 if ( isset( $this->domain ) ) {
99 return $this->domain;
100 } else {
101 return 'invaliddomain';
106 * Check to see if the specific domain is a valid domain.
108 * @param string $domain authentication domain.
109 * @return bool
111 public function validDomain( $domain ) {
112 # Override this!
113 return true;
117 * When a user logs in, optionally fill in preferences and such.
118 * For instance, you might pull the email address or real name from the
119 * external user database.
121 * The User object is passed by reference so it can be modified; don't
122 * forget the & on your function declaration.
124 * @param $user User object
125 * @return bool
127 public function updateUser( &$user ) {
128 # Override this and do something
129 return true;
133 * Return true if the wiki should create a new local account automatically
134 * when asked to login a user who doesn't exist locally but does in the
135 * external auth database.
137 * If you don't automatically create accounts, you must still create
138 * accounts in some way. It's not possible to authenticate without
139 * a local account.
141 * This is just a question, and shouldn't perform any actions.
143 * @return Boolean
145 public function autoCreate() {
146 return false;
150 * Allow a property change? Properties are the same as preferences
151 * and use the same keys. 'Realname' 'Emailaddress' and 'Nickname'
152 * all reference this.
154 * @param $prop string
156 * @return Boolean
158 public function allowPropChange( $prop = '' ) {
159 if ( $prop == 'realname' && is_callable( array( $this, 'allowRealNameChange' ) ) ) {
160 return $this->allowRealNameChange();
161 } elseif ( $prop == 'emailaddress' && is_callable( array( $this, 'allowEmailChange' ) ) ) {
162 return $this->allowEmailChange();
163 } elseif ( $prop == 'nickname' && is_callable( array( $this, 'allowNickChange' ) ) ) {
164 return $this->allowNickChange();
165 } else {
166 return true;
171 * Can users change their passwords?
173 * @return bool
175 public function allowPasswordChange() {
176 return true;
180 * Should MediaWiki store passwords in its local database?
182 * @return bool
184 public function allowSetLocalPassword() {
185 return true;
189 * Set the given password in the authentication database.
190 * As a special case, the password may be set to null to request
191 * locking the password to an unusable value, with the expectation
192 * that it will be set later through a mail reset or other method.
194 * Return true if successful.
196 * @param $user User object.
197 * @param string $password password.
198 * @return bool
200 public function setPassword( $user, $password ) {
201 return true;
205 * Update user information in the external authentication database.
206 * Return true if successful.
208 * @param $user User object.
209 * @return Boolean
211 public function updateExternalDB( $user ) {
212 return true;
216 * Update user groups in the external authentication database.
217 * Return true if successful.
219 * @param $user User object.
220 * @param $addgroups Groups to add.
221 * @param $delgroups Groups to remove.
222 * @return Boolean
224 public function updateExternalDBGroups( $user, $addgroups, $delgroups = array() ) {
225 return true;
229 * Check to see if external accounts can be created.
230 * Return true if external accounts can be created.
231 * @return Boolean
233 public function canCreateAccounts() {
234 return false;
238 * Add a user to the external authentication database.
239 * Return true if successful.
241 * @param $user User: only the name should be assumed valid at this point
242 * @param $password String
243 * @param $email String
244 * @param $realname String
245 * @return Boolean
247 public function addUser( $user, $password, $email = '', $realname = '' ) {
248 return true;
252 * Return true to prevent logins that don't authenticate here from being
253 * checked against the local database's password fields.
255 * This is just a question, and shouldn't perform any actions.
257 * @return Boolean
259 public function strict() {
260 return false;
264 * Check if a user should authenticate locally if the global authentication fails.
265 * If either this or strict() returns true, local authentication is not used.
267 * @param string $username username.
268 * @return Boolean
270 public function strictUserAuth( $username ) {
271 return false;
275 * When creating a user account, optionally fill in preferences and such.
276 * For instance, you might pull the email address or real name from the
277 * external user database.
279 * The User object is passed by reference so it can be modified; don't
280 * forget the & on your function declaration.
282 * @param $user User object.
283 * @param $autocreate Boolean: True if user is being autocreated on login
285 public function initUser( &$user, $autocreate = false ) {
286 # Override this to do something.
290 * If you want to munge the case of an account name before the final
291 * check, now is your chance.
292 * @param $username string
293 * @return string
295 public function getCanonicalName( $username ) {
296 return $username;
300 * Get an instance of a User object
302 * @param $user User
304 * @return AuthPluginUser
306 public function getUserInstance( User &$user ) {
307 return new AuthPluginUser( $user );
311 * Get a list of domains (in HTMLForm options format) used.
313 * @return array
315 public function domainList() {
316 return array();
320 class AuthPluginUser {
321 function __construct( $user ) {
322 # Override this!
325 public function getId() {
326 # Override this!
327 return -1;
330 public function isLocked() {
331 # Override this!
332 return false;
335 public function isHidden() {
336 # Override this!
337 return false;
340 public function resetAuthToken() {
341 # Override this!
342 return true;