[MediaWiki-commits] [Gerrit] Cleaner response for captcha-related createaccount API failure - change (mediawiki...ConfirmEdit)

2014-03-06 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Cleaner response for captcha-related createaccount API failure
..


Cleaner response for captcha-related createaccount API failure

Instead of a generic API error, you get back a non-Success-resulted
creataccount response, with result='NeedCaptcha'. There's also a warning
included with the message key, and of course the captcha key:

array (
  'createaccount' =>
  array (
'result' => 'NeedCaptcha',
'warnings' =>
array (
  0 =>
  array (
'type' => 'warning',
'message' => 'captcha-createaccount-fail',
'params' =>
array (
),
  ),
),
'captcha' =>
array (
  'type' => 'simple',
  'mime' => 'text/plain',
  'id' => '91510936',
  'question' => '76−3',
),
  ),
)

Change-Id: Id1c9e387c592e6d51a5bd58d99ce3d644dfa300b
---
M Captcha.php
1 file changed, 15 insertions(+), 1 deletion(-)

Approvals:
  CSteipp: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Captcha.php b/Captcha.php
index 20b2dfd..df9a314 100644
--- a/Captcha.php
+++ b/Captcha.php
@@ -547,7 +547,12 @@
// For older MediaWiki
$message = wfMessage( 
'captcha-createaccount-fail' )->text();
// For MediaWiki 1.23+
-   $status = Status::newFatal( 
'captcha-createaccount-fail' );
+   $status = Status::newGood();
+   
+   // Apply a *non*-fatal warning. This will still 
abort the
+   // account creation but returns a "Warning" 
response to the
+   // API or UI.
+   $status->warning( 'captcha-createaccount-fail' 
);
return false;
}
}
@@ -830,6 +835,15 @@
function addNewAccountApiResult( $apiModule, $loginPage, &$result ) {
if ( $result['result'] !== 'Success' && 
$this->needCreateAccountCaptcha() ) {
$this->addCaptchaAPI( $result );
+
+   // If we failed a captcha, override the generic 
'Warning' result string
+   if ( $result['result'] === 'Warning' && isset( 
$result['warnings'] ) ) {
+   foreach ( $result['warnings'] as $warning ) {
+   if ( $warning['message'] === 
'captcha-createaccount-fail' ) {
+   $result['result'] = 
'NeedCaptcha';
+   }
+   }
+   }
}
return true;
}

-- 
To view, visit https://gerrit.wikimedia.org/r/116170
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id1c9e387c592e6d51a5bd58d99ce3d644dfa300b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: master
Gerrit-Owner: Brion VIBBER 
Gerrit-Reviewer: CSteipp 
Gerrit-Reviewer: Legoktm 
Gerrit-Reviewer: MaxSem 
Gerrit-Reviewer: Yuvipanda 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Cleaner response for captcha-related createaccount API failure - change (mediawiki...ConfirmEdit)

2014-02-28 Thread Brion VIBBER (Code Review)
Brion VIBBER has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/116170

Change subject: Cleaner response for captcha-related createaccount API failure
..

Cleaner response for captcha-related createaccount API failure

Instead of a generic API error, you get back a non-Success-resulted
createapi response, with result='NeedCaptcha'. There's also a warning
included with the message key, and of course the captcha key:

array (
  'createaccount' =>
  array (
'result' => 'NeedCaptcha',
'warnings' =>
array (
  0 =>
  array (
'type' => 'warning',
'message' => 'captcha-createaccount-fail',
'params' =>
array (
),
  ),
),
'captcha' =>
array (
  'type' => 'simple',
  'mime' => 'text/plain',
  'id' => '91510936',
  'question' => '76−3',
),
  ),
)

Change-Id: Id1c9e387c592e6d51a5bd58d99ce3d644dfa300b
---
M Captcha.php
1 file changed, 15 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit 
refs/changes/70/116170/1

diff --git a/Captcha.php b/Captcha.php
index 20b2dfd..df9a314 100644
--- a/Captcha.php
+++ b/Captcha.php
@@ -547,7 +547,12 @@
// For older MediaWiki
$message = wfMessage( 
'captcha-createaccount-fail' )->text();
// For MediaWiki 1.23+
-   $status = Status::newFatal( 
'captcha-createaccount-fail' );
+   $status = Status::newGood();
+   
+   // Apply a *non*-fatal warning. This will still 
abort the
+   // account creation but returns a "Warning" 
response to the
+   // API or UI.
+   $status->warning( 'captcha-createaccount-fail' 
);
return false;
}
}
@@ -830,6 +835,15 @@
function addNewAccountApiResult( $apiModule, $loginPage, &$result ) {
if ( $result['result'] !== 'Success' && 
$this->needCreateAccountCaptcha() ) {
$this->addCaptchaAPI( $result );
+
+   // If we failed a captcha, override the generic 
'Warning' result string
+   if ( $result['result'] === 'Warning' && isset( 
$result['warnings'] ) ) {
+   foreach ( $result['warnings'] as $warning ) {
+   if ( $warning['message'] === 
'captcha-createaccount-fail' ) {
+   $result['result'] = 
'NeedCaptcha';
+   }
+   }
+   }
}
return true;
}

-- 
To view, visit https://gerrit.wikimedia.org/r/116170
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1c9e387c592e6d51a5bd58d99ce3d644dfa300b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: master
Gerrit-Owner: Brion VIBBER 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits