Extension:Chat

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

Release status: beta

ExtensionChat.png
Implementation Skin
Description Adds a Chat tab to every article that links to an embedded chatroom by the same name.
Author(s) Firebreathertalk
Latest version 0.3.9 (2012-08-30)
MediaWiki tested with 1.15.1, not tested with 1.16, should work from 1.9.3 on, might work on 1.6.8. Newest version tested on 1.19.1.
Tables chathistory
License GNU Lesser General Public License
Download get WikiChat.php code below and phpfreechat from PhpFreeChat
Example WikiChat.org
NomicWiki.com

Translate the Chat extension if possible

Check usage and version matrix; code metrics

The Chat extension adds a chat tab to every wiki article that switches to an embedded chatroom with the same name as the article title. It can be configured to have only one chatroom for the entire site, rather than one chatroom per article (the default). This extension uses PhpFreeChat.

Usage[edit | edit source]

Once the extension is installed, a 'chat' tab will appear on every article. Clicking on the chat tab will switch to an embedded chatroom for the article.

Prerequisite[edit | edit source]

You MUST be using MySQL as the MediaWiki database for this extension to work.

Installation[edit | edit source]

Quick start instructions are below.

Detailed instructions can be found here on WikiChat.org

Just five easy steps:-

1. Download PhpFreeChat 1.2 (google it) and follow the installation instructions to install it into your wiki somewhere. I have mine under /wiki/phpfreechat. (NOTE: You MUST download exactly phpfreechat 1.2)
2.
  • Create a file called "WikiChat.php" in your wiki extensions/WikiChat directory (which you will need to create) and copy the WikiChat.php source code into it.
  • Create a file called "DatabaseFunctions.php" in your wiki extensions/WikiChat directory and copy the DatabaseFunctions.php source code into it.
3. Modify the directory path at the top of WikiChat.php to point to your PhpFreeChat installation directory:-
define('WC_PFC_DIRECTORY', 'phpfreechat');
4. Add this line to the end of LocalSettings.php:
require_once( "$IP/extensions/WikiChat/WikiChat.php" );
5. You might need to change the access permissions on some of the directories...
# Give the web server write rights to phpfreechat-x.x/data/public and 
phpfreechat-x.x/data/private directories.

If you are using FTP:

CHMOD 777 phpfreechat-x.x/data/private

CHMOD 777 phpfreechat-x.x/data/public

If you are using SSH:

chmod 777 phpfreechat-x.x/data/*

Its probably more sensible to use 755 than 777.

The chat function should be working now. Refresh your main page (or any page) and you should see a "chat" tab at the top. Click on the tab to start chatting.

Please report any issues by adding them to the discussion for this extension.

Chat not loading?[edit | edit source]

If you are still having problems you may need to manually "rehash" the chat cache. Make sure to read this discussion. For an explanation of rehashing see this page.

You may also like to read the known issues.

Optional Parameters[edit | edit source]

Most of the optional parameters in WikiChat.php are parameters to PhpFreeChat. You need to refer to the PhpFreeChat documentation for information about how to change the PhpFreeChat parameters. See http://www.phpfreechat.net/parameters for information on particular parameters.

WikiChat optional parameters are detailed below...

Disabling Anonymous Access[edit | edit source]

Anonymous users are allowed access to the chatroom by default and assume the nickname 'Guest'

If you would like to deny access to anonymous users change the appropriate define statements at the top of WikiChat.php:

define('WC_ALLOW_ANONYMOUS_USERS', false);

define('WC_DENY_ACCESS_MESSAGE', 'whatever you want displayed to the user when denied access');

Making all tabs point to one chatroom[edit | edit source]

The default setting is to open a new chatroom tab for each article, with the name of the article as the title of the chatroom. This is set by the following line in WikiChat.php

define('WC_ROOM_PER_ARTICLE', true);

If you would like to have all articles share one room then you need to change that line to:-

define('WC_ROOM_PER_ARTICLE', false);

All articles will now put users entering through the chat tab, into the single site-wide chatroom.

Other parameters[edit | edit source]

Place these parameters after the require_once line in LocalSettings.php.

// This is the maximum nickname length.
$wgChatMaxNickLen = 30;
// This is the maximum message length in characters.
$wgChatMaxTextLen = 480;
// The maximum number of allowed channels for each user.
$wgChatMaxChannels = 6;
// This is the maximum number of private message allowed
// at the same time for one user.
$wgChatMaxPrivMsg = 3;
// This is the time to wait between two refreshes, in msecs.
$wgChatRefreshDelay = 2000;
// This is the number of messages kept in the history.
$wgChatMaxMsg = 600;
// The maximum number of lines displayed in the window.
$wgChatMaxDisplayedLines = 600;
// Height of the chat area.
$wgChatHeight = "230px";
// msecs until user is disconnected
$wgChatTimeout = 600000;
// Usernames of those with admin (i.e. chat moderator) rights
$wgChatAdmins = array( 'Jimbo Wales', 'Tim Starling' );
// User groups with chat moderator rights
$wgChatAdminGroups = array( 'sysop' );

Help with chat commands[edit | edit source]

Detailed help is available on WikiChat.org

Known issues[edit | edit source]

  • Sometimes when entering the chatroom you get a message saying you are not allowed that nickname (because it is in use). This occurs because a user of that name is already in the chat room. Note that when a user closes their browser to leave a chatroom it takes a long time before their chat session ends. This is a limitation of browsers as there is no way catch a window close event for all browsers and automatically end the chat user's session.
  • Error: 'chat.js.tpl.php' could not be found, please check your themepath This can happen if you move your wiki to a different path; it is a result of cached files in phpfreechat/data/private/cache retaining your original path. Delete those files and all will be well.

ChangeLog[edit | edit source]

0.3.9, 2012.08.30

  • Added support for table prefixes
  • Added support for sysops and other user groups to be automatically added as moderators
  • Added Vector support
  • Added DatabaseFunctions.php
  • Changed getDBKey() to getPrefixedText() so room names would have namespace prefix
  • Added a bunch of globals

0.3.8, 2010-09-03

  • fixed bug where MYSQL returned error 1071 caused by the index being >1024 bytes. Keys sizes have been reduced in the chathistory table.

0.3.7, 2010-02-01

  • fixed bug where chat didn't work on subpages i.e. /wiki/index.php/Page/SubPage

0.3.6, 2010-01-26

  • changed it so that anonymous users can pick their nickname when they join the chat. Will make it a configurable option in the future so that anonymous users can optionally be assigned a fixed nickname as it was in previous versions e.g. 'Guest'.
  • fixed a bug where the deny access message wasn't displayed when WikiChat was configured to deny access to anonymous users.
  • put the following code back in as it is needed so that phpfreechat can find itself in wiki installations that are below the web root e.g. http://example.com/abc/def/wiki. Check the discussion page if you have this kind of wiki installation and WikiChat is not working.
$params["data_public_url"] = "$wgPFC_Directory/data/public";
$params["data_public_path"] = "$wgPFC_Directory/data/public";

0.3.4, 2010-01-22

  • fixed bug where chat wouldn't work properly for pages with a space in the title
  • fixed bug where anonymous users wouldn't be prevented from access when configured to deny them
  • chat logging is now going into the database
  • refactored the code to make it easier to maintain
  • changed user configuration options to use define statements like MediaWiki does
  • fixed small security hole

0.3.2, 2010-01-21

  • fixed page title
  • made room per article function configurable through a configuration variable
  • made configuration a tiny bit easier by adding the $wgPFC_Directory variable

0.3.0, 2010-01-20

  • updated the code to work with PhpFreeChat 1.2
  • fixed the issue where "Chat loading" is displayed but the chat never finishes loading.
  • tested and working on MediaWiki 1.15.1
  • new source code below
  • Firebreather 09:48, 20 January 2010 (UTC)

0.2.2, 2007-07-25

  • changed the default setting for the "timeout" parameter to increase the amount time before a user is disconnected. The default setting is ridiculously low.

0.2.1, 2007-07-03

  • upgraded WikiChat.php to be compatible with phpfreechat-1.0-beta11. It now won't work with earlier versions of phpfreechat. Phpfreechat-1.0-beta11 has lots of bug fixes and is more stable with Internet Explorer. If you were having problems with IE or other connectivity issues, this release should fix them.

0.2, 2007-06-06

  • fixed the html and page title so they are now there
  • added an option to disable anonymous user access and display a wikitext message instead
  • added a small message at the bottom to 'type /help for a list of all commands'

0.11

  • fixed two bugs that could blow up Special:Version page

0.1

  • first release

Source code[edit | edit source]

First check which version of MediaWiki you are using.

For 1.19 and later use MediaWiki 1.19 and later.

For 1.16 use MediaWiki 1.16.

For releases prior to 1.16 use MediaWiki prior to 1.16.

MediaWiki 1.19 and later[edit | edit source]

WikiChat.php[edit | edit source]

<?php
/**
* MediaWiki WikiChat extension
* See: http://www.mediawiki.org/wiki/Extension:Chat for installation
* Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
* Author: http://www.wikichat.org/User:Firebreather
*/
 
