This extension is the popular “Whos Online extension” of ChekMate Security Group(http://www.chekmate.org/). This extension is modified version in order to make it work with MediaWiki version 1.8.2 and above. In order to work it with previous versions earlier than 1.8.2 , please visit their site to download the code.
URL: http://www.chekmate.org/wiki/index.php/MW:_Whos_Online_Extension
here are the steps that you have to perform to make this extension work.
1. Add one new table in your database, named online. If database uses a prefix, then add the prefix before the table name. Here is the SQL code for creating the table:
CREATE TABLE online
(
userid
int(5) NOT NULL default ‘0’,
username
varchar(255) NOT NULL default ”,
timestamp
varchar(255) NOT NULL default ”
) TYPE=MyISAM;
2. Download the code below and Save the following in your ./extensions/ directory
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
<?php # WhosOnline Mediawiki extension # # by Shannon McNaught 22.06.2006 # http://www.chekmate.org/wiki/index.php/Projects # Installation: # * Add new table to your wikidb. # * put this file (WhosOnline.php) into the extension directory of your mediawiki installation # * add the following to the end of LocalSettings.php: include("extensions/WhosOnline.php"); # # Example: # <whosonline></whosonline> # #install extension hook $wgExtensionFunctions[] = "wfWhosOnlineExtension"; #extension hook callback function function wfWhosOnlineExtension() { global $wgParser; #install parser hook for <rss> tags $wgParser->setHook( "whosonline", "renderWhosOnline" ); } #parser hook callback function function renderWhosOnline( $input, $arge, &$parser ) { global $wgUser, $wgDBprefix,$wgVersion,$wgOut; global $wgOutputEncoding; $dbr =& wfGetDB( DB_SLAVE ); // ###### INVALIDATE CACHE ###### global $wgTitle; $ts = mktime(); $now = gmdate("YmdHis", $ts + 120); $ns = $wgTitle->getNamespace(); #$ti = wfStrencode($wgTitle->getDBkey()); $ti = $wgTitle->getDBkey(); $version = preg_replace("/^([1-9]).([1-9]).*/", "12", $wgVersion); if ($version>14) $sql = "UPDATE $wgDBprefix"."page SET page_touched='$now' WHERE page_namespace=$ns AND page_title='$ti'"; else $sql = "UPDATE $wgDBprefix"."cur SET cur_touched='$now' WHERE cur_namespace=$ns AND cur_title='$ti'"; #wfQuery($sql, DB_WRITE, ""); $dbr->query( $sql ); $timeperiod = 3600; # number of seconds $DefaultEncoding = "ISO-8859-1"; $DisableCache = true; $ts = mktime(); $now = gmdate("YmdHis", $ts); $old = gmdate("YmdHis", $ts-$timeperiod); $userid = $wgUser->getID(); $username = $wgUser->getName(); $tblname = $wgDBprefix."online"; $sql = "DELETE from $tblname WHERE username = '$username' OR timestamp < '$old' "; $db =& wfGetDB( DB_WRITE ); if ( $db !== false ) { $ret = $db->query( $sql, '', true ); } else { $ret = false; } if ( false === $ret ) { $sql = "CREATE TABLE $tblname ( `userid` int(5) NOT NULL default '0', `username` varchar(255) NOT NULL default '', `timestamp` varchar(255) NOT NULL default '' ) TYPE=MyISAM "; #$ret = wfQuery($sql, DB_WRITE, ""); $ret = $dbr->query( $sql ); } $sql = "INSERT INTO $wgDBprefix"."online (userid,username,timestamp) VALUES ('$userid','$username','$now')"; $output = $sql; #wfQuery($sql, DB_WRITE, ""); $dbr->query( $sql ); $sql = "select * from $wgDBprefix"."online where userid = 0"; $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query ( $sql ) ; $guests = $dbr->numRows($res) + 0; $sql = "select username from $wgDBprefix"."online where userid != 0"; $res = $dbr->query ( $sql ) ; $registered = $dbr->numRows($res) + 0; $Userlist =""; while( $row = $dbr->fetchObject( $res ) ){ $Userlist .= " [[User:".$row->username."|".$row->username."]] "; } $dbr->freeResult( $res ); $output = "Guests: $guests Registered: $registered ($Userlist)"; #return $output; #return $wgOut->parse($output,false); $localParser = new Parser(); $parserOutput = $localParser->parse( $output, $parser->mTitle, $parser->mOptions, false ); return $parserOutput->getText(); } ?> |
3. Add the following to the end of LocalSettings.php:
1 |
require_once("extensions/WhosOnline.php"); |
4. Add the following code in your wiki page:
<b>Users Online</b>: <whosonline></whosonline>
Now save the page and view it in browser. You are done.
Hi Mizanur,
Sounds like an interesting extension, but I am puzzled a bit at what it offers exactly. Does it show the logged-in users (would be a bit strange since some people never log off)? Or is it something else, like users being active the last x minutes?
Thanks in advance for your answer.
Best regards,
Marcel
hi Marcel
thank for your query. This script actually shows active users on last x minutes. it shows both guest and registered users.
the updated one can be found at .
http://www.chekmate.org/wiki/index.php/Talk:MW:_Whos_Online_Extension
thanks
Mizan
Hi!
I really wanna make this extension work on my wiki.. I get this error when I try to create the table though (I’m not so handy at MySQL):
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘0′,
username
varchar(255) NOT NULL default â€Can you help me?