0ba026cd799a385f797bcd1c0eea5eece9266669
[lhc/web/wiklou.git] / irc / rcdumper.php
1 <?php
2
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 putenv( "wikilang=$lang");
11 $settingsFile = "/apache/htdocs/{$argv[1]}/w/LocalSettings.php";
12 $newpath = "/apache/common/php$sep";
13 } else {
14 $settingsFile = "../LocalSettings.php";
15 $newpath = "";
16 }
17
18 if ( $argv[2] ) {
19 $patterns = explode( ",", $argv[2]);
20 } else {
21 $patterns = false;
22 }
23
24 if ( ! is_readable( $settingsFile ) ) {
25 print "A copy of your installation's LocalSettings.php\n" .
26 "must exist in the source directory.\n";
27 exit();
28 }
29
30 ini_set( "include_path", "$newpath$IP$sep$include_path" );
31
32 $wgCommandLineMode = true;
33 $DP = "../includes";
34 include_once( $settingsFile );
35 include_once( "Setup.php" );
36 $wgTitle = Title::newFromText( "RC dumper" );
37 $wgCommandLineMode = true;
38 set_time_limit(0);
39
40 sleep(30);
41
42 $res = wfQuery( "SELECT rc_timestamp FROM recentchanges ORDER BY rc_timestamp DESC LIMIT 1", DB_READ );
43 $row = wfFetchObject( $res );
44 $oldTimestamp = $row->rc_timestamp;
45
46 while (1) {
47 $res = wfQuery( "SELECT * FROM recentchanges WHERE rc_timestamp>'$oldTimestamp' ORDER BY rc_timestamp", DB_READ );
48 $rowIndex = 0;
49 while ( $row = wfFetchObject( $res ) ) {
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 = "http://$lang.wikipedia.org/wiki/" . urlencode($title);
70 } else {
71 $url = "http://$lang.wikipedia.org/w/wiki.phtml?title=" . urlencode($title) .
72 "&diff=0&oldid=$lastid";
73 }
74 $boldTitle = $fmB . str_replace("_", " ", $title) . $fmB;
75
76 if ( $patterns ) {
77 foreach ( $patterns as $pattern ) {
78 if ( preg_match( $pattern, $comment ) ) {
79 print chr(7);
80 break;
81 }
82 }
83 }
84 if ( $comment !== "" ) {
85 $comment = "($comment)";
86 }
87
88 $fullString = "$boldTitle $flag $url $user $comment\n";
89
90 if ( $fullString{0} == "/" ) {
91 $fullString = " $fullString";
92 }
93 print( $fullString );
94 $oldTimestamp = $row->rc_timestamp;
95 sleep(2);
96 }
97 sleep(5);
98 }
99
100 exit();
101
102 ?>