Extension:VBulletin stats

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
VBulletin stats

Release status: unknown

Implementation Tag
Description
License No license specified
Download package

Check usage (experimental)

WARNING: Some of the information on this page refers to a site that was username/password restricted. Fortunately the source code could be recovered from the Internet Archive Wayback Machine. Excellent illustration of why code should be hosted on google code, sourceforge or similar.

Note: the most up-to-date version of this extension will be on my wiki.

I wanted to incorporate my vBulletin forum statistics into my wiki page(s). So I looked into creating an extension and came out with this - the vBStats extension. It retrieves an array of data from your vBulletin database and displays it according to conditions you supply (a list of conditions is below).

This hack has been tested on the following vBulletin and MediaWiki combinations;

vBulletin MediaWiki
3.0.8 1.4.7
3.5.2 1.5.3

Contents

[edit] Demo

You can see a demonstration of this extension in action here. (password protected now)

[edit] Installation

To install the script, copy the source code available at the bottom of this page (choose between versions 3.0.8 and 3.5.2), save it to a file named vbStats.php and upload it to yourwiki/extensions/

Next, put the following code at the bottom of your localSettings.php file:

# include vBStatsExtension
include("extensions/vbStats.php");

Finally, change these values in vbStats.php:

########### EDIT THESE VARS ########### 
$server = "localhost"; # if you don't know what this is just leave it as localhost
$username = "username"; # your MySQL username
$password = "password"; # your MySQL password
$forumdb = "forum"; # your forum MySQL database name
$wikidb = "wiki"; # your wiki MySQL database name
$maxThreadLimit = 10; # max number of threads to show
$maxUserLimit = 10; # max number of users to show
$forum_url = "http://www.yourwebsite.com/forum"; # your forum url - DO NOT put an ending forward slash on (site.com/forum/ <-WRONG)
########### /EDIT THESE VARS ###########

[edit] Usage

[edit] Options

To use the script, simply put the following tags in a mediaWiki article;

<vbThreadStats>
limit=[number]
sort=[ASC,DESC]
order by=[date,title,rand]
</vbThreadStats>

<vbUserStats>
limit=[number]
sort=[ASC,DESC]
order by=[posts,joindate,username,rand]
</vbUserStats>

<vbBoardStats>
show total posts=[true,false]
show total threads=[true,false]
show total members=[true,false]
show largest thread=[true,false]
show most popular thread=[true,false]
show most popular forum=[true,false]
</vbBoardStats>

<vbUserActivityStats>
show active users=[true,false]
show inactive users=[true,false]
show sub-heading=[true,false]
show last 30 days=[true,false]
show last 14 days=[true,false]
show last 7 days=[true,false]
</vbUserActivityStats>

[edit] Example

<!-- show latest threads -->
<vbThreadStats>
limit=5
sort=DESC
order by=date
</vbThreadStats>

[edit] Source code

[edit] Version 3.0.8

<?php
# upload extension to wiki/extensions/
# to activate the extension, include it at the bottom of LocalSettings.php
# with: include("extensions/vbStats.php");
# author; Ross Oliver, http://www.developersdigest.org
# tag list;
/*
<vbThreadStats>
limit=(number)
sort=(ASC,DESC)
order by=(date,title,rand)
</vbThreadStats>
 
<vbUserStats>
limit=(number)
sort=(ASC,DESC)
order by=(posts,joindate,username,rand)
</vbUserStats>
 
<vbBoardStats>
show total posts=(true/false)
show total threads=(true/false)
show total members=(true/false)
show largest thread=(true/false)
show most popular thread=(true/false)
show most popular forum=(true/false)
</vbBoardStats>
 
<vbUserActivityStats>
show active users=(true/false)
show inactive users=(true/false)
show sub-heading=(true/false)
show last 30 days=(true/false)
show last 14 days=(true/false)
show last 7 days=(true/false)
</vbUserActivityStats>
*/
$wgExtensionFunctions[] = "wfVbStats";
 
########### EDIT THESE VARS ########### 
$server = "localhost"; # if you don't know what this is just leave it as localhost
$username = "username"; # your MySQL username
$password = "password"; # your MySQL password
$forumdb = "forum"; # your forum MySQL database name
$wikidb = "wiki"; # your wiki MySQL database name
$maxThreadLimit = 10; # max number of threads to show
$maxUserLimit = 10; # max number of users to show
$forum_url = "http://www.yourwebsite.com/forum"; # your forum url - DO NOT put an ending forward slash on (site.com/forum/ <-WRONG)
########### /EDIT THESE VARS ########### 

function wfVbStats() {
    global $wgParser;
 
    $wgParser->setHook( "vbThreadStats", "vbThreadStats" );
    $wgParser->setHook( "vbUserStats", "vbUserStats" );
        $wgParser->setHook( "vbBoardStats", "vbBoardStats" );
        $wgParser->setHook( "vbUserActivityStats", "vbUserActivityStats" );
}
 
function databaseConnect($database) {
        # connect to vbulletin database
 global $server;
        global $username;
        global $password;
        global $forumdb;
        global $wikidb;
        mysql_connect($server, $username, $password) or die("could not connect to database");
        if($database == "forum") {
                mysql_select_db($forumdb) or die("could not select database (".$database.")");
        } else {
                mysql_select_db($wikidb) or die("could not select database (".$database.")");
        }
}
 
//----------------------------------------------- THREAD STATS -----------------------------------------------\\
# the callback function for converting the input text to HTML output
function vbThreadStats($input) {
#global vars
global $maxThreadLimit;
global $forum_url;
 
# connect to forum database
databaseConnect("forum");
 
# set default arguments
$args['limit'] = 5;
$args['order_by'] = "threadid";
$args['sort'] = "DESC";
# get input args
$aParams = explode("\n", $input); # ie 'limit=5'
 foreach($aParams as $sParam) {
                $aParam = explode("=", $sParam); # ie $aParam[0] = 'limit' and $aParam[1] = '5'
                 if( count( $aParam ) < 2 ) # no arguments passed
                         continue;
                $sType = trim($aParam[0]); # ie 'limit'
         $sArg = trim($aParam[1]); # ie '5'
         
                switch ($sType) {
                        case 'limit':
                                if(!is_numeric($sArg)) { #contains string
                                 die("the limit argument must be numeric (default 5)");
                                } else {
                                        if($sArg > $maxThreadLimit) {
                                                $args['limit'] = $maxThreadLimit;
                                        } else {
                                                $args['limit'] = $sArg;
                                        }
                                }
                        break;
 
                        case 'sort':
                                if(($sArg != "ASC") && ($sArg != "DESC")) {
                                        die("the sort argument must be; 'ASC' or 'DESC'");
                                } else {
                                        $args['sort'] = $sArg;
                                }
                        break;
 
                        case 'order by':
                                if(($sArg != "date") && ($sArg != "title") && ($sArg != "rand")) {
                                        die("the order by argument must be; 'date', 'title'");
                                } else {
                                        if($sArg == "date") {
                                                $args['order_by'] = "threadid";
                                        } 
                                        elseif($sArg == "rand") {
                                                $args['order_by'] = "RAND()";
                                        } else {
                                                $args['order_by'] = $sArg;
                                        }
                                }
                        break;                        
                }
        }
 
# build the sql query
$threadSQL = mysql_query("SELECT title, postusername, lastposter, forumid, replycount, views, firstpostid, forumid, postuserid, lastpost FROM thread WHERE visible = 1 ORDER BY ".$args['order_by']." ".$args['sort']." LIMIT ".$args['limit']."")
or die(mysql_error());
 
# fetch the threadSQL results
while($row = mysql_fetch_array($threadSQL)) {
        $threads['titles'][] = "[".$forum_url."/showthread.php?p=".$row['firstpostid']." ".$row['title']."]";
        $threads['posted_by'][] = "[".$forum_url."/member.php?find=lastposter&f=".$row['forumid']." ".$row['postusername']."]";
        $threads['last_post_by'][] = "[".$forum_url."/member.php?u=".$row['postuserid']." ".$row['lastposter']."]";
        $threads['num_replies'][] = "<b>(".$row['replycount']." replies)</b>";
        $threads['num_views'][] = "<b>(".$row['views']." views)</b>";
        $threads['last_post'][] = date("l j F Y", $row['lastpost']);
        # match the forum id to the forum name - there must be a better way of doing this. I will change it when i think of it.
 $forumName = mysql_query("SELECT title FROM forum WHERE forumid = '".$row['forumid']."' LIMIT 1")
        or die(mysql_error());
        $thisForumName = mysql_fetch_array($forumName);
        $threads['forum_name'][] = $thisForumName['title'];
}
 
# reselect the wiki database
databaseConnect("wiki");
 
# build thread output
for($i=0; $i <= (count($threads['titles'])-1); $i++) {
        $output .= # build threads output   
 "--".$threads['titles'][$i]." (<i>".$threads['forum_name'][$i]."</i>) ".$threads['num_views'][$i]." ".$threads['num_replies'][$i]."<br>
        <i>Started by; ".$threads['posted_by'][$i]." Last post by; ".$threads['last_post_by'][$i]." on ".$threads['last_post'][$i]."</i><br><br>";
}
 
# parse the output for wiki markup
global $wgTitle;
global $wgUser;
 
$parser = new Parser();
$parser->startExternalParse($wgTitle, ParserOptions::newFromUser( $wgUser ), OT_HTML);
# print to screen
return $parser->internalParse($output, 0, array(), false);
}
//----------------------------------------------- /THREAD STATS -----------------------------------------------\\
 
//------------------------------------------------ USER STATS -------------------------------------------------\\
# the callback function for converting the input text to HTML output
function vbUserStats($input) {
#global vars
global $maxUserLimit;
global $forum_url;
 
# connect to forum database
databaseConnect("forum");
 
# set default arguments
$args['limit'] = 5;
$args['order_by'] = "posts";
$args['sort'] = "DESC";
# get input args
$aParams = explode("\n", $input); # ie 'limit=5'
 foreach($aParams as $sParam) {
                $aParam = explode("=", $sParam); # ie $aParam[0] = 'limit' and $aParam[1] = '5'
                 if( count( $aParam ) < 2 ) # no arguments passed
                         continue;
                $sType = trim($aParam[0]); # ie 'limit'
         $sArg = trim($aParam[1]); # ie '5'
         
                switch ($sType) {
                        case 'limit':
                                if(!is_numeric($sArg)) { #contains string
                                 die("the limit argument must be numeric (default 5)");
                                } else {
                                        if($sArg > $maxUserLimit) {
                                                $args['limit'] = $maxUserLimit;
                                        } else {
                                                $args['limit'] = $sArg;
                                        }
                                }
                        break;
 
                        case 'sort':
                                if(($sArg != "ASC") && ($sArg != "DESC")) {
                                        die("the sort argument must be; 'ASC' or 'DESC'");
                                } else {
                                        $args['sort'] = $sArg;
                                }
                        break;
 
                        case 'order by':
                                if(($sArg != "posts") && ($sArg != "joindate") && ($sArg != "username") && ($sArg != "rand")) {
                                        die("the order by argument must be; 'date', 'title'");
                                } elseif($sArg == "rand") {
                                        $args['order_by'] = "RAND()";
                                } else {
                                        $args['order_by'] = $sArg;
                                }
                        break;                        
                }
        }
 
# get total forum posts (to work out percentage/user)
$numRows = mysql_query("SELECT postid FROM post")
or die(mysql_error());
 
$totalPosts = mysql_num_rows($numRows);
 
# build the sql query
$userSQL = mysql_query("SELECT username, userid, posts, joindate, reputation, usertitle FROM user ORDER BY ".$args['order_by']." ".$args['sort']." LIMIT ".$args['limit']."")
or die(mysql_error());
 
# fetch the userSQL results
while($row = mysql_fetch_array($userSQL)) {
        $users['posts'][] = "(<b>".$row['posts']." posts</b>)";
        $users['reputation'][] = "".$row['reputation']."";
        $users['user_title'][] = "".$row['usertitle']."";
        $users['join_date'][] = date("l j F Y", $row['joindate']);
        $users['username'][] = "[".$forum_url."/member.php?u=".$row['userid']." ".$row['username']."]";
        $users['post_percentage'][] = (($row['posts']/$totalPosts)*100);
        if($row['posts'] == 0) {
                $users['bar_color'][] = "#FF0000"; # bar color for 0 posts
 } else {
                $users['bar_color'][] = "#00CC33"; # bar color for more than 0 posts
 }
}
 
# reselect the wiki database
databaseConnect("wiki");
 
# build thread output
for($i=0; $i <= (count($users['username'])-1); $i++) {
        $output .= # build user stats output        
 "--".$users['username'][$i]." ".$users['posts'][$i]." <i>Join date; ".$users['join_date'][$i]."<br>
        User title; <b>".$users['user_title'][$i]."</b> Reputation; <b>".$users['reputation'][$i]."</b><br>
        <div style=\"\">Posts; </div>
        <div style=\"height:8px; overflow:hidden; width:".(($users['post_percentage'][$i]*1.8)+5)."px; background-color:".$users['bar_color'][$i]."; margin-top:-13px; margin-left:43px;\"></div>
        <div style=\"margin-left:".(($users['post_percentage'][$i]*1.8)+55)."px; margin-top:-15px;\">(".round($users['post_percentage'][$i], 2)."% of total posts)</div></i><br>";
}
 
# parse the output for wiki markup
global $wgTitle;
global $wgUser;
 
$parser = new Parser();
$parser->startExternalParse($wgTitle, ParserOptions::newFromUser( $wgUser ), OT_HTML);
# print to screen
return $parser->internalParse($output, 0, array(), false);
}
//------------------------------------------------ /USER STATS -------------------------------------------------\\
 
