Fandom

Pixiepidea

WikiChat.php

82pages on
this wiki
Add New Page
Comments0 Share

DatabaseFunctions.php

<?php /**

  1. set to the directory phpfreechat is installed in

define('WC_PFC_DIRECTORY', 'phpfreechat');

  1. set to false to deny access to anonymous users

define('WC_ALLOW_ANONYMOUS_USERS', true);

  1. message shown when denying anonymous users. Change if you want a
  2. different message. WikiText ok..

define('WC_DENY_ACCESS_MESSAGE', 'You must login to be allowed into this chatroom');

  1. when true there will be a chat room per article. Set to false to have
  2. 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('

Type /help for a list of all commands

');

$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' )

  1. '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 */

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupWikiChat() {

       global $wgWikiChat;
       $wgWikiChat = new WikiChat();

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki