fixed syntax error, added /SERVER output
[lhc/web/wiklou.git] / irc / rcdumper.php
1 <?php
2 ini_set( "display_errors", 1 );
3 $wgCommandLineMode = true;
4 $fmB = chr(2);
5 $fmU = chr(31);
6 /*
7 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
8 if ( $argv[1] ) {
9 $lang = $argv[1];
10 $site = "wikipedia";
11 putenv( "wikilang=$lang");
12 $settingsFile = "/apache/htdocs/{$argv[1]}/w/LocalSettings.php";
13 $newpath = "/apache/common/php$sep";
14 } else {
15 $settingsFile = "../LocalSettings.php";
16 $newpath = "";
17 }
18
19 if ( $argv[2] ) {
20 $patterns = explode( ",", $argv[2]);
21 } else {
22 $patterns = false;
23 }
24
25 if ( ! is_readable( $settingsFile ) ) {
26 print "A copy of your installation's LocalSettings.php\n" .
27 "must exist in the source directory.\n";
28 exit();
29 }
30
31 ini_set( "include_path", "$newpath$IP$sep$include_path" );
32
33 $wgCommandLineMode = true;
34 $DP = "../includes";
35 include_once( $settingsFile );
36 include_once( "Setup.php" );*/
37
38 require_once("../maintenance/liveCmdLine.inc" );
39
40 $wgTitle = Title::newFromText( "RC dumper" );
41 $wgCommandLineMode = true;
42 set_time_limit(0);
43
44 sleep(30);
45
46 $res = wfQuery( "SELECT rc_timestamp FROM recentchanges ORDER BY rc_timestamp DESC LIMIT 1", DB_READ );
47 $row = wfFetchObject( $res );
48 $oldTimestamp = $row->rc_timestamp;
49 $serverCount = 0;
50
51 while (1) {
52 $res = wfQuery( "SELECT * FROM recentchanges WHERE rc_timestamp>'$oldTimestamp' ORDER BY rc_timestamp", DB_READ );
53 $rowIndex = 0;
54 while ( $row = wfFetchObject( $res ) ) {
55 if ( ++$serverCount % 20 == 0 ) {
56 print "/server irc.freenode.net\n";
57 }
58 $ns = $wgLang->getNsText( $row->rc_namespace ) ;
59 if ( $ns ) {
60 $title = "$ns:{$row->rc_title}";
61 } else {
62 $title = $row->rc_title;
63 }
64 /*if ( strlen( $row->rc_comment ) > 50 ) {
65 $comment = substr( $row->rc_comment, 0, 50 );
66 } else {*/
67 $comment = $row->rc_comment;
68 // }
69 $bad = array("\n", "\r");
70 $empty = array("", "");
71 $comment = str_replace($bad, $empty, $comment);
72 $title = str_replace($bad, $empty, $title);
73 $user = str_replace($bad, $empty, $row->rc_user_text);
74 $lastid = IntVal($row->rc_last_oldid);
75 $flag = ($row->rc_minor ? "M" : "") . ($row->rc_new ? "N" : "");
76 if ( $row->rc_new ) {
77 $url = "http://$lang.wikipedia.org/wiki/" . urlencode($title);
78 } else {
79 $url = "http://$lang.wikipedia.org/w/wiki.phtml?title=" . urlencode($title) .
80 "&diff=0&oldid=$lastid";
81 }
82 $boldTitle = $fmB . str_replace("_", " ", $title) . $fmB;
83
84 if ( $patterns ) {
85 foreach ( $patterns as $pattern ) {
86 if ( preg_match( $pattern, $comment ) ) {
87 print chr(7);
88 break;
89 }
90 }
91 }
92 if ( $comment !== "" ) {
93 $comment = "($comment)";
94 }
95
96 $fullString = "$boldTitle $flag $url $user $comment\n";
97
98 if ( $fullString{0} == "/" ) {
99 $fullString = " $fullString";
100 }
101 print( $fullString );
102 $oldTimestamp = $row->rc_timestamp;
103 sleep(2);
104 }
105 sleep(5);
106 }
107
108 exit();
109
110 ?>