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", "w" );
45 $sqlfile = fopen( "attribute.sql", "w" );
47 fwrite( $logfile, "* $source → $dest\n" );
50 "-- Changing attribution SQL file
51 -- Generated with attribute.php
52 -- $source -> $dest ($uid)
56 print "Getting old entries";
58 $res = wfQuery( "SELECT old_namespace, old_title, old_id, old_timestamp FROM old WHERE old_user_text='$eSource'", DB_READ
);
59 $row = wfFetchObject( $res );
63 if ( $row->old_title=='Votes_for_deletion' && $row->old_namespace == 4 ) {
64 # We don't have that long
68 fwrite( $logfile, "**Old IDs: " );
69 fwrite( $sqlfile, "UPDATE old SET old_user=$uid, old_user_text='$eDest' WHERE old_id IN (\n" );
71 for ( $first=true; $row; $row = wfFetchObject( $res ) ) {
72 $ns = $wgLang->getNsText( $row->old_namespace
);
74 $fullTitle = "$ns:{$row->old_title}";
76 $fullTitle = $row->old_title
;
78 $url = "http://$lang.wikipedia.org/w/wiki.phtml?title=" . urlencode( $fullTitle );
79 $eTitle = wfStrencode( $row->old_title
);
82 $lastres = wfQuery( "SELECT old_id FROM old WHERE
83 old_title='$eTitle' AND old_namespace={$row->old_namespace} AND
84 old_timestamp<'{$row->old_timestamp}' ORDER BY inverse_timestamp LIMIT 1", DB_READ );
85 $lastrow = wfFetchObject( $lastres );
87 $last = $lastrow->old_id;
88 $url .= "&diff={$row->old_id}&oldid=$last";
90 $url .= "&oldid={$row->old_id}";
94 fwrite( $sqlfile, " " );
98 fwrite( $sqlfile, ", " );
99 fwrite( $logfile, ", " );
102 fwrite( $sqlfile, "{$row->old_id} -- $url\n" );
103 fwrite( $logfile, "[$url {$row->old_id}]" );
107 fwrite( $sqlfile, ");\n" );
108 fwrite( $logfile, "\n" );
113 print "Getting cur entries";
114 $res = wfQuery( "SELECT cur_title, cur_namespace, cur_timestamp, cur_id FROM cur WHERE cur_user_text='$eSource'",
116 $row = wfFetchObject( $res );
118 fwrite( $sqlfile, "\n\nUPDATE cur SET cur_user=$uid, cur_user_text='$eDest' WHERE cur_id IN(\n" );
119 fwrite( $logfile, "**Cur entries:\n" );
120 for ( $first=true; $row; $row = wfFetchObject( $res ) ) {
121 $ns = $wgLang->getNsText( $row->cur_namespace
);
123 $fullTitle = "$ns:{$row->cur_title}";
125 $fullTitle = $row->cur_title
;
127 $url = "http://$lang.wikipedia.org/wiki/" . urlencode($fullTitle);
129 fwrite( $sqlfile, " " );
132 fwrite( $sqlfile, " , " );
134 fwrite( $sqlfile, "{$row->cur_id} -- $url\n" );
135 fwrite( $logfile, "***[[$fullTitle]] {$row->cur_timestamp}\n" );
138 fwrite( $sqlfile, ");\n" );