MediaWiki REL1_30
CaptchaStore.php
Go to the documentation of this file.
1<?php
2
4
5abstract class CaptchaStore {
11 abstract public function store( $index, $info );
12
18 abstract public function retrieve( $index );
19
24 abstract public function clear( $index );
25
30 abstract public function cookiesNeeded();
31
36 private static $instance;
37
44 final public static function get() {
45 if ( !self::$instance instanceof self ) {
46 global $wgCaptchaStorageClass;
47 if ( in_array( 'CaptchaStore', class_parents( $wgCaptchaStorageClass ) ) ) {
48 self::$instance = new $wgCaptchaStorageClass;
49 } else {
50 throw new Exception( "Invalid CaptchaStore class $wgCaptchaStorageClass" );
51 }
52 }
53 return self::$instance;
54 }
55
56 final public static function unsetInstanceForTests() {
57 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
58 throw new MWException( 'Cannot unset ' . __CLASS__ . ' instance in operation.' );
59 }
60 self::$instance = null;
61 }
62
66 protected function __construct() {
67 }
68}
69
71 protected function __construct() {
72 // Make sure the session is started
73 SessionManager::getGlobalSession()->persist();
74 }
75
76 function store( $index, $info ) {
77 SessionManager::getGlobalSession()->set( 'captcha' . $index, $info );
78 }
79
80 function retrieve( $index ) {
81 return SessionManager::getGlobalSession()->get( 'captcha' . $index, false );
82 }
83
84 function clear( $index ) {
85 SessionManager::getGlobalSession()->remove( 'captcha' . $index );
86 }
87
88 function cookiesNeeded() {
89 return true;
90 }
91}
92
94 function store( $index, $info ) {
95 global $wgCaptchaSessionExpiration;
96
97 ObjectCache::getMainStashInstance()->set(
98 wfMemcKey( 'captcha', $index ),
99 $info,
100 $wgCaptchaSessionExpiration
101 );
102 }
103
104 function retrieve( $index ) {
105 $info = ObjectCache::getMainStashInstance()->get( wfMemcKey( 'captcha', $index ) );
106 if ( $info ) {
107 return $info;
108 } else {
109 return false;
110 }
111 }
112
113 function clear( $index ) {
114 ObjectCache::getMainStashInstance()->delete( wfMemcKey( 'captcha', $index ) );
115 }
116
117 function cookiesNeeded() {
118 return false;
119 }
120}
121
123 protected $data = [];
124
125 public function store( $index, $info ) {
126 $this->data[$index] = $info;
127 }
128
129 public function retrieve( $index ) {
130 if ( array_key_exists( $index, $this->data ) ) {
131 return $this->data[$index];
132 }
133 return false;
134 }
135
136 public function clear( $index ) {
137 unset( $this->data[$index] );
138 }
139
140 public function cookiesNeeded() {
141 return false;
142 }
143
144 public function clearAll() {
145 $this->data = [];
146 }
147}
wfMemcKey()
Make a cache key for the local wiki.
retrieve( $index)
Retrieve the answer for a given captcha.
clear( $index)
Delete a result once the captcha has been used, so it cannot be reused.
cookiesNeeded()
Whether this type of CaptchaStore needs cookies.
store( $index, $info)
Store the correct answer for a given captcha.
cookiesNeeded()
Whether this type of CaptchaStore needs cookies.
retrieve( $index)
Retrieve the answer for a given captcha.
clear( $index)
Delete a result once the captcha has been used, so it cannot be reused.
store( $index, $info)
Store the correct answer for a given captcha.
__construct()
Protected constructor: no creating instances except through the factory method above.
clear( $index)
Delete a result once the captcha has been used, so it cannot be reused.
cookiesNeeded()
Whether this type of CaptchaStore needs cookies.
retrieve( $index)
Retrieve the answer for a given captcha.
store( $index, $info)
Store the correct answer for a given captcha.
__construct()
Protected constructor: no creating instances except through the factory method above.
cookiesNeeded()
Whether this type of CaptchaStore needs cookies.
static unsetInstanceForTests()
clear( $index)
Delete a result once the captcha has been used, so it cannot be reused.
static CaptchaStore $instance
The singleton instance.
store( $index, $info)
Store the correct answer for a given captcha.
retrieve( $index)
Retrieve the answer for a given captcha.
MediaWiki exception.
This serves as the entry point to the MediaWiki session handling system.