colours
[lhc/web/wiklou.git] / irc / rcdumper.php
1 <?php
2
3 /*
4 Example command-line:
5 php rcdumper.php | irc -d -c \#channel-to-join nick-of-bot some.irc.server
6 where irc is the name of the ircII executable.
7 The name of the the IRC should match $ircServer below.
8 */
9
10 $ircServer = "irc.freenode.net";
11
12 # Set the below if this is running on a non-Wikimedia site:
13 #$serverName="your.site.here";
14
15
16 ini_set( "display_errors", 1 );
17 $wgCommandLineMode = true;
18
19 require_once("../maintenance/commandLine.inc" );
20
21 if ($wgWikiFarm) {
22 $serverName="$lang.wikipedia.org";
23 $newPageURLFirstPart="http://$serverName/wiki/";
24 $URLFirstPart="http://$serverName/w/wiki.phtml?title=";
25 } else {
26 $newPageURLFirstPart="http://$serverName$wgScript/";
27 $URLFirstPart="http://$serverName$wgScript?title=";
28 }
29
30 $wgTitle = Title::newFromText( "RC dumper" );
31 $wgCommandLineMode = true;
32 set_time_limit(0);
33
34 sleep(30);
35
36 $res = wfQuery( "SELECT rc_timestamp FROM recentchanges ORDER BY rc_timestamp DESC LIMIT 1", DB_READ );
37 $row = wfFetchObject( $res );
38 $oldTimestamp = $row->rc_timestamp;
39 $serverCount = 0;
40
41 while (1) {
42 $res = wfQuery( "SELECT * FROM recentchanges WHERE rc_timestamp>'$oldTimestamp' ORDER BY rc_timestamp", DB_READ );
43 $rowIndex = 0;
44 while ( $row = wfFetchObject( $res ) ) {
45 if ( ++$serverCount % 20 == 0 ) {
46 print "/server $ircServer\n";
47 }
48 $ns = $wgLang->getNsText( $row->rc_namespace ) ;
49 if ( $ns ) {
50 $title = "$ns:{$row->rc_title}";
51 } else {
52 $title = $row->rc_title;
53 }
54 /*if ( strlen( $row->rc_comment ) > 50 ) {
55 $comment = substr( $row->rc_comment, 0, 50 );
56 } else {*/
57 $comment = $row->rc_comment;
58 // }
59 $bad = array("\n", "\r");
60 $empty = array("", "");
61 $comment = str_replace($bad, $empty, $comment);
62 $title = str_replace($bad, $empty, $title);
63 $user = str_replace($bad, $empty, $row->rc_user_text);
64 $lastid = IntVal($row->rc_last_oldid);
65 $flag = ($row->rc_minor ? "M" : "") . ($row->rc_new ? "N" : "");
66 if ( $row->rc_new ) {
67 $url = $newPageURLFirstPart . urlencode($title);
68 } else {
69 $url = $URLFirstPart . urlencode($title) .
70 "&diff=0&oldid=$lastid";
71 }
72 $title = str_replace("_", " ", $title);
73 # see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003,
74 # no colour (\003) switches back to the term default
75 $fullString = "\0033$title \0037$flag \00310$url \0037*\003 $user \0037*\003 $comment\n";
76
77 if ( $fullString{0} == "/" ) {
78 $fullString = " $fullString";
79 }
80 print( $fullString );
81 $oldTimestamp = $row->rc_timestamp;
82 sleep(2);
83 }
84 sleep(5);
85 }
86
87 exit();
88
89 ?>