MediaWiki REL1_34
CaptchaAuthenticationRequest.php
Go to the documentation of this file.
1<?php
2
5
12 public $captchaId;
13
17
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}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Generic captcha authentication request class.
string $captchaWord
Captcha solution submitted by the user.
string $captchaId
Identifier of the captcha.
getMetadata()
Returns metadata about this request.
getFieldInfo()
Fetch input field info.The field info is an associative array mapping field names to info arrays....
static __set_state( $data)
Implementing this mainly for use from the unit tests.
array $captchaData
Information about the captcha (e.g.
loadFromSubmission(array $data)
Initialize form submitted form data.
This serves as the entry point to the authentication system.
This is a value object for authentication requests.
string null $action
The AuthManager::ACTION_* constant this request was created to be used for.