Convert many comments to phpdoc style, and document some more functions
[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
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 $dbr =& wfGetDB( DB_SLAVE );
36 $recentchanges = $dbr->tableName( 'recentchanges' );
37
38 $res = $dbr->query( "SELECT rc_timestamp FROM $recentchanges ORDER BY rc_timestamp DESC LIMIT 1" );
39 $row = $dbr->fetchObject( $res );
40 $oldTimestamp = $row->rc_timestamp;
41 $serverCount = 0;
42
43 while (1) {
44 $res = $dbr->query( "SELECT * FROM $recentchanges WHERE rc_timestamp>'$oldTimestamp' ORDER BY rc_timestamp" );
45 $rowIndex = 0;
46 while ( $row = $dbr->fetchObject( $res ) ) {
47 if ( ++$serverCount % 20 == 0 ) {
48 print "/server $ircServer\n";
49 }
50 $ns = $wgLang->getNsText( $row->rc_namespace ) ;
51 if ( $ns ) {
52 $title = "$ns:{$row->rc_title}";
53 } else {
54 $title = $row->rc_title;
55 }
56 /*if ( strlen( $row->rc_comment ) > 50 ) {
57 $comment = substr( $row->rc_comment, 0, 50 );
58 } else {*/
59 $comment = $row->rc_comment;
60 // }
61 $bad = array("\n", "\r");
62 $empty = array("", "");
63 $comment = str_replace($bad, $empty, $comment);
64 $title = str_replace($bad, $empty, $title);
65 $user = str_replace($bad, $empty, $row->rc_user_text);
66 $lastid = IntVal($row->rc_last_oldid);
67 $flag = ($row->rc_minor ? "M" : "") . ($row->rc_new ? "N" : "");
68 if ( $row->rc_new ) {
69 $url = $newPageURLFirstPart . urlencode($title);
70 } else {
71 $url = $URLFirstPart . urlencode($title) .
72 "&diff=0&oldid=$lastid";
73 }
74 $title = str_replace("_", " ", $title);
75 # see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003,
76 # no colour (\003) switches back to the term default
77 $fullString = "\00303$title\0037 $flag\00310 $url \0037*\003 $user \0037*\003 $comment\n";
78
79 print( $fullString );
80 $oldTimestamp = $row->rc_timestamp;
81 sleep(2);
82 }
83 sleep(5);
84 }
85
86 exit();
87
88 ?>