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