Extension:Chat

From MediaWiki.org

Jump to: navigation, search

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
Chat

Release status: beta

Implementation  Skin
Description Adds a Chat tab to every article that links to an embedded chatroom by the same name.
Author(s)  User:Firebreather
Last Version  0.2.1 (2007-07-03)
MediaWiki  tested with 1.9.3 only, known to work on 1.6.8
License No license specified
Download WikiChat.php

check usage (experimental)

Contents

[edit] 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. It can be configured to have only one chatroom for all articles, rather than one chatroom per article (the default).
  • Storage is just to the filesystem at the moment.
  • Come to WikiChat.org for a demo or if you would like to contribute.

If you have different requirements for embedded chat on your wiki, you might like to consider Extension:Chat/Lace

[edit] 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.

[edit] Installation

Just five easy steps:-

1. Download PhpFreeChat 1.0-beta11 and install it into your wiki somewhere. I have mine under /wiki/phpfreechat. (NOTE: You MUST download exactly phpfreechat 1.0.beta11 the more recent versions fail)
2. Copy the WikiChat.php code into the extensions directory.
3. Modify the paths at the top of WikiChat.php to point to your PhpFreeChat installation:-
require_once "$IP/phpfreechat-1.0-beta11/src/pfcglobalconfig.class.php";
require_once "$IP/phpfreechat-1.0-beta11/src/phpfreechat.class.php";
4. Add this line to the end of LocalSettings.php:-
include( "$IP/extensions/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/*

Tip: On the lastest version 1.x maybe it will not work and it will
show you "Error: the chat cannot be loaded!...", then try with 755 rights.

Its probably more sensible to use 755 than 777.

The chat function should be working now. Please report any issues to Firebreather or add them to the discussion for this extension.

[edit] Optional Parameters

Most of 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.

[edit] Disabling Anonymous Access

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 follow these 2 steps:-

1. set the variable $wgAllowAnonUsers from true to false
2. change the $wgDenyAccessMessage if you so desire

[edit] Making all tabs point to one chatroom

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

$params["channels"] = array($wgTitle->getPrefixedText());

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

$params["channels"] = array("MyChatRoom");

All articles will now put users entering through the chat tab, into the chatroom named MyChatRoom.

[edit] ChangeLog

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

  • highly recommended for sites using earlier versions of this extension to upgrade WikiChat.php to 0.2.1 (current version) and phpfreechat to 1.0.beta11
  • 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

[edit] Source code

The following is a copy from an old website archive (this copy is not yet tested) !


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
*/
 
require_once "$IP/phpfreechat-1.0-beta11/src/pfcglobalconfig.class.php";
require_once "$IP/phpfreechat-1.0-beta11/src/phpfreechat.class.php";
 
 
/* Global variables */
$wgAllowAnonUsers = true; # set to false to deny access to anonymous users
 
# message shown when denying anonymous users. Change if you want a different message. WikiText ok..
$wgDenyAccessMessage = 'You must [[Special:Userlogin|login]] to be allowed into this chatroom';
 
/* Extension variables */
$wgExtensionFunctions[] = 'wfSetupWikiChat';
$wgExtensionCredits['other'][] = array(
    'name' => 'WikiChat',
    'version' => '0.2.2, 2007-07-25',
    '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
	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, $wgDenyAccessMessage, $wgAllowAnonUsers;
 
		$wgCachePages = false;
 
		if($action == 'chat') {
 
			$wgOut->setHTMLTitle("WikiChat");
			$wgOut->setPageTitle("WikiChat");
 
			if($wgUser->isAnon()) {
				if(!$wgAllowAnonUsers) {
					$wgOut->addWikiText($wgDenyAccessMessage);
				  	return false;
				}
				else {
					$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 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["width"]          = "800px";  // width of chat area is 800px
			$params["debug"]          = false;     // activate debug console
                        $params["timeout"]        = 600000;   // msecs until user is disconnected
 
			$pfc = new phpFreeChat($params);
        	$wgOut->addHTML($pfc->printChat(true));
        	$wgOut->addHTML('<br><br><p>Type /help for a list of all commands</p>');
 
       		return false;
       	}
		else {
       		return true;
       	}
	}
 
	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
	function __toString() { return 'WikiChat'; }
 }
 
/* Global function */
# Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWikiChat() {
	global $wgWikiChat;
	$wgWikiChat = new WikiChat();
}
 
?>

[edit] See also