#set to the directory phpfreechat is installed in
define('WC_PFC_DIRECTORY', 'phpfreechat');
 
# set to false to deny access to anonymous users
define('WC_ALLOW_ANONYMOUS_USERS', true);
 
# message shown when denying anonymous users. Change if you want a 
# different message. WikiText ok..
define('WC_DENY_ACCESS_MESSAGE', 'You must [[Special:Userlogin|login]] 
to be allowed into this chatroom');
 
# when true there will be a chat room per article. Set to false to have 
# a single site-wide chat room.
define('WC_ROOM_PER_ARTICLE', true);
 
if (!defined('MEDIAWIKI')) die ('Not an entry point');
 
$wgPFC_Directory = WC_PFC_DIRECTORY;
 
require_once "$IP/$wgPFC_Directory/src/phpfreechat.class.php";
require_once "$IP/extensions/WikiChat/DatabaseFunctions.php";
 
$wgRoomPerArticle = WC_ROOM_PER_ARTICLE;
$wgAllowAnonUsers = WC_ALLOW_ANONYMOUS_USERS;
$wgDenyAccessMessage = WC_DENY_ACCESS_MESSAGE;
// This is the maximum nickname length.
$wgChatMaxNickLen = 30;
// This is the maximum message length in characters.
$wgChatMaxTextLen = 480;
// The maximum number of allowed channels for each user.
$wgChatMaxChannels = 6;
// This is the maximum number of private message allowed
// at the same time for one user.
$wgChatMaxPrivMsg = 3;
// This is the time to wait between two refreshes, in msecs.
$wgChatRefreshDelay = 2000;
// This is the number of messages kept in the history.
$wgChatMaxMsg = 600;
// The maximum number of lines displayed in the window.
$wgChatMaxDisplayedLines = 600;
// Height of the chat area.
$wgChatHeight = "230px";
// msecs until user is disconnected
$wgChatTimeout = 600000;
// Usernames of those with admin (i.e. chat moderator) rights
$wgChatAdmins = array();
// User groups with chat moderator rights
$wgChatAdminGroups = array( 'sysop' );
 
/* Extension variables */
$wgExtensionFunctions[] = 'wfSetupWikiChat';
$wgExtensionCredits['other'][] = array(
    'name' => 'WikiChat',
    'version' => '0.3.9, 2012-08-30, 1.19',
    'author' => '[http://www.wikichat.org/User:Firebreather '.
'User:Firebreather]',
    'url' => 'http://www.wikichat.org/',
    'description' => 'Adds a tab to each article that switches to a 
chatroom',
);              
 
class WikiChat {
 
        // Constructor
        public function WikiChat() {
                global $wgHooks;
 
                # Add all our needed hooks
                $wgHooks['UnknownAction'][] = $this;
                $wgHooks['SkinTemplateTabs'][] = $this;
                // Vector support
                $wgHooks['SkinTemplateNavigation'][] = $this;
        }
 
        // main entry point
        public function onUnknownAction($action, $article) {
                global $wgOut, $wgCachePages, $wgTitle, $wgDBprefix, 
$wgDenyAccessMessage;
 
                $wgCachePages = false;
 
                if($action == 'chat') {
                        $wgOut->setPageTitle(str_replace('_', ' ', 
$wgTitle->getPrefixedText()));
 
                        if($this->isAnonDenied()) {
 
$wgOut->addWikiText($wgDenyAccessMessage);
                                return false;
                        }
 
                        $params = $this->configurePFC_Params();
 
                        $tblname = $wgDBprefix."chathistory";
 
                        $this->createChatHistoryDBTable($tblname);
 
                        $this->configurePFC_DB_Params($tblname, 
$params);
 
                        $this->configureNick($params);
 
                        $this->showChat($params);
 
                        return false;
                }
                else {
                        return true;
                }
        }
 
        private function isAnonDenied() {
                global $wgUser, $wgAllowAnonUsers;
 
                return !$wgAllowAnonUsers && $wgUser->isAnon();
        }
 
        private function configureNick(&$params) {
                global $wgUser, $wgOut, $wgAllowAnonUsers, 
$wgDenyAccessMessage, $wgTitle;
 
                $nick = "";
 
                if($wgUser->isAnon()) {
                }
                else {
                        $nick = $wgUser->getName();
                }
 
                $params["nick"]          = $nick; // setup the initial nickname
 
                return $nick;
        }
 
        private function configurePFC_Params() {
                global $wgTitle, $wgRoomPerArticle, $wgPFC_Directory;
                global $wgOut;
                global $wgChatMaxNickLen, $wgChatMaxTextLen,
                        $wgChatMaxChannels, $wgChatMaxPrivMsg,
                        $wgChatRefreshDelay, $wgChatMaxMsg,  
                        $wgChatMaxDisplayedLines, $wgChatHeight,
                        $wgChatTimeout, $wgChatAdmins, $wgChatAdminGroups,
			$wgDBprefix;
 
		// Assign all members of the chat admin groups to be chat admins
		$userTable = $wgDBprefix . 'user';
		$userGroupsTable = $wgDBprefix . 'user_groups';
		if ( !empty ( $wgChatAdminGroups ) ) {
                      	$sql = "SELECT user_name
 	                       FROM `$userTable`
                               JOIN $userGroupsTable ON
           	                    $userGroupsTable.ug_user = $userTable.user_id
                               WHERE ( ";
			$isFirstOne = true;
			foreach ( $wgChatAdminGroups as $thisGroup ) {
				if ( $isFirstOne == false ) {
	                                $sql .= " OR ";
				}
				$isFirstOne = false;
				$sql .= "$userGroupsTable.ug_group = '".
					"$thisGroup'";
			}
			$sql .= " )";
                	$dbr =& wfGetDB( DB_SLAVE );
			$res = $dbr->query ( $sql );
			$numRows = $dbr->numRows ( $res );
			for ( $i = 1; $i <= $numRows; $i++ ) {
				$row = $dbr->fetchRow( $res );
				$wgChatAdmins[] = $row['user_name'];
			}
		}	
 
                $params["title"]         = "WikiChat";
 
                // apply room per page or site-wide room configuration option
                if($wgRoomPerArticle) {
                        //replace slashes in the page db key to ensure
                        // chat works for subpages
                        $params["serverid"]      = str_replace('/', 
'##', $wgTitle->getPrefixedText());
                }
                else {
                        $params["serverid"]      = md5(__FILE__);
                }
 
                $params["data_public_url"] = 
"$wgPFC_Directory/data/public";
                $params["data_public_path"] = 
"$wgPFC_Directory/data/public";
 
                $params["server_script_url"] = $_SERVER['REQUEST_URI'];
                $params["openlinknewwindow"] = true;
                $params["channels"] = array(str_replace('_', ' ', 
$wgTitle->getPrefixedText()));
                $params["frozen_nick"]    = true;     /* do not allow to 
                change the nickname */
                $params["shownotice"]     = 0;        /* 0 = nothing, 1 
= just nickname changes, 2 = connect/quit, 3 = nick + connect */
                $params["max_nick_len"]   = $wgChatMaxNickLen;
                $params["max_text_len"]   = $wgChatMaxTextLen;
                $params["max_channels"]   = $wgChatMaxChannels;
                $params["max_privmsg"]    = $wgChatMaxPrivMsg;
                $params["refresh_delay"]  = $wgChatRefreshDelay;
                $params["max_msg"]        = $wgChatMaxMsg;
                $params["max_displayed_lines"]  = $wgChatMaxDisplayedLines;
                $params["height"]         = $wgChatHeight;
                $params["debug"]          = false;
                $params["timeout"]        = $wgChatTimeout;
                $params["admins"]          = $wgChatAdmins;
 
                return $params;
        }
 
        private function createChatHistoryDBTable($tblname) {
                $dbr =& wfGetDB( DB_SLAVE );
 
                $sql = "show tables like '$tblname'";
                $res = $dbr->query ( $sql ) ;
                $num_rows = $dbr->numRows($res) + 0;
                $dbr->freeResult( $res );
 
                //create the chathistory table if it doesn't exist
                if($num_rows == 0) {
                        $sql =
                          "CREATE TABLE IF NOT EXISTS `$tblname` (
                            `server` varchar(32) NOT NULL default '',
                            `group` varchar(64) NOT NULL default '',
                            `subgroup` varchar(64) NOT NULL default '',
                            `leaf` varchar(64) NOT NULL default '',
                            `leafvalue` text NOT NULL,
                            `timestamp` int(11) NOT NULL default 0,
                            PRIMARY KEY  
(`server`,`group`,`subgroup`,`leaf`),
                            INDEX 
(`server`,`group`,`subgroup`,`timestamp`)
                          ) ENGINE=InnoDB;";
                        $ret = wfQuery($sql, DB_WRITE, "");
                }
        }
 
        private function configurePFC_DB_Params($tblname, &$params) {
                global $wgDBserver, $wgDBname, $wgDBprefix, $wgDBuser, 
$wgDBpassword;
 
                $params["container_type"]               = "mysql";
                $params["container_cfg_mysql_host"]     = $wgDBserver;
                $params["container_cfg_mysql_database"] = $wgDBname;
                $params["container_cfg_mysql_port"]     = 3306;
                $params["container_cfg_mysql_table"]    = $tblname;
                $params["container_cfg_mysql_username"] = $wgDBuser;
                $params["container_cfg_mysql_password"] = $wgDBpassword;
        }
 
        private function showChat($params) {
                global $wgOut;
 
                $pfc = new phpFreeChat($params);
                $wgOut->addHTML($pfc->printChat(true));
                $wgOut->addHTML('<br><br><p>Type /help for a list of all 
commands</p>');
 
$wgOut->addWikiText("[http://www.wikichat.org/index.php/WikiChat_help". 
" More help on WikiChat.org]");
        }
 
       public function onSkinTemplateTabs( $skin, &$content_actions ) {
                global $wgRequest;
 
                $action = $wgRequest->getText( 'action' );
 
                $content_actions['chat'] = array(
                                            'class' => ($action == 
'chat') ? 'selected' : false,
                                            'text' => "Chat",
// Vector support
'href' => $skin->getTitle()->getLocalUrl( 'action=chat' )
#'href' => $skin->mTitle->getLocalURL( 'action=chat' )
                                             );
 
                return true;
        }
 
        // Vector support
        public function onSkinTemplateNavigation( $skin, &$links ) {
               return self::onSkinTemplateTabs($skin, $links['views']);
        }
 
        # Needed in some versions to prevent Special:Version from breaking
        public function __toString() { return 'WikiChat'; }
 } /* class WikiChat */
 
/* Global function */
# Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWikiChat() {
        global $wgWikiChat;
        $wgWikiChat = new WikiChat();
}

DatabaseFunctions.php[edit | edit source]

<?php
/**
 * Legacy database functions, for compatibility with pre-1.3 code
 * NOTE: this file is no longer loaded by default.
 * @file
 * @ingroup Database
 */
 
/**
 * Usually aborts on failure
 * If errors are explicitly ignored, returns success
 * @param $sql String: SQL query
 * @param $db Mixed: database handler
 * @param $fname String: name of the php function calling
 */
function wfQuery( $sql, $db, $fname = '' ) {
	if ( !is_numeric( $db ) ) {
		# Someone has tried to call this the old way
		throw new FatalError( wfMsgNoDB( 'wrong_wfQuery_params', $db, $sql ) );
	}
	$c = wfGetDB( $db );
	if ( $c !== false ) {
		return $c->query( $sql, $fname );
	} else {
		return false;
	}
}
 
/**
 *
 * @param $sql String: SQL query
 * @param $dbi
 * @param $fname String: name of the php function calling
 * @return Array: first row from the database
 */
function wfSingleQuery( $sql, $dbi, $fname = '' ) {
	$db = wfGetDB( $dbi );
	$res = $db->query($sql, $fname );
	$row = $db->fetchRow( $res );
	$ret = $row[0];
	$db->freeResult( $res );
	return $ret;
}
 
/**
 * Turns on (false) or off (true) the automatic generation and sending
 * of a "we're sorry, but there has been a database error" page on
 * database errors. Default is on (false). When turned off, the
 * code should use wfLastErrno() and wfLastError() to handle the
 * situation as appropriate.
 *
 * @param $newstate
 * @param $dbi
 * @return Returns the previous state.
 */
function wfIgnoreSQLErrors( $newstate, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->ignoreErrors( $newstate );
	} else {
		return null;
	}
}
 
