Merge "Add ss_active_users in SiteStats::isSane"
[mediawiki.git] / includes / revisiondelete / RevisionDeleteUser.php
blob4505ee10c2bb9fd34954b11b1cf026b5f10bc9cc
1 <?php
2 /**
3 * Backend functions for suppressing and unsuppressing all references to a given user.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup RevisionDelete
24 /**
25 * Backend functions for suppressing and unsuppressing all references to a given user,
26 * used when blocking with HideUser enabled. This was spun out of SpecialBlockip.php
27 * in 1.18; at some point it needs to be rewritten to either use RevisionDelete abstraction,
28 * or at least schema abstraction.
30 * @ingroup RevisionDelete
32 class RevisionDeleteUser {
34 /**
35 * Update *_deleted bitfields in various tables to hide or unhide usernames
36 * @param $name String username
37 * @param $userId Int user id
38 * @param $op String operator '|' or '&'
39 * @param $dbw null|DatabaseBase, if you happen to have one lying around
40 * @return bool
42 private static function setUsernameBitfields( $name, $userId, $op, $dbw ) {
43 if ( !$userId || ( $op !== '|' && $op !== '&' ) ) {
44 return false; // sanity check
46 if ( !$dbw instanceof DatabaseBase ) {
47 $dbw = wfGetDB( DB_MASTER );
50 # To suppress, we OR the current bitfields with Revision::DELETED_USER
51 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
52 # current bitfields with the inverse of Revision::DELETED_USER. The
53 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
54 # The same goes for the sysop-restricted *_deleted bit.
55 $delUser = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
56 $delAction = LogPage::DELETED_ACTION | Revision::DELETED_RESTRICTED;
57 if ( $op == '&' ) {
58 $delUser = "~{$delUser}";
59 $delAction = "~{$delAction}";
62 # Normalize user name
63 $userTitle = Title::makeTitleSafe( NS_USER, $name );
64 $userDbKey = $userTitle->getDBkey();
66 # Hide name from live edits
67 $dbw->update(
68 'revision',
69 array( "rev_deleted = rev_deleted $op $delUser" ),
70 array( 'rev_user' => $userId ),
71 __METHOD__ );
73 # Hide name from deleted edits
74 $dbw->update(
75 'archive',
76 array( "ar_deleted = ar_deleted $op $delUser" ),
77 array( 'ar_user_text' => $name ),
78 __METHOD__
81 # Hide name from logs
82 $dbw->update(
83 'logging',
84 array( "log_deleted = log_deleted $op $delUser" ),
85 array( 'log_user' => $userId, "log_type != 'suppress'" ),
86 __METHOD__
88 $dbw->update(
89 'logging',
90 array( "log_deleted = log_deleted $op $delAction" ),
91 array( 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
92 "log_type != 'suppress'" ),
93 __METHOD__
96 # Hide name from RC
97 $dbw->update(
98 'recentchanges',
99 array( "rc_deleted = rc_deleted $op $delUser" ),
100 array( 'rc_user_text' => $name ),
101 __METHOD__
103 $dbw->update(
104 'recentchanges',
105 array( "rc_deleted = rc_deleted $op $delAction" ),
106 array( 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ),
107 __METHOD__
110 # Hide name from live images
111 $dbw->update(
112 'oldimage',
113 array( "oi_deleted = oi_deleted $op $delUser" ),
114 array( 'oi_user_text' => $name ),
115 __METHOD__
118 # Hide name from deleted images
119 $dbw->update(
120 'filearchive',
121 array( "fa_deleted = fa_deleted $op $delUser" ),
122 array( 'fa_user_text' => $name ),
123 __METHOD__
125 # Done!
126 return true;
129 public static function suppressUserName( $name, $userId, $dbw = null ) {
130 return self::setUsernameBitfields( $name, $userId, '|', $dbw );
133 public static function unsuppressUserName( $name, $userId, $dbw = null ) {
134 return self::setUsernameBitfields( $name, $userId, '&', $dbw );