(bug 4760) Prevent creation of entries in protection log when protection levels haven...
[lhc/web/wiklou.git] / maintenance / reassignEdits.inc
1 <?php
2
3 /**
4 * Support functions for the reassignEdits script
5 *
6 * @package MediaWiki
7 * @subpackage Maintenance
8 * @author Rob Church <robchur@gmail.com>
9 */
10
11 function ReassignEdits( $from, $to ) {
12
13 # This stuff needs to come off the master, wrapped in a transaction
14 $dbw =& wfGetDB( DB_MASTER );
15 $dbw->begin();
16
17 $tbl_arc = $dbw->tableName( 'archive' );
18 $tbl_rev = $dbw->tableName( 'revision' );
19
20 $from_txt = $from['text'];
21 $to_id = $to['id'];
22 $to_txt = $to['text'];
23
24 echo( "Searching for current revisions..." );
25 $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_user_text = \"$from_txt\"" );
26 while( $row = $dbw->fetchObject( $res ) ) {
27 $cur[] = $row->rev_id;
28 }
29 $ccount = count( $cur );
30 echo( "found $ccount.\n" );
31
32 echo( "Searching for deleted revisions..." );
33 $res = $dbw->query( "SELECT ar_rev_id FROM $tbl_arc WHERE ar_user_text = \"$from_txt\"" );
34 while( $row = $dbw->fetchObject( $res ) ){
35 $old[] = $row->ar_rev_id;
36 }
37 $ocount = count( $old );
38 echo( "found $ocount.\n" );
39
40 if( $ccount > 0 || $ocount > 0 ) {
41 echo( "Reassigning edits to $to_txt..." );
42 }
43
44 if( $ccount > 0 ) {
45 $set = implode( ', ', $cur );
46 $res = $dbw->query( "UPDATE $tbl_rev SET rev_user = $to_id, rev_user_text = \"$to_txt\" WHERE rev_id IN ( $set )" );
47 }
48
49 if( $ocount > 0 ) {
50 $set = implode( ', ', $old );
51 $res = $dbw->query( "UPDATE $tbl_arc SET ar_user = $to_id, ar_user_text = \"$to_txt\" WHERE ar_rev_id IN ( $set )" );
52 }
53
54 if( $ccount > 0 || $ocount > 0 ) {
55 echo( "done.\n" );
56 }
57
58 $dbw->commit();
59 return( true );
60
61 }
62
63 function GetUserDetails( $spec ) {
64
65 # IP addresses are quick to handle
66 if( User::isIP( $spec ) ) {
67 return( array( 'id' => 0, 'text' => $spec, 'valid' => true ) );
68 }
69
70 # Need to check the user exists and get ID and canonical username
71 $user = User::newFromName( $spec );
72 if( $user->getID() ) {
73 # We have them
74 return( array( 'id' => $user->getID(), 'text' => $user->getName(), 'valid' => true ) );
75 } else {
76 # No such user
77 return( array( 'id' => 0, 'text' => $spec, 'valid' => false ) );
78 }
79
80 }
81
82
83 ?>