/**#@+
 * @param $res Database result handler
 * @param $dbi
*/
 
/**
 * Free a database result
 * @return Bool: whether result is sucessful or not.
 */
function wfFreeResult( $res, $dbi = DB_LAST )
{
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		$db->freeResult( $res );
		return true;
	} else {
		return false;
	}
}
 
/**
 * Get an object from a database result
 * @return object|false object we requested
 */
function wfFetchObject( $res, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->fetchObject( $res, $dbi = DB_LAST );
	} else {
		return false;
	}
}
 
/**
 * Get a row from a database result
 * @return object|false row we requested
 */
function wfFetchRow( $res, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->fetchRow ( $res, $dbi = DB_LAST );
	} else {
		return false;
	}
}
 
/**
 * Get a number of rows from a database result
 * @return integer|false number of rows
 */
function wfNumRows( $res, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->numRows( $res, $dbi = DB_LAST );
	} else {
		return false;
	}
}
 
/**
 * Get the number of fields from a database result
 * @return integer|false number of fields
 */
function wfNumFields( $res, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->numFields( $res );
	} else {
		return false;
	}
}
 
/**
 * Return name of a field in a result
 * @param $res Mixed: Ressource link see Database::fieldName()
 * @param $n Integer: id of the field
 * @param $dbi Default DB_LAST
 * @return string|false name of field
 */
