MediaWiki REL1_31
RevisionDeleteUser.php
Go to the documentation of this file.
1<?php
25
35
44 private static function setUsernameBitfields( $name, $userId, $op, $dbw ) {
46
47 if ( !$userId || ( $op !== '|' && $op !== '&' ) ) {
48 return false; // sanity check
49 }
50 if ( !$dbw instanceof IDatabase ) {
51 $dbw = wfGetDB( DB_MASTER );
52 }
53
54 # To suppress, we OR the current bitfields with Revision::DELETED_USER
55 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
56 # current bitfields with the inverse of Revision::DELETED_USER. The
57 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
58 # The same goes for the sysop-restricted *_deleted bit.
59 $delUser = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
60 $delAction = LogPage::DELETED_ACTION | Revision::DELETED_RESTRICTED;
61 if ( $op == '&' ) {
62 $delUser = $dbw->bitNot( $delUser );
63 $delAction = $dbw->bitNot( $delAction );
64 }
65
66 # Normalize user name
67 $userTitle = Title::makeTitleSafe( NS_USER, $name );
68 $userDbKey = $userTitle->getDBkey();
69
71 # Hide name from live edits
72 $dbw->update(
73 'revision',
74 [ self::buildSetBitDeletedField( 'rev_deleted', $op, $delUser, $dbw ) ],
75 [ 'rev_user' => $userId ],
76 __METHOD__ );
77
78 # Hide name from deleted edits
79 $dbw->update(
80 'archive',
81 [ self::buildSetBitDeletedField( 'ar_deleted', $op, $delUser, $dbw ) ],
82 [ 'ar_user_text' => $name ],
83 __METHOD__
84 );
85
86 # Hide name from logs
87 $dbw->update(
88 'logging',
89 [ self::buildSetBitDeletedField( 'log_deleted', $op, $delUser, $dbw ) ],
90 [ 'log_user' => $userId, 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
91 __METHOD__
92 );
93
94 # Hide name from RC
95 $dbw->update(
96 'recentchanges',
97 [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delUser, $dbw ) ],
98 [ 'rc_user_text' => $name ],
99 __METHOD__
100 );
101
102 # Hide name from live images
103 $dbw->update(
104 'oldimage',
105 [ self::buildSetBitDeletedField( 'oi_deleted', $op, $delUser, $dbw ) ],
106 [ 'oi_user_text' => $name ],
107 __METHOD__
108 );
109
110 # Hide name from deleted images
111 $dbw->update(
112 'filearchive',
113 [ self::buildSetBitDeletedField( 'fa_deleted', $op, $delUser, $dbw ) ],
114 [ 'fa_user_text' => $name ],
115 __METHOD__
116 );
117 }
118
120 $actorId = $dbw->selectField( 'actor', 'actor_id', [ 'actor_name' => $name ], __METHOD__ );
121 if ( $actorId ) {
122 # Hide name from live edits
123 $subquery = $dbw->selectSQLText(
124 'revision_actor_temp', 'revactor_rev', [ 'revactor_actor' => $actorId ], __METHOD__
125 );
126 $dbw->update(
127 'revision',
128 [ self::buildSetBitDeletedField( 'rev_deleted', $op, $delUser, $dbw ) ],
129 [ "rev_id IN ($subquery)" ],
130 __METHOD__ );
131
132 # Hide name from deleted edits
133 $dbw->update(
134 'archive',
135 [ self::buildSetBitDeletedField( 'ar_deleted', $op, $delUser, $dbw ) ],
136 [ 'ar_actor' => $actorId ],
137 __METHOD__
138 );
139
140 # Hide name from logs
141 $dbw->update(
142 'logging',
143 [ self::buildSetBitDeletedField( 'log_deleted', $op, $delUser, $dbw ) ],
144 [ 'log_actor' => $actorId, 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
145 __METHOD__
146 );
147
148 # Hide name from RC
149 $dbw->update(
150 'recentchanges',
151 [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delUser, $dbw ) ],
152 [ 'rc_actor' => $actorId ],
153 __METHOD__
154 );
155
156 # Hide name from live images
157 $dbw->update(
158 'oldimage',
159 [ self::buildSetBitDeletedField( 'oi_deleted', $op, $delUser, $dbw ) ],
160 [ 'oi_actor' => $actorId ],
161 __METHOD__
162 );
163
164 # Hide name from deleted images
165 $dbw->update(
166 'filearchive',
167 [ self::buildSetBitDeletedField( 'fa_deleted', $op, $delUser, $dbw ) ],
168 [ 'fa_actor' => $actorId ],
169 __METHOD__
170 );
171 }
172 }
173
174 # Hide log entries pointing to the user page
175 $dbw->update(
176 'logging',
177 [ self::buildSetBitDeletedField( 'log_deleted', $op, $delAction, $dbw ) ],
178 [ 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
179 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
180 __METHOD__
181 );
182
183 # Hide RC entries pointing to the user page
184 $dbw->update(
185 'recentchanges',
186 [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delAction, $dbw ) ],
187 [ 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ],
188 __METHOD__
189 );
190
191 # Done!
192 return true;
193 }
194
195 private static function buildSetBitDeletedField( $field, $op, $value, $dbw ) {
196 return $field . ' = ' . ( $op === '&'
197 ? $dbw->bitAnd( $field, $value )
198 : $dbw->bitOr( $field, $value ) );
199 }
200
201 public static function suppressUserName( $name, $userId, $dbw = null ) {
202 return self::setUsernameBitfields( $name, $userId, '|', $dbw );
203 }
204
205 public static function unsuppressUserName( $name, $userId, $dbw = null ) {
206 return self::setUsernameBitfields( $name, $userId, '&', $dbw );
207 }
208}
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
const DELETED_ACTION
Definition LogPage.php:32
Backend functions for suppressing and unsuppressing all references to a given user,...
static suppressUserName( $name, $userId, $dbw=null)
static unsuppressUserName( $name, $userId, $dbw=null)
static setUsernameBitfields( $name, $userId, $op, $dbw)
Update *_deleted bitfields in various tables to hide or unhide usernames.
static buildSetBitDeletedField( $field, $op, $value, $dbw)
const MIGRATION_NEW
Definition Defines.php:305
const MIGRATION_OLD
Definition Defines.php:302
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
const DB_MASTER
Definition defines.php:29