SimpleCaptcha: Show captcha-edit message if forceShowCaptcha is set

Why:

- forceShowCaptcha is set if another extension wants to ensure that a
  CAPTCHA is presented to the user. In this case, the 'captcha-edit'
  message is more appropriate than 'captcha-edit-fail' as
  'captcha-edit-fail' implies that the user already tried and failed to
  solve the CAPTCHA.

What:

- Use 'captcha-edit' message on confirm edit hook failure if
  'shouldForceShowCaptcha' is set
  - ... but use 'captcha-edit-fail' if the user submitted an attempt.
    Note that the updated message only works in the source editor,
	not in VisualEditor or DiscussionTools

Depends-On: I5a0698d84932a474800a68dba9b76b3433b19290
Bug: T20110
Change-Id: Ie13181b78b8e2903c6cc0f0f778689bcc8b8ce2e
This commit is contained in:
Kosta Harlan 2024-07-09 09:29:18 +02:00
parent 685c662918
commit 6f78a3ac57

View file

@ -884,7 +884,24 @@ class SimpleCaptcha {
// this can't be done for addurl trigger, because this requires one "free" save
// for the user, which we don't know, when he did it.
if ( $this->action === 'edit' ) {
$status->fatal( 'captcha-edit-fail' );
// Default message is that the user failed a CAPTCHA, so show 'captcha-edit-fail'.
$message = 'captcha-edit-fail';
if ( $this->shouldForceShowCaptcha() ) {
// If an extension set the forceShowCaptcha property, then it likely means
// that the user already submitted an edit, and so the 'captcha-edit'
// message is more appropriate.
$message = 'captcha-edit';
[ $_index, $word ] = $this->getCaptchaParamsFromRequest(
RequestContext::getMain()->getRequest()
);
// But if there's a word supplied in the request, then we should
// use 'captcha-edit-fail' as it indicates a failed attempt
// at solving the CAPTCHA by the user.
if ( $word ) {
$message = 'captcha-edit-fail';
}
}
$status->fatal( $message );
}
$this->addCaptchaAPI( $status->statusData );
$key = CacheKeyHelper::getKeyForPage( $page );