//------------------------------------------------ BOARD STATS -------------------------------------------------\\
# the callback function for converting the input text to HTML output
function vbBoardStats($input) {
#global vars
global $forum_url;
 
# connect to forum database
databaseConnect("forum");
 
# set default arguments
$args['show_total_posts'] = "true";
$args['show_total_threads'] = "true";
$args['show_total_members'] = "true";
$args['show_largest_thread'] = "true";
$args['show_most_popular_thread'] = "true";
$args['show_most_popular_forum'] = "true";
# get input args
$aParams = explode("\n", $input); # ie 'limit=5'
 foreach($aParams as $sParam) {
                $aParam = explode("=", $sParam); # ie $aParam[0] = 'limit' and $aParam[1] = '5'
                 if( count( $aParam ) < 2 ) # no arguments passed
                         continue;
                $sType = trim($aParam[0]); # ie 'limit'
         $sArg = trim($aParam[1]); # ie '5'
         
                switch ($sType) {
                        case 'show total posts':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show total posts' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_total_posts'] = $sArg;
                                }
                        break;
 
                        case 'show total threads':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show total threads' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_total_threads'] = $sArg;
                                }
                        break;
 
                        case 'show total members':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show total members' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_total_members'] = $sArg;
                                }
                        break;
 
                        case 'show largest thread':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show largest thread' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_largest_thread'] = $sArg;
                                }
                        break;
 
                        case 'show most popular thread':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show most popular thread' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_most_popular_thread'] = $sArg;
                                }
                        break;
 
                        case 'show most popular forum':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show most popular thread' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_most_popular_forum'] = $sArg;
                                }
                        break;
                }
        }
 
# build the sql queries
if($args['show_total_posts'] == "true") { # build the show total posts query
 $totalPosts = mysql_query("SELECT postid FROM post")
        or die(mysql_error());
        $numPosts = mysql_num_rows($totalPosts);
        # build board stats output
 $output .= "Total posts; <b>".$numPosts."</b>";
}
if($args['show_total_threads'] == "true") { # build the show total threads query
 $totalThreads = mysql_query("SELECT threadid FROM thread")
        or die(mysql_error());
        $numThreads = mysql_num_rows($totalThreads);
        # build board stats output
 if($args['show_total_posts'] == "true") { 
                $spacer = " -- ";
        }
        $output .= $spacer."Total threads; <b>".$numThreads."</b>";
}
if($args['show_total_members'] == "true") { # build the show total members query
 $totalMembers = mysql_query("SELECT userid FROM user")
        or die(mysql_error());
        $numMembers = mysql_num_rows($totalMembers);
        if(($args['show_total_posts'] == "true") || ($args['show_total_threads'] == "true")) {
                $spacer = " -- ";
        } else {
                $spacer = "";
        }
        # build board stats output
 $output .= " -- Total members; <b>".$numMembers."</b><br><br>";
}
if($args['show_largest_thread'] == "true") { # build the show largest thread query
 $largestThread = mysql_query("SELECT title, postusername, postuserid, lastposter, views, lastpost, firstpostid, forumid, replycount FROM thread WHERE visible = 1 ORDER BY replycount DESC LIMIT 1")
        or die(mysql_error());
        $lThread = mysql_fetch_array($largestThread);
        $lastPost = date("l j F Y", $lThread['lastpost']);
        # get forum name relevant to id
 $forumName = mysql_query("SELECT title FROM forum WHERE forumid = '".$lThread['forumid']."' LIMIT 1")
        or die(mysql_error());
        $thisForumName = mysql_fetch_array($forumName);
        # build board stats output
 $output .= "--Largest thread; [".$forum_url."/showthread.php?p=".$lThread['firstpostid']." ".$lThread['title']."] <i>(".$thisForumName['title']."</i>) <b>(".$lThread['views']." views) (".$lThread['replycount']." replies)</b><br>
        <i>Started by; [".$forum_url."/member.php?find=lastposter&f=".$lThread['forumid']." ".$lThread['postusername']."] Last post by; [".$forum_url."/member.php?u=".$lThread['postuserid']." ".$lThread['lastposter']."] on ".$lastPost."</i><br><br>";
}
if($args['show_most_popular_thread'] == "true") { # build the show most popular thread query
 $mostPopularThread = mysql_query("SELECT title, postusername, lastposter, views, lastpost, firstpostid, forumid, replycount, postuserid FROM thread WHERE visible = 1 ORDER BY views DESC LIMIT 1")
        or die(mysql_error());
        $mpThread = mysql_fetch_array($mostPopularThread);
        $lastPost = date("l j F Y", $mpThread['lastpost']);
        # get forum name relevant to id
 $forumName = mysql_query("SELECT title FROM forum WHERE forumid = '".$mpThread['forumid']."' LIMIT 1")
        or die(mysql_error());
        $thisForumName = mysql_fetch_array($forumName);
        # build board stats output
 $output .= "--Most popular thread; [".$forum_url."/showthread.php?p=".$mpThread['firstpostid']." ".$mpThread['title']."] <i>(".$thisForumName['title']."</i>) <b>(".$mpThread['views']." views) (".$mpThread['replycount']." replies)</b><br>
        <i>Started by; [".$forum_url."/member.php?find=lastposter&f=".$mpThread['forumid']." ".$mpThread['postusername']."] Last post by; [".$forum_url."/member.php?u=".$mpThread['postuserid']." ".$mpThread['lastposter']."] on ".$lastPost."</i><br><br>";
}
if($args['show_most_popular_forum'] == "true") { # build the show most popular forum query
 $mostPopularForum = mysql_query("SELECT title, replycount, lastpost, lastposter, lastthread, lastthreadid, forumid FROM forum ORDER BY threadcount DESC LIMIT 1")
        or die(mysql_error());
        $mpForum = mysql_fetch_array($mostPopularForum);
        $lastPost = date("l j F Y", $mpForum['lastpost']);
        # build board stats output
 $output .= "--Most popular forum; [".$forum_url."/forumdisplay.php?f=".$mpForum['forumid']." ".$mpForum['title']."] <b>(".$mpForum['replycount']." replies)</b><br>
        <i>Last post by; [".$forum_url."/member.php?find=lastposter&f=".$mpForum['forumid']." ".$mpForum['lastposter']."] in [".$forum_url."/showthread.php?t=".$mpForum['lastthreadid']." ".$mpForum['lastthread']."] on ".$lastPost."</i><br><br>";
}
 
# reselect the wiki database
databaseConnect("wiki");
 
# parse the output for wiki markup
global $wgTitle;
global $wgUser;
 
$parser = new Parser();
$parser->startExternalParse($wgTitle, ParserOptions::newFromUser( $wgUser ), OT_HTML);
# print to screen
return $parser->internalParse($output, 0, array(), false);
}
//------------------------------------------------ /BOARD STATS -------------------------------------------------\\
 
//------------------------------------------------ USER ACTIVITY STATS -------------------------------------------------\\
# the callback function for converting the input text to HTML output
function vbUserActivityStats($input) {
#global vars
global $forum_url;
 
# connect to forum database
databaseConnect("forum");
 
# set default arguments
$args['show_active_users'] = "true";
$args['show_inactive_users'] = "true";
$args['show_sub-heading'] = "true";
$args['show_last_30_days'] = "true";
$args['show_last_14_days'] = "true";
$args['show_last_7_days'] = "true";
# get input args
$aParams = explode("\n", $input); # ie 'limit=5'
 foreach($aParams as $sParam) {
                $aParam = explode("=", $sParam); # ie $aParam[0] = 'limit' and $aParam[1] = '5'
                 if( count( $aParam ) < 2 ) # no arguments passed
                         continue;
                $sType = trim($aParam[0]); # ie 'limit'
         $sArg = trim($aParam[1]); # ie '5'
         
                switch ($sType) {
                        case 'show sub-heading':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show sub-heading' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_sub-heading'] = $sArg;
                                }
                        break;
 
                        case 'show active users':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show active users' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_active_users'] = $sArg;
                                }
                        break;
 
                        case 'show inactive users':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show inactive users' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_inactive_users'] = $sArg;
                                }
                        break;
 
                        case 'show last 30 days':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show last 30 days' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_last_30_days'] = $sArg;
                                }
                        break;
 
                        case 'show last 14 days':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show last 14 days' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_last_14_days'] = $sArg;
                                }
                        break;
 
                        case 'show last 7 days':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show last 7 days' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_last_7_days'] = $sArg;
                                }
                        break;
                }
        }
 
# get total users on forum (used in several queries)
$users = mysql_query("SELECT userid FROM user")
or die(mysql_error());
$numUsers = mysql_num_rows($users);
# work out dates
$now = date(U); # date in epoch seconds
$DaysAgo30 = $now - 2592000; # 30 days ago in epoch seconds
$DaysAgo14 = $now - 1209600; # 14 days ago in epoch seconds
$DaysAgo7 = $now - 604800; # 7 days ago in epoch seconds

# build the sql queries
if($args['show_active_users'] == "true") { # build the show active users query
 $activeUsers = mysql_query("SELECT userid FROM user WHERE posts > 0")
        or die(mysql_error());
        $numActiveUsers = mysql_num_rows($activeUsers);
        $term = "have"; # grammer is important :)
 if($numActiveUsers <= 1) {
                $term = "has";
        }
        # percentage that have posted
 $precentageActive = ($numActiveUsers/$numUsers)*100;
        # output user activity
 $output .= "--Active users; <div style=\"height:8px; overflow:hidden; width:".(($precentageActive*1.8)+5)."px; background-color:#00CC33; margin-top:-12px; margin-left:88px;\"></div><div style=\"margin-top:-13px; margin-left:".(100+($precentageActive*1.8))."px;\"><i>".round($precentageActive, 2)."% (".$numActiveUsers." ".$term." posted)</i></div>";
}
if($args['show_inactive_users'] == "true") { # build the show inactive users query
 $numInactiveUsers = $numUsers - $numActiveUsers;
        $percentageInactive = ($numInactiveUsers/$numUsers)*100;
        $term = "have"; # grammer is important :)
 if($numInactiveUsers <= 1) {
                $term = "has";
        }
        # output user inactivity
 $output .= "--Inctive users; <div style=\"height:8px; overflow:hidden; width:".(($percentageInactive*1.8)+5)."px; background-color:#FF0000; margin-top:-12px; margin-left:90px;\"></div><div style=\"margin-top:-13px; margin-left:".(102+($percentageInactive*1.8))."px;\"><i>".round($percentageInactive, 2)."% (".$numInactiveUsers." ".$term." not posted)</i></div><br>";
}
if($args['show_sub-heading'] == "true") { # add title for users on in last x days to output
$output .= "<b>Visits of registered members for the last 30, 14 and 7 days</b><br><br>";
}
if($args['show_last_30_days'] == "true") { # build the show last 30 days query
 $last30Days = mysql_query("SELECT userid FROM user WHERE lastvisit >= $DaysAgo30")
        or die(mysql_error());
        $numLast30 = mysql_num_rows($last30Days);
        $percentageUsersLast30 = ($numLast30/$numUsers)*100;
        # output users who visited in last 30 days
 $output .= "--The last 30 days; <div style=\"height:8px; overflow:hidden; width:".$percentageUsersLast30."px; background-color:#FF9900; margin-top:-12px; margin-left:110px;\"></div><div style=\"margin-top:-13px; margin-left:".($percentageUsersLast30+115)."px;\"><i>".round($percentageUsersLast30, 2)."%</i> (<b>".$numLast30."</b>)</div><br>";
}
if($args['show_last_14_days'] == "true") { # build the show last 14 days query
 $last14Days = mysql_query("SELECT userid FROM user WHERE lastvisit >= $DaysAgo14")
        or die(mysql_error());
        $numLast14 = mysql_num_rows($last14Days);
        $percentageUsersLast14 = ($numLast14/$numUsers)*100;
        # output users who visited in last 30 days
 $output .= "--The last 14 days; <div style=\"height:8px; overflow:hidden; width:".$percentageUsersLast14."px; background-color:#0000FF; margin-top:-12px; margin-left:110px;\"></div><div style=\"margin-top:-13px; margin-left:".($percentageUsersLast14+115)."px;\"><i>".round($percentageUsersLast14, 2)."%</i> (<b>".$numLast14."</b>)</div><br>";
}
if($args['show_last_7_days'] == "true") { # build the show last 7 days query
 $last7Days = mysql_query("SELECT userid FROM user WHERE lastvisit >= $DaysAgo7")
        or die(mysql_error());
        $numLast7 = mysql_num_rows($last7Days);
        $percentageUsersLast7 = ($numLast7/$numUsers)*100;
        # output users who visited in last 30 days
 $output .= "--The last 7 days; <div style=\"height:8px; overflow:hidden; width:".$percentageUsersLast7."px; background-color:#00CC33; margin-top:-12px; margin-left:105px;\"></div><div style=\"margin-top:-13px; margin-left:".($percentageUsersLast7+115)."px;\"><i>".round($percentageUsersLast7, 2)."%</i> (<b>".$numLast7."</b>)</div><br>";
}
# reselect the wiki database
databaseConnect("wiki");
 
