3 * A recentchanges IRC bot
5 * Example command-line where irc is the name of the ircII executable:
6 * php rcdumper.php | irc -d -c \#channel nick server
7 * The name of the IRC server should match $ircServer below.
13 $ircServer = "irc.freenode.net";
15 # Set the below if this is running on a non-Wikimedia site:
16 #$serverName="your.site.here";
18 ini_set( "display_errors", 1 );
19 $wgCommandLineMode = true;
20 $optionsWithArgs = array( 'm' );
21 require_once("../maintenance/commandLine.inc" );
23 if ( !empty( $options['m'] ) ) {
24 $channel = $options['m'];
29 if ($lang == "commons") $site = "wikimedia";
32 $serverName="$lang.$site.org";
33 $newPageURLFirstPart="http://$serverName/wiki/";
34 $URLFirstPart="http://$serverName/w/wiki.phtml?title=";
36 $newPageURLFirstPart="http://$serverName$wgScript/";
37 $URLFirstPart="http://$serverName$wgScript?title=";
40 $wgTitle = Title
::newFromText( "RC dumper" );
41 $wgCommandLineMode = true;
44 if ( empty($options['b']) ) {
45 $bots = "AND NOT(rc_bot)";
50 if (isset($args[0]) && isset($args[1])) {
54 #$highest = $args[0][1];
58 $res = $dbr->query( "SELECT rc_timestamp FROM $recentchanges ORDER BY rc_timestamp DESC LIMIT 1" );
59 $row = $dbr->fetchObject( $res );
60 $oldTimestamp = $row->rc_timestamp
;
64 $res = $dbr->query( "SELECT * FROM $recentchanges WHERE rc_timestamp>'$oldTimestamp' ORDER BY rc_timestamp" );
66 while ( $row = $dbr->fetchObject( $res ) ) {
67 if ( ++
$serverCount %
20 == 0 ) {
68 print "/server $ircServer\n";
70 $ns = $wgLang->getNsText( $row->rc_namespace
) ;
72 $title = "$ns:{$row->rc_title}";
74 $title = $row->rc_title
;
76 /*if ( strlen( $row->rc_comment ) > 50 ) {
77 $comment = substr( $row->rc_comment, 0, 50 );
79 $comment = $row->rc_comment
;
81 $bad = array("\n", "\r");
82 $empty = array("", "");
83 $comment = str_replace($bad, $empty, $comment);
84 $title = str_replace($bad, $empty, $title);
86 if ($a < 'A' ||
$a > 'Z')
88 #if ((isset($highest)) && (($what == "<" && $a > "$highest") || ($what == ">" && $a <= "$highest")))
89 if ((isset($highest) && ($a > $highest)) ||
(isset($lowest) && $a <= $lowest))
91 $user = str_replace($bad, $empty, $row->rc_user_text
);
92 $lastid = IntVal($row->rc_last_oldid
);
93 $flag = ($row->rc_minor ?
"M" : "") . ($row->rc_new ?
"N" : "");
94 $stupid_urlencode = array("%2F", "%3A");
95 $haha_take_that = array("/", ":");
97 $url = $newPageURLFirstPart . urlencode($title);
99 $url = $URLFirstPart . urlencode($title) .
100 "&diff=0&oldid=$lastid";
102 $url = str_replace($stupid_urlencode, $haha_take_that, $url);
103 $title = str_replace("_", " ", $title);
104 # see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003,
105 # no colour (\003) switches back to the term default
106 $comment = preg_replace("/\/\* (.*) \*\/(.*)/", "\00315\$1\003 - \00310\$2\003", $comment);
107 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
108 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 \00310$comment\003\n";
110 $fullString = "$channel\t$fullString";
113 print( $fullString );
114 $oldTimestamp = $row->rc_timestamp
;