3 error_reporting(E_ALL
);
5 require_once( "commandLine.inc" );
6 require_once( 'includes/SpecialExport.php' );
8 function dumpReplayLog( $start ) {
9 $dbw =& wfGetDB( DB_MASTER
);
10 $recentchanges = $dbw->tableName( 'recentchanges' );
11 $result =& $dbw->safeQuery( "SELECT * FROM $recentchanges WHERE rc_timestamp >= "
12 . $dbw->timestamp( $start ) . ' ORDER BY rc_timestamp');
14 global $wgInputEncoding;
15 echo '<' . '?xml version="1.0" encoding="' . $wgInputEncoding . '" ?' . ">\n";
16 echo "<wikilog version='experimental'>\n";
17 echo "<!-- Do not use this script for any purpose. It's scary. -->\n";
18 while( $row = $dbw->fetchObject( $result ) ) {
19 echo dumpReplayEntry( $row );
22 $dbw->freeResult( $result );
25 function dumpReplayEntry( $row ) {
26 $title = Title
::MakeTitle( $row->rc_namespace
, $row->rc_title
);
27 switch( $row->rc_type
) {
31 $dbr =& wfGetDB( DB_MASTER
);
34 $out .= " <title>" . xmlsafe( $title->getPrefixedText() ) . "</title>\n";
36 # Get previous edit timestamp
37 if( $row->rc_last_oldid
) {
38 $s = $dbr->selectRow( 'old',
39 array( 'old_timestamp' ),
40 array( 'old_id' => $row->rc_last_oldid
) );
41 $out .= " <lastedit>" . wfTimestamp2ISO8601( $s->old_timestamp
) . "</lastedit>\n";
43 $out .= " <newpage/>\n";
46 if( $row->rc_this_oldid
) {
47 $s = $dbr->selectRow( 'old', array( 'old_id as id','old_timestamp as timestamp',
48 'old_user as user', 'old_user_text as user_text', 'old_comment as comment',
49 'old_text as text', 'old_flags as flags' ),
50 array( 'old_id' => $row->rc_this_oldid
) );
51 $out .= revision2xml( $s, true, false );
53 $s = $dbr->selectRow( 'cur', array( 'cur_id as id','cur_timestamp as timestamp','cur_user as user',
54 'cur_user_text as user_text', 'cur_restrictions as restrictions','cur_comment as comment',
56 array( 'cur_id' => $row->rc_cur_id
) );
57 $out .= revision2xml( $s, true, true );
62 $dbr =& wfGetDB( DB_MASTER
);
63 $s = $dbr->selectRow( 'logging',
64 array( 'log_type', 'log_action', 'log_timestamp', 'log_user',
65 'log_namespace', 'log_title', 'log_comment' ),
66 array( 'log_timestamp' => $row->rc_timestamp
,
67 'log_user' => $row->rc_user
) );
68 $ts = wfTimestamp2ISO8601( $row->rc_timestamp
);
69 $target = Title
::MakeTitle( $s->log_namespace
, $s->log_title
);
71 $out .= " <type>" . xmlsafe( $s->log_type
) . "</type>\n";
72 $out .= " <action>" . xmlsafe( $s->log_action
) . "</action>\n";
73 $out .= " <timestamp>" . $ts . "</timestamp>\n";
74 $out .= " <contributor><username>" . xmlsafe( $row->rc_user_text
) . "</username></contributor>\n";
75 $out .= " <target>" . xmlsafe( $target->getPrefixedText() ) . "</target>\n";
76 $out .= " <comment>" . xmlsafe( $s->log_comment
) . "</comment>\n";
80 case RC_MOVE_OVER_REDIRECT
:
81 $target = Title
::MakeTitle( $row->rc_moved_to_ns
, $row->rc_moved_to_title
);
83 $out .= " <title>" . xmlsafe( $title->getPrefixedText() ) . "</title>\n";
84 $out .= " <target>" . xmlsafe( $target->getPrefixedText() ) . "</target>\n";
85 if( $row->rc_type
== RC_MOVE_OVER_REDIRECT
) {
86 $out .= " <override/>\n";
88 $ts = wfTimestamp2ISO8601( $row->rc_timestamp
);
89 $out .= " <id>$row->rc_cur_id</id>\n";
90 $out .= " <timestamp>$ts</timestamp>\n";
91 if($row->rc_user_text
) {
92 $u = "<username>" . xmlsafe( $row->rc_user_text
) . "</username>";
93 $u .= "<id>$row->rc_user</id>";
95 $u = "<ip>" . xmlsafe( $row->rc_user_text
) . "</ip>";
97 $out .= " <contributor>$u</contributor>\n";
104 if( isset( $options['start'] ) ) {
105 $start = wfTimestamp( TS_MW
, $options['start'] );
106 dumpReplayLog( $start );
108 echo "This is an experimental script to encapsulate data from recent edits.\n";
109 echo "Usage: php dumpReplayLog.php --start=20050118032544\n";