Somewhat improved
[lhc/web/wiklou.git] / maintenance / rcdumper.php
1 <?
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 $res = wfQuery( "SELECT rc_timestamp FROM recentchanges ORDER BY rc_timestamp DESC LIMIT 1", DB_READ );
41 $row = wfFetchObject( $res );
42 $oldTimestamp = $row->rc_timestamp;
43
44 while (1) {
45 $res = wfQuery( "SELECT * FROM recentchanges WHERE rc_timestamp>'$oldTimestamp' ORDER BY rc_timestamp", DB_READ );
46 $rowIndex = 0;
47 while ( $row = wfFetchObject( $res ) ) {
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 = "http://$lang.wikipedia.org/wiki/" . urlencode($title);
68 } else {
69 $url = "http://$lang.wikipedia.org/w/wiki.phtml?title=" . urlencode($title) .
70 "&diff=0&oldid=$lastid";
71 }
72 $boldTitle = $fmB . str_replace("_", " ", $title) . $fmB;
73
74 if ( $patterns ) {
75 foreach ( $patterns as $pattern ) {
76 if ( preg_match( $pattern, $comment ) ) {
77 print chr(7);
78 break;
79 }
80 }
81 }
82 if ( $comment !== "" ) {
83 $comment = "($comment)";
84 }
85
86 $fullString = "$boldTitle $flag $url $user $comment\n";
87
88 if ( $fullString{0} == "/" ) {
89 $fullString = " $fullString";
90 }
91 print( $fullString );
92 $oldTimestamp = $row->rc_timestamp;
93 sleep(1);
94 }
95 sleep(5);
96 }
97
98 exit();
99
100 ?>