2017-12-16 12:32:46 +00:00
|
|
|
<?php
|
|
|
|
|
2022-04-08 16:40:15 +00:00
|
|
|
namespace MediaWiki\Extension\ConfirmEdit\Store;
|
|
|
|
|
|
|
|
use BagOStuff;
|
2019-05-05 14:40:54 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2017-12-16 12:32:46 +00:00
|
|
|
class CaptchaCacheStore extends CaptchaStore {
|
2019-05-05 14:40:54 +00:00
|
|
|
/** @var BagOStuff */
|
2023-11-20 17:34:02 +00:00
|
|
|
private $mainStashStore;
|
|
|
|
|
|
|
|
/** @var BagOStuff */
|
|
|
|
private $microStashStore;
|
2019-05-05 14:40:54 +00:00
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
2023-11-20 17:34:02 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$this->mainStashStore = $services->getMainObjectStash();
|
|
|
|
$this->microStashStore = $services->getMicroStash();
|
2019-05-05 14:40:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 23:29:18 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2018-06-15 21:08:14 +00:00
|
|
|
public function store( $index, $info ) {
|
2017-12-16 12:32:46 +00:00
|
|
|
global $wgCaptchaSessionExpiration;
|
|
|
|
|
2023-11-20 17:34:02 +00:00
|
|
|
$microStashStore = $this->microStashStore;
|
|
|
|
$microStashStore->set(
|
|
|
|
$microStashStore->makeKey( 'captcha', $index ),
|
2017-12-16 12:32:46 +00:00
|
|
|
$info,
|
2023-06-06 19:57:53 +00:00
|
|
|
$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
|
2023-11-20 17:34:02 +00:00
|
|
|
$microStashStore::WRITE_BACKGROUND
|
2017-12-16 12:32:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-14 23:29:18 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2018-06-15 21:08:14 +00:00
|
|
|
public function retrieve( $index ) {
|
2023-11-20 17:34:02 +00:00
|
|
|
$microStashStore = $this->microStashStore;
|
|
|
|
$data = $microStashStore->get( $microStashStore->makeKey( 'captcha', $index ) );
|
|
|
|
|
|
|
|
if ( !$data ) {
|
|
|
|
$mainStashStore = $this->mainStashStore;
|
|
|
|
$data = $mainStashStore->get( $mainStashStore->makeKey( 'captcha', $index ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
2017-12-16 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 23:29:18 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2018-06-15 21:08:14 +00:00
|
|
|
public function clear( $index ) {
|
2023-11-20 17:34:02 +00:00
|
|
|
$mainStashStore = $this->mainStashStore;
|
|
|
|
$mainStashStore->delete( $mainStashStore->makeKey( 'captcha', $index ) );
|
|
|
|
|
|
|
|
$microStashStore = $this->microStashStore;
|
|
|
|
$microStashStore->delete( $microStashStore->makeKey( 'captcha', $index ) );
|
2017-12-16 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 21:08:14 +00:00
|
|
|
public function cookiesNeeded() {
|
2017-12-16 12:32:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-04-08 16:40:15 +00:00
|
|
|
|
|
|
|
class_alias( CaptchaCacheStore::class, 'CaptchaCacheStore' );
|