MediaWiki  1.30.0
CaptchaStore.php
Go to the documentation of this file.
1 <?php
2 
4 
5 abstract 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 
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 }
CaptchaStore\retrieve
retrieve( $index)
Retrieve the answer for a given captcha.
CaptchaStore\store
store( $index, $info)
Store the correct answer for a given captcha.
CaptchaCacheStore\cookiesNeeded
cookiesNeeded()
Whether this type of CaptchaStore needs cookies.
Definition: CaptchaStore.php:117
CaptchaSessionStore\__construct
__construct()
Protected constructor: no creating instances except through the factory method above.
Definition: CaptchaStore.php:71
CaptchaSessionStore
Definition: CaptchaStore.php:70
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
CaptchaSessionStore\store
store( $index, $info)
Store the correct answer for a given captcha.
Definition: CaptchaStore.php:76
CaptchaStore\unsetInstanceForTests
static unsetInstanceForTests()
Definition: CaptchaStore.php:56
CaptchaHashStore\$data
$data
Definition: CaptchaStore.php:123
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
CaptchaStore\clear
clear( $index)
Delete a result once the captcha has been used, so it cannot be reused.
CaptchaSessionStore\cookiesNeeded
cookiesNeeded()
Whether this type of CaptchaStore needs cookies.
Definition: CaptchaStore.php:88
CaptchaCacheStore\retrieve
retrieve( $index)
Retrieve the answer for a given captcha.
Definition: CaptchaStore.php:104
CaptchaStore\cookiesNeeded
cookiesNeeded()
Whether this type of CaptchaStore needs cookies.
MWException
MediaWiki exception.
Definition: MWException.php:26
wfMemcKey
wfMemcKey()
Make a cache key for the local wiki.
Definition: GlobalFunctions.php:2756
ObjectCache\getMainStashInstance
static getMainStashInstance()
Get the cache object for the main stash.
Definition: ObjectCache.php:393
CaptchaHashStore\retrieve
retrieve( $index)
Retrieve the answer for a given captcha.
Definition: CaptchaStore.php:129
CaptchaHashStore\cookiesNeeded
cookiesNeeded()
Whether this type of CaptchaStore needs cookies.
Definition: CaptchaStore.php:140
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
CaptchaCacheStore\clear
clear( $index)
Delete a result once the captcha has been used, so it cannot be reused.
Definition: CaptchaStore.php:113
CaptchaStore
Definition: CaptchaStore.php:5
MediaWiki\Session\SessionManager
This serves as the entry point to the MediaWiki session handling system.
Definition: SessionManager.php:49
CaptchaCacheStore\store
store( $index, $info)
Store the correct answer for a given captcha.
Definition: CaptchaStore.php:94
CaptchaSessionStore\clear
clear( $index)
Delete a result once the captcha has been used, so it cannot be reused.
Definition: CaptchaStore.php:84
CaptchaHashStore
Definition: CaptchaStore.php:122
CaptchaHashStore\clearAll
clearAll()
Definition: CaptchaStore.php:144
CaptchaHashStore\clear
clear( $index)
Delete a result once the captcha has been used, so it cannot be reused.
Definition: CaptchaStore.php:136
CaptchaSessionStore\retrieve
retrieve( $index)
Retrieve the answer for a given captcha.
Definition: CaptchaStore.php:80
CaptchaStore\$instance
static CaptchaStore $instance
The singleton instance.
Definition: CaptchaStore.php:36
CaptchaHashStore\store
store( $index, $info)
Store the correct answer for a given captcha.
Definition: CaptchaStore.php:125
CaptchaCacheStore
Definition: CaptchaStore.php:93
data
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of data
Definition: hooks.txt:6
CaptchaStore\__construct
__construct()
Protected constructor: no creating instances except through the factory method above.
Definition: CaptchaStore.php:66