MyBB Community Forums

Full Version: MediaWiki - Mybb Bridge
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I successfully bridged the two, however:


Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'myusername'@'localhost' (using password: NO) in /home/myusername/public_html/getreadyforum.com/wiki/AuthMyBB.php on line 51
Unable to connect to MyBB database.



Is this bridge not working with mybb 1.6.7? Or could it be the mediawiki?


Any thoughts?
Could you post a link to the exact bridge you're using? THis also doesn't really belong in MyBB support - moved to the correct forum.
Sorry about the misplacement of this thread.

Here is the link you requested: http://community.mybb.com/thread-90914.html
It seems that the database login is incorrect. I'm just downloading the files now to take a look.

EDIT: had a look at the file. It could be that the configuration isn't being read properly for some reason. Could you open the AuthMyBB.php file and add the following before line 51:

echo "<pre>";
		var_dump($this->config);
		echo "</pre>";

Then you should see all the configuration data dumped to the screen (hopefully - I have no idea how this works exactly as I've never used MediaWiki) so you can check the password and stuff is all correct.
Sorry this is all that was returned:

Parse error: syntax error, unexpected T_ECHO, expecting T_FUNCTION in /home/me/public_html/getreadyforum.com/wiki/AuthMyBB.php on line 48
Hm. Paste the contents of your file - I get a feeling I didn't explain what I meant well enough.
<?php
require_once "AuthMyBB.php";

class AuthMyBB extends AuthPlugin {
	/**
	 * @var string The path to your copy of MyBB (with a trailing slash)
	 */
	var $forum_path = "/home/me/public_html/getreadyforum.com/boards/";

	/**
	 * @var array An array of user group IDs for banned user groups (defaults to the MyBB banned group)
	 */
	var $banned_usergroups = array(7);
	
	/**
	 * @var array An array of group IDs which should have SysOp/Administrative access to the wiki (defaults to Super Moderators and Administrators)
	 */
	var $admin_usergroups = array(4,3);
	var $searchpattern = "/[^a-zA-Z0-9 ]+/";

	var $db;
	var $table_prefix;
	var $config;

	function AuthMyBB()
	{
		if(!file_exists($this->forum_path."inc/config.php"))
		{
			die("Could not find MyBB configuration file. Please check the path is correct.");
		}

		require_once $this->forum_path."inc/config.php";
		$this->table_prefix = $config['database']['table_prefix'];
		$this->config = $config;
	}

	/* Interface documentation copied in from AuthPlugin */
	/**
	 * Check whether there exists a user account with the given name.
	 * The name will be normalized to MediaWiki's requirements, so
	 * you might need to munge it (for instance, for lowercase initial
	 * letters).
	 *
	 * @param string $username
	 * @return bool
	 * @access public
	 */
 
	function openDB()echo "<pre>";
        var_dump($this->config);
        echo "</pre>";
	{
		$this->db = mysql_connect($this->config['database']['hostname'], $this->config['database']['username'], $this->config['database']['password']) or die("Unable to connect to MyBB database.");
		mysql_select_db($this->config['database']['database']) or die("Unable to select MyBB database");
		
	}

	function userExists($username)
	{
		if(!is_object($this->db)) { $this->openDB(); }
		$query = mysql_query("SELECT username FROM {$this->table_prefix}users WHERE username='".$this->escape_string($username)."'", $this->db);
		$user = mysql_fetch_assoc($query);
		if($user['username'])
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	/**
	 * Check if a username+password pair is a valid login.
	 * The name will be normalized to MediaWiki's requirements, so
	 * you might need to munge it (for instance, for lowercase initial
	 * letters).
	 *
	 * @param string $username
	 * @param string $password
	 * @return bool
	 * @access public
	 */

	function authenticate($username, $password)
	{
		if(!is_object($this->db)) { $this->openDB(); }
		$query = mysql_query("SELECT username,password,salt,usergroup FROM {$this->table_prefix}users WHERE username='".$this->escape_string($username)."'", $this->db);
		$user = mysql_fetch_array($query);
		$saltedpw = md5(md5($user['salt']).md5($password));
		if($user['username'] && $user['password'] == $saltedpw)
		{
			if(in_array($user['usergroup'], $this->banned_usergroups))
			{
				return false;
			}
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * Modify options in the login template.
	 *
	 * @param UserLoginTemplate $template
	 * @access public
	 */
	function modifyUITemplate(&$template)
	{
		$template->set('usedomain', false);
		$template->set('useemail', false);
		$template->set('create', false);
	}

	/**
	 * Set the domain this plugin is supposed to use when authenticating.
	 *
	 * @param string $domain
	 * @access public
	 */
	function setDomain( $domain ) {
		$this->domain = $domain;
	}

	/**
	 * Check to see if the specific domain is a valid domain.
	 *
	 * @param string $domain
	 * @return bool
	 * @access public
	 */
	function validDomain( $domain ) {
		# Override this!
		return true;
	}

	/**
	 * When a user logs in, optionally fill in preferences and such.
	 * For instance, you might pull the email address or real name from the
	 * external user database.
	 *
	 * The User object is passed by reference so it can be modified; don't
	 * forget the & on your function declaration.
	 *
	 * @param User $user
	 * @access public
	 */
	function updateUser( &$user ) {
		if(!is_resource($this->db)) { $this->openDB(); }
		$query = mysql_query("SELECT username,email,usergroup,additionalgroups FROM {$this->table_prefix}users WHERE username='".$this->escape_string($user->mName)."'", $this->db);
		$res = mysql_fetch_array($query);

		if($res)
		{
			if(in_array($res['usergroup'], $this->admin_usergroups))
			{
				$is_admin = true;
			}
			$memberships = explode(",", $res['additionalgroups']);
			
			for($i=0;$i<count($memberships);$i++)
			{
				if(in_array($memberships[$x], $this->admin_usergroups))
				{
					$is_admin = true;
				}
			}
			
			if($is_admin == true)
			{
				// If a user is not a sysop, make them a sysop
				if (!in_array("sysop", $user->getEffectiveGroups())) {
					$user->addGroup('sysop');
				}				
			}
			else
			{
				if (in_array("sysop", $user->getEffectiveGroups())) {
					$user->removeGroup('sysop');
					return TRUE;
				}				
			}
			
			$user->setEmail($res['email']);
			$user->setRealName($res['username']);
			return TRUE;
		}
		return false;
	}


	/**
	 * Return true if the wiki should create a new local account automatically
	 * when asked to login a user who doesn't exist locally but does in the
	 * external auth database.
	 *
	 * If you don't automatically create accounts, you must still create
	 * accounts in some way. It's not possible to authenticate without
	 * a local account.
	 *
	 * This is just a question, and shouldn't perform any actions.
	 *
	 * @return bool
	 * @access public
	 */
	function autoCreate() {
		return true;
	}
	
	/**
	 * Set the given password in the authentication database.
	 * Return true if successful.
	 *
	 * @param string $password
	 * @return bool
	 * @access public
	 */
	function setPassword( $password ) {
		return true;
	}

	/**
	 * Update user information in the external authentication database.
	 * Return true if successful.
	 *
	 * @param User $user
	 * @return bool
	 * @access public
	 */
	function updateExternalDB( $user ) {
		return false;
	}

	/**
	 * Check to see if external accounts can be created.
	 * Return true if external accounts can be created.
	 * @return bool
	 * @access public
	 */
	function canCreateAccounts() {
		return false;
	}

	/**
	 * Add a user to the external authentication database.
	 * Return true if successful.
	 *
	 * @param User $user
	 * @param string $password
	 * @return bool
	 * @access public
	 */
	function addUser( $user, $password ) {
		return false;
	}


	/**
	 * Return true to prevent logins that don't authenticate here from being
	 * checked against the local database's password fields.
	 *
	 * This is just a question, and shouldn't perform any actions.
	 *
	 * @return bool
	 * @access public
	 */
	function strict() {
		return true;
	}
	
	/**
	 * When creating a user account, optionally fill in preferences and such.
	 * For instance, you might pull the email address or real name from the
	 * external user database.
	 *
	 * The User object is passed by reference so it can be modified; don't
	 * forget the & on your function declaration.
	 *
	 * @param User $user
	 * @access public
	 */
	function initUser(&$user,  $autocreate) {
		$user->mEmailAuthenticated = wfTimestampNow();
		$this->updateUser( $user );
	}

	/**
	 * If you want to munge the case of an account name before the final
	 * check, now is your chance.
	 */
	function getCanonicalName ( $username ) {
		// connecting to MediaWiki database for this check 		
		$dbr =& wfGetDB( DB_SLAVE );
		
		$res = $dbr->selectRow('user',
				       array("user_name"),
				       "lower(user_name)=lower(".
				         $dbr->addQuotes($username).")",
				       "AuthMyBB::getCanonicalName" );
		
		if($res) {
			return $res->user_name;
		} else {
			return $username;
		}
	}

	function escape_string($string)
	{
		if(function_exists("mysql_real_escape_string"))
		{
			return mysql_real_escape_string($string, $this->db);
		}
		else
		{
			return addslashes($string);
		}
	}
}
 require_once( './AuthMyBB.php' );
   $wgAuth = new AuthMyBB();
?>


If there are any sensitive things I need to delete from this aside from my server username please let me know. Thanks, and thank you for the fast responses.

Sorry this made the page run over.
Ok, try this instead:

<?php
require_once "AuthMyBB.php";

class AuthMyBB extends AuthPlugin {
    /**
     * @var string The path to your copy of MyBB (with a trailing slash)
     */
    var $forum_path = "/home/me/public_html/getreadyforum.com/boards/";

    /**
     * @var array An array of user group IDs for banned user groups (defaults to the MyBB banned group)
     */
    var $banned_usergroups = array(7);
    
    /**
     * @var array An array of group IDs which should have SysOp/Administrative access to the wiki (defaults to Super Moderators and Administrators)
     */
    var $admin_usergroups = array(4,3);
    var $searchpattern = "/[^a-zA-Z0-9 ]+/";

    var $db;
    var $table_prefix;
    var $config;

    function AuthMyBB()
    {
        if(!file_exists($this->forum_path."inc/config.php"))
        {
            die("Could not find MyBB configuration file. Please check the path is correct.");
        }

        require_once $this->forum_path."inc/config.php";
        $this->table_prefix = $config['database']['table_prefix'];
        $this->config = $config;
    }

    /* Interface documentation copied in from AuthPlugin */
    /**
     * Check whether there exists a user account with the given name.
     * The name will be normalized to MediaWiki's requirements, so
     * you might need to munge it (for instance, for lowercase initial
     * letters).
     *
     * @param string $username
     * @return bool
     * @access public
     */
 
    function openDB()
    {
        echo "<pre>";
        var_dump($this->config);
        echo "</pre>";
        $this->db = mysql_connect($this->config['database']['hostname'], $this->config['database']['username'], $this->config['database']['password']) or die("Unable to connect to MyBB database.");
        mysql_select_db($this->config['database']['database']) or die("Unable to select MyBB database");
        
    }

    function userExists($username)
    {
        if(!is_object($this->db)) { $this->openDB(); }
        $query = mysql_query("SELECT username FROM {$this->table_prefix}users WHERE username='".$this->escape_string($username)."'", $this->db);
        $user = mysql_fetch_assoc($query);
        if($user['username'])
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /**
     * Check if a username+password pair is a valid login.
     * The name will be normalized to MediaWiki's requirements, so
     * you might need to munge it (for instance, for lowercase initial
     * letters).
     *
     * @param string $username
     * @param string $password
     * @return bool
     * @access public
     */

    function authenticate($username, $password)
    {
        if(!is_object($this->db)) { $this->openDB(); }
        $query = mysql_query("SELECT username,password,salt,usergroup FROM {$this->table_prefix}users WHERE username='".$this->escape_string($username)."'", $this->db);
        $user = mysql_fetch_array($query);
        $saltedpw = md5(md5($user['salt']).md5($password));
        if($user['username'] && $user['password'] == $saltedpw)
        {
            if(in_array($user['usergroup'], $this->banned_usergroups))
            {
                return false;
            }
            return true;
        }
        else
        {
            return false;
        }
    }
    
    /**
     * Modify options in the login template.
     *
     * @param UserLoginTemplate $template
     * @access public
     */
    function modifyUITemplate(&$template)
    {
        $template->set('usedomain', false);
        $template->set('useemail', false);
        $template->set('create', false);
    }

    /**
     * Set the domain this plugin is supposed to use when authenticating.
     *
     * @param string $domain
     * @access public
     */
    function setDomain( $domain ) {
        $this->domain = $domain;
    }

    /**
     * Check to see if the specific domain is a valid domain.
     *
     * @param string $domain
     * @return bool
     * @access public
     */
    function validDomain( $domain ) {
        # Override this!
        return true;
    }

    /**
     * When a user logs in, optionally fill in preferences and such.
     * For instance, you might pull the email address or real name from the
     * external user database.
     *
     * The User object is passed by reference so it can be modified; don't
     * forget the & on your function declaration.
     *
     * @param User $user
     * @access public
     */
    function updateUser( &$user ) {
        if(!is_resource($this->db)) { $this->openDB(); }
        $query = mysql_query("SELECT username,email,usergroup,additionalgroups FROM {$this->table_prefix}users WHERE username='".$this->escape_string($user->mName)."'", $this->db);
        $res = mysql_fetch_array($query);

        if($res)
        {
            if(in_array($res['usergroup'], $this->admin_usergroups))
            {
                $is_admin = true;
            }
            $memberships = explode(",", $res['additionalgroups']);
            
            for($i=0;$i<count($memberships);$i++)
            {
                if(in_array($memberships[$x], $this->admin_usergroups))
                {
                    $is_admin = true;
                }
            }
            
            if($is_admin == true)
            {
                // If a user is not a sysop, make them a sysop
                if (!in_array("sysop", $user->getEffectiveGroups())) {
                    $user->addGroup('sysop');
                }                
            }
            else
            {
                if (in_array("sysop", $user->getEffectiveGroups())) {
                    $user->removeGroup('sysop');
                    return TRUE;
                }                
            }
            
            $user->setEmail($res['email']);
            $user->setRealName($res['username']);
            return TRUE;
        }
        return false;
    }


    /**
     * Return true if the wiki should create a new local account automatically
     * when asked to login a user who doesn't exist locally but does in the
     * external auth database.
     *
     * If you don't automatically create accounts, you must still create
     * accounts in some way. It's not possible to authenticate without
     * a local account.
     *
     * This is just a question, and shouldn't perform any actions.
     *
     * @return bool
     * @access public
     */
    function autoCreate() {
        return true;
    }
    
    /**
     * Set the given password in the authentication database.
     * Return true if successful.
     *
     * @param string $password
     * @return bool
     * @access public
     */
    function setPassword( $password ) {
        return true;
    }

    /**
     * Update user information in the external authentication database.
     * Return true if successful.
     *
     * @param User $user
     * @return bool
     * @access public
     */
    function updateExternalDB( $user ) {
        return false;
    }

    /**
     * Check to see if external accounts can be created.
     * Return true if external accounts can be created.
     * @return bool
     * @access public
     */
    function canCreateAccounts() {
        return false;
    }

    /**
     * Add a user to the external authentication database.
     * Return true if successful.
     *
     * @param User $user
     * @param string $password
     * @return bool
     * @access public
     */
    function addUser( $user, $password ) {
        return false;
    }


    /**
     * Return true to prevent logins that don't authenticate here from being
     * checked against the local database's password fields.
     *
     * This is just a question, and shouldn't perform any actions.
     *
     * @return bool
     * @access public
     */
    function strict() {
        return true;
    }
    
    /**
     * When creating a user account, optionally fill in preferences and such.
     * For instance, you might pull the email address or real name from the
     * external user database.
     *
     * The User object is passed by reference so it can be modified; don't
     * forget the & on your function declaration.
     *
     * @param User $user
     * @access public
     */
    function initUser(&$user,  $autocreate) {
        $user->mEmailAuthenticated = wfTimestampNow();
        $this->updateUser( $user );
    }

    /**
     * If you want to munge the case of an account name before the final
     * check, now is your chance.
     */
    function getCanonicalName ( $username ) {
        // connecting to MediaWiki database for this check         
        $dbr =& wfGetDB( DB_SLAVE );
        
        $res = $dbr->selectRow('user',
                       array("user_name"),
                       "lower(user_name)=lower(".
                         $dbr->addQuotes($username).")",
                       "AuthMyBB::getCanonicalName" );
        
        if($res) {
            return $res->user_name;
        } else {
            return $username;
        }
    }

    function escape_string($string)
    {
        if(function_exists("mysql_real_escape_string"))
        {
            return mysql_real_escape_string($string, $this->db);
        }
        else
        {
            return addslashes($string);
        }
    }
}
 require_once( './AuthMyBB.php' );
   $wgAuth = new AuthMyBB();
?>
I now get this :

Could not find MyBB configuration file. Please check the path is correct.

Oh, hold on, ........forgot to change username

Ok Sir now this is returned:
NULL


Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'me'@'localhost' (using password: NO) in /home/me/public_html/getreadyforum.com/wiki/AuthMyBB.php on line 54
Unable to connect to MyBB database.

I solved this issue.
(2012-04-26, 04:24 PM)tracker Wrote: [ -> ]I solved this issue.

Can you please tell me how you solved this?

I have successfully configured LocalSettings.php and AuthMyBB.php (had to change line 2 from 'require_once "AuthPlugin.php";' to 'require_once "includes/AuthPlugin.php";').

However if I try to login I get an SQL error saying „1146: Table 'usr_web1234_14.objectcache' doesn't exist (localhost)“.
usr_web1234_14 is the database of my MyBB installation - objectcache is a MediaWiki table. So it's logical that it doesn't find the table.
Am I supposed to use the same database for MediaWiki and MyBB?

Thanks for your help!

Versions I'm using: MW: 1.19.2, MyBB: 1.6.8