Add an extension for logging MediaWiki events to the system logger
[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 IRC server 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 $optionsWithArgs = array( 'm' );
19 require_once("../maintenance/commandLine.inc" );
20
21 if ( !empty( $options['m'] ) ) {
22 $channel = $options['m'];
23 } else {
24 $channel = false;
25 }
26
27 if ($lang == "commons") $site = "wikimedia";
28
29 if ($wgWikiFarm) {
30 $serverName="$lang.$site.org";
31 $newPageURLFirstPart="http://$serverName/wiki/";
32 $URLFirstPart="http://$serverName/w/wiki.phtml?title=";
33 } else {
34 $newPageURLFirstPart="http://$serverName$wgScript/";
35 $URLFirstPart="http://$serverName$wgScript?title=";
36 }
37
38 $wgTitle = Title::newFromText( "RC dumper" );
39 $wgCommandLineMode = true;
40 set_time_limit(0);
41
42 if ( empty($options['b']) ) {
43 $bots = "AND NOT(rc_bot)";
44 } else {
45 $bots = "";
46 }
47
48 if (isset($args[0]) && isset($args[1])) {
49 $lowest = $args[0];
50 $highest = $args[1];
51 #$what = $args[0][0];
52 #$highest = $args[0][1];
53 }
54 #sleep(30);
55
56 $res = $dbr->query( "SELECT rc_timestamp FROM $recentchanges ORDER BY rc_timestamp DESC LIMIT 1" );
57 $row = $dbr->fetchObject( $res );
58 $oldTimestamp = $row->rc_timestamp;
59 $serverCount = 0;
60
61 while (1) {
62 $res = $dbr->query( "SELECT * FROM $recentchanges WHERE rc_timestamp>'$oldTimestamp' ORDER BY rc_timestamp" );
63 $rowIndex = 0;
64 while ( $row = $dbr->fetchObject( $res ) ) {
65 if ( ++$serverCount % 20 == 0 ) {
66 print "/server $ircServer\n";
67 }
68 $ns = $wgLang->getNsText( $row->rc_namespace ) ;
69 if ( $ns ) {
70 $title = "$ns:{$row->rc_title}";
71 } else {
72 $title = $row->rc_title;
73 }
74 /*if ( strlen( $row->rc_comment ) > 50 ) {
75 $comment = substr( $row->rc_comment, 0, 50 );
76 } else {*/
77 $comment = $row->rc_comment;
78 // }
79 $bad = array("\n", "\r");
80 $empty = array("", "");
81 $comment = str_replace($bad, $empty, $comment);
82 $title = str_replace($bad, $empty, $title);
83 $a = $title[0];
84 if ($a < 'A' || $a > 'Z')
85 $a = 'Z';
86 #if ((isset($highest)) && (($what == "<" && $a > "$highest") || ($what == ">" && $a <= "$highest")))
87 if ((isset($highest) && ($a > $highest)) || (isset($lowest) && $a <= $lowest))
88 continue;
89 $user = str_replace($bad, $empty, $row->rc_user_text);
90 $lastid = IntVal($row->rc_last_oldid);
91 $flag = ($row->rc_minor ? "M" : "") . ($row->rc_new ? "N" : "");
92 $stupid_urlencode = array("%2F", "%3A");
93 $haha_take_that = array("/", ":");
94 if ( $row->rc_new ) {
95 $url = $newPageURLFirstPart . urlencode($title);
96 } else {
97 $url = $URLFirstPart . urlencode($title) .
98 "&diff=0&oldid=$lastid";
99 }
100 $url = str_replace($stupid_urlencode, $haha_take_that, $url);
101 $title = str_replace("_", " ", $title);
102 # see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003,
103 # no colour (\003) switches back to the term default
104 $comment = preg_replace("/\/\* (.*) \*\/(.*)/", "\00315\$1\003 - \00310\$2\003", $comment);
105 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
106 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 \00310$comment\003\n";
107 if ( $channel ) {
108 $fullString = "$channel\t$fullString";
109 }
110
111 print( $fullString );
112 $oldTimestamp = $row->rc_timestamp;
113 sleep(2);
114 }
115 sleep(5);
116 }
117
118 exit();
119
120 ?>