function wfFieldName( $res, $n, $dbi = DB_LAST )
{
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->fieldName( $res, $n, $dbi = DB_LAST );
	} else {
		return false;
	}
}
/**#@-*/
 
/**
 * @todo document function
 * @see Database::insertId()
 */
function wfInsertId( $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->insertId();
	} else {
		return false;
	}
}
 
/**
 * @todo document function
 * @see Database::dataSeek()
 */
function wfDataSeek( $res, $row, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->dataSeek( $res, $row );
	} else {
		return false;
	}
}
 
/**
 * Get the last error number
 * @see Database::lastErrno()
 */
function wfLastErrno( $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->lastErrno();
	} else {
		return false;
	}
}
 
/**
 * Get the last error
 * @see Database::lastError()
 */
function wfLastError( $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->lastError();
	} else {
		return false;
	}
}
 
/**
 * Get the number of affected rows
 * @see Database::affectedRows()
 */
function wfAffectedRows( $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->affectedRows();
	} else {
		return false;
	}
}
 
/**
 * Get the last query ran
 * @see Database::lastQuery
 */
function wfLastDBquery( $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->lastQuery();
	} else {
		return false;
	}
}
 
/**
 * @see Database::Set()
 * @todo document function
 * @param $table
 * @param $var
 * @param $value
 * @param $cond
 * @param $dbi Default DB_MASTER
 */
function wfSetSQL( $table, $var, $value, $cond, $dbi = DB_MASTER )
{
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->set( $table, $var, $value, $cond );
	} else {
		return false;
	}
}
 
 
/**
 * Simple select wrapper, return one field
 * @see Database::selectField()
 * @param $table
 * @param $var
 * @param $cond Default ''
 * @param $dbi Default DB_LAST
 */
function wfGetSQL( $table, $var, $cond='', $dbi = DB_LAST )
{
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->selectField( $table, $var, $cond );
	} else {
		return false;
	}
}
 
/**
 * Does a given field exist on the specified table?
 * @see Database::fieldExists()
 * @param $table
 * @param $field
 * @param $dbi Default DB_LAST
 * @return Result of Database::fieldExists() or false.
 */
function wfFieldExists( $table, $field, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->fieldExists( $table, $field );
	} else {
		return false;
	}
}
 
/**
 * Does the requested index exist on the specified table?
 * @see Database::indexExists()
 * @param $table String
 * @param $index
 * @param $dbi Default DB_LAST
 * @return Result of Database::indexExists() or false.
 */
function wfIndexExists( $table, $index, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->indexExists( $table, $index );
	} else {
		return false;
	}
}
 
/**
 * @see Database::insert()
 * @todo document function
 * @param $table String
 * @param $array Array
 * @param $fname String, default 'wfInsertArray'.
 * @param $dbi Default DB_MASTER
 * @return result of Database::insert() or false.
 */
function wfInsertArray( $table, $array, $fname = 'wfInsertArray', $dbi = DB_MASTER ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->insert( $table, $array, $fname );
	} else {
		return false;
	}
}
 
/**
 * @see Database::getArray()
 * @todo document function
 * @param $table String
 * @param $vars
 * @param $conds
 * @param $fname String, default 'wfGetArray'.
 * @param $dbi Default DB_LAST
 * @return result of Database::getArray() or false.
 */
