6 print "Not enough parameters\n";
7 print "Usage: php attribute.php <lang> <source> <destination>\n";
17 $wgCommandLineMode = true;
20 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ?
";" : ":";
21 ini_set( "include_path", "$IP$sep$include_path" );
23 include_once( "/apache/htdocs/$lang/w/LocalSettings.php" );
24 include_once( "Setup.php" );
26 $wgTitle = Title
::newFromText( "Changing attribution script" );
28 $wgCommandLineMode = true;
30 $eSource = wfStrencode( $source );
31 $eDest = wfStrencode( $dest );
34 $res = wfQuery( "SELECT user_id FROM user WHERE user_name='$eDest'", DB_READ
);
35 $row = wfFetchObject( $res );
37 print "Warning: the target name \"$dest\" does not exist";
44 $logfile = fopen( "attribute.log", "a" );
45 $sqlfile = fopen( "attribute.sql", "a" );
47 fwrite( $logfile, "* $source → $dest\n" );
50 "-- Changing attribution SQL file
51 -- Generated with attribute.php
52 -- $source -> $dest ($uid)
55 $omitTitle = "Wikipedia:Changing_attribution_for_an_edit";
58 print "\nOld entries\n\n";
60 $res = wfQuery( "SELECT old_namespace, old_title, old_id, old_timestamp FROM old WHERE old_user_text='$eSource'", DB_READ
);
61 $row = wfFetchObject( $res );
65 if ( $row->old_title=='Votes_for_deletion' && $row->old_namespace == 4 ) {
66 # We don't have that long
70 fwrite( $logfile, "**Old IDs: " );
71 fwrite( $sqlfile, "UPDATE old SET old_user=$uid, old_user_text='$eDest' WHERE old_id IN (\n" );
73 for ( $first=true; $row; $row = wfFetchObject( $res ) ) {
74 $ns = $wgLang->getNsText( $row->old_namespace
);
76 $fullTitle = "$ns:{$row->old_title}";
78 $fullTitle = $row->old_title
;
80 if ( $fullTitle == $omitTitle ) {
85 $url = "http://$lang.wikipedia.org/w/wiki.phtml?title=" . urlencode( $fullTitle );
86 $eTitle = wfStrencode( $row->old_title
);
89 $lastres = wfQuery( "SELECT old_id FROM old WHERE
90 old_title='$eTitle' AND old_namespace={$row->old_namespace} AND
91 old_timestamp<'{$row->old_timestamp}' ORDER BY inverse_timestamp LIMIT 1", DB_READ );
92 $lastrow = wfFetchObject( $lastres );
94 $last = $lastrow->old_id;
95 $url .= "&diff={$row->old_id}&oldid=$last";
97 $url .= "&oldid={$row->old_id}";
101 fwrite( $sqlfile, " " );
105 fwrite( $sqlfile, ", " );
106 fwrite( $logfile, ", " );
109 fwrite( $sqlfile, "{$row->old_id} -- $url\n" );
110 fwrite( $logfile, "[$url {$row->old_id}]" );
113 fwrite( $sqlfile, ");\n" );
114 fwrite( $logfile, "\n" );
118 print "\n\nCur entries\n\n";
120 $res = wfQuery( "SELECT cur_title, cur_namespace, cur_timestamp, cur_id FROM cur WHERE cur_user_text='$eSource'",
122 $row = wfFetchObject( $res );
124 fwrite( $sqlfile, "\n\nUPDATE cur SET cur_user=$uid, cur_user_text='$eDest' WHERE cur_id IN(\n" );
125 fwrite( $logfile, "**Cur entries:\n" );
126 for ( $first=true; $row; $row = wfFetchObject( $res ) ) {
127 $ns = $wgLang->getNsText( $row->cur_namespace
);
129 $fullTitle = "$ns:{$row->cur_title}";
131 $fullTitle = $row->cur_title
;
133 if ( $fullTitle == $omitTitle ) {
136 $url = "http://$lang.wikipedia.org/wiki/" . urlencode($fullTitle);
138 fwrite( $sqlfile, " " );
141 fwrite( $sqlfile, " , " );
143 fwrite( $sqlfile, "{$row->cur_id} -- $url\n" );
144 fwrite( $logfile, "***[[$fullTitle]] {$row->cur_timestamp}\n" );
145 print "$fullTitle\n";
147 fwrite( $sqlfile, ");\n" );