3 * @addtogroup Maintenance
5 error_reporting(E_ALL
);
8 require_once( "commandLine.inc" );
9 require_once( 'includes/SpecialExport.php' );
12 function dumpReplayLog( $start ) {
13 $dbw = wfGetDB( DB_MASTER
);
14 $recentchanges = $dbw->tableName( 'recentchanges' );
15 $result =& $dbw->safeQuery( "SELECT * FROM $recentchanges WHERE rc_timestamp >= "
16 . $dbw->timestamp( $start ) . ' ORDER BY rc_timestamp');
18 global $wgInputEncoding;
19 echo '<' . '?xml version="1.0" encoding="' . $wgInputEncoding . '" ?' . ">\n";
20 echo "<wikilog version='experimental'>\n";
21 echo "<!-- Do not use this script for any purpose. It's scary. -->\n";
22 while( $row = $dbw->fetchObject( $result ) ) {
23 echo dumpReplayEntry( $row );
26 $dbw->freeResult( $result );
30 function dumpReplayEntry( $row ) {
31 $title = Title
::MakeTitle( $row->rc_namespace
, $row->rc_title
);
32 switch( $row->rc_type
) {
36 $dbr = wfGetDB( DB_MASTER
);
39 $out .= " <title>" . xmlsafe( $title->getPrefixedText() ) . "</title>\n";
41 # Get previous edit timestamp
42 if( $row->rc_last_oldid
) {
43 $s = $dbr->selectRow( 'old',
44 array( 'old_timestamp' ),
45 array( 'old_id' => $row->rc_last_oldid
) );
46 $out .= " <lastedit>" . wfTimestamp2ISO8601( $s->old_timestamp
) . "</lastedit>\n";
48 $out .= " <newpage/>\n";
51 if( $row->rc_this_oldid
) {
52 $s = $dbr->selectRow( 'old', array( 'old_id as id','old_timestamp as timestamp',
53 'old_user as user', 'old_user_text as user_text', 'old_comment as comment',
54 'old_text as text', 'old_flags as flags' ),
55 array( 'old_id' => $row->rc_this_oldid
) );
56 $out .= revision2xml( $s, true, false );
58 $s = $dbr->selectRow( 'cur', array( 'cur_id as id','cur_timestamp as timestamp','cur_user as user',
59 'cur_user_text as user_text', 'cur_restrictions as restrictions','cur_comment as comment',
61 array( 'cur_id' => $row->rc_cur_id
) );
62 $out .= revision2xml( $s, true, true );
67 $dbr = wfGetDB( DB_MASTER
);
68 $s = $dbr->selectRow( 'logging',
69 array( 'log_type', 'log_action', 'log_timestamp', 'log_user',
70 'log_namespace', 'log_title', 'log_comment' ),
71 array( 'log_timestamp' => $row->rc_timestamp
,
72 'log_user' => $row->rc_user
) );
73 $ts = wfTimestamp2ISO8601( $row->rc_timestamp
);
74 $target = Title
::MakeTitle( $s->log_namespace
, $s->log_title
);
76 $out .= " <type>" . xmlsafe( $s->log_type
) . "</type>\n";
77 $out .= " <action>" . xmlsafe( $s->log_action
) . "</action>\n";
78 $out .= " <timestamp>" . $ts . "</timestamp>\n";
79 $out .= " <contributor><username>" . xmlsafe( $row->rc_user_text
) . "</username></contributor>\n";
80 $out .= " <target>" . xmlsafe( $target->getPrefixedText() ) . "</target>\n";
81 $out .= " <comment>" . xmlsafe( $s->log_comment
) . "</comment>\n";
85 case RC_MOVE_OVER_REDIRECT
:
86 $target = Title
::MakeTitle( $row->rc_moved_to_ns
, $row->rc_moved_to_title
);
88 $out .= " <title>" . xmlsafe( $title->getPrefixedText() ) . "</title>\n";
89 $out .= " <target>" . xmlsafe( $target->getPrefixedText() ) . "</target>\n";
90 if( $row->rc_type
== RC_MOVE_OVER_REDIRECT
) {
91 $out .= " <override/>\n";
93 $ts = wfTimestamp2ISO8601( $row->rc_timestamp
);
94 $out .= " <id>$row->rc_cur_id</id>\n";
95 $out .= " <timestamp>$ts</timestamp>\n";
96 if($row->rc_user_text
) {
97 $u = "<username>" . xmlsafe( $row->rc_user_text
) . "</username>";
98 $u .= "<id>$row->rc_user</id>";
100 $u = "<ip>" . xmlsafe( $row->rc_user_text
) . "</ip>";
102 $out .= " <contributor>$u</contributor>\n";
103 $out .= " </move>\n";
109 if( isset( $options['start'] ) ) {
110 $start = wfTimestamp( TS_MW
, $options['start'] );
111 dumpReplayLog( $start );
113 echo "This is an experimental script to encapsulate data from recent edits.\n";
114 echo "Usage: php dumpReplayLog.php --start=20050118032544\n";