<?php
/* MediaWiki extension to report changes through a Supybot IRC bot
* Copyright (C) 2011 Ian Weller <ian@ianweller.org>
* http://www.mediawiki.org/wiki/Extension:SupybotNotify
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
$wgExtensionCredits["other"][] = array(
'path' => __FILE__,
'name' => 'Supybot Notify',
'description' => 'Sends recent changes through a Supybot with the Notify plugin to an IRC channel',
'version' => '1.0',
'author' => 'Ian Weller',
'url' => 'http://www.mediawiki.org/wiki/Extension:SupybotNotify',
);
$wgHooks['RecentChange_save'][] = 'sendToSupybotNotify';
// Default variables
if (!isset($wgSupybotNotifyChannels)) { $wgSupybotNotifyChannels = array(); }
if (!isset($wgSupybotNotifyHost)) { $wgSupybotNotifyHost = '127.0.0.1'; }
if (!isset($wgSupybotNotifyPort)) { $wgSupybotNotifyPort = 5050; }
function sendToSupybotNotify($recentChange)
{
global $wgSupybotNotifyChannels, $wgSupybotNotifyHost, $wgSupybotNotifyPort;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false)
{
return true;
}
if (socket_connect($sock, $wgSupybotNotifyHost, $wgSupybotNotifyPort) === false)
{
return true;
}
foreach ($wgSupybotNotifyChannels as $channel)
{
$line = $channel . ' ' . $recentChange->getIRCLine();
socket_write($sock, $line, strlen($line));
}
socket_close($sock);
return true;
}