Thread: Integration with vBulletin - MediaWiki/vBulletin Single Sign-On
View Single Post
  #164  
Old 02-06-2010, 10:46 AM
bepe bepe is offline
 
Join Date: Nov 2009
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's not really a mod... it's more like a new version

AuthPlugin_vbMediaWiki.php
PHP Code:
<?php
/**
 */
# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
# http://www.mediawiki.org/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# http://www.gnu.org/copyleft/gpl.html

/**
 * 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.
 */

$current_dir getcwd();
chdir'../forum' );
require_once( 
"global.php" );
require_once( 
"includes/functions.php" );
chdir$current_dir );

require_once( 
"$IP/includes/AuthPlugin.php" );

/**
 * Users can't change their passwords here
 */
class AuthPlugin_vbMediaWiki extends AuthPlugin {

    public function 
allowPasswordChange() {
        return 
false;
    }
}
$wgAuth = new AuthPlugin_vbMediaWiki();

/**
 * Set the 'vbmediawikiskin' skin as default and prevent users from changing it
 * - we have only one integrated skin right now
 */
$wgDefaultSkin   'vbwikiskin';
$wgAllowUserSkin false;

/**
 * Disable email and real name
 * - Not sure yet how to solve conflicts between vBulletin and MediWiki user data changes
 */
$wgEnableEmail   false;
$wgAllowRealName false;

/**
 * Disable 'pretty' URLs, e.g. index.php/Page_title
 * - We need to disable it or rewrite code for vBulletin's "Who's Online"
 */
$wgUsePathInfo false;

/**
 * Set this to false to avoid forcing the first letter of links to capitals.
 * - vBulletin user names can be lower case, so we need that
 */
$wgCapitalLinks false;
 
/**
 * Disabling new user registrations and anonymous edits
 * - vBulletin user names can be lower case, so we need that
 */
$wgGroupPermissions['*']['createaccount'] = false;
$wgGroupPermissions['*']['edit'] = false;

/**
 * Disable manual login and logout functions for all users and remove the ChangePassword page
 * - vBulletin will do the login/logout stuff and also the Password should be changes there
 */
function SpecialPage_initListHook( &$aSpecialPages )
{
    unset( 
$aSpecialPages['Userlogout'] );
    unset( 
$aSpecialPages['Userlogin'] );
    unset( 
$aSpecialPages['Resetpass'] );
    return 
true;
}
$wgHooks['SpecialPage_initList'][] = 'SpecialPage_initListHook';

/**
 * Remove login and logout buttons for all users
 * - vBulletin shows them in the navbar anyway
 */
function PersonalUrlsHook( &$personal_urls, &$title )
{
    unset( 
$personal_urls["login"] );
    unset( 
$personal_urls["logout"] );
    unset( 
$personal_urls['anonlogin'] );    
    return 
true;
}
$wgHooks['PersonalUrls'][] = 'PersonalUrlsHook';

/**
 * User Group Translation
 * - NoLogin:    Can't login to wiki... only to vBulletin
 * - Sysop:      Wiki Administrators
 * - Bureaucrat: Could edit user rights... but they will be reseted anyway
 *               It's more clear if we only allow a group like moderators to Administrate the Wiki
 */
$vwNoLoginGroups    = array();
$vwSysopGroups      = array(6,7);
$vwBureaucratGroups = array(6);

/**
 * Minimum number of posts a user need in to login to the Wiki 
 * - This is a community portal... only real members of the community should edit the Wiki
 */
$vwMinReputationPosts       5;
$vwMinReputationPostsNotice 'wiki_posts';

/**
 * Sync user to vBulletin
 * - Same user for the Wiki as in vBulletin
 */
function UserLoadFromSessionHook$user, &$result ) {
    global 
$vbulletin;
    global 
$vwNoLoginGroups$vwSysopGroups$vwBureaucratGroups;
    global 
$vwMinReputationPosts$vwMinReputationPostsNotice;

    
// check if user is authenticated (by another hook)
    
if ( $user != null ) {
        if ( !
$user->isAnon() ) {
            
// User is not anonymous. 
            // Check for the existence of a valid vB userid.  If we don't have one, log the old user out.
            
if ( $vbulletin->userinfo['userid'] == ) {
                
$user->logout();
            }

            
// Check vwNoLoginGroups
            // If they're logged in and shouldn't be, log them out!
            
if ( is_member_of$vbulletin->userinfo$vwNoLoginGroups ) ) {
                
$user->logout();
                break;
            }
            
            if( 
$vbulletin->userinfo['posts'] < $vwMinReputationPosts ) {
                
                if( 
$vwMinReputationPostsNotice != null ) {
                    
$vbulletin->noticecache = array(
                        
$vwMinReputationPostsNotice => array(
                            
'has_x_postcount' => array(0,$vwMinReputationPosts 1)
                        )
                    );
                }
                
                
$user->logout();
                break;
            }

            return 
true;
        }
        
$user->logout();
    }
    
    if ( 
$vbulletin->userinfo['userid'] )
    {
        
// Check vwNoLoginGroups
        
if ( is_member_of$vbulletin->userinfo$vwNoLoginGroups ) ) {
            return 
true;
        }

        if( 
$vbulletin->userinfo['posts'] < $vwMinReputationPosts ) {
            
            if( 
$vwMinReputationPostsNotice != null ) {
                
$vbulletin->noticecache = array(
                    
$vwMinReputationPostsNotice => array(
                        
'has_x_postcount' => array(0,$vwMinReputationPosts 1)
                    )
                );
            }
            
            return 
true;
        }
            
        
$username $vbulletin->userinfo['username'];

        if ( 
$username ) {
            
$u User::newFromName$username );
            if (
is_null($u)) {
                
// Invalid username or some other error...
                
return;
            }
            if ( 
$u->getID() == ) {
                
$u->addToDatabase();
                
$u->setToken();
            }
            else 
$u->loadFromDatabase();
            
            
$user $u;
            
$user->setOption'rememberpassword');
            
$user->saveSettings();
            
$user->setCookies();
            
            
// Check vwSysopGroups.
            
$user->removeGroup'sysop' );
            if ( 
is_member_of$vbulletin->userinfo$vwSysopGroups ) ) {
                
$user->addGroup'sysop' );
            }

            
// Check vwBureaucratGroups.
            
$user->removeGroup'bureaucrat' );
            if ( 
is_member_of$vbulletin->userinfo$vwBureaucratGroups ) ) {
                
$user->addGroup'bureaucrat' );
            }
        }
    }
    else 
$user->logout();

    return 
true;
}    
$wgHooks['UserLoadFromSession'][] = 'UserLoadFromSessionHook';
and there are much more changes, like a new wiki skin and other changes for getting the vB WOL working right
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01470 seconds
  • Memory Usage 1,885KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete