Extension talk:PunBB Authentication
Add topicThis extension does what it says on the tin.. If you log into your forum you're logged into MediaWiki. However there are problems with it:
- The code, as is, doesn't let you log out of Mediawiki unless you use the logout link on the forums.
- If you change your preferences, you wont be able to log out of media wiki, no matter what you do short of cleaning your cookies.
Noopectro 11:11, 19 March 2007 (UTC)
Some fixes
[edit]In order to get your plugin working on my installation of MediaWiki (v. 1.9.1), I had to add
$user->mFrom = 'name';
right after
$user->setId($user->idFromName($pun_user['username']));
. I know that this is probably not best practice, but somehow MediaWiki called the hook more than once and did not cache that the user was added in the first run, thus getID() returning 0 again and the name being reset to NULL which resulted in MediaWiki trying to add the user with the NULL-username more than once.
I also changed the extension to use the canonicalName-function of the User-class, which can also check if the username is creatable etc.. :)
--89.245.117.127 10:59, 6 December 2007 (UTC)
mediawiki 1.12 / fluxbb 1.2.20
[edit]Just in case someone whith the same config as I have tries this extension, he'll probably want to try this code from eliot (works fine for me) (make sure you don't let any [space] caracter before "<?php").
This one implements it with the gestion of latin caracters in logins : many thanks to Krimpet who corrected this issue.
I suggest it could replace the actual main plugin page (I don't have the rights to do so).--NewMorning 10:29, 7 August 2008 (UTC)
<?php
# PunBB MediaWiki extension
if( !defined( 'MEDIAWIKI' ) )
die();
$wgExtensionCredits['other'][] = array(
'name' => 'PunBB Authentication',
'description' => 'Auto-authenticates the current PunBB user',
'author' => 'Bradley Bell'
);
# PunBB integration
//define('PUN_QUIET_VISIT', 1);
define('PUN_ROOT', '../');
require PUN_ROOT.'include/common.php';
$wgHooks['AutoAuthenticate'][] = 'AutoAuthenticatePunBB';
$wgHooks['UserLogout'][] = 'UserLogoutPunBB';
$wgHooks['UserLoginForm'][] = 'UserLoginFormPunBB';
function AutoAuthenticatePunBB(&$user) {
global $pun_user;
if ($pun_user['is_guest']) {
return true;
}
$utf8name = iconv("ISO-8859-1", "UTF-8", $pun_user['username']);
$user = User::newFromName(ucfirst($utf8name));
if ( $user->getID() == 0 ) {
$user->addToDatabase();
$user->setId($user->idFromName(ucfirst($utf8name)));
$user->setToken();
$user->setRealName(iconv("ISO-8859-1", "UTF-8", $pun_user['realname']));
$user->setEmail(iconv("ISO-8859-1", "UTF-8", $pun_user['email']));
$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('../login.php?action=out&id='.$pun_user['id'].'&csrf_token='.sha1($pun_user['id'].sha1(get_remote_address())), 'Logging out. Redirecting …');
}
function UserLoginFormPunBB(&$template) {
$referer = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : 'index.php';
header('Location: ../login.php?redirect_url='.$referer);
return true;
}
case of upper cases
[edit]I still have a small trouble with the code up there : mediawiki only uses the first capital letters, not very convenient for loggins that are made with capital letters, especially with such as "Firstname FAMILYNAME" (strange login, though, but imposed...) that become "Firstname familyname" all small cases after the first letter. How could this be improved ?--NewMorning 14:10, 18 August 2008 (UTC)