2017-12-16 12:32:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class CaptchaStore {
|
|
|
|
/**
|
|
|
|
* Store the correct answer for a given captcha
|
|
|
|
* @param string $index
|
2019-05-26 20:19:03 +00:00
|
|
|
* @param array $info the captcha result
|
2017-12-16 12:32:46 +00:00
|
|
|
*/
|
|
|
|
abstract public function store( $index, $info );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the answer for a given captcha
|
|
|
|
* @param string $index
|
2019-05-26 20:19:03 +00:00
|
|
|
* @return array|false
|
2017-12-16 12:32:46 +00:00
|
|
|
*/
|
|
|
|
abstract public function retrieve( $index );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a result once the captcha has been used, so it cannot be reused
|
|
|
|
* @param string $index
|
|
|
|
*/
|
|
|
|
abstract public function clear( $index );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this type of CaptchaStore needs cookies
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
abstract public function cookiesNeeded();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The singleton instance
|
2019-12-21 02:46:59 +00:00
|
|
|
* @var CaptchaStore|null
|
2017-12-16 12:32:46 +00:00
|
|
|
*/
|
|
|
|
private static $instance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get somewhere to store captcha data that will persist between requests
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
* @return CaptchaStore
|
|
|
|
*/
|
|
|
|
final public static function get() {
|
2021-09-08 18:12:24 +00:00
|
|
|
global $wgCaptchaStorageClass;
|
2017-12-16 12:32:46 +00:00
|
|
|
if ( !self::$instance instanceof self ) {
|
|
|
|
if ( in_array( 'CaptchaStore', class_parents( $wgCaptchaStorageClass ) ) ) {
|
|
|
|
self::$instance = new $wgCaptchaStorageClass;
|
|
|
|
} else {
|
|
|
|
throw new Exception( "Invalid CaptchaStore class $wgCaptchaStorageClass" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public static function unsetInstanceForTests() {
|
|
|
|
if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
|
|
|
|
throw new MWException( 'Cannot unset ' . __CLASS__ . ' instance in operation.' );
|
|
|
|
}
|
|
|
|
self::$instance = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Protected constructor: no creating instances except through the factory method above
|
|
|
|
*/
|
|
|
|
protected function __construct() {
|
|
|
|
}
|
|
|
|
}
|