MediaWiki  REL1_19
ExternalUser Class Reference

A class intended to supplement, and perhaps eventually replace, AuthPlugin. More...

Inheritance diagram for ExternalUser:

List of all members.

Public Member Functions

 authenticate ($password)
 Is the given password valid for the external user? The password is provided in plaintext.
 getGroups ()
 Return an array of identifiers for all the foreign groups that this user has.
 getId ()
 This must return some identifier that stably, uniquely identifies the user.
 getLocalUser ()
 Check whether this external user id is already linked with a local user.
 getName ()
 This must return the name that the user would normally use for login to the external database.
 getPref ($pref)
 Retrieve the value corresponding to the given preference key.
 linkToLocal ($id)
 Create a link for future reference between this object and the provided user_id.

Static Public Member Functions

static getPrefMessage ($pref)
 Given a preference key (e.g., 'emailaddress'), provide an HTML message telling the user how to change it in the external database.
static newFromCookie ()
static newFromId ($id)
static newFromName ($name)
 Wrappers around initFrom*().
static newFromUser ($user)
 Creates the object corresponding to the given User object, assuming the user exists on the wiki and is linked to an external account.
static setPref ($key, $value)
 Set the given preference key to the given value.

Protected Member Functions

 __construct ()
 initFromCookie ()
 Try to magically initialize the user from cookies or similar information so he or she can be logged in on just viewing the wiki.
 initFromId ($id)
 Given an id, which was at some previous point in history returned by getId(), initialize this object to be the corresponding ExternalUser.
 initFromName ($name)
 Given a name, which is a string exactly as input by the user in the login form but with whitespace stripped, initialize this object to be the corresponding ExternalUser.

Detailed Description

A class intended to supplement, and perhaps eventually replace, AuthPlugin.

See: http://www.mediawiki.org/wiki/ExternalAuth

The class represents a user whose data is in a foreign database. The database may have entirely different conventions from MediaWiki, but it's assumed to at least support the concept of a user id (possibly not an integer), a user name (possibly not meeting MediaWiki's username requirements), and a password.

Definition at line 39 of file ExternalUser.php.


Constructor & Destructor Documentation

ExternalUser::__construct ( ) [protected]

Definition at line 40 of file ExternalUser.php.


Member Function Documentation

ExternalUser::authenticate ( password) [abstract]

Is the given password valid for the external user? The password is provided in plaintext.

Parameters:
$passwordstring
Returns:
bool

Reimplemented in ExternalUser_MediaWiki, ExternalUser_vB, and ExternalUser_Hardcoded.

Return an array of identifiers for all the foreign groups that this user has.

The identifiers are opaque objects that only need to be specifiable by the administrator in LocalSettings.php when configuring $wgAutopromote. They may be, for instance, strings or integers.

TODO: Support this in $wgAutopromote.

Returns:
array

Reimplemented in ExternalUser_MediaWiki, and ExternalUser_vB.

Definition at line 229 of file ExternalUser.php.

ExternalUser::getId ( ) [abstract]

This must return some identifier that stably, uniquely identifies the user.

In a typical web application, this could be an integer representing the "user id". In other cases, it might be a string. In any event, the return value should be a string between 1 and 255 characters in length; must uniquely identify the user in the foreign database; and, if at all possible, should be permanent.

This will only ever be used to reconstruct this ExternalUser object via newFromId(). The resulting object in that case should correspond to the same user, even if details have changed in the interim (e.g., renames or preference changes).

Returns:
string

Reimplemented in ExternalUser_vB, ExternalUser_MediaWiki, and ExternalUser_Hardcoded.

Referenced by getLocalUser(), and linkToLocal().

Here is the caller graph for this function:

Check whether this external user id is already linked with a local user.

Returns:
Mixed User if the account is linked, Null otherwise.

Definition at line 295 of file ExternalUser.php.

References $dbr, getId(), newFromId(), and wfGetDB().

Here is the call graph for this function:

ExternalUser::getName ( ) [abstract]

This must return the name that the user would normally use for login to the external database.

It is subject to no particular restrictions beyond rudimentary sanity, and in particular may be invalid as a MediaWiki username. It's used to auto-generate an account name that *is* valid for MediaWiki, either with or without user input, but basically is only a hint.

Returns:
string

Reimplemented in ExternalUser_MediaWiki, ExternalUser_vB, and ExternalUser_Hardcoded.

ExternalUser::getPref ( pref)

Retrieve the value corresponding to the given preference key.

The most important values are:

  • emailaddress
  • language

