Problem solved!
The newest version of MediaWiki (1.13.1) dose not support this funtion: AutoAuthenticate
So my friend changed to use MediaWiki ver.1.21, this version support this function. And then we use the following codes and succeeded in the end :
<?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('FORUM_QUIET_VISIT', 1);
define('FORUM_ROOT', '/home/andywxy/andywxy.cn/arch/');
require FORUM_ROOT.'include/common.php';
$wgHooks['AutoAuthenticate'][] = 'AutoAuthenticatePunBB';
$wgHooks['UserLogout'][] = 'UserLogoutPunBB';
$wgHooks['UserLoginForm'][] = 'UserLoginFormPunBB';
function AutoAuthenticatePunBB(&$user) {
global $forum_user;
if ($forum_user['is_guest']) {
return true;
}
$user = User::newFromName(ucfirst(strtolower($forum_user["username"])));
if ( $user->getID() == 0 ) {
$user->addToDatabase();
$user->setId($user->idFromName(ucfirst(strtolower($forum_user["username"]))));
$user->setToken();
$user->setRealName($forum_user['realname']);
$user->setEmail($forum_user['email']);
$user->confirmEmail();
if ($forum_user['g_id'] == FORUM_ADMIN) {
$user->addGroup("sysop");
}
} else {
/* Should cache some day, I guess :) */
$user->loadFromDatabase();
$user->setToken();
}
return true;
}
function UserLogoutPunBB(&$user) {
global $forum_user;
$target_url = 'logout'.$forum_user['id'];
$referer = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : 'index.php';
$token = '&csrf_token='. sha1(str_replace('&', '&', $target_url) . $forum_user['csrf_token']);
//$token ="";
redirect('../login.php?action=out&id='.$forum_user['id'].$token.'&redirect_url='.$referer, 'Logging out now ....');
}
function UserLoginFormPunBB(&$template) {
$referer = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : 'index.php';
redirect('../login.php?redirect_url='.$referer, 'Loggin now ....');
#header('Location: http://arch.andywxy.cn/login.php?redirect_url='.$referer);
return true;
}
?>