49 private static function setUsernameBitfields( $name, $userId, $op,
IDatabase $dbw =
null ) {
50 if ( !$userId || ( $op !==
'|' && $op !==
'&' ) ) {
54 $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
57 # To suppress, we OR the current bitfields with RevisionRecord::DELETED_USER
58 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
59 # current bitfields with the inverse of RevisionRecord::DELETED_USER. The
60 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
61 # The same goes for the sysop-restricted *_deleted bit.
62 $delUser = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
63 $delAction = LogPage::DELETED_ACTION | RevisionRecord::DELETED_RESTRICTED;
65 $delUser = $dbw->bitNot( $delUser );
66 $delAction = $dbw->bitNot( $delAction );
70 $userTitle = Title::makeTitleSafe(
NS_USER, $name );
71 $userDbKey = $userTitle->getDBkey();
73 $actorId = $dbw->newSelectQueryBuilder()
74 ->select(
'actor_id' )
76 ->where( [
'actor_name' => $name ] )
77 ->caller( __METHOD__ )->fetchField();
79 # Hide name from live edits
80 $dbw->newUpdateQueryBuilder()
81 ->update(
'revision' )
82 ->set( self::buildSetBitDeletedField(
'rev_deleted', $op, $delUser, $dbw ) )
83 ->where( [
'rev_actor' => $actorId ] )
84 ->caller( __METHOD__ )->execute();
86 # Hide name from deleted edits
87 $dbw->newUpdateQueryBuilder()
89 ->set( self::buildSetBitDeletedField(
'ar_deleted', $op, $delUser, $dbw ) )
90 ->where( [
'ar_actor' => $actorId ] )
91 ->caller( __METHOD__ )->execute();
94 $dbw->newUpdateQueryBuilder()
96 ->set( self::buildSetBitDeletedField(
'log_deleted', $op, $delUser, $dbw ) )
97 ->where( [
'log_actor' => $actorId, $dbw->expr(
'log_type',
'!=',
'suppress' ) ] )
98 ->caller( __METHOD__ )->execute();
101 $dbw->newUpdateQueryBuilder()
102 ->update(
'recentchanges' )
103 ->set( self::buildSetBitDeletedField(
'rc_deleted', $op, $delUser, $dbw ) )
104 ->where( [
'rc_actor' => $actorId ] )
105 ->caller( __METHOD__ )->execute();
107 # Hide name from live images
108 $dbw->newUpdateQueryBuilder()
109 ->update(
'oldimage' )
110 ->set( self::buildSetBitDeletedField(
'oi_deleted', $op, $delUser, $dbw ) )
111 ->where( [
'oi_actor' => $actorId ] )
112 ->caller( __METHOD__ )->execute();
114 # Hide name from deleted images
115 $dbw->newUpdateQueryBuilder()
116 ->update(
'filearchive' )
117 ->set( self::buildSetBitDeletedField(
'fa_deleted', $op, $delUser, $dbw ) )
118 ->where( [
'fa_actor' => $actorId ] )
119 ->caller( __METHOD__ )->execute();
122 # Hide log entries pointing to the user page
123 $dbw->newUpdateQueryBuilder()
124 ->update(
'logging' )
125 ->set( self::buildSetBitDeletedField(
'log_deleted', $op, $delAction, $dbw ) )
128 'log_title' => $userDbKey,
129 $dbw->expr(
'log_type',
'!=',
'suppress' )
131 ->caller( __METHOD__ )->execute();
133 # Hide RC entries pointing to the user page
134 $dbw->newUpdateQueryBuilder()
135 ->update(
'recentchanges' )
136 ->set( self::buildSetBitDeletedField(
'rc_deleted', $op, $delAction, $dbw ) )
137 ->where( [
'rc_namespace' =>
NS_USER,
'rc_title' => $userDbKey, $dbw->expr(
'rc_logid',
'>', 0 ) ] )
138 ->caller( __METHOD__ )->execute();
143 private static function buildSetBitDeletedField( $field, $op, $value,
IDatabase $dbw ) {
145 ? $dbw->
bitAnd( $field, $value )
146 : $dbw->
bitOr( $field, $value )
157 return self::setUsernameBitfields( $name, $userId,
'|', $dbw );
167 return self::setUsernameBitfields( $name, $userId,
'&', $dbw );