# parse the output for wiki markup
global $wgTitle;
global $wgUser;
 
$parser = new Parser();
$parser->startExternalParse($wgTitle, ParserOptions::newFromUser( $wgUser ), OT_HTML);
# print to screen
return $parser->internalParse($output, 0, array(), false);
}
//------------------------------------------------ /USER ACTIVITY STATS -------------------------------------------------\\
?>

[edit] Version 3.5.2

<?php
# to activate the extension, include it from your LocalSettings.php
# with: include("extensions/YourExtensionName.php");

$wgExtensionFunctions[] = "wfVbStats";
 
########### EDIT THESE VARS ########### 
$server = "localhost"; # if you don't know what this is just leave it as localhost
$username = "username"; # your MySQL username
$password = "password"; # your MySQL password
$forumdb = "forum"; # your forum MySQL database name
$wikidb = "wiki"; # your wiki MySQL database name
$maxThreadLimit = 10; # max number of threads to show
$maxUserLimit = 10; # max number of users to show
$forum_url = "http://www.yourwebsite.com/forum"; # your forum url - DO NOT put an ending forward slash on (site.com/forum/ <-WRONG)
########### /EDIT THESE VARS ########### 

function wfVbStats() {
    global $wgParser;
 
    $wgParser->setHook( "vbThreadStats", "vbThreadStats" );
    $wgParser->setHook( "vbUserStats", "vbUserStats" );
        $wgParser->setHook( "vbBoardStats", "vbBoardStats" );
        $wgParser->setHook( "vbUserActivityStats", "vbUserActivityStats" );
}
 
function databaseConnect($database) {
        # connect to vbulletin database
 global $server;
        global $username;
        global $password;
        global $forumdb;
        global $wikidb;
        mysql_connect($server, $username, $password) or die("could not connect to database");
        if($database == "forum") {
                mysql_select_db($forumdb) or die("could not select database (".$database.")");
        } else {
                mysql_select_db($wikidb) or die("could not select database (".$database.")");
        }
}
 
//----------------------------------------------- THREAD STATS -----------------------------------------------\\
# the callback function for converting the input text to HTML output
function vbThreadStats($input) {
#global vars
global $maxThreadLimit;
global $forum_url;
 
# connect to forum database
databaseConnect("forum");
 
# set default arguments
$args['limit'] = 5;
$args['order_by'] = "threadid";
$args['sort'] = "DESC";
# get input args
$aParams = explode("\n", $input); # ie 'limit=5'
 foreach($aParams as $sParam) {
                $aParam = explode("=", $sParam); # ie $aParam[0] = 'limit' and $aParam[1] = '5'
                 if( count( $aParam ) < 2 ) # no arguments passed
                         continue;
                $sType = trim($aParam[0]); # ie 'limit'
         $sArg = trim($aParam[1]); # ie '5'
         
                switch ($sType) {
                        case 'limit':
                                if(!is_numeric($sArg)) { #contains string
                                 die("the limit argument must be numeric (default 5)");
                                } else {
                                        if($sArg > $maxThreadLimit) {
                                                $args['limit'] = $maxThreadLimit;
                                        } else {
                                                $args['limit'] = $sArg;
                                        }
                                }
                        break;
 
                        case 'sort':
                                if(($sArg != "ASC") && ($sArg != "DESC")) {
                                        die("the sort argument must be; 'ASC' or 'DESC'");
                                } else {
                                        $args['sort'] = $sArg;
                                }
                        break;
 
                        case 'order by':
                                if(($sArg != "date") && ($sArg != "title") && ($sArg != "rand")) {
                                        die("the order by argument must be; 'date', 'title'");
                                } else {
                                        if($sArg == "date") {
                                                $args['order_by'] = "threadid";
                                        } 
                                        elseif($sArg == "rand") {
                                                $args['order_by'] = "RAND()";
                                        } else {
                                                $args['order_by'] = $sArg;
                                        }
                                }
                        break;                        
                }
        }
 
# build the sql query
$threadSQL = mysql_query("SELECT title, postusername, lastposter, forumid, replycount, views, firstpostid, forumid, postuserid, lastpost FROM thread WHERE visible = 1 ORDER BY ".$args['order_by']." ".$args['sort']." LIMIT ".$args['limit']."")
or die(mysql_error());
 
# fetch the threadSQL results
while($row = mysql_fetch_array($threadSQL)) {
        $threads['titles'][] = "[".$forum_url."/showthread.php?p=".$row['firstpostid']." ".$row['title']."]";
        $threads['posted_by'][] = "[".$forum_url."/member.php?find=lastposter&f=".$row['forumid']." ".$row['postusername']."]";
        $threads['last_post_by'][] = "[".$forum_url."/member.php?u=".$row['postuserid']." ".$row['lastposter']."]";
        $threads['num_replies'][] = "<b>(".$row['replycount']." replies)</b>";
        $threads['num_views'][] = "<b>(".$row['views']." views)</b>";
        $threads['last_post'][] = date("l j F Y", $row['lastpost']);
        # match the forum id to the forum name - there must be a better way of doing this. I will change it when i think of it.
 $forumName = mysql_query("SELECT title FROM forum WHERE forumid = '".$row['forumid']."' LIMIT 1")
        or die(mysql_error());
        $thisForumName = mysql_fetch_array($forumName);
        $threads['forum_name'][] = $thisForumName['title'];
}
 
# reselect the wiki database
databaseConnect("wiki");
 
# build thread output
for($i=0; $i <= (count($threads['titles'])-1); $i++) {
        $output .= # build threads output   
 "--".$threads['titles'][$i]." (<i>".$threads['forum_name'][$i]."</i>) ".$threads['num_views'][$i]." ".$threads['num_replies'][$i]."<br>
        <i>Started by; ".$threads['posted_by'][$i]." Last post by; ".$threads['last_post_by'][$i]." on ".$threads['last_post'][$i]."</i><br><br>";
}
 
# parse the output for wiki markup
global $wgTitle;
global $wgUser;
 
$parser = new Parser();
$parser->startExternalParse($wgTitle, ParserOptions::newFromUser( $wgUser ), OT_HTML);
# print to screen
return $parser->internalParse($output, 0, array(), false);
}
//----------------------------------------------- /THREAD STATS -----------------------------------------------\\
 
