MediaWiki REL1_30
RevisionDeleteUser.php
Go to the documentation of this file.
1<?php
25
35
44 private static function setUsernameBitfields( $name, $userId, $op, $dbw ) {
45 if ( !$userId || ( $op !== '|' && $op !== '&' ) ) {
46 return false; // sanity check
47 }
48 if ( !$dbw instanceof IDatabase ) {
49 $dbw = wfGetDB( DB_MASTER );
50 }
51
52 # To suppress, we OR the current bitfields with Revision::DELETED_USER
53 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
54 # current bitfields with the inverse of Revision::DELETED_USER. The
55 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
56 # The same goes for the sysop-restricted *_deleted bit.
59 if ( $op == '&' ) {
60 $delUser = $dbw->bitNot( $delUser );
61 $delAction = $dbw->bitNot( $delAction );
62 }
63
64 # Normalize user name
65 $userTitle = Title::makeTitleSafe( NS_USER, $name );
66 $userDbKey = $userTitle->getDBkey();
67
68 # Hide name from live edits
69 $dbw->update(
70 'revision',
71 [ self::buildSetBitDeletedField( 'rev_deleted', $op, $delUser, $dbw ) ],
72 [ 'rev_user' => $userId ],
73 __METHOD__ );
74
75 # Hide name from deleted edits
76 $dbw->update(
77 'archive',
78 [ self::buildSetBitDeletedField( 'ar_deleted', $op, $delUser, $dbw ) ],
79 [ 'ar_user_text' => $name ],
80 __METHOD__
81 );
82
83 # Hide name from logs
84 $dbw->update(
85 'logging',
86 [ self::buildSetBitDeletedField( 'log_deleted', $op, $delUser, $dbw ) ],
87 [ 'log_user' => $userId, 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
88 __METHOD__
89 );
90 $dbw->update(
91 'logging',
92 [ self::buildSetBitDeletedField( 'log_deleted', $op, $delAction, $dbw ) ],
93 [ 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
94 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
95 __METHOD__
96 );
97
98 # Hide name from RC
99 $dbw->update(
100 'recentchanges',
101 [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delUser, $dbw ) ],
102 [ 'rc_user_text' => $name ],
103 __METHOD__
104 );
105 $dbw->update(
106 'recentchanges',
107 [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delAction, $dbw ) ],
108 [ 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ],
109 __METHOD__
110 );
111
112 # Hide name from live images
113 $dbw->update(
114 'oldimage',
115 [ self::buildSetBitDeletedField( 'oi_deleted', $op, $delUser, $dbw ) ],
116 [ 'oi_user_text' => $name ],
117 __METHOD__
118 );
119
120 # Hide name from deleted images
121 $dbw->update(
122 'filearchive',
123 [ self::buildSetBitDeletedField( 'fa_deleted', $op, $delUser, $dbw ) ],
124 [ 'fa_user_text' => $name ],
125 __METHOD__
126 );
127 # Done!
128 return true;
129 }
130
131 private static function buildSetBitDeletedField( $field, $op, $value, $dbw ) {
132 return $field . ' = ' . ( $op === '&'
133 ? $dbw->bitAnd( $field, $value )
134 : $dbw->bitOr( $field, $value ) );
135 }
136
137 public static function suppressUserName( $name, $userId, $dbw = null ) {
138 return self::setUsernameBitfields( $name, $userId, '|', $dbw );
139 }
140
141 public static function unsuppressUserName( $name, $userId, $dbw = null ) {
142 return self::setUsernameBitfields( $name, $userId, '&', $dbw );
143 }
144}
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 DELETED_USER
Definition Revision.php:92
const DELETED_RESTRICTED
Definition Revision.php:93
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
const DB_MASTER
Definition defines.php:26