Contents

What is this? The WikiCasting Tool!

The psycnotify.php extension for MediaWiki. Informs people or applications connected to a PSYC entity (usually a chatroom with one or one billion members connected to it, but it could as well be a projector in a nightclub, a whistle on a boat to Cairo or a blinkenlights) about a change that has been submitted to a Wiki.

It also demonstrates how trivial it is to send a PSYC notification from a PHP or any other language application.

Messages in PSYC will show up something like this, depending on your user interface to PSYC:

(Wiki:lynx) has made a major change in http://about.psyc.eu/Routing saying: packet ids
(Wiki:fippo) has made a minor change in http://about.psyc.eu/Jabber

You may obviously have some translations of the message installed in the text database of your PSYC client or gateway server, so that it shows up in your native language.

Requirements and Getting Started

You will need a chatroom on a psyced server, but you can use any running psyced out there if the administrators like your face. If you roll your own, it comes with a pre-configured wikinotify place in http://www.psyced.org/dist/place/wikinotify.c

Then you can use any IRC or Jabber client, using the client access facilities of psyced. Taking the out-of-the-box place as an example, with an IRC client you would have to access #wikinotify on your psyced/wiki server, whereas using Jabber you would join a MUC called *wikinotify@example.org with example.org being the address of your psyced. The asterisk (*) cannot be left out! You can also register an account on psyced directly, so you avoid having Jabber servers in-between. See the IRC and Jabber help pages for further information.

Relaying this type of messages into an IRC network hasn't been implemented yet, but it isn't too hard to do. The existing gateways just need a little tweak.

Software Installation by Cut & Paste

Here goes the magnificently short code:


<?php
/* 
psycnotify.php 1.1:
    deliver a change notification to a PSYC group.
    written by psyc://goodadvice.pages.de/~fippo
    flirted up by psyc://psyced.org/~lynX
    released as freeware. wash your socks with it.

http://www.psyc.eu - the answer in messaging and conferencing

this script uses UDP because (a) the wiki is running on the localhost of the
server (b) you could just as well use TCP (c) then again if you don't mind
potential fake messages, you can use this across the network too - if the
network is really congested enough to lose a wiki notification, is it really
worth congesting the network even more?

now comes the two line config zone.

$psyctarget: if you don't know the uniform of your chatroom, a /status
command will tell you.

$psychost: in some cases when you want to use a neat domain name you will
have to resort to using SRV to map it onto a different host from where your
webserver resides. since implementing SRV here looks like too much work,
we simply ask you to provide the ip or hostname of the receiving machine
where the $psyctarget actually resides on, into $psychost. under normal
circumstances $psychost has the same hostname as $psyctarget.

our settings look like this:
  $psyctarget = "psyc://psyced.org/@welcome";
  $psychost = "udp://psyced.org";

but the easiest way to set this up is to install a psyced on the same
host, then you don't need to change anything below and the "wikinotify"
chatroom will work out of the box (feel free to edit it, though).
 */

$psyctarget = "psyc://localhost/@wikinotify";
$psychost = "udp://localhost";
$psycport = 4404;

/* in an ideal world, there is nothing you need to do below here */

function psycnotify($article, $user, $text, $summary, $isminor, $iswatch, $section) {
    global $psyctarget, $psychost, $psycport;

    $url = "http://" . $_SERVER['SERVER_NAME'];
    $url .= str_replace("index.php?title=", "index.php/",
       substr($_SERVER['REQUEST_URI'], 0, -14));
    # header
    $s = ":_target\t$psyctarget\n"
#      . ":_encoding\tutf-8\n" # PSYC uses UTF-8 anyway
       . "\n"                  # move on from routing layer to application layer
       . ":_nick_wiki\t". strToLower($user->mName) ."\n"
       . ":_article\t". $article->mTitle->mTextform ."\n"
       . ":_page\t$url$section\n";
    if ($section) {
        $s .= ":_section\t$section\n";
        if ($summary && ($p = strpos($summary, " */ ")))
            $summary = substr($summary, $p + 4);
    }
    if ($summary) $s .= ":_summary\t$summary\n";

    # method
    $mc = "_notice_update_wiki";
    if ($isminor) $mc .= "_minor";
    $s .= $mc ."\n";

    # body
    $s .= "(Wiki:[_nick_wiki]) has made a "
       . ($isminor ? "minor" : "major")
       . " change in [_page]\n";
    if ($summary) $s .= "saying: [_summary]\n";

    # deliver, as simple as that
    $udp = fsockopen($psychost, $psycport);
    fwrite($udp, ".\n". $s .".\n");
    fclose($udp);
    return true;
}

$wgHooks['ArticleSaveComplete'][] = array('psycnotify');
?>

put it into extensions/psycnotify.php, then add

require_once( "extensions/psycnotify.php" );

to LocalSettings.php

Gotchas

Using the relaying feature of psyced you can also put a target on a completely different server or even protocol, like an xmpp: address, into $psyctarget. The $psychost needs to trust the source, but then it will forward the notification to wherever you want. A place where many can subscribe to it and proper routing is ensured, is a good idea.


See also