//------------------------------------------------ USER STATS -------------------------------------------------\\
# the callback function for converting the input text to HTML output
function vbUserStats($input) {
#global vars
global $maxUserLimit;
global $forum_url;
 
# connect to forum database
databaseConnect("forum");
 
# set default arguments
$args['limit'] = 5;
$args['order_by'] = "posts";
$args['sort'] = "DESC";
# get input args
$aParams = explode("\n", $input); # ie 'limit=5'
 foreach($aParams as $sParam) {
                $aParam = explode("=", $sParam); # ie $aParam[0] = 'limit' and $aParam[1] = '5'
                 if( count( $aParam ) < 2 ) # no arguments passed
                         continue;
                $sType = trim($aParam[0]); # ie 'limit'
         $sArg = trim($aParam[1]); # ie '5'
         
                switch ($sType) {
                        case 'limit':
                                if(!is_numeric($sArg)) { #contains string
                                 die("the limit argument must be numeric (default 5)");
                                } else {
                                        if($sArg > $maxUserLimit) {
                                                $args['limit'] = $maxUserLimit;
                                        } else {
                                                $args['limit'] = $sArg;
                                        }
                                }
                        break;
 
                        case 'sort':
                                if(($sArg != "ASC") && ($sArg != "DESC")) {
                                        die("the sort argument must be; 'ASC' or 'DESC'");
                                } else {
                                        $args['sort'] = $sArg;
                                }
                        break;
 
                        case 'order by':
                                if(($sArg != "posts") && ($sArg != "joindate") && ($sArg != "username") && ($sArg != "rand")) {
                                        die("the order by argument must be; 'date', 'title'");
                                } elseif($sArg == "rand") {
                                        $args['order_by'] = "RAND()";
                                } else {
                                        $args['order_by'] = $sArg;
                                }
                        break;                        
                }
        }
 
# get total forum posts (to work out percentage/user)
$numRows = mysql_query("SELECT postid FROM post")
or die(mysql_error());
 
$totalPosts = mysql_num_rows($numRows);
 
# build the sql query
$userSQL = mysql_query("SELECT username, userid, posts, joindate, reputation, usertitle FROM user WHERE userid != 4 and userid != 5 ORDER BY ".$args['order_by']." ".$args['sort']." LIMIT ".$args['limit']."")
or die(mysql_error());
 
# fetch the userSQL results
while($row = mysql_fetch_array($userSQL)) {
        $users['posts'][] = "(<b>".$row['posts']." posts</b>)";
        $users['reputation'][] = "".$row['reputation']."";
        $users['user_title'][] = "".$row['usertitle']."";
        $users['join_date'][] = date("l j F Y", $row['joindate']);
        $users['username'][] = "[".$forum_url."/member.php?u=".$row['userid']." ".$row['username']."]";
        $users['post_percentage'][] = (($row['posts']/$totalPosts)*100);
        if($row['posts'] == 0) {
                $users['bar_color'][] = "#FF0000"; # bar color for 0 posts
 } else {
                $users['bar_color'][] = "#00CC33"; # bar color for more than 0 posts
 }
}
 
# reselect the wiki database
databaseConnect("wiki");
 
# build thread output
for($i=0; $i <= (count($users['username'])-1); $i++) {
        $output .= # build user stats output        
 "--".$users['username'][$i]." ".$users['posts'][$i]." <i>Join date; ".$users['join_date'][$i]."<br>
        User title; <b>".$users['user_title'][$i]."</b> Reputation; <b>".$users['reputation'][$i]."</b><br>
        <div style=\"\">Posts; </div>
        <div style=\"height:8px; overflow:hidden; width:".(($users['post_percentage'][$i]*1.8)+5)."px; background-color:".$users['bar_color'][$i]."; margin-top:-13px; margin-left:43px;\"></div>
        <div style=\"margin-left:".(($users['post_percentage'][$i]*1.8)+55)."px; margin-top:-15px;\">(".round($users['post_percentage'][$i], 2)."% of total posts)</div></i><br>";
}
 
# parse the output for wiki markup
global $wgTitle;
global $wgUser;
 
$parser = new Parser();
$parser->startExternalParse($wgTitle, ParserOptions::newFromUser( $wgUser ), OT_HTML);
# print to screen
return $parser->internalParse($output, 0, array(), false);
}
//------------------------------------------------ /USER STATS -------------------------------------------------\\
 
//------------------------------------------------ BOARD STATS -------------------------------------------------\\
# the callback function for converting the input text to HTML output
function vbBoardStats($input) {
#global vars
global $forum_url;
 
# connect to forum database
databaseConnect("forum");
 
# set default arguments
$args['show_total_posts'] = "true";
$args['show_total_threads'] = "true";
$args['show_total_members'] = "true";
$args['show_largest_thread'] = "true";
$args['show_most_popular_thread'] = "true";
$args['show_most_popular_forum'] = "true";
# get input args
$aParams = explode("\n", $input); # ie 'limit=5'
 foreach($aParams as $sParam) {
                $aParam = explode("=", $sParam); # ie $aParam[0] = 'limit' and $aParam[1] = '5'
                 if( count( $aParam ) < 2 ) # no arguments passed
                         continue;
                $sType = trim($aParam[0]); # ie 'limit'
         $sArg = trim($aParam[1]); # ie '5'
         
                switch ($sType) {
                        case 'show total posts':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show total posts' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_total_posts'] = $sArg;
                                }
                        break;
 
                        case 'show total threads':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show total threads' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_total_threads'] = $sArg;
                                }
                        break;
 
                        case 'show total members':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show total members' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_total_members'] = $sArg;
                                }
                        break;
 
                        case 'show largest thread':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show largest thread' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_largest_thread'] = $sArg;
                                }
                        break;
 
                        case 'show most popular thread':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show most popular thread' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_most_popular_thread'] = $sArg;
                                }
                        break;
 
                        case 'show most popular forum':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show most popular thread' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_most_popular_forum'] = $sArg;
                                }
                        break;
                }
        }
 
# build the sql queries
if($args['show_total_posts'] == "true") { # build the show total posts query
 $totalPosts = mysql_query("SELECT postid FROM post")
        or die(mysql_error());
        $numPosts = mysql_num_rows($totalPosts);
        # build board stats output
 $output .= "Total posts; <b>".$numPosts."</b>";
}
if($args['show_total_threads'] == "true") { # build the show total threads query
 $totalThreads = mysql_query("SELECT threadid FROM thread")
        or die(mysql_error());
        $numThreads = mysql_num_rows($totalThreads);
        # build board stats output
 if($args['show_total_posts'] == "true") { 
                $spacer = " -- ";
        }
        $output .= $spacer."Total threads; <b>".$numThreads."</b>";
}
if($args['show_total_members'] == "true") { # build the show total members query
 $totalMembers = mysql_query("SELECT userid FROM user")
        or die(mysql_error());
        $numMembers = mysql_num_rows($totalMembers);
        if(($args['show_total_posts'] == "true") || ($args['show_total_threads'] == "true")) {
                $spacer = " -- ";
        } else {
                $spacer = "";
        }
        # build board stats output
 $output .= " -- Total members; <b>".$numMembers."</b><br><br>";
}
if($args['show_largest_thread'] == "true") { # build the show largest thread query
 $largestThread = mysql_query("SELECT title, postusername, postuserid, lastposter, views, lastpost, firstpostid, forumid, replycount FROM thread WHERE visible = 1 ORDER BY replycount DESC LIMIT 1")
        or die(mysql_error());
        $lThread = mysql_fetch_array($largestThread);
        $lastPost = date("l j F Y", $lThread['lastpost']);
        # get forum name relevant to id
 $forumName = mysql_query("SELECT title FROM forum WHERE forumid = '".$lThread['forumid']."' LIMIT 1")
        or die(mysql_error());
        $thisForumName = mysql_fetch_array($forumName);
        # build board stats output
 $output .= "--Largest thread; [".$forum_url."/showthread.php?p=".$lThread['firstpostid']." ".$lThread['title']."] <i>(".$thisForumName['title']."</i>) <b>(".$lThread['views']." views) (".$lThread['replycount']." replies)</b><br>
        <i>Started by; [".$forum_url."/member.php?find=lastposter&f=".$lThread['forumid']." ".$lThread['postusername']."] Last post by; [".$forum_url."/member.php?u=".$lThread['postuserid']." ".$lThread['lastposter']."] on ".$lastPost."</i><br><br>";
}
if($args['show_most_popular_thread'] == "true") { # build the show most popular thread query
 $mostPopularThread = mysql_query("SELECT title, postusername, lastposter, views, lastpost, firstpostid, forumid, replycount, postuserid FROM thread WHERE visible = 1 ORDER BY views DESC LIMIT 1")
        or die(mysql_error());
        $mpThread = mysql_fetch_array($mostPopularThread);
        $lastPost = date("l j F Y", $mpThread['lastpost']);
        # get forum name relevant to id
 $forumName = mysql_query("SELECT title FROM forum WHERE forumid = '".$mpThread['forumid']."' LIMIT 1")
        or die(mysql_error());
        $thisForumName = mysql_fetch_array($forumName);
        # build board stats output
 $output .= "--Most popular thread; [".$forum_url."/showthread.php?p=".$mpThread['firstpostid']." ".$mpThread['title']."] <i>(".$thisForumName['title']."</i>) <b>(".$mpThread['views']." views) (".$mpThread['replycount']." replies)</b><br>
        <i>Started by; [".$forum_url."/member.php?find=lastposter&f=".$mpThread['forumid']." ".$mpThread['postusername']."] Last post by; [".$forum_url."/member.php?u=".$mpThread['postuserid']." ".$mpThread['lastposter']."] on ".$lastPost."</i><br><br>";
}
if($args['show_most_popular_forum'] == "true") { # build the show most popular forum query
 $mostPopularForum = mysql_query("SELECT title, replycount, lastpost, lastposter, lastthread, lastthreadid, forumid FROM forum ORDER BY threadcount DESC LIMIT 1")
        or die(mysql_error());
        $mpForum = mysql_fetch_array($mostPopularForum);
        $lastPost = date("l j F Y", $mpForum['lastpost']);
        # build board stats output
 $output .= "--Most popular forum; [".$forum_url."/forumdisplay.php?f=".$mpForum['forumid']." ".$mpForum['title']."] <b>(".$mpForum['replycount']." replies)</b><br>
        <i>Last post by; [".$forum_url."/member.php?find=lastposter&f=".$mpForum['forumid']." ".$mpForum['lastposter']."] in [".$forum_url."/showthread.php?t=".$mpForum['lastthreadid']." ".$mpForum['lastthread']."] on ".$lastPost."</i><br><br>";
}
 
# reselect the wiki database
databaseConnect("wiki");
 
# parse the output for wiki markup
global $wgTitle;
global $wgUser;
 
$parser = new Parser();
$parser->startExternalParse($wgTitle, ParserOptions::newFromUser( $wgUser ), OT_HTML);
# print to screen
return $parser->internalParse($output, 0, array(), false);
}
//------------------------------------------------ /BOARD STATS -------------------------------------------------\\
 
