MediaWiki  1.34.0
CaptchaAuthenticationRequest.php
Go to the documentation of this file.
1 <?php
2 
5 
12  public $captchaId;
13 
16  public $captchaData;
17 
19  public $captchaWord;
20 
21  public function __construct( $id, $data ) {
22  $this->captchaId = $id;
23  $this->captchaData = $data;
24  }
25 
26  public function loadFromSubmission( array $data ) {
27  $success = parent::loadFromSubmission( $data );
28  if ( $success ) {
29  // captchaId and captchaWord was set from the submission but captchaData was not.
30  $captcha = ConfirmEditHooks::getInstance();
31  $this->captchaData = $captcha->retrieveCaptcha( $this->captchaId );
32  if ( !$this->captchaData ) {
33  return false;
34  }
35  }
36  return $success;
37  }
38 
43  public function getFieldInfo() {
44  $captcha = ConfirmEditHooks::getInstance();
45 
46  // doesn't actually exist but *Captcha::getMessage will handle that
47  $action = 'generic';
48  switch ( $this->action ) {
49  case AuthManager::ACTION_LOGIN:
50  $action = 'badlogin';
51  break;
52  case AuthManager::ACTION_CREATE:
53  $action = 'createaccount';
54  break;
55  }
56 
57  $fields = [
58  'captchaId' => [
59  'type' => 'hidden',
60  'value' => $this->captchaId,
61  'label' => wfMessage( 'captcha-id-label' ),
62  'help' => wfMessage( 'captcha-id-help' ),
63  ],
64  'captchaInfo' => [
65  'type' => 'null',
66  'label' => $captcha->getMessage( $action ),
67  'value' => $captcha->getCaptchaInfo( $this->captchaData, $this->captchaId ),
68  'help' => wfMessage( 'captcha-info-help' ),
69  ],
70  'captchaWord' => [
71  'type' => 'string',
72  'label' => wfMessage( 'captcha-label' ),
73  'help' => wfMessage( 'captcha-help' ),
74  ],
75  ];
76 
77  return $fields;
78  }
79 
80  public function getMetadata() {
81  $captcha = ConfirmEditHooks::getInstance();
82  return $captcha->describeCaptchaType();
83  }
84 
85  public static function __set_state( $data ) {
86  $ret = new static( null, null );
87  foreach ( $data as $k => $v ) {
88  $ret->$k = $v;
89  }
90  return $ret;
91  }
92 }
CaptchaAuthenticationRequest\getMetadata
getMetadata()
Returns metadata about this request.
Definition: CaptchaAuthenticationRequest.php:80
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1264
ConfirmEditHooks\getInstance
static getInstance()
Get the global Captcha instance.
Definition: ConfirmEditHooks.php:13
$success
$success
Definition: NoLocalSettings.php:42
MediaWiki\Auth\AuthenticationRequest\$action
string null $action
The AuthManager::ACTION_* constant this request was created to be used for.
Definition: AuthenticationRequest.php:58
CaptchaAuthenticationRequest\$captchaData
array $captchaData
Information about the captcha (e.g.
Definition: CaptchaAuthenticationRequest.php:16
CaptchaAuthenticationRequest\$captchaId
string $captchaId
Identifier of the captcha.
Definition: CaptchaAuthenticationRequest.php:12
CaptchaAuthenticationRequest\__set_state
static __set_state( $data)
Implementing this mainly for use from the unit tests.
Definition: CaptchaAuthenticationRequest.php:85
CaptchaAuthenticationRequest\getFieldInfo
getFieldInfo()
Fetch input field info.The field info is an associative array mapping field names to info arrays....
Definition: CaptchaAuthenticationRequest.php:43
CaptchaAuthenticationRequest\$captchaWord
string $captchaWord
Captcha solution submitted by the user.
Definition: CaptchaAuthenticationRequest.php:19
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:85
CaptchaAuthenticationRequest\__construct
__construct( $id, $data)
Definition: CaptchaAuthenticationRequest.php:21
CaptchaAuthenticationRequest\loadFromSubmission
loadFromSubmission(array $data)
Initialize form submitted form data.
Definition: CaptchaAuthenticationRequest.php:26
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:37
CaptchaAuthenticationRequest
Generic captcha authentication request class.
Definition: CaptchaAuthenticationRequest.php:10