From 4e0570e5cfb4c6d2454d9d27fa52bfb684c55920 Mon Sep 17 00:00:00 2001 From: Wandji69 Date: Mon, 10 Jun 2024 02:37:01 +0100 Subject: [PATCH] Use ObjectCacheFactory methods Bug: T363770 Change-Id: I66ffd2d559a22c72a72b1f664a9332900704d503 --- FancyCaptcha/includes/FancyCaptcha.php | 7 +++---- includes/Auth/LoginAttemptCounter.php | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/FancyCaptcha/includes/FancyCaptcha.php b/FancyCaptcha/includes/FancyCaptcha.php index 3df08fc04..90512f58f 100644 --- a/FancyCaptcha/includes/FancyCaptcha.php +++ b/FancyCaptcha/includes/FancyCaptcha.php @@ -16,7 +16,6 @@ use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\Utils\MWTimestamp; use MediaWiki\WikiMap\WikiMap; use NullLockManager; -use ObjectCache; use StatusValue; use UnderflowException; @@ -223,7 +222,7 @@ class FancyCaptcha extends SimpleCaptcha { } $backend = $this->getBackend(); - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); $key = $cache->makeGlobalKey( 'fancycaptcha-dirlist', @@ -283,7 +282,7 @@ class FancyCaptcha extends SimpleCaptcha { */ protected function pickImageFromDir( $directory, &$lockouts ) { $backend = $this->getBackend(); - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); $key = $cache->makeGlobalKey( 'fancycaptcha-filelist', @@ -341,7 +340,7 @@ class FancyCaptcha extends SimpleCaptcha { } $backend = $this->getBackend(); - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); // pick a random file $place = mt_rand( 0, count( $files ) - 1 ); diff --git a/includes/Auth/LoginAttemptCounter.php b/includes/Auth/LoginAttemptCounter.php index 546501300..2e1f471e2 100644 --- a/includes/Auth/LoginAttemptCounter.php +++ b/includes/Auth/LoginAttemptCounter.php @@ -8,7 +8,6 @@ use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha; use MediaWiki\MediaWikiServices; use MediaWiki\User\User; use MediaWiki\User\UserNameUtils; -use ObjectCache; /** * Helper to count login attempts per IP and per username. @@ -31,7 +30,7 @@ class LoginAttemptCounter { public function increaseBadLoginCounter( $username ) { global $wgCaptchaBadLoginExpiration, $wgCaptchaBadLoginPerUserExpiration; - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); if ( $this->captcha->triggersCaptcha( CaptchaTriggers::BAD_LOGIN ) ) { $key = $this->badLoginKey( $cache ); @@ -50,7 +49,7 @@ class LoginAttemptCounter { */ public function resetBadLoginCounter( $username ) { if ( $this->captcha->triggersCaptcha( CaptchaTriggers::BAD_LOGIN_PER_USER ) && $username ) { - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); $cache->delete( $this->badLoginPerUserKey( $username, $cache ) ); } } @@ -63,7 +62,7 @@ class LoginAttemptCounter { public function isBadLoginTriggered() { global $wgCaptchaBadLoginAttempts; - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); return $this->captcha->triggersCaptcha( CaptchaTriggers::BAD_LOGIN ) && (int)$cache->get( $this->badLoginKey( $cache ) ) >= $wgCaptchaBadLoginAttempts; } @@ -77,7 +76,7 @@ class LoginAttemptCounter { public function isBadLoginPerUserTriggered( $u ) { global $wgCaptchaBadLoginPerUserAttempts; - $cache = ObjectCache::getLocalClusterInstance(); + $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); if ( is_object( $u ) ) { $u = $u->getName();