Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Integrate or bridge with MediaWiki
HolisticEarth
Join Date: Apr 2006
Posts: 14

 

Winnipeg, MB, CAN
Show Printable Version Email this Page Subscription
HolisticEarth HolisticEarth is offline 04-13-2006, 10:00 PM

Do you want to use vBulletin's user database with your MediaWiki? You might like this.

I have taken Kai Backman's MediaWiki authentication plugin idea, fixed coding errors, and expanded greatly on it.

Working on:
vBulletin 3.5.4 and MediaWiki 1.6.3

Features:
  • Allows you to run MediaWiki with your vBulletin user database
  • Disallows users with invalid username characters
  • Disallows users who are not part of specified usergroups
  • Sets users to sysop status in MediaWiki if they are part of a specified admin usergroup
  • Removes users from sysop status in MediaWiki if they no longer are a part of a specified admin usergroup
  • For same-database setups, allows easy installation

Possible Future Features:
These are possible features for inclusion in the how-to in the future. They have not been investigated for their feasibility, but are here to let you know they have been requested and I am thinking about them. If you know how to add the features, please let us know.
  • No-login required (automatic) integration
  • Option: User profile field points to, or has option to link to vBulletin profile
  • To register, link the user to vBulletin's registration script on the login pages

How to:
  1. Install Reynaldovb's Restrict usernames to alphanumeric and underscore plugin, and disallow both spaces and underscores
  2. Optional: On boards that already have existing users, somehow have their usernames changed so that they are only alphanumeric. This is required if you wish your users to be able to login and edit the wiki using their vBulletin username. The reason you have to do this is because MediaWiki has some Restrictions on what can go in a page title, and as usernames have to be passed as page titles, they also have to adhere to the same restrictions. If you do not change the usernames, I have included a check to not allow users to login if their username contains non-alphanumeric characters.
  3. Open your wiki/LocalSettings.php file
  4. Insert the following code at the end of the file, before the ?>:
    PHP Code:
    # vBulletin integration script
    require_once("AuthPlugin_vBulletin.php");
    // if vBulletin and MediaWiki are not installed on the same database
    // change these values to reflect your vBulletin database information
    $wgAuth = new AuthPlugin_vBulletin($wgDBserver$wgDBuser$wgDBpassword$wgDBname"vb_"); 
    If you are running vBulletin and MediaWiki in the same database, then it already uses the connection information.
    If you are not running vBulletin and MediaWiki in the same database, please change the strings to reflect your vBulletin database information.
    In either case, the last value is whatever your vBulletin table prefix is.
  5. Insert this code below the require_once( "includes/DefaultSettings.php" ); at the top of the LocalSettings.php file:
    PHP Code:
    # Disabling new user registrations
    $wgWhitelistAccount = array ( "sysop" => 1"developer" => );
    # Disabling anonymous edits
    $wgGroupPermissions['*']['createaccount'] = false;
    $wgGroupPermissions['*']['read'] = false;
    $wgGroupPermissions['*']['edit'] = false;
    $wgWhitelistRead = array ("Special:Userlogin"); 
    This prevents people from registering new accounts on the wiki, requiring people to register on vBulletin. It also prevents anonymous edits. This code may only work on MediaWiki 1.5.x and above, but I am unsure.
  6. Download the AuthPlugin_vBulletin.php file and put it in your main wiki directory, ie: /wiki/AuthPlugin_vBulletin.php

Please let me know if this was helpful, or if you can expand on this code.
Attached Files
File Type: php AuthPlugin_vBulletin.php (7.4 KB, 490 views)
Reply With Quote
  #52  
Old 08-21-2006, 03:53 PM
dsl55dsl dsl55dsl is offline
 
Join Date: Jun 2006
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Still getting the same error.

Login error:Incorrect password entered. Please try again

This is what the AuthPlugin_Vbulletin.php file looks like:

Quote:
<?php
/**
* Authentication plugin interface. Instantiate a subclass of AuthPlugin
* and set $wgAuth to it to authenticate against some external tool.
*
* The default behavior is not to do anything, and use the local user
* database for all authentication. A subclass can require that all
* accounts authenticate externally, or use it only as a fallback; also
* you can transparently create internal wiki accounts the first time
* someone logs in who can be authenticated externally.
*
* This interface is new, and might change a bit before 1.4.0 final is
* done...
*
* AuthPlugin extension by Daniel Gravenor c/o HolisticEarth.org
* AuthPlugin original by Kai Backman
*
* @package MediaWiki
*/
require_once("includes/AuthPlugin.php");

class AuthPlugin_vBulletin extends AuthPlugin {

// Create a persistent DB connection
var $vb_database;

function AuthPlugin_vBulletin($host, $username, $password, $dbname, $prefix) {
$this->vb_database = mysql_pconnect($host, $username, $password);
mysql_select_db($dbname, $this->vb_database);
$this->vb_prefix = $prefix;
// set the usergroups for those who can edit the wiki
$this->allowed_usergroups = Array(29);
// set the usergroups for the administrators
$this->admin_usergroups = Array(6, 9);
$this->user_rights = Array("sysop");
// search pattern to only accept alphanumeric or underscore characters in usernames
// if they have illegal characters, their name cannot exist, period
$this->searchpattern = "/[^a-zA-Z0-9]+/";
}


/**
* 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 userExists( $username ) {
// if no illegal characters are found in their username, then check to see if they exist
if (!preg_match($this->searchpattern, $username)) {
$username = addslashes($username);
$vb_find_user_query = "SELECT usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . $username . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
// make sure that there is only one person with the username
if (mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
// Only registered and admins. Banned and unregistered don't belong here.
$vb_usergroups = explode(",", $vb_userinfo['membergroupids']); // make an array of membergroupids
$vb_usergroups[] = $vb_userinfo['usergroupid']; // add the primary usergroup to the array
foreach ( $vb_usergroups as $vb_groupiter )
if (in_array( $vb_groupiter, $this->allowed_usergroups)) {
return TRUE;
}
}
}
// if no one is registered with that username, or there are more than 1 entries
// or they have illegal characters return FALSE (they do not exist)
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 their name does not contain any illegal characters, let them try to login
if (!preg_match($this->searchpattern, $username)) {
$username = addslashes($username);
$vb_find_user_query = "SELECT password, salt, usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . $username . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
if (mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
// Only registered and admins. Banned and unregistered don't belong here.
$vb_usergroups = explode(",", $vb_userinfo['membergroupids']); // make an array of membergroupids
$vb_usergroups[] = $vb_userinfo['usergroupid']; // add the primary usergroup to the array
foreach ( $vb_usergroups as $vb_groupiter )
if (in_array( $vb_groupiter, $this->allowed_usergroups)) {
return TRUE;
if(md5(md5($password) . $vb_userinfo['salt']) == $vb_userinfo['password']) return true;
}
}
}
return false;
}

/**
* 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 ) {
# Override this and do something
$vb_find_user_query = "SELECT usergroupid, membergroupids FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . addslashes($user->mName) . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database) or die("Could not find username");
if(mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
// go through the users member groups to see if one of them is administrative
$user_membergroups = explode(",", $vb_userinfo['membergroupids']);
$admin_secondary = FALSE;
for ($x = 0; $x < count($user_membergroups); $x++) {
if (in_array($user_membergroups[$x], $this->admin_usergroups)) $admin_secondary = TRUE;
}

if (in_array($vb_userinfo['usergroupid'], $this->admin_usergroups) || $admin_secondary === TRUE) {
// if a user is not a sysop, make them a sysop
if (!in_array("sysop", $user->getEffectiveGroups())) {
$user->addGroup('sysop');
return TRUE;
}
}
// if the user is not an administrator, but they were, and they are still a sysop, remove their sysop status
if (!in_array($vb_userinfo['usergroupid'], $this->admin_usergroups) && $admin_secondary === FALSE) {
if (in_array("sysop", $user->getEffectiveGroups())) {
$user->removeGroup('sysop');
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;
}

/**
* 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 ) {
$vb_find_user_query = "SELECT email, usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . addslashes($user->mName) . "')";
$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
if(mysql_num_rows($vb_find_result) == 1) {
$vb_userinfo = mysql_fetch_assoc($vb_find_result);
mysql_free_result($vb_find_result);
$user->mEmail = $vb_userinfo['email'];
$user->mEmailAuthenticated = wfTimestampNow();
}
}
}
?>
Reply With Quote
  #53  
Old 08-22-2006, 01:40 AM
ElfMage ElfMage is offline
 
Join Date: Jul 2006
Location: Miami
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

:-) If I had dedicated some time to test the changes I was suggesting, we would have had it working by now... If this time it doesn't work, I will take the time to test it before my next post... <g>

Now, realize that this AuthPlugin_vBulletin was not written by me, and as such, the original author may not like/agree with my suggestions...

In the original code, the function authenticate checks for the allowed_usergroups. I personally think that this is not needed, since 'userExists' is always called before 'authenticate'.

Try changing the function 'authenticate' for the following code. Let me know if it doesn't work, and I will try it on my test server.

Code:
 
	function authenticate( $username, $password ) {
		// if their name does not contain any illegal characters, let them try to login
		if (!preg_match($this->searchpattern, $username)) { 
			$username = addslashes($username);
			$vb_find_user_query = "SELECT password, salt, usergroupid FROM " . $this->vb_prefix . "user WHERE LOWER(username)=LOWER('" . $username . "')";
			$vb_find_result = mysql_query($vb_find_user_query, $this->vb_database);
			if (mysql_num_rows($vb_find_result) == 1) {
				$vb_userinfo = mysql_fetch_assoc($vb_find_result);
				mysql_free_result($vb_find_result);
				// check password
				if(md5(md5($password) .  $vb_userinfo['salt']) == $vb_userinfo['password']) return true;
			}
		}
		return false;
	}
Reply With Quote
  #54  
Old 09-14-2006, 04:59 PM
Rowen Rowen is offline
 
Join Date: Apr 2005
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Does anyone know how this project is coming along?

vBulletin 3.6.1 is now out, last I heard, this was for 3.5.4

I would be willing to donate to help progression of this plugin.
Reply With Quote
  #55  
Old 09-14-2006, 05:03 PM
yessir's Avatar
yessir yessir is offline
 
Join Date: Jul 2005
Location: Canada
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The Luxury Wiki bridge is for 3.6 and Mediawiki 1.7.x
Reply With Quote
  #56  
Old 09-15-2006, 01:41 PM
HolisticEarth HolisticEarth is offline
 
Join Date: Apr 2006
Location: Winnipeg, MB, CAN
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Rowen
Does anyone know how this project is coming along?

vBulletin 3.6.1 is now out, last I heard, this was for 3.5.4

I would be willing to donate to help progression of this plugin.
The plugin is still working good in its original format, for both 1.7.x and 3.6.0:
http://holisticearth.org/wiki/

3.6.1 must have just come out ... I will give my forum an upgrade asap to make sure it still works.
Reply With Quote
  #57  
Old 10-20-2006, 06:45 AM
Clayton Clayton is offline
 
Join Date: Nov 2004
Posts: 216
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

some nice design styling done with wiki and your forums

:up:
Reply With Quote
  #58  
Old 12-03-2006, 02:50 AM
mfarmerhi mfarmerhi is offline
 
Join Date: Apr 2003
Posts: 74
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Gah...!

3.5.7 board. For security I recently changed the DB username and password... The integration is no longer working.

I'm getting "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/totalli/public_html/wiki/AuthPlugin_vBulletin.php on line 73" and "The password you entered is incorrect (or missing). Please try again" errors upon trying to log in.

Ideas?
Reply With Quote
  #59  
Old 03-03-2007, 04:33 PM
Hensa Hensa is offline
 
Join Date: Mar 2007
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Does this solution allow users to login to MW and vBulletin on the same domain with a single login? I want MW to be separate from, rather than integrated into, vBulletin, but with a single login.
Reply With Quote
  #60  
Old 03-03-2007, 10:31 PM
ElfMage ElfMage is offline
 
Join Date: Jul 2006
Location: Miami
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, vbWiki Standard will allow you to do that.
Reply With Quote
  #61  
Old 09-13-2007, 04:16 PM
snoopy5 snoopy5 is offline
 
Join Date: May 2007
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

does this work with vb 3.68 also?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:04 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05608 seconds
  • Memory Usage 2,358KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (2)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete