MediaWiki fundraising/REL1_35
RevisionDeleteUser.php
Go to the documentation of this file.
1<?php
26
36
46 private static function setUsernameBitfields( $name, $userId, $op, IDatabase $dbw = null ) {
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 RevisionRecord::DELETED_USER
55 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
56 # current bitfields with the inverse of RevisionRecord::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 = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
60 $delAction = LogPage::DELETED_ACTION | RevisionRecord::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
70 $actorId = $dbw->selectField( 'actor', 'actor_id', [ 'actor_name' => $name ], __METHOD__ );
71 if ( $actorId ) {
72 # Hide name from live edits
73 $ids = $dbw->selectFieldValues(
74 'revision_actor_temp', 'revactor_rev', [ 'revactor_actor' => $actorId ], __METHOD__
75 );
76 if ( $ids ) {
77 $dbw->update(
78 'revision',
79 [ self::buildSetBitDeletedField( 'rev_deleted', $op, $delUser, $dbw ) ],
80 [ 'rev_id' => $ids ],
81 __METHOD__
82 );
83 }
84
85 # Hide name from deleted edits
86 $dbw->update(
87 'archive',
88 [ self::buildSetBitDeletedField( 'ar_deleted', $op, $delUser, $dbw ) ],
89 [ 'ar_actor' => $actorId ],
90 __METHOD__
91 );
92
93 # Hide name from logs
94 $dbw->update(
95 'logging',
96 [ self::buildSetBitDeletedField( 'log_deleted', $op, $delUser, $dbw ) ],
97 [ 'log_actor' => $actorId, 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
98 __METHOD__
99 );
100
101 # Hide name from RC
102 $dbw->update(
103 'recentchanges',
104 [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delUser, $dbw ) ],
105 [ 'rc_actor' => $actorId ],
106 __METHOD__
107 );
108
109 # Hide name from live images
110 $dbw->update(
111 'oldimage',
112 [ self::buildSetBitDeletedField( 'oi_deleted', $op, $delUser, $dbw ) ],
113 [ 'oi_actor' => $actorId ],
114 __METHOD__
115 );
116
117 # Hide name from deleted images
118 $dbw->update(
119 'filearchive',
120 [ self::buildSetBitDeletedField( 'fa_deleted', $op, $delUser, $dbw ) ],
121 [ 'fa_actor' => $actorId ],
122 __METHOD__
123 );
124 }
125
126 # Hide log entries pointing to the user page
127 $dbw->update(
128 'logging',
129 [ self::buildSetBitDeletedField( 'log_deleted', $op, $delAction, $dbw ) ],
130 [ 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
131 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
132 __METHOD__
133 );
134
135 # Hide RC entries pointing to the user page
136 $dbw->update(
137 'recentchanges',
138 [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delAction, $dbw ) ],
139 [ 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ],
140 __METHOD__
141 );
142
143 return true;
144 }
145
146 private static function buildSetBitDeletedField( $field, $op, $value, IDatabase $dbw ) {
147 return $field . ' = ' . ( $op === '&'
148 ? $dbw->bitAnd( $field, $value )
149 : $dbw->bitOr( $field, $value ) );
150 }
151
158 public static function suppressUserName( $name, $userId, IDatabase $dbw = null ) {
159 return self::setUsernameBitfields( $name, $userId, '|', $dbw );
160 }
161
168 public static function unsuppressUserName( $name, $userId, IDatabase $dbw = null ) {
169 return self::setUsernameBitfields( $name, $userId, '&', $dbw );
170 }
171}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
const DELETED_ACTION
Definition LogPage.php:38
Page revision base class.
Backend functions for suppressing and unsuppressing all references to a given user,...
static setUsernameBitfields( $name, $userId, $op, IDatabase $dbw=null)
Update *_deleted bitfields in various tables to hide or unhide usernames.
static suppressUserName( $name, $userId, IDatabase $dbw=null)
static buildSetBitDeletedField( $field, $op, $value, IDatabase $dbw)
static unsuppressUserName( $name, $userId, IDatabase $dbw=null)
const NS_USER
Definition Defines.php:72
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
bitAnd( $fieldLeft, $fieldRight)
bitOr( $fieldLeft, $fieldRight)
const DB_MASTER
Definition defines.php:29