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