The value must meet MediaWiki's requirements for values of this type, and will be checked for validity before use. If the preference makes no sense for the backend, or it makes sense but is unset for this user, or is unrecognized, return null.

$pref will never equal 'password', since passwords are usually hashed and cannot be directly retrieved. authenticate() is used for this instead.

TODO: Currently this is only called for 'emailaddress'; generalize! Add some config option to decide which values are grabbed on user initialization.

Parameters:
$prefstring
Returns:
mixed

Reimplemented in ExternalUser_MediaWiki, ExternalUser_vB, and ExternalUser_Hardcoded.

Definition at line 215 of file ExternalUser.php.

static ExternalUser::getPrefMessage ( pref) [static]

Given a preference key (e.g., 'emailaddress'), provide an HTML message telling the user how to change it in the external database.

The administrator has specified that this preference cannot be changed on the wiki, and may only be changed in the foreign database. If no message is available, such as for an unrecognized preference, return false.

TODO: Use this somewhere.

Parameters:
$prefstring
Returns:
mixed String or false

Definition at line 246 of file ExternalUser.php.

Try to magically initialize the user from cookies or similar information so he or she can be logged in on just viewing the wiki.

If this is impossible to do, just return false.

TODO: Actually use this.

Returns:
bool Success?

Reimplemented in ExternalUser_vB.

Definition at line 150 of file ExternalUser.php.

ExternalUser::initFromId ( id) [abstract, protected]

Given an id, which was at some previous point in history returned by getId(), initialize this object to be the corresponding ExternalUser.

Return true if successful, false otherwise.

Parameters:
$idstring
Returns:
bool Success?

Reimplemented in ExternalUser_MediaWiki, ExternalUser_Hardcoded, and ExternalUser_vB.

ExternalUser::initFromName ( name) [abstract, protected]

Given a name, which is a string exactly as input by the user in the login form but with whitespace stripped, initialize this object to be the corresponding ExternalUser.

Return true if successful, otherwise false.

Parameters:
$namestring
Returns:
bool Success?

Reimplemented in ExternalUser_MediaWiki, ExternalUser_vB, and ExternalUser_Hardcoded.

ExternalUser::linkToLocal ( id) [final]

Create a link for future reference between this object and the provided user_id.

If the user was already linked, the old link will be overwritten.

This is part of the core code and is not overridable by specific plugins. It's in this class only for convenience.

Parameters:
$idint user_id

Definition at line 281 of file ExternalUser.php.

References getId(), and wfGetDB().

Here is the call graph for this function:

static ExternalUser::newFromCookie ( ) [static]
Returns:
mixed ExternalUser, or false on failure

Definition at line 81 of file ExternalUser.php.

References $wgExternalAuthType.

Referenced by User\loadFromSession().

Here is the caller graph for this function:

static ExternalUser::newFromId ( id) [static]
Parameters:
$idstring
Returns:
mixed ExternalUser, or false on failure

Definition at line 66 of file ExternalUser.php.

References $wgExternalAuthType.

Referenced by getLocalUser(), and newFromUser().

Here is the caller graph for this function:

static ExternalUser::newFromName ( name) [static]

Wrappers around initFrom*().

Parameters:
$namestring
Returns:
mixed ExternalUser, or false on failure

Definition at line 50 of file ExternalUser.php.

References $wgExternalAuthType.

Referenced by LoginForm\authenticateUserData().

Here is the caller graph for this function:

static ExternalUser::newFromUser ( user) [static]

Creates the object corresponding to the given User object, assuming the user exists on the wiki and is linked to an external account.

If either of these is false, this will return false.

This is a wrapper around newFromId().

Parameters:
$userUser
Returns:
ExternalUser|false

Definition at line 103 of file ExternalUser.php.

References $dbr, $user, $wgExternalAuthType, newFromId(), and wfGetDB().

Referenced by User\saveOptions().

Here is the call graph for this function:

Here is the caller graph for this function:

static ExternalUser::setPref ( key,
value 
) [static]

Set the given preference key to the given value.

Two important preference keys that you might want to implement are 'password' and 'emailaddress'. If the set fails, such as because the preference is unrecognized or because the external database can't be changed right now, return false. If it succeeds, return true.

If applicable, you should make sure to validate the new value against any constraints the external database may have, since MediaWiki may have more limited constraints (e.g., on password strength).

TODO: Untested.

Parameters:
$keystring
$valuestring
Returns:
bool Success?

Definition at line 267 of file ExternalUser.php.


The documentation for this class was generated from the following file: