Go to the documentation of this file.
8 protected static $messagePrefix =
'renocaptcha-';
10 private $error =
null;
18 global $wgReCaptchaSiteKey,
$wgLang;
19 $lang = htmlspecialchars( urlencode(
$wgLang->getCode() ) );
21 $output = Html::element(
'div', [
24 'mw-confirmedit-captcha-fail' => (
bool)$this->error,
26 'data-sitekey' => $wgReCaptchaSiteKey
28 $htmlUrlencoded = htmlspecialchars( urlencode( $wgReCaptchaSiteKey ) );
32 <div style=
"width: 302px; height: 422px; position: relative;">
33 <div style=
"width: 302px; height: 422px; position: absolute;">
34 <iframe src=
"https://www.google.com/recaptcha/api/fallback?k={$htmlUrlencoded}&hl={$lang}"
35 frameborder=
"0" scrolling=
"no"
36 style=
"width: 302px; height:422px; border-style: none;">
40 <div style=
"width: 300px; height: 60px; border-style: none;
41 bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px;
42 background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px;">
43 <textarea
id=
"g-recaptcha-response" name=
"g-recaptcha-response"
44 class=
"g-recaptcha-response"
45 style=
"width: 250px; height: 40px; border: 1px solid #c1c1c1;
46 margin: 10px 25px; padding: 0px; resize: none;" >
58 "<script src=\"https://www.google.com/recaptcha/api.js?hl={$lang}\" async defer></script>"
66 protected function logCheckError( $info ) {
67 if ( $info instanceof
Status ) {
68 $errors = $info->getErrorsArray();
69 $error = $errors[0][0];
70 } elseif ( is_array( $info ) ) {
71 $error = implode(
',', $info );
76 wfDebugLog(
'captcha',
'Unable to validate response: ' . $error );
89 $request->
getVal(
'captchaWord',
90 $request->
getVal(
'captchaword' )
106 global
$wgRequest, $wgReCaptchaSecretKey, $wgReCaptchaSendRemoteIP;
108 $url =
'https://www.google.com/recaptcha/api/siteverify';
111 'secret' => $wgReCaptchaSecretKey,
114 if ( $wgReCaptchaSendRemoteIP ) {
121 $this->error =
'http';
122 $this->logCheckError(
$status );
127 $this->error =
'json';
128 $this->logCheckError( $this->error );
131 if ( isset(
$response[
'error-codes'] ) ) {
132 $this->error =
'recaptcha-api';
133 $this->logCheckError(
$response[
'error-codes'] );
145 $resultArr[
'captcha'][
'error'] = $this->error;
152 global $wgReCaptchaSiteKey;
154 'type' =>
'recaptchanocaptcha',
155 'mime' =>
'image/png',
156 'key' => $wgReCaptchaSiteKey,
168 $msg = parent::getMessage( $action );
169 if ( $this->error ) {
170 $msg =
new RawMessage(
'<div class="error">$1</div>', [ $msg ] );
183 $params[
'g-recaptcha-response'] = [
203 return [
'index' => $index ];
234 array $requests, array $fieldInfo, array &$formDescriptor, $action
236 global $wgReCaptchaSiteKey;
238 $req = AuthenticationRequest::getRequestByClass( $requests,
239 CaptchaAuthenticationRequest::class,
true );
247 $formDescriptor[
'captchaWord'] = [
248 'class' => HTMLReCaptchaNoCaptchaField::class,
249 'key' => $wgReCaptchaSiteKey,
250 'error' => $captcha->getError(),
251 ] + $formDescriptor[
'captchaWord'];
if(!isset( $args[0])) $lang
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static getInstance()
Get the global Captcha instance.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getCaptchaInfo( $captchaData, $id)
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
addCaptchaAPI(&$resultArr)
Authentication request for ReCaptcha v2.
getCaptcha()
Returns an array with 'question' and 'answer' keys.
getCaptchaParamsFromRequest(WebRequest $request)
onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
Modify the appearance of the captcha field.
apiGetAllowedParams(&$module, &$params, $flags)
retrieveCaptcha( $index)
Fetch this session's captcha info.
createAuthenticationRequest()
Demo CAPTCHA (not for production usage) and base class for real CAPTCHAs.
getError()
Return the error from the last passCaptcha* call.
storeCaptcha( $info)
Generate a captcha session ID and save the info in PHP's session storage.
getMessage( $action)
Show a message asking the user to enter a captcha on edit The result will be treated as wiki text.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
describeCaptchaType()
Describes the captcha type for API clients.
isAPICaptchaModule( $module)
getVal( $name, $default=null)
Fetch a scalar from the input or return $default if it's not set.
passCaptcha( $index, $word)
Given a required captcha run, test form input for correct input on the open session.
if(! $wgDBerrorLogTZ) $wgRequest
Variant of the Message class.
getFormInformation( $tabIndex=1)
Insert a captcha prompt into the edit form.
static factory( $url, array $options=null, $caller=__METHOD__)
Generate a new request object.