MediaWiki REL1_39
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;
49 }
50 if ( !$dbw instanceof IDatabase ) {
51 $dbw = wfGetDB( DB_PRIMARY );
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 $dbw->update(
74 'revision',
75 [ self::buildSetBitDeletedField( 'rev_deleted', $op, $delUser, $dbw ) ],
76 [ 'rev_actor' => $actorId ],
77 __METHOD__
78 );
79
80 # Hide name from deleted edits
81 $dbw->update(
82 'archive',
83 [ self::buildSetBitDeletedField( 'ar_deleted', $op, $delUser, $dbw ) ],
84 [ 'ar_actor' => $actorId ],
85 __METHOD__
86 );
87
88 # Hide name from logs
89 $dbw->update(
90 'logging',
91 [ self::buildSetBitDeletedField( 'log_deleted', $op, $delUser, $dbw ) ],
92 [ 'log_actor' => $actorId, 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
93 __METHOD__
94 );
95
96 # Hide name from RC
97 $dbw->update(
98 'recentchanges',
99 [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delUser, $dbw ) ],
100 [ 'rc_actor' => $actorId ],
101 __METHOD__
102 );
103
104 # Hide name from live images
105 $dbw->update(
106 'oldimage',
107 [ self::buildSetBitDeletedField( 'oi_deleted', $op, $delUser, $dbw ) ],
108 [ 'oi_actor' => $actorId ],
109 __METHOD__
110 );
111
112 # Hide name from deleted images
113 $dbw->update(
114 'filearchive',
115 [ self::buildSetBitDeletedField( 'fa_deleted', $op, $delUser, $dbw ) ],
116 [ 'fa_actor' => $actorId ],
117 __METHOD__
118 );
119 }
120
121 # Hide log entries pointing to the user page
122 $dbw->update(
123 'logging',
124 [ self::buildSetBitDeletedField( 'log_deleted', $op, $delAction, $dbw ) ],
125 [ 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
126 'log_type != ' . $dbw->addQuotes( 'suppress' ) ],
127 __METHOD__
128 );
129
130 # Hide RC entries pointing to the user page
131 $dbw->update(
132 'recentchanges',
133 [ self::buildSetBitDeletedField( 'rc_deleted', $op, $delAction, $dbw ) ],
134 [ 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ],
135 __METHOD__
136 );
137
138 return true;
139 }
140
141 private static function buildSetBitDeletedField( $field, $op, $value, IDatabase $dbw ) {
142 return $field . ' = ' . ( $op === '&'
143 ? $dbw->bitAnd( $field, $value )
144 : $dbw->bitOr( $field, $value ) );
145 }
146
153 public static function suppressUserName( $name, $userId, IDatabase $dbw = null ) {
154 return self::setUsernameBitfields( $name, $userId, '|', $dbw );
155 }
156
163 public static function unsuppressUserName( $name, $userId, IDatabase $dbw = null ) {
164 return self::setUsernameBitfields( $name, $userId, '&', $dbw );
165 }
166}
const NS_USER
Definition Defines.php:66
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
const DELETED_ACTION
Definition LogPage.php:40
Page revision base class.
Backend functions for suppressing and unsuppressing all references to a given user,...
static suppressUserName( $name, $userId, IDatabase $dbw=null)
static unsuppressUserName( $name, $userId, IDatabase $dbw=null)
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39
bitOr( $fieldLeft, $fieldRight)
bitAnd( $fieldLeft, $fieldRight)
const DB_PRIMARY
Definition defines.php:28