summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/ConfirmEdit/includes/store/CaptchaStore.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/ConfirmEdit/includes/store/CaptchaStore.php')
-rw-r--r--www/wiki/extensions/ConfirmEdit/includes/store/CaptchaStore.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/www/wiki/extensions/ConfirmEdit/includes/store/CaptchaStore.php b/www/wiki/extensions/ConfirmEdit/includes/store/CaptchaStore.php
new file mode 100644
index 00000000..20cb6a26
--- /dev/null
+++ b/www/wiki/extensions/ConfirmEdit/includes/store/CaptchaStore.php
@@ -0,0 +1,66 @@
+<?php
+
+abstract class CaptchaStore {
+ /**
+ * Store the correct answer for a given captcha
+ * @param string $index
+ * @param string $info the captcha result
+ */
+ abstract public function store( $index, $info );
+
+ /**
+ * Retrieve the answer for a given captcha
+ * @param string $index
+ * @return string|false
+ */
+ 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
+ * @var CaptchaStore
+ */
+ private static $instance;
+
+ /**
+ * Get somewhere to store captcha data that will persist between requests
+ *
+ * @throws Exception
+ * @return CaptchaStore
+ */
+ final public static function get() {
+ if ( !self::$instance instanceof self ) {
+ global $wgCaptchaStorageClass;
+ 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() {
+ }
+}