From: Brion Vibber Date: Tue, 18 Jan 2005 06:20:21 +0000 (+0000) Subject: Somewhat experimental tool for pulling edit data from recentchanges & attached tables. X-Git-Tag: 1.5.0alpha1~899 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=e5e7d6e0267abb467763d8efcdda3a27d180b84c;p=lhc%2Fweb%2Fwiklou.git Somewhat experimental tool for pulling edit data from recentchanges & attached tables. Output is a scary relative of the Special:Export XML. Current code works with 1.4, not 1.5. --- diff --git a/maintenance/dumpReplayLog.php b/maintenance/dumpReplayLog.php new file mode 100644 index 0000000000..b4481674cf --- /dev/null +++ b/maintenance/dumpReplayLog.php @@ -0,0 +1,112 @@ +tableName( 'recentchanges' ); + $result =& $dbw->safeQuery( "SELECT * FROM $recentchanges WHERE rc_timestamp >= " + . $dbw->timestamp( $start ) . ' ORDER BY rc_timestamp'); + + global $wgInputEncoding; + echo '<' . '?xml version="1.0" encoding="' . $wgInputEncoding . '" ?' . ">\n"; + echo "\n"; + echo "\n"; + while( $row = $dbw->fetchObject( $result ) ) { + echo dumpReplayEntry( $row ); + } + echo "\n"; + $dbw->freeResult( $result ); +} + +function dumpReplayEntry( $row ) { + $title = Title::MakeTitle( $row->rc_namespace, $row->rc_title ); + switch( $row->rc_type ) { + case RC_EDIT: + case RC_NEW: + # Edit + $dbr =& wfGetDB( DB_MASTER ); + + $out = " \n"; + $out .= " " . xmlsafe( $title->getPrefixedText() ) . "\n"; + + # Get previous edit timestamp + if( $row->rc_last_oldid ) { + $s = $dbr->selectRow( 'old', + array( 'old_timestamp' ), + array( 'old_id' => $row->rc_last_oldid ) ); + $out .= " " . wfTimestamp2ISO8601( $s->old_timestamp ) . "\n"; + } else { + $out .= " \n"; + } + + if( $row->rc_this_oldid ) { + $s = $dbr->selectRow( 'old', array( 'old_id as id','old_timestamp as timestamp', + 'old_user as user', 'old_user_text as user_text', 'old_comment as comment', + 'old_text as text', 'old_flags as flags' ), + array( 'old_id' => $row->rc_this_oldid ) ); + $out .= revision2xml( $s, true, false ); + } else { + $s = $dbr->selectRow( 'cur', array( 'cur_id as id','cur_timestamp as timestamp','cur_user as user', + 'cur_user_text as user_text', 'cur_restrictions as restrictions','cur_comment as comment', + 'cur_text as text' ), + array( 'cur_id' => $row->rc_cur_id ) ); + $out .= revision2xml( $s, true, true ); + } + $out .= " \n"; + break; + case RC_LOG: + $dbr =& wfGetDB( DB_MASTER ); + $s = $dbr->selectRow( 'logging', + array( 'log_type', 'log_action', 'log_timestamp', 'log_user', + 'log_namespace', 'log_title', 'log_comment' ), + array( 'log_timestamp' => $row->rc_timestamp, + 'log_user' => $row->rc_user ) ); + $ts = wfTimestamp2ISO8601( $row->rc_timestamp ); + $target = Title::MakeTitle( $s->log_namespace, $s->log_title ); + $out = " \n"; + $out .= " " . xmlsafe( $s->log_type ) . "\n"; + $out .= " " . xmlsafe( $s->log_action ) . "\n"; + $out .= " " . $ts . "\n"; + $out .= " " . xmlsafe( $row->rc_user_text ) . "\n"; + $out .= " " . xmlsafe( $target->getPrefixedText() ) . "\n"; + $out .= " " . xmlsafe( $s->log_comment ) . "\n"; + $out .= " \n"; + break; + case RC_MOVE: + case RC_MOVE_OVER_REDIRECT: + $target = Title::MakeTitle( $row->rc_moved_to_ns, $row->rc_moved_to_title ); + $out = " \n"; + $out .= " " . xmlsafe( $title->getPrefixedText() ) . "\n"; + $out .= " " . xmlsafe( $target->getPrefixedText() ) . "\n"; + if( $row->rc_type == RC_MOVE_OVER_REDIRECT ) { + $out .= " \n"; + } + $ts = wfTimestamp2ISO8601( $row->rc_timestamp ); + $out .= " $row->rc_cur_id\n"; + $out .= " $ts\n"; + if($row->rc_user_text) { + $u = "" . xmlsafe( $row->rc_user_text ) . ""; + $u .= "$row->rc_user"; + } else { + $u = "" . xmlsafe( $row->rc_user_text ) . ""; + } + $out .= " $u\n"; + $out .= " \n"; + } + return $out; +} + + +if( isset( $options['start'] ) ) { + $start = wfTimestamp( TS_MW, $options['start'] ); + dumpReplayLog( $start ); +} else { + echo "This is an experimental script to encapsulate data from recent edits.\n"; + echo "Usage: php dumpReplayLog.php --start=20050118032544\n"; +} + +?> \ No newline at end of file