function wfGetArray( $table, $vars, $conds, $fname = 'wfGetArray', $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->getArray( $table, $vars, $conds, $fname );
	} else {
		return false;
	}
}
 
/**
 * @see Database::update()
 * @param $table String
 * @param $values
 * @param $conds
 * @param $fname String, default 'wfUpdateArray'
 * @param $dbi Default DB_MASTER
 * @return Result of Database::update()) or false;
 * @todo document function
 */
function wfUpdateArray( $table, $values, $conds, $fname = 'wfUpdateArray', $dbi = DB_MASTER ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		$db->update( $table, $values, $conds, $fname );
		return true;
	} else {
		return false;
	}
}
 
/**
 * Get fully usable table name
 * @see Database::tableName()
 */
function wfTableName( $name, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->tableName( $name );
	} else {
		return false;
	}
}
 
/**
 * @todo document function
 * @see Database::strencode()
 */
function wfStrencode( $s, $dbi = DB_LAST ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->strencode( $s );
	} else {
		return false;
	}
}
 
/**
 * @todo document function
 * @see Database::nextSequenceValue()
 */
function wfNextSequenceValue( $seqName, $dbi = DB_MASTER ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->nextSequenceValue( $seqName );
	} else {
		return false;
	}
}
 
/**
 * @todo document function
 * @see Database::useIndexClause()
 */
function wfUseIndexClause( $index, $dbi = DB_SLAVE ) {
	$db = wfGetDB( $dbi );
	if ( $db !== false ) {
		return $db->useIndexClause( $index );
	} else {
		return false;
	}
}

MediaWiki 1.16[edit | edit source]

Save WikiChat.php in the "extensions/WikiChat" directory.

<?php
/**
* MediaWiki WikiChat extension
* See: http://www.mediawiki.org/wiki/Extension:Chat for installation
* Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
* Author: http://www.wikichat.org/User:Firebreather
*/
 
#set to the directory phpfreechat is installed in
define('WC_PFC_DIRECTORY', 'phpfreechat');
 
# set to false to deny access to anonymous users
define('WC_ALLOW_ANONYMOUS_USERS', true);
 
# message shown when denying anonymous users. Change if you want a different message. WikiText ok..
define('WC_DENY_ACCESS_MESSAGE', 'You must [[Special:Userlogin|login]] to be allowed into this chatroom');
 
# when true there will be a chat room per article. Set to false to have a single site-wide chat room.
define('WC_ROOM_PER_ARTICLE', true);
 
if (!defined('MEDIAWIKI')) die ('Not an entry point');
 
$wgPFC_Directory = WC_PFC_DIRECTORY;
 
require_once "$IP/$wgPFC_Directory/src/phpfreechat.class.php";
require_once "$IP/includes/DatabaseFunctions.php";
 
$wgRoomPerArticle = WC_ROOM_PER_ARTICLE;
$wgAllowAnonUsers = WC_ALLOW_ANONYMOUS_USERS;
$wgDenyAccessMessage = WC_DENY_ACCESS_MESSAGE;
 
/* Extension variables */
$wgExtensionFunctions[] = 'wfSetupWikiChat';
$wgExtensionCredits['other'][] = array(
    'name' => 'WikiChat',
    'version' => '0.3.8, 2010-09-03, 1.16',
    'author' => '[http://www.wikichat.org/User:Firebreather  User:Firebreather]',
    'url' => 'http://www.wikichat.org/',
    'description' => 'Adds a tab to each article that switches to a chatroom',
);              
 
class WikiChat {
 
        // Constructor
        public function WikiChat() {
                global $wgHooks;
 
                # Add all our needed hooks
                $wgHooks['UnknownAction'][] = $this;
                $wgHooks['SkinTemplateTabs'][] = $this;
        }
 
        // main entry point
        public function onUnknownAction($action, $article) {
                global $wgOut, $wgCachePages, $wgTitle, $wgDBprefix, $wgDenyAccessMessage;
 
                $wgCachePages = false;
 
                if($action == 'chat') {
                        $wgOut->setPageTitle(str_replace('_', ' ', $wgTitle->getDBKey()));
 
                        if($this->isAnonDenied()) {
                                $wgOut->addWikiText($wgDenyAccessMessage);
                                return false;
                        }
 
                        $params = $this->configurePFC_Params();
 
                        $tblname = $wgDBprefix."chathistory";
 
                        $this->createChatHistoryDBTable($tblname);
 
                        $this->configurePFC_DB_Params($tblname, $params);
 
                        $this->configureNick($params);
 
                        $this->showChat($params);
 
                        return false;
                }
                else {
                        return true;
                }
        }
 
        private function isAnonDenied() {
                global $wgUser, $wgAllowAnonUsers;
 
                return !$wgAllowAnonUsers && $wgUser->isAnon();
        }
 
        private function configureNick(&$params) {
                global $wgUser, $wgOut, $wgAllowAnonUsers, $wgDenyAccessMessage, $wgTitle;
 
                $nick = "";
 
                if($wgUser->isAnon()) {
                }
                else {
                        $nick = $wgUser->getName();
                }
 
                $params["nick"]          = $nick; // setup the initial nickname
 
                return $nick;
        }
 
        private function configurePFC_Params() {
                global $wgTitle, $wgRoomPerArticle, $wgPFC_Directory;
                global $wgOut;
 
                $params["title"]         = "WikiChat";
 
                // apply room per page or site-wide room configuration option
                if($wgRoomPerArticle) {
                        //replace slashes in the page db key to ensure chat works for subpages
                        $params["serverid"]      = str_replace('/', '##', $wgTitle->getDBKey());
                }
                else {
                        $params["serverid"]      = md5(__FILE__);
                }
 
                $params["data_public_url"] = "$wgPFC_Directory/data/public";
                $params["data_public_path"] = "$wgPFC_Directory/data/public";
 
                $params["server_script_url"] = $_SERVER['REQUEST_URI'];
                $params["openlinknewwindow"] = true;
                $params["channels"] = array(str_replace('_', ' ', $wgTitle->getDBKey()));
                $params["frozen_nick"]    = true;     // do not allow to change the nickname
                $params["shownotice"]     = 0;        // 0 = nothing, 1 = just nickname changes, 2 = connect/quit, 3 = nick + connect
                $params["max_nick_len"]   = 30;       // nickname length could not be longer than 10 caracteres
                $params["max_text_len"]   = 300;      // a message cannot be longer than 50 caracteres
                $params["max_channels"]   = 3;        // limit the number of joined channels tab to 3
                $params["max_privmsg"]    = 1;        // limit the number of private message tab to 1
                $params["refresh_delay"]  = 2000;    // chat refresh speed is 2 secondes (2000ms)
                $params["max_msg"]        = 30;       // max message in the history is 15 (message seen when reloading the chat)
                $params["height"]         = "230px";  // height of chat area is 230px
                $params["debug"]          = false;     // activate debug console
                $params["timeout"]        = 600000;   // msecs until user is disconnected
 
                return $params;
        }
 
