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.
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 }
Revision\DELETED_USER
const DELETED_USER
Definition: Revision.php:49
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:50
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:305
RevisionDeleteUser\buildSetBitDeletedField
static buildSetBitDeletedField( $field, $op, $value, $dbw)
Definition: RevisionDeleteUser.php:195
RevisionDeleteUser\unsuppressUserName
static unsuppressUserName( $name, $userId, $dbw=null)
Definition: RevisionDeleteUser.php:205
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:37
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:2812
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
DB_MASTER
const DB_MASTER
Definition: defines.php:26
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:32
MIGRATION_OLD
const MIGRATION_OLD
Definition: Defines.php:302
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:562
$value
$value
Definition: styleTest.css.php:45
RevisionDeleteUser
Backend functions for suppressing and unsuppressing all references to a given user,...
Definition: RevisionDeleteUser.php:34
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
RevisionDeleteUser\setUsernameBitfields
static setUsernameBitfields( $name, $userId, $op, $dbw)
Update *_deleted bitfields in various tables to hide or unhide usernames.
Definition: RevisionDeleteUser.php:44
NS_USER
const NS_USER
Definition: Defines.php:76
RevisionDeleteUser\suppressUserName
static suppressUserName( $name, $userId, $dbw=null)
Definition: RevisionDeleteUser.php:201
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:8878