3 * @addtogroup Maintenance
5 error_reporting(E_ALL
);
8 require_once( "commandLine.inc" );
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');
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 );
25 $dbw->freeResult( $result );
29 function dumpReplayEntry( $row ) {
30 $title = Title
::MakeTitle( $row->rc_namespace
, $row->rc_title
);
31 switch( $row->rc_type
) {
35 $dbr = wfGetDB( DB_MASTER
);
38 $out .= " <title>" . xmlsafe( $title->getPrefixedText() ) . "</title>\n";
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";
47 $out .= " <newpage/>\n";
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 );
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',
60 array( 'cur_id' => $row->rc_cur_id
) );
61 $out .= revision2xml( $s, true, true );
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
);
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";
84 case RC_MOVE_OVER_REDIRECT
:
85 $target = Title
::MakeTitle( $row->rc_moved_to_ns
, $row->rc_moved_to_title
);
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";
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>";
99 $u = "<ip>" . xmlsafe( $row->rc_user_text
) . "</ip>";
101 $out .= " <contributor>$u</contributor>\n";
102 $out .= " </move>\n";
108 if( isset( $options['start'] ) ) {
109 $start = wfTimestamp( TS_MW
, $options['start'] );
110 dumpReplayLog( $start );
112 echo "This is an experimental script to encapsulate data from recent edits.\n";
113 echo "Usage: php dumpReplayLog.php --start=20050118032544\n";