3 abstract class CaptchaStore {
5 * Store the correct answer for a given captcha
7 * @param $info String the captcha result
9 public abstract function store( $index, $info );
12 * Retrieve the answer for a given captcha
13 * @param $index String
16 public abstract function retrieve( $index );
19 * Delete a result once the captcha has been used, so it cannot be reused
22 public abstract function clear( $index );
25 * Whether this type of CaptchaStore needs cookies
28 public abstract function cookiesNeeded();
31 * The singleton instance
34 private static $instance;
37 * Get somewhere to store captcha data that will persist between requests
40 * @return CaptchaStore
42 public final static function get() {
43 if( !self::$instance instanceof self ){
44 global $wgCaptchaStorageClass;
45 if( in_array( 'CaptchaStore', class_parents( $wgCaptchaStorageClass ) ) ) {
46 self::$instance = new $wgCaptchaStorageClass;
48 throw new MWException( "Invalid CaptchaStore class $wgCaptchaStorageClass" );
51 return self::$instance;
55 * Protected constructor: no creating instances except through the factory method above
57 protected function __construct(){}
60 class CaptchaSessionStore extends CaptchaStore {
62 function store( $index, $info ) {
63 $_SESSION['captcha' . $info['index']] = $info;
66 function retrieve( $index ) {
67 if ( isset( $_SESSION['captcha' . $index] ) ) {
68 return $_SESSION['captcha' . $index];
74 function clear( $index ) {
75 unset( $_SESSION['captcha' . $index] );
78 function cookiesNeeded() {
83 class CaptchaCacheStore extends CaptchaStore {
85 function store( $index, $info ) {
86 global $wgMemc, $wgCaptchaSessionExpiration;
87 $wgMemc->set( wfMemcKey( 'captcha', $index ), $info,
88 $wgCaptchaSessionExpiration );
91 function retrieve( $index ) {
93 $info = $wgMemc->get( wfMemcKey( 'captcha', $index ) );
101 function clear( $index ) {
103 $wgMemc->delete( wfMemcKey( 'captcha', $index ) );
106 function cookiesNeeded() {