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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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
const NS_USER
Definition Defines.php:67
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
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
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
const DB_MASTER
Definition defines.php:26