        private function createChatHistoryDBTable($tblname) {
                $dbr =& wfGetDB( DB_SLAVE );
 
                $sql = "show tables like '$tblname'";
                $res = $dbr->query ( $sql ) ;
                $num_rows = $dbr->numRows($res) + 0;
                $dbr->freeResult( $res );
 
                //create the chathistory table if it doesn't exist
                if($num_rows == 0) {
                        $sql =
                          "CREATE TABLE IF NOT EXISTS `$tblname` (
                            `server` varchar(32) NOT NULL default '',
                            `group` varchar(64) NOT NULL default '',
                            `subgroup` varchar(64) NOT NULL default '',
                            `leaf` varchar(64) NOT NULL default '',
                            `leafvalue` text NOT NULL,
                            `timestamp` int(11) NOT NULL default 0,
                            PRIMARY KEY  (`server`,`group`,`subgroup`,`leaf`),
                            INDEX (`server`,`group`,`subgroup`,`timestamp`)
                          ) ENGINE=InnoDB;";
                        $ret = wfQuery($sql, DB_WRITE, "");
                }
        }
 
        private function configurePFC_DB_Params($tblname, &$params) {
                global $wgDBserver, $wgDBname, $wgDBprefix, $wgDBuser, $wgDBpassword;
 
                $params["container_type"]               = "mysql";
                $params["container_cfg_mysql_host"]     = $wgDBserver;
                $params["container_cfg_mysql_database"] = $wgDBname;
                $params["container_cfg_mysql_port"]     = 3306;
                $params["container_cfg_mysql_table"]    = $tblname;
                $params["container_cfg_mysql_username"] = $wgDBuser;
                $params["container_cfg_mysql_password"] = $wgDBpassword;
        }
 
        private function showChat($params) {
                global $wgOut;
 
                $pfc = new phpFreeChat($params);
                $wgOut->addHTML($pfc->printChat(true));
                $wgOut->addHTML('<br><br><p>Type /help for a list of all commands</p>');
                $wgOut->addWikiText("[http://www.wikichat.org/index.php/WikiChat_help More help on WikiChat.org]");
        }
 
       public function onSkinTemplateTabs( $skin, &$content_actions ) {
                global $wgRequest;
 
                $action = $wgRequest->getText( 'action' );
 
                $content_actions['chat'] = array(
                                            'class' => ($action == 'chat') ? 'selected' : false,
                                            'text' => "chat",
                                            'href' => $skin->mTitle->getLocalURL( 'action=chat' )
                                             );
 
                return true;
        }
 
        # Needed in some versions to prevent Special:Version from breaking
        public function __toString() { return 'WikiChat'; }
 } /* class WikiChat */
 
/* Global function */
# Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWikiChat() {
        global $wgWikiChat;
        $wgWikiChat = new WikiChat();
}

MediaWiki 1.16[edit | edit source]

Save WikiChat.php in the "extensions" directory.

<?php
/**
* MediaWiki WikiChat extension
* See: http://www.mediawiki.org/wiki/Extension:Chat for installation
* Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
* Author: http://www.wikichat.org/User:Firebreather
*/
 
#set to the directory phpfreechat is installed in
define('WC_PFC_DIRECTORY', 'phpfreechat');
 
# set to false to deny access to anonymous users
define('WC_ALLOW_ANONYMOUS_USERS', true);
 
# message shown when denying anonymous users. Change if you want a different message. WikiText ok..
define('WC_DENY_ACCESS_MESSAGE', 'You must [[Special:Userlogin|login]] to be allowed into this chatroom');
 
# when true there will be a chat room per article. Set to false to have a single site-wide chat room.
define('WC_ROOM_PER_ARTICLE', true);
 
if (!defined('MEDIAWIKI')) die ('Not an entry point');
 
$wgPFC_Directory = WC_PFC_DIRECTORY;
 
require_once "$IP/$wgPFC_Directory/src/phpfreechat.class.php";
require_once "$IP/includes/DatabaseFunctions.php";
 
$wgRoomPerArticle = WC_ROOM_PER_ARTICLE;
$wgAllowAnonUsers = WC_ALLOW_ANONYMOUS_USERS;
$wgDenyAccessMessage = WC_DENY_ACCESS_MESSAGE;
 
/* Extension variables */
$wgExtensionFunctions[] = 'wfSetupWikiChat';
$wgExtensionCredits['other'][] = array(
    'name' => 'WikiChat',
    'version' => '0.3.8, 2010-09-03',
    'author' => '[http://www.wikichat.org/User:Firebreather  User:Firebreather]',
    'url' => 'http://www.wikichat.org/',
    'description' => 'Adds a tab to each article that switches to a chatroom',
);              
 
class WikiChat {
 
        // Constructor
        public function WikiChat() {
                global $wgHooks;
 
                # Add all our needed hooks
                $wgHooks['UnknownAction'][] = $this;
                $wgHooks['SkinTemplateTabs'][] = $this;
        }
 
        // main entry point
        public function onUnknownAction($action, $article) {
                global $wgOut, $wgCachePages, $wgTitle, $wgDBprefix, $wgDenyAccessMessage;
 
                $wgCachePages = false;
 
                if($action == 'chat') {
                        $wgOut->setPageTitle(str_replace('_', ' ', $wgTitle->getDBKey()));
 
                        if($this->isAnonDenied()) {
                                $wgOut->addWikiText($wgDenyAccessMessage);
                                return false;
                        }
 
                        $params = $this->configurePFC_Params();
 
                        $tblname = $wgDBprefix."chathistory";
 
                        $this->createChatHistoryDBTable($tblname);
 
                        $this->configurePFC_DB_Params($tblname, $params);
 
                        $this->configureNick($params);
 
                        $this->showChat($params);
 
                        return false;
                }
                else {
                        return true;
                }
        }
 
        private function isAnonDenied() {
                global $wgUser, $wgAllowAnonUsers;
 
                return !$wgAllowAnonUsers && $wgUser->isAnon();
        }
 
        private function configureNick(&$params) {
                global $wgUser, $wgOut, $wgAllowAnonUsers, $wgDenyAccessMessage, $wgTitle;
 
                $nick = "";
 
                if($wgUser->isAnon()) {
                }
                else {
                        $nick = $wgUser->getName();
                }
 
                $params["nick"]          = $nick; // setup the initial nickname
 
                return $nick;
        }
 
