* Skip additional setting of include_path in commandLine.inc (for non-Wikimedia mode)
[lhc/web/wiklou.git] / maintenance / dumpReplayLog.php
1 <?php
2 /**
3 * @addtogroup Maintenance
4 */
5 error_reporting(E_ALL);
6
7 /** */
8 require_once( "commandLine.inc" );
9
10 /** */
11 function dumpReplayLog( $start ) {
12 $dbw = wfGetDB( DB_MASTER );
13 $recentchanges = $dbw->tableName( 'recentchanges' );
14 $result =& $dbw->safeQuery( "SELECT * FROM $recentchanges WHERE rc_timestamp >= "
15 . $dbw->timestamp( $start ) . ' ORDER BY rc_timestamp');
16
17 global $wgInputEncoding;
18 echo '<' . '?xml version="1.0" encoding="' . $wgInputEncoding . '" ?' . ">\n";
19 echo "<wikilog version='experimental'>\n";
20 echo "<!-- Do not use this script for any purpose. It's scary. -->\n";
21 while( $row = $dbw->fetchObject( $result ) ) {
22 echo dumpReplayEntry( $row );
23 }
24 echo "</wikilog>\n";
25 $dbw->freeResult( $result );
26 }
27
28 /** */
29 function dumpReplayEntry( $row ) {
30 $title = Title::MakeTitle( $row->rc_namespace, $row->rc_title );
31 switch( $row->rc_type ) {
32 case RC_EDIT:
33 case RC_NEW:
34 # Edit
35 $dbr = wfGetDB( DB_MASTER );
36
37 $out = " <edit>\n";
38 $out .= " <title>" . xmlsafe( $title->getPrefixedText() ) . "</title>\n";
39
40 # Get previous edit timestamp
41 if( $row->rc_last_oldid ) {
42 $s = $dbr->selectRow( 'old',
43 array( 'old_timestamp' ),
44 array( 'old_id' => $row->rc_last_oldid ) );
45 $out .= " <lastedit>" . wfTimestamp2ISO8601( $s->old_timestamp ) . "</lastedit>\n";
46 } else {
47 $out .= " <newpage/>\n";
48 }
49
50 if( $row->rc_this_oldid ) {
51 $s = $dbr->selectRow( 'old', array( 'old_id as id','old_timestamp as timestamp',
52 'old_user as user', 'old_user_text as user_text', 'old_comment as comment',
53 'old_text as text', 'old_flags as flags' ),
54 array( 'old_id' => $row->rc_this_oldid ) );
55 $out .= revision2xml( $s, true, false );
56 } else {
57 $s = $dbr->selectRow( 'cur', array( 'cur_id as id','cur_timestamp as timestamp','cur_user as user',
58 'cur_user_text as user_text', 'cur_restrictions as restrictions','cur_comment as comment',
59 'cur_text as text' ),
60 array( 'cur_id' => $row->rc_cur_id ) );
61 $out .= revision2xml( $s, true, true );
62 }
63 $out .= " </edit>\n";
64 break;
65 case RC_LOG:
66 $dbr = wfGetDB( DB_MASTER );
67 $s = $dbr->selectRow( 'logging',
68 array( 'log_type', 'log_action', 'log_timestamp', 'log_user',
69 'log_namespace', 'log_title', 'log_comment' ),
70 array( 'log_timestamp' => $row->rc_timestamp,
71 'log_user' => $row->rc_user ) );
72 $ts = wfTimestamp2ISO8601( $row->rc_timestamp );
73 $target = Title::MakeTitle( $s->log_namespace, $s->log_title );
74 $out = " <log>\n";
75 $out .= " <type>" . xmlsafe( $s->log_type ) . "</type>\n";
76 $out .= " <action>" . xmlsafe( $s->log_action ) . "</action>\n";
77 $out .= " <timestamp>" . $ts . "</timestamp>\n";
78 $out .= " <contributor><username>" . xmlsafe( $row->rc_user_text ) . "</username></contributor>\n";
79 $out .= " <target>" . xmlsafe( $target->getPrefixedText() ) . "</target>\n";
80 $out .= " <comment>" . xmlsafe( $s->log_comment ) . "</comment>\n";
81 $out .= " </log>\n";
82 break;
83 case RC_MOVE:
84 case RC_MOVE_OVER_REDIRECT:
85 $target = Title::MakeTitle( $row->rc_moved_to_ns, $row->rc_moved_to_title );
86 $out = " <move>\n";
87 $out .= " <title>" . xmlsafe( $title->getPrefixedText() ) . "</title>\n";
88 $out .= " <target>" . xmlsafe( $target->getPrefixedText() ) . "</target>\n";
89 if( $row->rc_type == RC_MOVE_OVER_REDIRECT ) {
90 $out .= " <override/>\n";
91 }
92 $ts = wfTimestamp2ISO8601( $row->rc_timestamp );
93 $out .= " <id>$row->rc_cur_id</id>\n";
94 $out .= " <timestamp>$ts</timestamp>\n";
95 if($row->rc_user_text) {
96 $u = "<username>" . xmlsafe( $row->rc_user_text ) . "</username>";
97 $u .= "<id>$row->rc_user</id>";
98 } else {
99 $u = "<ip>" . xmlsafe( $row->rc_user_text ) . "</ip>";
100 }
101 $out .= " <contributor>$u</contributor>\n";
102 $out .= " </move>\n";
103 }
104 return $out;
105 }
106
107
108 if( isset( $options['start'] ) ) {
109 $start = wfTimestamp( TS_MW, $options['start'] );
110 dumpReplayLog( $start );
111 } else {
112 echo "This is an experimental script to encapsulate data from recent edits.\n";
113 echo "Usage: php dumpReplayLog.php --start=20050118032544\n";
114 }
115
116 ?>