2 # Script for re-attributing edits
3 require_once( "commandLine.inc" );
6 if ( count( $args ) < 2 ) {
7 print "Not enough parameters\n";
9 print "Usage: php attribute.php <language> <site> <source> <destination>\n";
11 print "Usage: php attribute.php <source> <destination>\n";
19 $eSource = wfStrencode( $source );
20 $eDest = wfStrencode( $dest );
23 $res = wfQuery( "SELECT user_id FROM user WHERE user_name='$eDest'", DB_READ
);
24 $row = wfFetchObject( $res );
26 print "Warning: the target name \"$dest\" does not exist";
33 $logfile = fopen( "attribute.log", "a" );
34 $sqlfile = fopen( "attribute.sql", "a" );
36 fwrite( $logfile, "* $source → $dest\n" );
39 "-- Changing attribution SQL file
40 -- Generated with attribute.php
41 -- $source -> $dest ($uid)
44 $omitTitle = "Wikipedia:Changing_attribution_for_an_edit";
47 print "\nOld entries\n\n";
49 $res = wfQuery( "SELECT old_namespace, old_title, old_id, old_timestamp FROM old WHERE old_user_text='$eSource'", DB_READ
);
50 $row = wfFetchObject( $res );
54 if ( $row->old_title=='Votes_for_deletion' && $row->old_namespace == 4 ) {
55 # We don't have that long
59 fwrite( $logfile, "**Old IDs: " );
60 fwrite( $sqlfile, "UPDATE old SET old_user=$uid, old_user_text='$eDest' WHERE old_id IN (\n" );
62 for ( $first=true; $row; $row = wfFetchObject( $res ) ) {
63 $ns = $wgLang->getNsText( $row->old_namespace
);
65 $fullTitle = "$ns:{$row->old_title}";
67 $fullTitle = $row->old_title
;
69 if ( $fullTitle == $omitTitle ) {
74 $url = "http://$lang.wikipedia.org/w/wiki.phtml?title=" . urlencode( $fullTitle );
75 $eTitle = wfStrencode( $row->old_title
);
78 $lastres = wfQuery( "SELECT old_id FROM old WHERE
79 old_title='$eTitle' AND old_namespace={$row->old_namespace} AND
80 old_timestamp<'{$row->old_timestamp}' ORDER BY inverse_timestamp LIMIT 1", DB_READ );
81 $lastrow = wfFetchObject( $lastres );
83 $last = $lastrow->old_id;
84 $url .= "&diff={$row->old_id}&oldid=$last";
86 $url .= "&oldid={$row->old_id}";
90 fwrite( $sqlfile, " " );
94 fwrite( $sqlfile, ", " );
95 fwrite( $logfile, ", " );
98 fwrite( $sqlfile, "{$row->old_id} -- $url\n" );
99 fwrite( $logfile, "[$url {$row->old_id}]" );
102 fwrite( $sqlfile, ");\n" );
103 fwrite( $logfile, "\n" );
107 print "\n\nCur entries\n\n";
109 $res = wfQuery( "SELECT cur_title, cur_namespace, cur_timestamp, cur_id FROM cur WHERE cur_user_text='$eSource'",
111 $row = wfFetchObject( $res );
113 fwrite( $sqlfile, "\n\nUPDATE cur SET cur_user=$uid, cur_user_text='$eDest' WHERE cur_id IN(\n" );
114 fwrite( $logfile, "**Cur entries:\n" );
115 for ( $first=true; $row; $row = wfFetchObject( $res ) ) {
116 $ns = $wgLang->getNsText( $row->cur_namespace
);
118 $fullTitle = "$ns:{$row->cur_title}";
120 $fullTitle = $row->cur_title
;
122 if ( $fullTitle == $omitTitle ) {
125 $url = "http://$lang.wikipedia.org/wiki/" . urlencode($fullTitle);
127 fwrite( $sqlfile, " " );
130 fwrite( $sqlfile, " , " );
132 fwrite( $sqlfile, "{$row->cur_id} -- $url\n" );
133 fwrite( $logfile, "***[[$fullTitle]] {$row->cur_timestamp}\n" );
134 print "$fullTitle\n";
136 fwrite( $sqlfile, ");\n" );