Extension:PunBB Authentication

PunBB Authentication is an extension that will automatically authenticate the currently logged-in PunBB user to MediaWiki.

PunBB is a discussion board.

The login and logout hooks will not work with a stock installation of PunBB, but they could be made to work with a little customization to PunBB's login.php.

Add the line: include("extensions/PunBBAuth.php"); to LocalSettings.php.

Save this code as extensions/PunBBAuthentication.php  'PunBB Authentication',    'description' => '[Hopefully] authenticates using PunBB database',    'author' => 'Bradley B' );


 * 1) PunBB integration

//define('PUN_QUIET_VISIT', 1); define('PUN_ROOT', '/path/to/punbb/'); require PUN_ROOT.'include/common.php';

$wgHooks['AutoAuthenticate'][] = 'AutoAuthenticatePunBB'; //$wgHooks['UserLogout'][] = 'UserLogoutPunBB'; //$wgHooks['UserLoginForm'][] = 'UserLoginFormPunBB';

function AutoAuthenticatePunBB(&$user) { global $pun_user;

wfSetupSession;

if ($pun_user['is_guest']) { return true; }

/*        * A lot of this is from User::newFromName */

$validate = true;

// Force usernames to capital global $wgContLang; $name = $wgContLang->ucfirst( $pun_user['username'] );

// Clean up name according to title rules $t = Title::newFromText( $name ); if( is_null( $t ) ) { return null; }

// Reject various classes of invalid names $canonicalName = $t->getText; global $wgAuth; $canonicalName = $wgAuth->getCanonicalName( $t->getText );

if( $validate && !User::isValidUserName( $canonicalName ) ) { return null; }

$user->setName($pun_user['username']); $user->setId($user->idFromName($pun_user['username'])); if ( $user->getID == 0 ) { /*          * A lot of this is from LoginForm::initUser */               $user->addToDatabase; $user->setEmail($pun_user['email']); $user->setRealName($pun_user['realname']); $user->setToken; $user->confirmEmail; if ($pun_user['g_id'] == PUN_ADMIN) { $user->addGroup("sysop"); }       } else { /* Should cache some day, I guess :) */               $user->loadFromDatabase;                $user->setToken;        }

return true; }

function UserLogoutPunBB(&$user) { global $pun_user;

redirect('/forums/login.php?action=out&id='.$pun_user['id'], 'Logging out. Redirecting &hellip;'); }

function UserLoginFormPunBB(&$template) { $referer = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : 'index.php'; header('Location: http://hostname/forums/login.php?redirect_url='.$referer); }

?>