00001 <?php 00002 00021 function reassignEdits( &$from, &$to, $rc = false, $report = false ) { 00022 $dbw = wfGetDB( DB_MASTER ); 00023 $dbw->immediateBegin(); 00024 $fname = 'reassignEdits'; 00025 00026 # Count things 00027 out( "Checking current edits..." ); 00028 $res = $dbw->select( 'revision', 'COUNT(*) AS count', userConditions( $from, 'rev_user', 'rev_user_text' ), $fname ); 00029 $row = $dbw->fetchObject( $res ); 00030 $cur = $row->count; 00031 out( "found {$cur}.\n" ); 00032 00033 out( "Checking deleted edits..." ); 00034 $res = $dbw->select( 'archive', 'COUNT(*) AS count', userConditions( $from, 'ar_user', 'ar_user_text' ), $fname ); 00035 $row = $dbw->fetchObject( $res ); 00036 $del = $row->count; 00037 out( "found {$del}.\n" ); 00038 00039 # Don't count recent changes if we're not supposed to 00040 if( $rc ) { 00041 out( "Checking recent changes..." ); 00042 $res = $dbw->select( 'recentchanges', 'COUNT(*) AS count', userConditions( $from, 'rc_user', 'rc_user_text' ), $fname ); 00043 $row = $dbw->fetchObject( $res ); 00044 $rec = $row->count; 00045 out( "found {$rec}.\n" ); 00046 } else { 00047 $rec = 0; 00048 } 00049 00050 $total = $cur + $del + $rec; 00051 out( "\nTotal entries to change: {$total}\n" ); 00052 00053 if( !$report ) { 00054 if( $total ) { 00055 # Reassign edits 00056 out( "\nReassigning current edits..." ); 00057 $res = $dbw->update( 'revision', userSpecification( $to, 'rev_user', 'rev_user_text' ), userConditions( $from, 'rev_user', 'rev_user_text' ), $fname ); 00058 out( "done.\nReassigning deleted edits..." ); 00059 $res = $dbw->update( 'archive', userSpecification( $to, 'ar_user', 'ar_user_text' ), userConditions( $from, 'ar_user', 'ar_user_text' ), $fname ); 00060 out( "done.\n" ); 00061 # Update recent changes if required 00062 if( $rc ) { 00063 out( "Updating recent changes..." ); 00064 $res = $dbw->update( 'recentchanges', userSpecification( $to, 'rc_user', 'rc_user_text' ), userConditions( $from, 'rc_user', 'rc_user_text' ), $fname ); 00065 out( "done.\n" ); 00066 } 00067 } 00068 } 00069 00070 $dbw->immediateCommit(); 00071 return (int)$total; 00072 } 00073 00083 function userConditions( &$user, $idfield, $utfield ) { 00084 return $user->getId() ? array( $idfield => $user->getId() ) : array( $utfield => $user->getName() ); 00085 } 00086 00096 function userSpecification( &$user, $idfield, $utfield ) { 00097 return array( $idfield => $user->getId(), $utfield => $user->getName() ); 00098 } 00099 00106 function out( $output ) { 00107 global $wgSilent; 00108 if( !$wgSilent ) { 00109 echo( $output ); 00110 return true; 00111 } else { 00112 return false; 00113 } 00114 } 00115 00121 function silent( $silent = true ) { 00122 global $wgSilent; 00123 $wgSilent = $silent; 00124 } 00125 00132 function initialiseUser( $username ) { 00133 if( User::isIP( $username ) ) { 00134 $user = new User(); 00135 $user->setId( 0 ); 00136 $user->setName( $username ); 00137 } else { 00138 $user = User::newFromName( $username ); 00139 } 00140 $user->load(); 00141 return $user; 00142 } 00143