        private function configurePFC_Params() {
                global $wgTitle, $wgRoomPerArticle, $wgPFC_Directory;
                global $wgOut;
 
                $params["title"]         = "WikiChat";
 
                // apply room per page or site-wide room configuration option
                if($wgRoomPerArticle) {
                        //replace slashes in the page db key to ensure chat works for subpages
                        $params["serverid"]      = str_replace('/', '##', $wgTitle->getDBKey());
                }
                else {
                        $params["serverid"]      = md5(__FILE__);
                }
 
                $params["data_public_url"] = "$wgPFC_Directory/data/public";
                $params["data_public_path"] = "$wgPFC_Directory/data/public";
 
                $params["server_script_url"] = $_SERVER['REQUEST_URI'];
                $params["openlinknewwindow"] = true;
                $params["channels"] = array(str_replace('_', ' ', $wgTitle->getDBKey()));
                $params["frozen_nick"]    = true;     // do not allow to change the nickname
                $params["shownotice"]     = 0;        // 0 = nothing, 1 = just nickname changes, 2 = connect/quit, 3 = nick + connect
                $params["max_nick_len"]   = 30;       // nickname length could not be longer than 10 caracteres
                $params["max_text_len"]   = 300;      // a message cannot be longer than 50 caracteres
                $params["max_channels"]   = 3;        // limit the number of joined channels tab to 3
                $params["max_privmsg"]    = 1;        // limit the number of private message tab to 1
                $params["refresh_delay"]  = 2000;    // chat refresh speed is 2 secondes (2000ms)
                $params["max_msg"]        = 30;       // max message in the history is 15 (message seen when reloading the chat)
                $params["height"]         = "230px";  // height of chat area is 230px
                $params["debug"]          = false;     // activate debug console
                $params["timeout"]        = 600000;   // msecs until user is disconnected
 
                return $params;
        }
 
        private function createChatHistoryDBTable($tblname) {
                $dbr =& wfGetDB( DB_SLAVE );
 
                $sql = "show tables like '$tblname'";
                $res = $dbr->query ( $sql ) ;
                $num_rows = $dbr->numRows($res) + 0;
                $dbr->freeResult( $res );
 
                //create the chathistory table if it doesn't exist
                if($num_rows == 0) {
                        $sql =
                          "CREATE TABLE IF NOT EXISTS `$tblname` (
                            `server` varchar(32) NOT NULL default '',
                            `group` varchar(64) NOT NULL default '',
                            `subgroup` varchar(64) NOT NULL default '',
                            `leaf` varchar(64) NOT NULL default '',
                            `leafvalue` text NOT NULL,
                            `timestamp` int(11) NOT NULL default 0,
                            PRIMARY KEY  (`server`,`group`,`subgroup`,`leaf`),
                            INDEX (`server`,`group`,`subgroup`,`timestamp`)
                          ) ENGINE=InnoDB;";
                        $ret = wfQuery($sql, DB_WRITE, "");
                }
        }
 
        private function configurePFC_DB_Params($tblname, &$params) {
                global $wgDBserver, $wgDBname, $wgDBprefix, $wgDBuser, $wgDBpassword;
 
                $params["container_type"]               = "mysql";
                $params["container_cfg_mysql_host"]     = $wgDBserver;
                $params["container_cfg_mysql_database"] = $wgDBname;
                $params["container_cfg_mysql_port"]     = 3306;
                $params["container_cfg_mysql_table"]    = $tblname;
                $params["container_cfg_mysql_username"] = $wgDBuser;
                $params["container_cfg_mysql_password"] = $wgDBpassword;
        }
 
        private function showChat($params) {
                global $wgOut;
 
                $pfc = new phpFreeChat($params);
                $wgOut->addHTML($pfc->printChat(true));
                $wgOut->addHTML('<br><br><p>Type /help for a list of all commands</p>');
                $wgOut->addWikiText("[http://www.wikichat.org/index.php/WikiChat_help More help on WikiChat.org]");
        }
 
       public function onSkinTemplateTabs( &$skin, &$content_actions ) {
                global $wgRequest;
 
                $action = $wgRequest->getText( 'action' );
 
                $content_actions['chat'] = array(
                                            'class' => ($action == 'chat') ? 'selected' : false,
                                            'text' => "chat",
                                            'href' => $skin->mTitle->getLocalURL( 'action=chat' )
                                             );
 
                return true;
        }
 
        # Needed in some versions to prevent Special:Version from breaking
        public function __toString() { return 'WikiChat'; }
 } /* class WikiChat */
 
/* Global function */
# Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWikiChat() {
        global $wgWikiChat;
        $wgWikiChat = new WikiChat();
}

MediaWiki prior to 1.16[edit | edit source]

Save WikiChat.php in the "extensions" directory.

<?php
/**
* MediaWiki WikiChat extension
* See: http://www.mediawiki.org/wiki/Extension:Chat for installation
* Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
* Author: http://www.wikichat.org/User:Firebreather
*/
 
#set to the directory phpfreechat is installed in
define('WC_PFC_DIRECTORY', 'phpfreechat');
 
# set to false to deny access to anonymous users
define('WC_ALLOW_ANONYMOUS_USERS', true);
 
# message shown when denying anonymous users. Change if you want a different message. WikiText ok..
define('WC_DENY_ACCESS_MESSAGE', 'You must [[Special:Userlogin|login]] to be allowed into this chatroom');
 
# when true there will be a chat room per article. Set to false to have a single site-wide chat room.
define('WC_ROOM_PER_ARTICLE', true);
 
if (!defined('MEDIAWIKI')) die ('Not an entry point');
 
$wgPFC_Directory = WC_PFC_DIRECTORY;
 
require_once "$IP/$wgPFC_Directory/src/phpfreechat.class.php";
require_once "$IP/includes/DatabaseFunctions.php";
 
$wgRoomPerArticle = WC_ROOM_PER_ARTICLE;
$wgAllowAnonUsers = WC_ALLOW_ANONYMOUS_USERS;
$wgDenyAccessMessage = WC_DENY_ACCESS_MESSAGE;
 
/* Extension variables */
$wgExtensionFunctions[] = 'wfSetupWikiChat';
$wgExtensionCredits['other'][] = array(
    'name' => 'WikiChat',
    'version' => '0.3.8, 2010-09-03',
    'author' => '[http://www.wikichat.org/User:Firebreather  User:Firebreather]',
    'url' => 'http://www.wikichat.org/',
    'description' => 'Adds a tab to each article that switches to a chatroom',
);              
 
class WikiChat {
 
        // Constructor
        public function WikiChat() {
                global $wgHooks;
 
                # Add all our needed hooks
                $wgHooks['UnknownAction'][] = $this;
                $wgHooks['SkinTemplateTabs'][] = $this;
        }
 
        // main entry point
        public function onUnknownAction($action, $article) {
                global $wgOut, $wgCachePages, $wgTitle, $wgDBprefix, $wgDenyAccessMessage;
 
                $wgCachePages = false;
 
                if($action == 'chat') {
                        $wgOut->setPageTitle(str_replace('_', ' ', $wgTitle->getDBKey()));
 
                        if($this->isAnonDenied()) {
                                $wgOut->addWikiText($wgDenyAccessMessage);
                                return false;
                        }
 
                        $params = $this->configurePFC_Params();
 
                        $tblname = $wgDBprefix."chathistory";
 
                        $this->createChatHistoryDBTable($tblname);
 
                        $this->configurePFC_DB_Params($tblname, $params);
 
                        $this->configureNick($params);
 
                        $this->showChat($params);
 
                        return false;
                }
                else {
                        return true;
                }
        }
 
        private function isAnonDenied() {
                global $wgUser, $wgAllowAnonUsers;
 
                return !$wgAllowAnonUsers && $wgUser->isAnon();
        }
 
        private function configureNick(&$params) {
                global $wgUser, $wgOut, $wgAllowAnonUsers, $wgDenyAccessMessage, $wgTitle;
 
                $nick = "";
 
                if($wgUser->isAnon()) {
                }
                else {
                        $nick = $wgUser->getName();
                }
 
                $params["nick"]          = $nick; // setup the initial nickname
 
                return $nick;
        }
 
        private function configurePFC_Params() {
                global $wgTitle, $wgRoomPerArticle, $wgPFC_Directory;
                global $wgOut;
 
                $params["title"]         = "WikiChat";
 
                // apply room per page or site-wide room configuration option
                if($wgRoomPerArticle) {
                        //replace slashes in the page db key to ensure chat works for subpages
                        $params["serverid"]      = str_replace('/', '##', $wgTitle->getDBKey());
                }
                else {
                        $params["serverid"]      = md5(__FILE__);
                }
 
                $params["data_public_url"] = "$wgPFC_Directory/data/public";
                $params["data_public_path"] = "$wgPFC_Directory/data/public";
 
                $params["server_script_url"] = $_SERVER['REQUEST_URI'];
                $params["openlinknewwindow"] = true;
                $params["channels"] = array(str_replace('_', ' ', $wgTitle->getDBKey()));
                $params["frozen_nick"]    = true;     // do not allow to change the nickname
                $params["shownotice"]     = 0;        // 0 = nothing, 1 = just nickname changes, 2 = connect/quit, 3 = nick + connect
                $params["max_nick_len"]   = 30;       // nickname length could not be longer than 10 caracteres
                $params["max_text_len"]   = 300;      // a message cannot be longer than 50 caracteres
                $params["max_channels"]   = 3;        // limit the number of joined channels tab to 3
                $params["max_privmsg"]    = 1;        // limit the number of private message tab to 1
                $params["refresh_delay"]  = 2000;    // chat refresh speed is 2 secondes (2000ms)
                $params["max_msg"]        = 30;       // max message in the history is 15 (message seen when reloading the chat)
                $params["height"]         = "230px";  // height of chat area is 230px
                $params["debug"]          = false;     // activate debug console
                $params["timeout"]        = 600000;   // msecs until user is disconnected
 
                return $params;
        }
 
        private function createChatHistoryDBTable($tblname) {
                $dbr =& wfGetDB( DB_SLAVE );
 
                $sql = "show tables like '$tblname'";
                $res = $dbr->query ( $sql ) ;
                $num_rows = $dbr->numRows($res) + 0;
                $dbr->freeResult( $res );
 
                //create the chathistory table if it doesn't exist
                if($num_rows == 0) {
                        $sql =
                          "CREATE TABLE IF NOT EXISTS `$tblname` (
                            `server` varchar(32) NOT NULL default '',
                            `group` varchar(64) NOT NULL default '',
                            `subgroup` varchar(64) NOT NULL default '',
                            `leaf` varchar(64) NOT NULL default '',
                            `leafvalue` text NOT NULL,
                            `timestamp` int(11) NOT NULL default 0,
                            PRIMARY KEY  (`server`,`group`,`subgroup`,`leaf`),
                            INDEX (`server`,`group`,`subgroup`,`timestamp`)
                          ) ENGINE=InnoDB;";
                        $ret = wfQuery($sql, DB_WRITE, "");
                }
        }
 
        private function configurePFC_DB_Params($tblname, &$params) {
                global $wgDBserver, $wgDBname, $wgDBprefix, $wgDBuser, $wgDBpassword;
 
                $params["container_type"]               = "mysql";
                $params["container_cfg_mysql_host"]     = $wgDBserver;
                $params["container_cfg_mysql_database"] = $wgDBname;
                $params["container_cfg_mysql_port"]     = 3306;
                $params["container_cfg_mysql_table"]    = $tblname;
                $params["container_cfg_mysql_username"] = $wgDBuser;
                $params["container_cfg_mysql_password"] = $wgDBpassword;
        }
 
        private function showChat($params) {
                global $wgOut;
 
                $pfc = new phpFreeChat($params);
                $wgOut->addHTML($pfc->printChat(true));
                $wgOut->addHTML('<br><br><p>Type /help for a list of all commands</p>');
                $wgOut->addWikiText("[http://www.wikichat.org/index.php/WikiChat_help More help on WikiChat.org]");
        }
 
       public function onSkinTemplateTabs( &$skin, &$content_actions ) {
                global $wgRequest;
 
                $action = $wgRequest->getText( 'action' );
 
                $content_actions['chat'] = array(
                                            'class' => ($action == 'chat') ? 'selected' : false,
                                            'text' => "chat",
                                            'href' => $skin->mTitle->getLocalURL( 'action=chat' )
                                             );
 
                return true;
        }
 
        # Needed in some versions to prevent Special:Version from breaking
        public function __toString() { return 'WikiChat'; }
 } /* class WikiChat */
 
/* Global function */
# Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWikiChat() {
        global $wgWikiChat;
        $wgWikiChat = new WikiChat();

Site List[edit | edit source]

Please add your wiki to the site list so we can visit you to see how you're using WikiChat and how to improve it. We'll also put a link to your wiki on the front page of WikiChat.org.

See also[edit | edit source]