* Adding a trailing ?>
[lhc/web/wiklou.git] / maintenance / dumpReplayLog.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 */
6 error_reporting(E_ALL);
7
8 /** */
9 require_once( "commandLine.inc" );
10 require_once( 'includes/SpecialExport.php' );
11
12 /** */
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');
18
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 );
25 }
26 echo "</wikilog>\n";
27 $dbw->freeResult( $result );
28 }
29
30 /** */
31 function dumpReplayEntry( $row ) {
32 $title = Title::MakeTitle( $row->rc_namespace, $row->rc_title );
33 switch( $row->rc_type ) {
34 case RC_EDIT:
35 case RC_NEW:
36 # Edit
37 $dbr =& wfGetDB( DB_MASTER );
38
39 $out = " <edit>\n";
40 $out .= " <title>" . xmlsafe( $title->getPrefixedText() ) . "</title>\n";
41
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";
48 } else {
49 $out .= " <newpage/>\n";
50 }
51
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 );
58 } else {
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',
61 'cur_text as text' ),
62 array( 'cur_id' => $row->rc_cur_id ) );
63 $out .= revision2xml( $s, true, true );
64 }
65 $out .= " </edit>\n";
66 break;
67 case RC_LOG:
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 );
76 $out = " <log>\n";
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";
83 $out .= " </log>\n";
84 break;
85 case RC_MOVE:
86 case RC_MOVE_OVER_REDIRECT:
87 $target = Title::MakeTitle( $row->rc_moved_to_ns, $row->rc_moved_to_title );
88 $out = " <move>\n";
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";
93 }
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>";
100 } else {
101 $u = "<ip>" . xmlsafe( $row->rc_user_text ) . "</ip>";
102 }
103 $out .= " <contributor>$u</contributor>\n";
104 $out .= " </move>\n";
105 }
106 return $out;
107 }
108
109
110 if( isset( $options['start'] ) ) {
111 $start = wfTimestamp( TS_MW, $options['start'] );
112 dumpReplayLog( $start );
113 } else {
114 echo "This is an experimental script to encapsulate data from recent edits.\n";
115 echo "Usage: php dumpReplayLog.php --start=20050118032544\n";
116 }
117
118 ?>