Extension talk:VBulletin

From MediaWiki.org
Jump to navigation Jump to search

This version works like a proper extension (sort of) in MW>= 1.19

<?php

define('VBULL_EXTENSION_VERSION', '2.1.2');

# if we're not in the mediawiki framework just die                                                                      
if ( !defined( 'MEDIAWIKI' ) ) die();

# extension credits                                                                                                     
$wgExtensionCredits['other'][] = array(
        'path' => __FILE__,
        'name' => 'MMOG Wiki',
        'author' => 'Paul Stout',
        'url' => 'http://www.mymmogames.net/',
        'description' => 'Single Sign On from vBulletin',
        'version' => '2.1.2',
);

# Set up                                                                                                                
$wgHooks['PersonalUrls'][] = 'set_personal_urls';
$wgHooks['UserLoadFromSession'][] = 'vBSSOAutoAuth';



# INITIALIZE VBULLETIN SUBSYSTEM                                                                                        

# The only var needed                                                                                                   
$VB_SYSTEM_PATH = '/home/seqadmin/seqanswers.com/forums';

if ( !defined( 'CWD' ) )
    define( 'CWD', ( $VB_SYSTEM_PATH ) );

define('THIS_SCRIPT', 'wiki');
require_once( CWD . '/global.php');
require_once( CWD . '/includes/functions.php');

$vBDonor = FALSE;
if ( is_member_of( $vbulletin->userinfo, 11 ) ) {
    $vBDonor = TRUE;
}

# END VBULLETIN SUBSYSTEM                                                                                               


function vBSSOAutoAuth(&$user) {
    global $wgRequest;
    global $vbulletin;
    global $wgUser;

    if ( $user != null ) {
        # user is authenticated (by another hook)                                                                       
        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'] == 0 ) {
                 $user->logout();
            }

            # Check NoLogin groups. If they're logged in and shouldn't                                                  
            # be, log them out!                                                                                         
            $mmog_nologin = explode( ',', str_replace( ' ', '',
              $vbulletin->options['mmog_wiki_nologin_ug'] ) );

            foreach ( $mmog_nologin as $nologin ) {
                if ( is_member_of( $vbulletin->userinfo, $nologin ) ) {
                    $user->logout();
                    break;
                }
            }
            return true;
        }
    }

    if ( $vbulletin->userinfo['userid'] ) {
        # Check Nologin Groups - if they're a member then do not log                                                    
        # them in.                                                                                                      
        $mmog_nologin = explode( ',', str_replace( ' ', '',
          $vbulletin->options['mmog_wiki_nologin_ug'] ) );

        foreach ( $mmog_nologin as $nologin ) {
            if ( is_member_of( $vbulletin->userinfo, $nologin ) )
                return true;
        }

        $username = $vbulletin->userinfo['username'];

        if ( $username ) {
            $u = User::newFromName( $username );
            if ( $u->getID() == 0 ) {
                $u->addToDatabase();
                $u->setToken();
            }
            else {
                $u->clearInstanceCache( 'id' );
                $u->load();
            }

            $user = $u;
            $user->setOption( 'rememberpassword', 1 );
            wfSetupSession();
            $user->setCookies();
            $user->invalidateCache();
            $user->saveSettings();

            # Check Sysop Groups                                                                                        
            $mmog_sysopgroup = explode( ',', str_replace( ' ', '',
              $vbulletin->options['mmog_wiki_sysop_ug'] ) );

            foreach( $mmog_sysopgroup as $sysopgroup ) {
                if ( is_member_of( $vbulletin->userinfo, $sysopgroup ) ) {
                    $user->addGroup( 'sysop' );
                    break;
                }
            }

            $mmog_bureaugroup = explode( ',', str_replace( ' ', '',
              $vbulletin->options['mmog_wiki_bureaucrat_ug'] ) );

            foreach ( $mmog_bureaugroup as $bureaugroup ) {
                if ( is_member_of( $vbulletin->userinfo, $bureaugroup ) ) {
                    $user->addGroup( 'bureaucrat' );
                    break;
                }
            }

        }
    }
    else
        $user->logout();

    return true;
}

function set_personal_urls( &$personal_urls, &$wgTitle ) {
    global $vbulletin;

    if ( $vbulletin->userinfo['userid'] !== 0 ) {
        $personal_urls['logout'] = array(
            'text' => wfMsg( 'userlogout' ),
            'href' => ( $vbulletin->options['bburl'] .
                        '/login.php?do=logout&logouthash=' .
                        $vbulletin->userinfo['logouthash'] ),
            'active' => false
            );
    }
    else{
        if(isset($personal_urls['login'])){
            $personal_urls['login'] = array(
                'text' => wfMsg( 'userlogin' ),
                'href' => ( 'http://seqanswers.com/' ),
                'active' => false
                );
        }
        if(isset($personal_urls['anonlogin'])){
            $personal_urls['anonlogin'] = array(
                'text' => wfMsg( 'userlogin' ),
                'href' => ( 'http://seqanswers.com/' ),
                'active' => false
            );
        }
    }
    return TRUE;
}



# Shut down the vBulletin registry - we no longer need it.                                                              
# Do not save reporting for raw output files (CSS, images, etc)                                                         

if ( $_SERVER['REQUEST_METHOD'] === 'GET' ) {
    if ( strpos( $_SERVER['REQUEST_URI'], 'action=raw' ) === FALSE ) {
        exec_shut_down();
    }
}