| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\ConfirmEdit\Auth; |
| 4 |
|
| 5 |
use MediaWiki\Auth\AuthenticationRequest; |
| 6 |
use MediaWiki\Auth\AuthManager; |
| 7 |
use MediaWiki\Extension\ConfirmEdit\Hooks; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class CaptchaAuthenticationRequest extends AuthenticationRequest { |
| 14 |
|
| 15 |
public $captchaId; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public $captchaData; |
| 21 |
|
| 22 |
|
| 23 |
public $captchaWord; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public function __construct( $id, $data ) { |
| 30 |
$this->captchaId = $id; |
| 31 |
$this->captchaData = $data; |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
public function getUniqueId() { |
| 36 |
return 'CaptchaAuthenticationRequest'; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function loadFromSubmission( array $data ) { |
| 43 |
$success = parent::loadFromSubmission( $data ); |
| 44 |
if ( $success ) { |
| 45 |
|
| 46 |
$captcha = Hooks::getInstance(); |
| 47 |
$this->captchaData = $captcha->retrieveCaptcha( $this->captchaId ); |
| 48 |
if ( !$this->captchaData ) { |
| 49 |
return false; |
| 50 |
} |
| 51 |
} |
| 52 |
return $success; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function getFieldInfo() { |
| 59 |
$captcha = Hooks::getInstance(); |
| 60 |
|
| 61 |
|
| 62 |
$action = 'generic'; |
| 63 |
switch ( $this->action ) { |
| 64 |
case AuthManager::ACTION_LOGIN: |
| 65 |
$action = 'badlogin'; |
| 66 |
break; |
| 67 |
case AuthManager::ACTION_CREATE: |
| 68 |
$action = 'createaccount'; |
| 69 |
break; |
| 70 |
} |
| 71 |
|
| 72 |
$fields = [ |
| 73 |
'captchaId' => [ |
| 74 |
'type' => 'hidden', |
| 75 |
'value' => $this->captchaId, |
| 76 |
'label' => wfMessage( 'captcha-id-label' ), |
| 77 |
'help' => wfMessage( 'captcha-id-help' ), |
| 78 |
], |
| 79 |
'captchaInfo' => [ |
| 80 |
'type' => 'null', |
| 81 |
'label' => $captcha->getMessage( $action ), |
| 82 |
'value' => $captcha->getCaptchaInfo( $this->captchaData, $this->captchaId ), |
| 83 |
'help' => wfMessage( 'captcha-info-help' ), |
| 84 |
], |
| 85 |
'captchaWord' => [ |
| 86 |
'type' => 'string', |
| 87 |
'label' => wfMessage( 'captcha-label' ), |
| 88 |
'help' => wfMessage( 'captcha-help' ), |
| 89 |
], |
| 90 |
]; |
| 91 |
|
| 92 |
return $fields; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public function getMetadata() { |
| 99 |
return ( Hooks::getInstance() )->describeCaptchaType(); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
public static function __set_state( $data ) { |
| 107 |
$ret = new static( '', [] ); |
| 108 |
foreach ( $data as $k => $v ) { |
| 109 |
$ret->$k = $v; |
| 110 |
} |
| 111 |
return $ret; |
| 112 |
} |
| 113 |
} |