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 wink:

<?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('&amp;', '&', $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;
}

?>

Thank you Anatoly! I just change all the "pun_" and "PUN_" to "forum_" and "FORUM_", and set the paths to my website. However, when I click login/register in MediaWiki, the whole page turns me back to the index page of my PunBB forum ...

It seems that there is a redirect problem when accessing PunBB's account information, following it my remodified PunBBAuth.php file:

<?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/abc/abc.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;

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

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

?>

The situation of mine is:

I installed PunBB 1.3rc in abc.cn/arch
              MediaWiki 1.13.1 in abc.cn/wiki

And I change the "cookie_domain = .abc.cn" in config.php

Slavok wrote:

1.Choose a user from the users list on page <FORUM_URL>/userlist.php. Go to tab "Administration" in the user's profile. In the bottom of the page there is a listbox with user's group. Select "Moderator" and click "Save".

2. User can modify his topics' title only if he/she is a moderator or administrator.

Thank you so much!:D

4

(52 replies, posted in PunBB 1.3 additions)

Wow, this new theme is awesome, but it is a little bit Opera-Style like? big_smile The current 1.3rc's default theme is too plain but it's OK, I love it simple. wink

I have used this extension with mediawiki 1.1.3.1 and punbb 1.3rc, but nothing happens after that, either.

In the half way it says FORUM_ROOT should be defined first so I define it the same as the PUN_ROOT. However, after I sign into punbb and then switch to mediawiki, it still ask me for account to access. Im faint ... what is the key?

Thank you for posting!

And I wanna know 2 following questions:

1. How can I set a user to become a moderator?

2. User can not modify his topics title later?

OK,I have solved it by setting editplus to UTF-8 when saving files. big_smile

Just as what 1.2.x Simplified Chinese language file (common.php) has indicated me, so I use the following code to translate:

<?php

// Simplified Chinese (UTF-8) was Translated by CoolHD
// Any suggestion just feel free to mail me.
// coolhd.tw@yahoo.com.tw
// Determine what locale to use
switch (PHP_OS)
{
    case 'WINNT':
    case 'WIN32':
        $locale = 'chinese-simplified';
        break;

    case 'FreeBSD':
    case 'NetBSD':
    case 'OpenBSD':
        $locale = 'zh_CN.UTF-8';
        break;

    default:
        $locale = 'zh_CN';
        break;
}

// Attempt to set the locale
setlocale(LC_CTYPE, $locale);


// Language definitions for frequently used strings
$lang_common = array(

// Text orientation and encoding
'lang_direction'        =>    'ltr',    // ltr (Left-To-Right) or rtl (Right-To-Left)
'lang_identifier'        =>    'chinese',
'lang_encoding'            =>    'UTF-8',
'lang_multibyte'        =>    true,

However I find that in 1.3 there is a new variable called lang_encoding but I dont know how to set it correctly to display Chinese characters ... so any one may help?

Thanks!

The following screenshot may help show the problem:
http://i3.6.cn/cvbnm/f1/36/e8/71e9313e530ad5ec74f73b65240a8c6f.jpg