--- /dev/null
+<?php
+
+/**
+ * Support functions for the reassignEdits script
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ * @author Rob Church <robchur@gmail.com>
+ */
+
+function ReassignEdits( $from, $to ) {
+
+ # This stuff needs to come off the master, wrapped in a transaction
+ $dbw =& wfGetDB( DB_MASTER );
+ $dbw->begin();
+
+ $tbl_arc = $dbw->tableName( 'archive' );
+ $tbl_rev = $dbw->tableName( 'revision' );
+
+ $from_txt = $from['text'];
+ $to_id = $to['id'];
+ $to_txt = $to['text'];
+
+ echo( "Searching for current revisions..." );
+ $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_user_text = \"$from_txt\"" );
+ while( $row = $dbw->fetchObject( $res ) ) {
+ $cur[] = $row->rev_id;
+ }
+ $ccount = count( $cur );
+ echo( "found $ccount.\n" );
+
+ echo( "Searching for deleted revisions..." );
+ $res = $dbw->query( "SELECT ar_rev_id FROM $tbl_arc WHERE ar_user_text = \"$from_txt\"" );
+ while( $row = $dbw->fetchObject( $res ) ){
+ $old[] = $row->ar_rev_id;
+ }
+ $ocount = count( $old );
+ echo( "found $ocount.\n" );
+
+ if( $ccount > 0 || $ocount > 0 ) {
+ echo( "Reassigning edits to $to_txt..." );
+ }
+
+ if( $ccount > 0 ) {
+ $set = implode( ', ', $cur );
+ $res = $dbw->query( "UPDATE $tbl_rev SET rev_user = $to_id, rev_user_text = \"$to_txt\" WHERE rev_id IN ( $set )" );
+ }
+
+ if( $ocount > 0 ) {
+ $set = implode( ', ', $old );
+ $res = $dbw->query( "UPDATE $tbl_arc SET ar_user = $to_id, ar_user_text = \"$to_txt\" WHERE ar_rev_id IN ( $set )" );
+ }
+
+ if( $ccount > 0 || $ocount > 0 ) {
+ echo( "done.\n" );
+ }
+
+ $dbw->commit();
+ return( true );
+
+}
+
+function GetUserDetails( $spec ) {
+
+ # IP addresses are quick to handle
+ if( User::isIP( $spec ) ) {
+ return( array( 'id' => 0, 'text' => $spec, 'valid' => true ) );
+ }
+
+ # Need to check the user exists and get ID and canonical username
+ $user = User::newFromName( $spec );
+ if( $user->getID() ) {
+ # We have them
+ return( array( 'id' => $user->getID(), 'text' => $user->getName(), 'valid' => true ) );
+ } else {
+ # No such user
+ return( array( 'id' => 0, 'text' => $spec, 'valid' => false ) );
+ }
+
+}
+
+
+?>
--- /dev/null
+<?php
+
+/**
+ * Reassign edits from a user or IP address to another user
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ * @author Rob Church <robchur@gmail.com>
+ */
+
+$options = array( 'force' );
+require_once( 'commandLine.inc' );
+require_once( 'reassignEdits.inc' );
+
+echo( "Reassign Edits\n\n" );
+
+if( @$args[0] && @$args[1] ) {
+
+ $from = GetUserDetails( $args[0] );
+ $to = GetUserDetails( $args[1] );
+ $tor = $args[1];
+
+ if( $to['valid'] || @$options['force'] ) {
+ ReassignEdits( $from, $to );
+ } else {
+ echo( "User \"$tor\" not found.\n" );
+ }
+
+} else {
+ ShowUsage();
+}
+
+/** Show script usage information */
+function ShowUsage() {
+ echo( "Reassign edits from one user to another.\n\n" );
+ echo( "Usage: php reassignEdits.php <from> <to> [--force]\n\n" );
+ echo( " <from> : Name of the user to assign edits from\n" );
+ echo( " <to> : Name of the user to assign edits to\n" );
+ echo( " --force : Reassign even if the target user doesn't exist\n\n" );
+}
+
+?>
\ No newline at end of file