3 * Script for re-attributing edits
4 * Use reassingEdits.php
11 require_once( "commandLine.inc" );
14 if ( count( $args ) < 2 ) {
15 print "Not enough parameters\n";
17 print "Usage: php attribute.php <language> <site> <source> <destination>\n";
19 print "Usage: php attribute.php <source> <destination>\n";
27 $dbr = wfGetDB( DB_SLAVE
);
28 extract( $dbr->tableNames( 'page', 'revision','user' ));
29 $eSource = $dbr->strencode( $source );
30 $eDest = $dbr->strencode( $dest );
33 $res = $dbr->query( "SELECT user_id FROM $user WHERE user_name='$eDest'" );
34 $row = $dbr->fetchObject( $res );
36 print "Warning: the target name \"$dest\" does not exist";
43 $logfile = fopen( "attribute.log", "a" );
44 $sqlfile = fopen( "attribute.sql", "a" );
46 fwrite( $logfile, "* $source → $dest\n" );
49 "-- Changing attribution SQL file
50 -- Generated with attribute.php
51 -- $source -> $dest ($uid)
54 $omitTitle = "Wikipedia:Changing_attribution_for_an_edit";
57 print "\nPage revisions\n\n";
59 $res = $dbr->query( "SELECT page_namespace, page_title, rev_id, rev_timestamp
61 WHERE rev_user_text='$eSource' and rev_page=page_id" );
62 $row = $dbr->fetchObject( $res );
66 if ( $row->old_title=='Votes_for_deletion' && $row->old_namespace == 4 ) {
67 # We don't have that long
71 fwrite( $logfile, "**Revision IDs: " );
72 fwrite( $sqlfile, "UPDATE $revision SET rev_user=$uid, rev_user_text='$eDest' WHERE rev_id IN (\n" );
74 for ( $first=true; $row; $row = $dbr->fetchObject( $res ) ) {
75 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
76 $fullTitle = $title->getPrefixedDbKey();
77 if ( $fullTitle == $omitTitle ) {
82 $url = $title->getFullUrl( "oldid={$row->rev_id}" );
85 fwrite( $sqlfile, " " );
89 fwrite( $sqlfile, ", " );
90 fwrite( $logfile, ", " );
93 fwrite( $sqlfile, "{$row->rev_id} -- $url\n" );
94 fwrite( $logfile, "[$url {$row->rev_id}]" );
97 fwrite( $sqlfile, ");\n" );
98 fwrite( $logfile, "\n" );