MediaWiki  1.33.0
RevisionDeleteUser.php
Go to the documentation of this file.
1 <?php
25 
35 
45  private static function setUsernameBitfields( $name, $userId, $op, IDatabase $dbw = null ) {
47 
48  if ( !$userId || ( $op !== '|' && $op !== '&' ) ) {
49  return false; // sanity check
50  }
51  if ( !$dbw instanceof IDatabase ) {
52  $dbw = wfGetDB( DB_MASTER );
53  }
54 
55  # To suppress, we OR the current bitfields with Revision::DELETED_USER
56  # to put a 1 in the username *_deleted bit. To unsuppress we AND the
57  # current bitfields with the inverse of Revision::DELETED_USER. The
58  # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
59  # The same goes for the sysop-restricted *_deleted bit.
62  if ( $op === '&' ) {
63  $delUser = $dbw->bitNot( $delUser );
64  $delAction = $dbw->bitNot( $delAction );
65  }
66 
67  # Normalize user name
68  $userTitle = Title::makeTitleSafe( NS_USER, $name );
69  $userDbKey = $userTitle->getDBkey();
70 
72  # Hide name from live edits
73  $dbw->update(
74  'revision',
75  [ self::buildSetBitDeletedField( 'rev_deleted', $op, $delUser, $dbw ) ],
76  [ 'rev_user' => $userId ],
77  __METHOD__ );
78 
79  # Hide name from deleted edits
80  $dbw->update(
81  'archive',
82  [ self::buildSetBitDeletedField( 'ar_deleted', $op, $delUser, $dbw ) ],
83  [ 'ar_user_text' => $name ],
84  __METHOD__
85  );
86 
87  # Hide name from logs
88  $dbw->update(
89  'logging',
90  [ self::buildSetBitDeletedField( 'log_deleted', $op, $delUser, $dbw ) ],
91  [ 'log_user' => $userId, 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
92  __METHOD__
93  );
94 
95  # Hide name from RC
96  $dbw->update(
97  'recentchanges',
98  [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delUser, $dbw ) ],
99  [ 'rc_user_text' => $name ],
100  __METHOD__
101  );
102 
103  # Hide name from live images
104  $dbw->update(
105  'oldimage',
106  [ self::buildSetBitDeletedField( 'oi_deleted', $op, $delUser, $dbw ) ],
107  [ 'oi_user_text' => $name ],
108  __METHOD__
109  );
110 
111  # Hide name from deleted images
112  $dbw->update(
113  'filearchive',
114  [ self::buildSetBitDeletedField( 'fa_deleted', $op, $delUser, $dbw ) ],
115  [ 'fa_user_text' => $name ],
116  __METHOD__
117  );
118  }
119 
121  $actorId = $dbw->selectField( 'actor', 'actor_id', [ 'actor_name' => $name ], __METHOD__ );
122  if ( $actorId ) {
123  # Hide name from live edits
124  $ids = $dbw->selectFieldValues(
125  'revision_actor_temp', 'revactor_rev', [ 'revactor_actor' => $actorId ], __METHOD__
126  );
127  if ( $ids ) {
128  $dbw->update(
129  'revision',
130  [ self::buildSetBitDeletedField( 'rev_deleted', $op, $delUser, $dbw ) ],
131  [ 'rev_id' => $ids ],
132  __METHOD__
133  );
134  }
135 
136  # Hide name from deleted edits
137  $dbw->update(
138  'archive',
139  [ self::buildSetBitDeletedField( 'ar_deleted', $op, $delUser, $dbw ) ],
140  [ 'ar_actor' => $actorId ],
141  __METHOD__
142  );
143 
144  # Hide name from logs
145  $dbw->update(
146  'logging',
147  [ self::buildSetBitDeletedField( 'log_deleted', $op, $delUser, $dbw ) ],
148  [ 'log_actor' => $actorId, 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
149  __METHOD__
150  );
151 
152  # Hide name from RC
153  $dbw->update(
154  'recentchanges',
155  [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delUser, $dbw ) ],
156  [ 'rc_actor' => $actorId ],
157  __METHOD__
158  );
159 
160  # Hide name from live images
161  $dbw->update(
162  'oldimage',
163  [ self::buildSetBitDeletedField( 'oi_deleted', $op, $delUser, $dbw ) ],
164  [ 'oi_actor' => $actorId ],
165  __METHOD__
166  );
167 
168  # Hide name from deleted images
169  $dbw->update(
170  'filearchive',
171  [ self::buildSetBitDeletedField( 'fa_deleted', $op, $delUser, $dbw ) ],
172  [ 'fa_actor' => $actorId ],
173  __METHOD__
174  );
175  }
176  }
177 
178  # Hide log entries pointing to the user page
179  $dbw->update(
180  'logging',
181  [ self::buildSetBitDeletedField( 'log_deleted', $op, $delAction, $dbw ) ],
182  [ 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
183  'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
184  __METHOD__
185  );
186 
187  # Hide RC entries pointing to the user page
188  $dbw->update(
189  'recentchanges',
190  [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delAction, $dbw ) ],
191  [ 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ],
192  __METHOD__
193  );
194 
195  return true;
196  }
197 
198  private static function buildSetBitDeletedField( $field, $op, $value, IDatabase $dbw ) {
199  return $field . ' = ' . ( $op === '&'
200  ? $dbw->bitAnd( $field, $value )
201  : $dbw->bitOr( $field, $value ) );
202  }
203 
210  public static function suppressUserName( $name, $userId, IDatabase $dbw = null ) {
211  return self::setUsernameBitfields( $name, $userId, '|', $dbw );
212  }
213 
220  public static function unsuppressUserName( $name, $userId, IDatabase $dbw = null ) {
221  return self::setUsernameBitfields( $name, $userId, '&', $dbw );
222  }
223 }
Revision\DELETED_USER
const DELETED_USER
Definition: Revision.php:48
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:49
RevisionDeleteUser\unsuppressUserName
static unsuppressUserName( $name, $userId, IDatabase $dbw=null)
Definition: RevisionDeleteUser.php:220
RevisionDeleteUser\buildSetBitDeletedField
static buildSetBitDeletedField( $field, $op, $value, IDatabase $dbw)
Definition: RevisionDeleteUser.php:198
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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:2636
RevisionDeleteUser\setUsernameBitfields
static setUsernameBitfields( $name, $userId, $op, IDatabase $dbw=null)
Update *_deleted bitfields in various tables to hide or unhide usernames.
Definition: RevisionDeleteUser.php:45
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
DB_MASTER
const DB_MASTER
Definition: defines.php:26
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:34
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:604
$value
$value
Definition: styleTest.css.php:49
SCHEMA_COMPAT_WRITE_OLD
const SCHEMA_COMPAT_WRITE_OLD
Definition: Defines.php:284
Wikimedia\Rdbms\IDatabase\bitOr
bitOr( $fieldLeft, $fieldRight)
SCHEMA_COMPAT_WRITE_NEW
const SCHEMA_COMPAT_WRITE_NEW
Definition: Defines.php:286
RevisionDeleteUser
Backend functions for suppressing and unsuppressing all references to a given user,...
Definition: RevisionDeleteUser.php:34
Wikimedia\Rdbms\IDatabase\bitAnd
bitAnd( $fieldLeft, $fieldRight)
NS_USER
const NS_USER
Definition: Defines.php:66
RevisionDeleteUser\suppressUserName
static suppressUserName( $name, $userId, IDatabase $dbw=null)
Definition: RevisionDeleteUser.php:210
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:8979