From bb201b86e44cd1b77be29b94d492b66dbe61357d Mon Sep 17 00:00:00 2001 From: Derick Alangi Date: Mon, 20 Nov 2023 18:34:02 +0100 Subject: [PATCH] Store: Enable ConfirmEdit to use MicroStash for captcha storage ConfirmEdit uses MainStash as the backend to write its captchas. We are migrating this extension to use the MicroStash store instead which is more suitable. This patch will store the captcha in MicroStash, read it from there or fallback to MainStash if lookup was not successful. The code will then clear both stores once after processing. Migration plan ============== step .1: Write to microstash store only, read from it or fallback to mainstash store. Then delete from both backends. step .2: Read from microstash store only, delete from the microstash store, and remove dead code afterward. Bug: T336004 Change-Id: Ie7c50a6efe7a0aefc97a712b2ad961e7837cc4cf --- includes/Store/CaptchaCacheStore.php | 35 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/includes/Store/CaptchaCacheStore.php b/includes/Store/CaptchaCacheStore.php index 625906f15..9733ca88c 100644 --- a/includes/Store/CaptchaCacheStore.php +++ b/includes/Store/CaptchaCacheStore.php @@ -7,12 +7,17 @@ use MediaWiki\MediaWikiServices; class CaptchaCacheStore extends CaptchaStore { /** @var BagOStuff */ - private $store; + private $mainStashStore; + + /** @var BagOStuff */ + private $microStashStore; public function __construct() { parent::__construct(); - $this->store = MediaWikiServices::getInstance()->getMainObjectStash(); + $services = MediaWikiServices::getInstance(); + $this->mainStashStore = $services->getMainObjectStash(); + $this->microStashStore = $services->getMicroStash(); } /** @@ -21,14 +26,14 @@ class CaptchaCacheStore extends CaptchaStore { public function store( $index, $info ) { global $wgCaptchaSessionExpiration; - $store = $this->store; - $store->set( - $store->makeKey( 'captcha', $index ), + $microStashStore = $this->microStashStore; + $microStashStore->set( + $microStashStore->makeKey( 'captcha', $index ), $info, $wgCaptchaSessionExpiration, // Assume the write will reach the master DC before the user sends the // HTTP POST request attempted to solve the captcha and perform an action - $store::WRITE_BACKGROUND + $microStashStore::WRITE_BACKGROUND ); } @@ -36,16 +41,26 @@ class CaptchaCacheStore extends CaptchaStore { * @inheritDoc */ public function retrieve( $index ) { - $store = $this->store; - return $store->get( $store->makeKey( 'captcha', $index ) ) ?: false; + $microStashStore = $this->microStashStore; + $data = $microStashStore->get( $microStashStore->makeKey( 'captcha', $index ) ); + + if ( !$data ) { + $mainStashStore = $this->mainStashStore; + $data = $mainStashStore->get( $mainStashStore->makeKey( 'captcha', $index ) ); + } + + return $data; } /** * @inheritDoc */ public function clear( $index ) { - $store = $this->store; - $store->delete( $store->makeKey( 'captcha', $index ) ); + $mainStashStore = $this->mainStashStore; + $mainStashStore->delete( $mainStashStore->makeKey( 'captcha', $index ) ); + + $microStashStore = $this->microStashStore; + $microStashStore->delete( $microStashStore->makeKey( 'captcha', $index ) ); } public function cookiesNeeded() {