wiki.techinc.nl/includes/extauth/vB.php
Aryeh Gregor 1d1ecfa10f Add experimental new auth framework, ExternalAuth
This should not affect any existing behavior.  (Except that it reorders
some error conditions in attemptAutoCreate(), but probably no one cares
about that.)  It adds a new database table, but it will be unused unless
you enable external authentication.

An outline of the rationale for this system, and the design planning, is
at <http://www.mediawiki.org/wiki/ExternalAuth>.  Essentially,
AuthPlugin puts too much of a burden on plugin authors, requiring them
to write a lot of policy logic instead of just handling the actual
interface to the external user database.  This system uses a standard
framework to decide policy questions, and auth plugins only need to
provide some low-level, clearly-specified data.

There are lots of features still missing, marked in the code, but basic
functionality is present.  The commit includes initial support for one
type of external authentication, the forum software vBulletin (which I
happen to know well, and want to integrate with my MediaWiki).

I'm encouraging the inclusion of ExternalAuth plugins in core because in
this framework, the amount of code required to add an additional backend
is quite small -- well under 100 lines in this case.  I'd hope to see a
lot more of these, and it seems unreasonable to make an armada of tiny
extensions instead of letting them live happily in their own directory
out of everyone's way.
2009-07-19 22:02:00 +00:00

97 lines
2.7 KiB
PHP

<?php
# Copyright (C) 2009 Aryeh Gregor
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# http://www.gnu.org/copyleft/gpl.html
/**
* This class supports the proprietary vBulletin forum system
* <http://www.vbulletin.com>, versions 3.5 and up. It calls no functions or
* code, only reads from the database. Example lines to put in
* LocalSettings.php:
*
* $wgExternalAuthType = 'vB';
* $wgExternalAuthConf = array(
* 'server' => 'localhost',
* 'username' => 'forum',
* 'password' => 'udE,jSqDJ<""p=fI.K9',
* 'dbname' => 'forum',
* 'tableprefix' => ''
* );
*/
class ExternalUser_vB extends ExternalUser {
private $mDb, $mRow;
protected function initFromName( $name ) {
return $this->initFromCond( array( 'username' => $name ) );
}
protected function initFromId( $id ) {
return $this->initFromCond( array( 'userid' => $id ) );
}
# initFromCookie() not yet implemented
private function initFromCond( $cond ) {
global $wgExternalAuthConf;
$this->mDb = new Database(
$wgExternalAuthConf['server'],
$wgExternalAuthConf['username'],
$wgExternalAuthConf['password'],
$wgExternalAuthConf['dbname'],
false, 0,
$wgExternalAuthConf['tableprefix']
);
$row = $this->mDb->selectRow(
'user',
array( 'userid', 'username', 'password', 'salt', 'email', 'usergroupid',
'membergroupids' ),
$cond,
__METHOD__
);
if ( !$row ) {
return false;
}
$this->mRow = $row;
return true;
}
public function getId() { return $this->mRow->userid; }
public function getName() { return $this->mRow->username; }
public function authenticate( $password ) {
return $this->mRow->password == md5( md5( $password )
. $this->mRow->salt );
}
public function getPref( $pref ) {
if ( $pref == 'emailaddress' && $this->mRow->email ) {
# TODO: only return if validated?
return $this->mRow->email;
}
return null;
}
public function getGroups() {
$groups = array( $this->mRow->usergroupid );
$groups = array_merge( $groups, explode( ',', $this->mRow->membergroupids ) );
$groups = array_unique( $groups );
return $groups;
}
}