//------------------------------------------------ USER ACTIVITY STATS -------------------------------------------------\\
# the callback function for converting the input text to HTML output
function vbUserActivityStats($input) {
#global vars
global $forum_url;
 
# connect to forum database
databaseConnect("forum");
 
# set default arguments
$args['show_active_users'] = "true";
$args['show_inactive_users'] = "true";
$args['show_sub-heading'] = "true";
$args['show_last_30_days'] = "true";
$args['show_last_14_days'] = "true";
$args['show_last_7_days'] = "true";
# get input args
$aParams = explode("\n", $input); # ie 'limit=5'
 foreach($aParams as $sParam) {
                $aParam = explode("=", $sParam); # ie $aParam[0] = 'limit' and $aParam[1] = '5'
                 if( count( $aParam ) < 2 ) # no arguments passed
                         continue;
                $sType = trim($aParam[0]); # ie 'limit'
         $sArg = trim($aParam[1]); # ie '5'
         
                switch ($sType) {
                        case 'show sub-heading':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show sub-heading' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_sub-heading'] = $sArg;
                                }
                        break;
 
                        case 'show active users':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show active users' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_active_users'] = $sArg;
                                }
                        break;
 
                        case 'show inactive users':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show inactive users' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_inactive_users'] = $sArg;
                                }
                        break;
 
                        case 'show last 30 days':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show last 30 days' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_last_30_days'] = $sArg;
                                }
                        break;
 
                        case 'show last 14 days':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show last 14 days' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_last_14_days'] = $sArg;
                                }
                        break;
 
                        case 'show last 7 days':
                                if(($sArg != "true") && ($sArg != "false")) { #not a boolean (is_bool() doesn't want to work)
                                 die("the 'show last 7 days' value you entered was not boolean (true/false)");
                                } else {
                                        $args['show_last_7_days'] = $sArg;
                                }
                        break;
                }
        }
 
# get total users on forum (used in several queries)
$users = mysql_query("SELECT userid FROM user")
or die(mysql_error());
$numUsers = mysql_num_rows($users);
# work out dates
$now = date(U); # date in epoch seconds
$DaysAgo30 = $now - 2592000; # 30 days ago in epoch seconds
$DaysAgo14 = $now - 1209600; # 14 days ago in epoch seconds
$DaysAgo7 = $now - 604800; # 7 days ago in epoch seconds

# build the sql queries
if($args['show_active_users'] == "true") { # build the show active users query
 $activeUsers = mysql_query("SELECT userid FROM user WHERE posts > 0")
        or die(mysql_error());
        $numActiveUsers = mysql_num_rows($activeUsers);
        $term = "have"; # grammer is important :)
 if($numActiveUsers <= 1) {
                $term = "has";
        }
        # percentage that have posted
 $precentageActive = ($numActiveUsers/$numUsers)*100;
        # output user activity
 $output .= "--Active users; <div style=\"height:8px; overflow:hidden; width:".(($precentageActive*1.8)+5)."px; background-color:#00CC33; margin-top:-12px; margin-left:88px;\"></div><div style=\"margin-top:-13px; margin-left:".(100+($precentageActive*1.8))."px;\"><i>".round($precentageActive, 2)."% (".$numActiveUsers." ".$term." posted)</i></div>";
}
if($args['show_inactive_users'] == "true") { # build the show inactive users query
 $numInactiveUsers = $numUsers - $numActiveUsers;
        $percentageInactive = ($numInactiveUsers/$numUsers)*100;
        $term = "have"; # grammer is important :)
 if($numInactiveUsers <= 1) {
                $term = "has";
        }
        # output user inactivity
 $output .= "--Inctive users; <div style=\"height:8px; overflow:hidden; width:".(($percentageInactive*1.8)+5)."px; background-color:#FF0000; margin-top:-12px; margin-left:90px;\"></div><div style=\"margin-top:-13px; margin-left:".(102+($percentageInactive*1.8))."px;\"><i>".round($percentageInactive, 2)."% (".$numInactiveUsers." ".$term." not posted)</i></div><br>";
}
if($args['show_sub-heading'] == "true") { # add title for users on in last x days to output
$output .= "<b>Visits of registered members for the last 30, 14 and 7 days</b><br><br>";
}
if($args['show_last_30_days'] == "true") { # build the show last 30 days query
 $last30Days = mysql_query("SELECT userid FROM user WHERE lastvisit >= $DaysAgo30")
        or die(mysql_error());
        $numLast30 = mysql_num_rows($last30Days);
        $percentageUsersLast30 = ($numLast30/$numUsers)*100;
        # output users who visited in last 30 days
 $output .= "--The last 30 days; <div style=\"height:8px; overflow:hidden; width:".$percentageUsersLast30."px; background-color:#FF9900; margin-top:-12px; margin-left:110px;\"></div><div style=\"margin-top:-13px; margin-left:".($percentageUsersLast30+115)."px;\"><i>".round($percentageUsersLast30, 2)."%</i> (<b>".$numLast30."</b>)</div><br>";
}
if($args['show_last_14_days'] == "true") { # build the show last 14 days query
 $last14Days = mysql_query("SELECT userid FROM user WHERE lastvisit >= $DaysAgo14")
        or die(mysql_error());
        $numLast14 = mysql_num_rows($last14Days);
        $percentageUsersLast14 = ($numLast14/$numUsers)*100;
        # output users who visited in last 30 days
 $output .= "--The last 14 days; <div style=\"height:8px; overflow:hidden; width:".$percentageUsersLast14."px; background-color:#0000FF; margin-top:-12px; margin-left:110px;\"></div><div style=\"margin-top:-13px; margin-left:".($percentageUsersLast14+115)."px;\"><i>".round($percentageUsersLast14, 2)."%</i> (<b>".$numLast14."</b>)</div><br>";
}
if($args['show_last_7_days'] == "true") { # build the show last 7 days query
 $last7Days = mysql_query("SELECT userid FROM user WHERE lastvisit >= $DaysAgo7")
        or die(mysql_error());
        $numLast7 = mysql_num_rows($last7Days);
        $percentageUsersLast7 = ($numLast7/$numUsers)*100;
        # output users who visited in last 30 days
 $output .= "--The last 7 days; <div style=\"height:8px; overflow:hidden; width:".$percentageUsersLast7."px; background-color:#00CC33; margin-top:-12px; margin-left:105px;\"></div><div style=\"margin-top:-13px; margin-left:".($percentageUsersLast7+115)."px;\"><i>".round($percentageUsersLast7, 2)."%</i> (<b>".$numLast7."</b>)</div><br>";
}
# reselect the wiki database
databaseConnect("wiki");
 
# parse the output for wiki markup
global $wgTitle;
global $wgUser;
 
$parser = new Parser();
$parser->startExternalParse($wgTitle, ParserOptions::newFromUser( $wgUser ), OT_HTML);
# print to screen
return $parser->internalParse($output, 0, array(), false);
}
//------------------------------------------------ /USER ACTIVITY STATS -------------------------------------------------\\
?>

[edit] Support/Requests

Please post any questions or requests (additions to the script you would like) on the vBulletin Stats extension page on my wiki. I rarely check the wikiMedia website.

[edit] See also

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox