MediaWiki  master
RevisionDeleteUser.php
Go to the documentation of this file.
1 <?php
26 
36 
46  private static function setUsernameBitfields( $name, $userId, $op, IDatabase $dbw = null ) {
48 
49  if ( !$userId || ( $op !== '|' && $op !== '&' ) ) {
50  return false;
51  }
52  if ( !$dbw instanceof IDatabase ) {
53  $dbw = wfGetDB( DB_PRIMARY );
54  }
55 
56  # To suppress, we OR the current bitfields with RevisionRecord::DELETED_USER
57  # to put a 1 in the username *_deleted bit. To unsuppress we AND the
58  # current bitfields with the inverse of RevisionRecord::DELETED_USER. The
59  # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
60  # The same goes for the sysop-restricted *_deleted bit.
61  $delUser = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
62  $delAction = LogPage::DELETED_ACTION | RevisionRecord::DELETED_RESTRICTED;
63  if ( $op === '&' ) {
64  $delUser = $dbw->bitNot( $delUser );
65  $delAction = $dbw->bitNot( $delAction );
66  }
67 
68  # Normalize user name
69  $userTitle = Title::makeTitleSafe( NS_USER, $name );
70  $userDbKey = $userTitle->getDBkey();
71 
72  $actorId = $dbw->selectField( 'actor', 'actor_id', [ 'actor_name' => $name ], __METHOD__ );
73  if ( $actorId ) {
74  # Hide name from live edits
75  # This query depends on the actor migration read stage, not the
76  # write stage, because the stage determines how we find the rows to
77  # delete. The write stage determines whether or not to write to
78  # rev_actor and revision_actor_temp which is not relevant here.
80  $ids = $dbw->selectFieldValues(
81  'revision_actor_temp', 'revactor_rev', [ 'revactor_actor' => $actorId ], __METHOD__
82  );
83  if ( $ids ) {
84  $dbw->update(
85  'revision',
86  [ self::buildSetBitDeletedField( 'rev_deleted', $op, $delUser, $dbw ) ],
87  [ 'rev_id' => $ids ],
88  __METHOD__
89  );
90  }
91  } else /* SCHEMA_COMPAT_READ_NEW */ {
92  $dbw->update(
93  'revision',
94  [ self::buildSetBitDeletedField( 'rev_deleted', $op, $delUser, $dbw ) ],
95  [ 'rev_actor' => $actorId ],
96  __METHOD__
97  );
98  }
99 
100  # Hide name from deleted edits
101  $dbw->update(
102  'archive',
103  [ self::buildSetBitDeletedField( 'ar_deleted', $op, $delUser, $dbw ) ],
104  [ 'ar_actor' => $actorId ],
105  __METHOD__
106  );
107 
108  # Hide name from logs
109  $dbw->update(
110  'logging',
111  [ self::buildSetBitDeletedField( 'log_deleted', $op, $delUser, $dbw ) ],
112  [ 'log_actor' => $actorId, 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
113  __METHOD__
114  );
115 
116  # Hide name from RC
117  $dbw->update(
118  'recentchanges',
119  [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delUser, $dbw ) ],
120  [ 'rc_actor' => $actorId ],
121  __METHOD__
122  );
123 
124  # Hide name from live images
125  $dbw->update(
126  'oldimage',
127  [ self::buildSetBitDeletedField( 'oi_deleted', $op, $delUser, $dbw ) ],
128  [ 'oi_actor' => $actorId ],
129  __METHOD__
130  );
131 
132  # Hide name from deleted images
133  $dbw->update(
134  'filearchive',
135  [ self::buildSetBitDeletedField( 'fa_deleted', $op, $delUser, $dbw ) ],
136  [ 'fa_actor' => $actorId ],
137  __METHOD__
138  );
139  }
140 
141  # Hide log entries pointing to the user page
142  $dbw->update(
143  'logging',
144  [ self::buildSetBitDeletedField( 'log_deleted', $op, $delAction, $dbw ) ],
145  [ 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
146  'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
147  __METHOD__
148  );
149 
150  # Hide RC entries pointing to the user page
151  $dbw->update(
152  'recentchanges',
153  [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delAction, $dbw ) ],
154  [ 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ],
155  __METHOD__
156  );
157 
158  return true;
159  }
160 
161  private static function buildSetBitDeletedField( $field, $op, $value, IDatabase $dbw ) {
162  return $field . ' = ' . ( $op === '&'
163  ? $dbw->bitAnd( $field, $value )
164  : $dbw->bitOr( $field, $value ) );
165  }
166 
173  public static function suppressUserName( $name, $userId, IDatabase $dbw = null ) {
174  return self::setUsernameBitfields( $name, $userId, '|', $dbw );
175  }
176 
183  public static function unsuppressUserName( $name, $userId, IDatabase $dbw = null ) {
184  return self::setUsernameBitfields( $name, $userId, '&', $dbw );
185  }
186 }
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
RevisionDeleteUser\unsuppressUserName
static unsuppressUserName( $name, $userId, IDatabase $dbw=null)
Definition: RevisionDeleteUser.php:183
RevisionDeleteUser\buildSetBitDeletedField
static buildSetBitDeletedField( $field, $op, $value, IDatabase $dbw)
Definition: RevisionDeleteUser.php:161
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2200
RevisionDeleteUser\setUsernameBitfields
static setUsernameBitfields( $name, $userId, $op, IDatabase $dbw=null)
Update *_deleted bitfields in various tables to hide or unhide usernames.
Definition: RevisionDeleteUser.php:46
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:39
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:692
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
Wikimedia\Rdbms\IDatabase\bitOr
bitOr( $fieldLeft, $fieldRight)
NS_USER
const NS_USER
Definition: Defines.php:66
RevisionDeleteUser
Backend functions for suppressing and unsuppressing all references to a given user,...
Definition: RevisionDeleteUser.php:35
Wikimedia\Rdbms\IDatabase\bitAnd
bitAnd( $fieldLeft, $fieldRight)
RevisionDeleteUser\suppressUserName
static suppressUserName( $name, $userId, IDatabase $dbw=null)
Definition: RevisionDeleteUser.php:173
SCHEMA_COMPAT_READ_TEMP
const SCHEMA_COMPAT_READ_TEMP
Definition: Defines.php:265
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage, for migration from the temporary table revision_actor_temp to the...
Definition: DefaultSettings.php:2416