diff options
Diffstat (limited to 'MLEB/Translate/utils/TranslateSandbox.php')
-rw-r--r-- | MLEB/Translate/utils/TranslateSandbox.php | 87 |
1 files changed, 31 insertions, 56 deletions
diff --git a/MLEB/Translate/utils/TranslateSandbox.php b/MLEB/Translate/utils/TranslateSandbox.php index 125c5afb..6b303081 100644 --- a/MLEB/Translate/utils/TranslateSandbox.php +++ b/MLEB/Translate/utils/TranslateSandbox.php @@ -43,16 +43,13 @@ class TranslateSandbox { 'realname' => '', ]; - $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); + $services = MediaWikiServices::getInstance(); + + $permissionManager = $services->getPermissionManager(); $creator = TranslateUserManager::getUser(); $guard = $permissionManager->addTemporaryUserRights( $creator, 'createaccount' ); - if ( method_exists( MediaWikiServices::class, 'getAuthManager' ) ) { - // MediaWiki 1.35+ - $authManager = MediaWikiServices::getInstance()->getAuthManager(); - } else { - $authManager = AuthManager::singleton(); - } + $authManager = $services->getAuthManager(); $reqs = $authManager->getAuthenticationRequests( AuthManager::ACTION_CREATE ); $reqs = AuthenticationRequest::loadRequestsFromSubmission( $reqs, $data ); $res = $authManager->beginAccountCreation( $creator, $reqs, 'null:' ); @@ -81,12 +78,7 @@ class TranslateSandbox { } // group-translate-sandboxed group-translate-sandboxed-member - if ( method_exists( MediaWikiServices::class, 'getUserGroupManager' ) ) { - // MediaWiki 1.35+ - MediaWikiServices::getInstance()->getUserGroupManager()->addUserToGroup( $user, 'translate-sandboxed' ); - } else { - $user->addGroup( 'translate-sandboxed' ); - } + $services->getUserGroupManager()->addUserToGroup( $user, 'translate-sandboxed' ); return $user; } @@ -107,12 +99,27 @@ class TranslateSandbox { } // Delete from database - $dbw = wfGetDB( DB_MASTER ); + $dbw = wfGetDB( DB_PRIMARY ); $dbw->delete( 'user', [ 'user_id' => $uid ], __METHOD__ ); $dbw->delete( 'user_groups', [ 'ug_user' => $uid ], __METHOD__ ); $dbw->delete( 'user_properties', [ 'up_user' => $uid ], __METHOD__ ); - $dbw->delete( 'actor', [ 'actor_user' => $uid ], __METHOD__ ); + if ( version_compare( MW_VERSION, '1.37', '>=' ) ) { + MediaWikiServices::getInstance()->getActorStore()->deleteActor( $user, $dbw ); + } else { + // MW < 1.37 + $dbw->delete( 'actor', [ 'actor_user' => $uid ], __METHOD__ ); + // In case we create an user with same name as was deleted during the same + // request, we must also reset this cache or the User class will try to load + // stuff for the old id, which is no longer present since we just deleted + // the cache above. But it would have the side effect or overwriting all + // member variables with null data. This used to manifest as a bug where + // inserting a new user fails because the mName properpty is set to null, + // which is then converted as the ip of the current user, and trying to + // add that twice results in a name conflict. It was fun to debug. + // @phan-suppress-next-line PhanUndeclaredStaticMethod + User::resetIdByNameCache(); + } // Assume no joins are needed for logging or recentchanges $dbw->delete( 'logging', [ 'log_actor' => $actorId ], __METHOD__ ); $dbw->delete( 'recentchanges', [ 'rc_actor' => $actorId ], __METHOD__ ); @@ -128,16 +135,6 @@ class TranslateSandbox { // Nobody should access the user by id anymore, but in case they do, purge // the cache so they wont get stale data $user->invalidateCache(); - - // In case we create an user with same name as was deleted during the same - // request, we must also reset this cache or the User class will try to load - // stuff for the old id, which is no longer present since we just deleted - // the cache above. But it would have the side effect or overwriting all - // member variables with null data. This used to manifest as a bug where - // inserting a new user fails because the mName properpty is set to null, - // which is then converted as the ip of the current user, and trying to - // add that twice results in a name conflict. It was fun to debug. - User::resetIdByNameCache(); } /** @@ -175,31 +172,16 @@ class TranslateSandbox { $services = MediaWikiServices::getInstance(); - if ( method_exists( $services, 'getUserGroupManager' ) ) { - // MediaWiki 1.35+ - $userGroupManager = $services->getUserGroupManager(); - $userGroupManager->removeUserFromGroup( $user, 'translate-sandboxed' ); + $userGroupManager = $services->getUserGroupManager(); + $userGroupManager->removeUserFromGroup( $user, 'translate-sandboxed' ); - if ( $wgTranslateSandboxPromotedGroup ) { - $userGroupManager->addUserToGroup( $user, $wgTranslateSandboxPromotedGroup ); - } - } else { - $user->removeGroup( 'translate-sandboxed' ); - - if ( $wgTranslateSandboxPromotedGroup ) { - $user->addGroup( $wgTranslateSandboxPromotedGroup ); - } + if ( $wgTranslateSandboxPromotedGroup ) { + $userGroupManager->addUserToGroup( $user, $wgTranslateSandboxPromotedGroup ); } - if ( method_exists( $services, 'getUserOptionsManager' ) ) { - // MW 1.35+ - $userOptionsManager = $services->getUserOptionsManager(); - $userOptionsManager->setOption( $user, 'translate-sandbox-reminders', '' ); - $userOptionsManager->saveOptions( $user ); - } else { - $user->setOption( 'translate-sandbox-reminders', '' ); - $user->saveSettings(); - } + $userOptionsManager = $services->getUserOptionsManager(); + $userOptionsManager->setOption( $user, 'translate-sandbox-reminders', '' ); + $userOptionsManager->saveOptions( $user ); } /** @@ -270,15 +252,8 @@ class TranslateSandbox { * @since 2013.06 */ public static function isSandboxed( User $user ) { - if ( method_exists( MediaWikiServices::class, 'getUserGroupManager' ) ) { - // MediaWiki 1.35+ - $userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager(); - $groups = $userGroupManager->getUserGroups( $user ); - } else { - $groups = $user->getGroups(); - } - - return in_array( 'translate-sandboxed', $groups, true ); + $userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager(); + return in_array( 'translate-sandboxed', $userGroupManager->getUserGroups( $user ), true ); } /** |