MediaWiki
REL1_22
|
00001 <?php 00032 class RevisionDeleteUser { 00033 00042 private static function setUsernameBitfields( $name, $userId, $op, $dbw ) { 00043 if ( !$userId || ( $op !== '|' && $op !== '&' ) ) { 00044 return false; // sanity check 00045 } 00046 if ( !$dbw instanceof DatabaseBase ) { 00047 $dbw = wfGetDB( DB_MASTER ); 00048 } 00049 00050 # To suppress, we OR the current bitfields with Revision::DELETED_USER 00051 # to put a 1 in the username *_deleted bit. To unsuppress we AND the 00052 # current bitfields with the inverse of Revision::DELETED_USER. The 00053 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x). 00054 # The same goes for the sysop-restricted *_deleted bit. 00055 $delUser = Revision::DELETED_USER | Revision::DELETED_RESTRICTED; 00056 $delAction = LogPage::DELETED_ACTION | Revision::DELETED_RESTRICTED; 00057 if ( $op == '&' ) { 00058 $delUser = "~{$delUser}"; 00059 $delAction = "~{$delAction}"; 00060 } 00061 00062 # Normalize user name 00063 $userTitle = Title::makeTitleSafe( NS_USER, $name ); 00064 $userDbKey = $userTitle->getDBkey(); 00065 00066 # Hide name from live edits 00067 $dbw->update( 00068 'revision', 00069 array( "rev_deleted = rev_deleted $op $delUser" ), 00070 array( 'rev_user' => $userId ), 00071 __METHOD__ ); 00072 00073 # Hide name from deleted edits 00074 $dbw->update( 00075 'archive', 00076 array( "ar_deleted = ar_deleted $op $delUser" ), 00077 array( 'ar_user_text' => $name ), 00078 __METHOD__ 00079 ); 00080 00081 # Hide name from logs 00082 $dbw->update( 00083 'logging', 00084 array( "log_deleted = log_deleted $op $delUser" ), 00085 array( 'log_user' => $userId, "log_type != 'suppress'" ), 00086 __METHOD__ 00087 ); 00088 $dbw->update( 00089 'logging', 00090 array( "log_deleted = log_deleted $op $delAction" ), 00091 array( 'log_namespace' => NS_USER, 'log_title' => $userDbKey, 00092 "log_type != 'suppress'" ), 00093 __METHOD__ 00094 ); 00095 00096 # Hide name from RC 00097 $dbw->update( 00098 'recentchanges', 00099 array( "rc_deleted = rc_deleted $op $delUser" ), 00100 array( 'rc_user_text' => $name ), 00101 __METHOD__ 00102 ); 00103 $dbw->update( 00104 'recentchanges', 00105 array( "rc_deleted = rc_deleted $op $delAction" ), 00106 array( 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ), 00107 __METHOD__ 00108 ); 00109 00110 # Hide name from live images 00111 $dbw->update( 00112 'oldimage', 00113 array( "oi_deleted = oi_deleted $op $delUser" ), 00114 array( 'oi_user_text' => $name ), 00115 __METHOD__ 00116 ); 00117 00118 # Hide name from deleted images 00119 $dbw->update( 00120 'filearchive', 00121 array( "fa_deleted = fa_deleted $op $delUser" ), 00122 array( 'fa_user_text' => $name ), 00123 __METHOD__ 00124 ); 00125 # Done! 00126 return true; 00127 } 00128 00129 public static function suppressUserName( $name, $userId, $dbw = null ) { 00130 return self::setUsernameBitfields( $name, $userId, '|', $dbw ); 00131 } 00132 00133 public static function unsuppressUserName( $name, $userId, $dbw = null ) { 00134 return self::setUsernameBitfields( $name, $userId, '&', $dbw ); 00135 } 00136 }