MediaWiki  REL1_19
RevisionDeleteUser.php
Go to the documentation of this file.
00001 <?php
00026 class RevisionDeleteUser {
00027 
00036         private static function setUsernameBitfields( $name, $userId, $op, $dbw ) {
00037                 if( $op !== '|' && $op !== '&' ){
00038                         return false; // sanity check
00039                 }
00040                 if( !$dbw instanceof DatabaseBase ){
00041                         $dbw = wfGetDB( DB_MASTER );
00042                 }
00043 
00044                 # To suppress, we OR the current bitfields with Revision::DELETED_USER
00045                 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
00046                 # current bitfields with the inverse of Revision::DELETED_USER. The
00047                 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
00048                 # The same goes for the sysop-restricted *_deleted bit.
00049                 $delUser = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
00050                 $delAction = LogPage::DELETED_ACTION | Revision::DELETED_RESTRICTED;
00051                 if( $op == '&' ) {
00052                         $delUser = "~{$delUser}";
00053                         $delAction = "~{$delAction}";
00054                 }
00055 
00056                 # Normalize user name
00057                 $userTitle = Title::makeTitleSafe( NS_USER, $name );
00058                 $userDbKey = $userTitle->getDBkey();
00059 
00060                 # Hide name from live edits
00061                 $dbw->update(
00062                         'revision',
00063                         array( "rev_deleted = rev_deleted $op $delUser" ),
00064                         array( 'rev_user' => $userId ),
00065                         __METHOD__ );
00066 
00067                 # Hide name from deleted edits
00068                 $dbw->update(
00069                         'archive',
00070                         array( "ar_deleted = ar_deleted $op $delUser" ),
00071                         array( 'ar_user_text' => $name ),
00072                         __METHOD__
00073                 );
00074 
00075                 # Hide name from logs
00076                 $dbw->update(
00077                         'logging',
00078                         array( "log_deleted = log_deleted $op $delUser" ),
00079                         array( 'log_user' => $userId, "log_type != 'suppress'" ),
00080                         __METHOD__
00081                 );
00082                 $dbw->update(
00083                         'logging',
00084                         array( "log_deleted = log_deleted $op $delAction" ),
00085                         array( 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
00086                                 "log_type != 'suppress'" ),
00087                         __METHOD__
00088                 );
00089 
00090                 # Hide name from RC
00091                 $dbw->update(
00092                         'recentchanges',
00093                         array( "rc_deleted = rc_deleted $op $delUser" ),
00094                         array( 'rc_user_text' => $name ),
00095                         __METHOD__
00096                 );
00097                 $dbw->update(
00098                         'recentchanges',
00099                         array( "rc_deleted = rc_deleted $op $delAction" ),
00100                         array( 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ),
00101                         __METHOD__
00102                 );
00103 
00104                 # Hide name from live images
00105                 $dbw->update(
00106                         'oldimage',
00107                         array( "oi_deleted = oi_deleted $op $delUser" ),
00108                         array( 'oi_user_text' => $name ),
00109                         __METHOD__
00110                 );
00111 
00112                 # Hide name from deleted images
00113                 $dbw->update(
00114                         'filearchive',
00115                         array( "fa_deleted = fa_deleted $op $delUser" ),
00116                         array( 'fa_user_text' => $name ),
00117                         __METHOD__
00118                 );
00119                 # Done!
00120                 return true;
00121         }
00122 
00123         public static function suppressUserName( $name, $userId, $dbw = null ) {
00124                 return self::setUsernameBitfields( $name, $userId, '|', $dbw );
00125         }
00126 
00127         public static function unsuppressUserName( $name, $userId, $dbw = null ) {
00128                 return self::setUsernameBitfields( $name, $userId, '&', $dbw );
00129         }
00130 }