====== DokuWiki Chat AJAX-driven plugin ====== ===== Info ===== Finally I finished the [[:dokuwiki|DokuWiki]] Chat plugin. After some painstaking polishing it is working as expected. Though the code base is probably not yet ready for public deployment, you can already test its functionality here. This chat plugin is AJAX driven so it means that you do not have to reload page to see new incoming messages. In the info-bar you can see the AJAX engine progress. If you have Java enabled you can as well have nice sound notification of new messages, even with sound volume / muting. There is already a bunch of AJAX chatting modules available out there. So why I made this one? It started as a improvement of Discussion plugin and ended in fully AJAX driven chat. I wanted to test the technology and to learn something new. How to use it? Just type your message into text field below and hit [Enter]. That's it... ===== Installation ===== If anybody wish to test this under own DokuWiki installation, feel free to {{:dokuwiki:plugin:dokuwiki-chat-1.1.2.zip?nocache|download it here}} (version 1.1.2),\\ [[http://pv.no-ip.org/bin/dokuwiki-chat-1.1.2.zip|Mirror 1 here]] (version 1.1.2), or \\ [[http://www.box.net/public/je8m1btjvg|Mirror 2 here]] (all versions). As have been said, code is probably not ready yet so it may fail to work for you under some circumstances, especially if you have older DokuWiki version. Improvements shall follow... ==== Installation ==== Unzip ''chat/'' directory into your DokuWiki plugins folder. Use included ''local.php.dist'' and add its contents to your ''local.php'' settings file. Change the values accordingly at your will. The DokuWiki uses the **AJAX tookit library SACK** for all AJAX operations. For the chat plugin to work correctly, you need to update **SACK** with latest 1.6 version. I provide in the installation zip updated version of **SACK**. It is only one file ''tw-sack.js''. You will have to copy this file over the original file in ''/lib/scripts/'' directory. Original ''tw-sack.js'' 1.6 version comes from [[http://www.twilightuniverse.com/resources/code/sack/]] where you can download complete package with documentation and demo. \\ Original file miss some ''";"'' on the end of declarations and it did not work well with DokuWiki javascript compression. That is the only modification I made. ==== User rights ==== Chat messages are stored into separate ''chat'' namespace under the page where it is included. So this current page stores chat into '':dokuwiki:plugin:chat:chat'' page. ++ Physical file would be ''data/pages/dokuwiki/plugin/chat/chat.txt'' ++\\ You will have to setup user-rights (ACL) for ''chat'' namespace. When only ''Read'' right is set, user can see the messages list but is not allowed to send the messages. ==== Chat include ==== To include chat on your page, use: %%~~CHAT~~%% Chat can be included only once per page. ==== Older DokuWiki versions ==== Chat plugin has been developed under latest development DokuWiki version. If you wish to run it on older versions, you will probably need to do some adjustments: * If your installation does not include {{:dokuwiki:plugin:events.js}}, download it and put it into ''lib/scripts'' directory * Edit ''ajax.php'' and change all occurrencies of $auth->getUserData(...) into auth_getUserData(...) ==== Server logs ==== In case you have access to your server configuration, consider excluding Chat plugin accesses from access.log. This is how it can be done for Apache2 (example): SetEnvIf Request_URI "^/wiki/lib/plugins/chat/ajax\.php$" dontlog SetEnvIf Request_URI "^/wiki/lib/exe/indexer\.php$" dontlog CustomLog /var/log/apache2/access.log combined env=!dontlog ===== Internal logic ===== There are rotating four AJAX checking states: - First, new messages are polled each 5 seconds. - After 30 seconds, checking interval is prolonged to 10 seconds. - After another 30 seconds, checking interval is changed to 30 seconds. - Now, mouse-movement over document window is monitored. If no mouse movement occures on document window in one minute, interval is again prolonged to 5 minutes which is longest checking interval. Now as soon as any mouse movement occures, checking interval is changed back to 10 seconds and the cycle repeats again. At any time if something is typed into message box, checking interval is changed back to fastest 5 seconds immediately. This logic ensures that if chatting heat goes high, messages are refreshed fast enough and still if there are no people chatting for some time, the polling cools down so the web-server is not overloaded with AJAX requests. You can modify the timings of course, but use common sense here. Although AJAX polling requests and responses are short chunks of data and usually complete very quickly, if there is a lot of users that have the page with the chat plugin open in browser, enough traffic can be generated to bring your server to its knees. So use it wisely... It is also advised to use some sort of PHP accelerator on the server side to improve performance((Latest [[http://eaccelerator.net|eAccelerator]] is maybe the best bet if you do not have this already)). ==== History ==== * 2006,11,8, **Version 1.1.2** * Security: Limited length of Name field to 30 characters. * Security: Limited length of Message field. Can be specified in configuration * Security: Filtering of Name field. Now it can consist of alphanumeric characters, dashes, underscores, dots or spaces only. * Added ''audio-notify'' setting into configuration. * Fixed cookies handling to work with newest DokuWiki * Provided updated Ajax toolkit library ''tw-sack.js'' (SACK 1.6 modified), you have to copy this over file in ''/lib/scripts/'' directory. Original comes from [[http://www.twilightuniverse.com/resources/code/sack/]] * 2006,2,21, **Version 1.1.1** * Fixed regular expression in line parsing. * 2006,2,21, **Version 1.1** * Optimized sent data, really only new messages are transferred * Limited sending rate so it is not possible to send more than 1 message per second * Added ''$conf['chat']['show-progress']'' for enabling info bar * ''[Clear messages]'' button is now visible for logged-in user that has edit rights for current page * Improved user-rights handling, now user must have write-rights for chat page to be able to see ''[Send]'' button and chat prompt. * More small fixes * 2006,2,20, **Version 1.0** * Added user rights checking * Added "Loading messages..." text on initial page load * Added error messages when user has insufficient rights