Extension:Chat

What can this extension do?

 * Adds a Chat tab to every wiki Article that switches to an embedded chatroom with the same name as the article title.


 * Uses PhpFreeChat.


 * Storage is just to the filesystem at the moment.


 * Come to WikiChat.org for more information and to help with the development.


 * This extension is in the early stages of development. I only just got it working. Many more things to do. Come to WikiChat.org for details.

Usage
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.

Installation

 * 1. Download PhpFreeChat 1.0-beta9 and install it into your wiki somewhere. I have mine under /wiki/custom/phpfreechat.


 * 2. Find the following file: phpfreechat/lib/xajax_0.5_beta1/xajax_core/xajaxResponse.inc.php and replace function getOutput with the code in the Code section below. (I'm trying to get it working without needing this hack)


 * 3. Copy the WikiChat.php code in the Code section below, into the extensions directory.


 * 4. Modify the pathes at the top of WikiChat.php to point to your PhpFreeChat installation:-

require_once "$IP/phpfreechat/src/pfcglobalconfig.class.php"; require_once "$IP/phpfreechat/src/phpfreechat.class.php";


 * 5. Add this line to the end of LocalSettings.php:-

Parameters
All the optional parameters are in WikiChat.php. They are parameters to PhpFreeChat. You need to refer to the PhpFreeChat documentation for information about how to change them.

Code
phpfreechat/lib/xajax_0.5_beta1/xajax_core/xajaxResponse.inc.php /**	 * Returns the output of the response suitable for sending to a Web browser * (i. e., XML or JSON) *	 * @return string */	function getOutput {		$xml = ""; if (is_array($this->aCommands)) {			foreach($this->aCommands as $aCommand) {				$sData = $aCommand['data']; unset($aCommand['data']); $xml .= $this->_getXMLForCommand($aCommand, $sData); }		}

/*		HACK have to remove the xml version stuff to work with MediaWiki tabs http://www.wikichat.org/User:Firebreather

$sXML = "sEncoding && strlen(trim($this->sEncoding)) > 0) $sXML .= " encoding=\"".$this->sEncoding."\""; $sXML .= " ?"."> ". $xml. " ";		$sXML .= " ". $xml. " ";

return $sXML; }

WikiChat.php <?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

require_once "$IP/phpfreechat/src/pfcglobalconfig.class.php"; require_once "$IP/phpfreechat/src/phpfreechat.class.php";

/* Global variable */ $wgExtensionFunctions[] = 'wfSetupWikiChat';

class WikiChat {

// Constructor function WikiChat { global $wgHooks;

# Add all our needed hooks $wgHooks['UnknownAction'][] = $this; $wgHooks['SkinTemplateTabs'][] = $this; }

function onUnknownAction($action, $article) { global $wgOut, $wgSitename, $wgCachePages, $wgUser, $wgTitle;

$wgCachePages = false;

if($action == 'chat') {

if($wgUser->isAnon) { $nick = "Guest"; }			else { $nick = $wgUser->getName; }

$params["title"]        = "WikiChat"; $params["nick"]         = $nick; // setup the initial nickname $params["serverid"]     = $wgSitename; $params["openlinknewwindow"] = true; $params["channels"] = array($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/quit $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 10 secondes (10000ms) $params["max_msg"]       = 15;       // max message in the history is 15 (message seen when reloading the chat) $params["height"]        = "230px";  // height of chat area is 230px $params["width"]         = "800px";  // width of chat area is 800px $params["debug"]         = false;     // activate debug console $params["debugxajax"]    = false;     // activate xajax debug (js popup)

$pfc = new phpFreeChat($params); $wgOut->addHTML($pfc->printChat(true));

return false; }		else { return true; }	}

function onSkinTemplateTabs( &$skin, &$content_actions ) { global $wgRequest;

$action = $wgRequest->getText( 'action' );

// $title = Title::newFromText( 'MainPage&action=chat' );

$content_actions['chat'] = array(							'class' => ($action == 'chat') ? 'selected' : false,							'text' => "chat",							'href' => $skin->mTitle->getLocalURL( 'action=chat' )				);

return true; }

}

/* Global function */ function wfSetupWikiChat { global $wgWikiChat; $wgWikiChat = new WikiChat; }
 * 1) Called from $wgExtensionFunctions array when initialising extensions

?>