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