Anomie has uploaded a new change for review.

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

Change subject: Update for API error i18n
......................................................................

Update for API error i18n

See Iae0e2ce3.

Change-Id: I7a8deec9a8c55408f1802dfaa6c9e7e0631dc1a2
---
M i18n/en.json
M i18n/qqq.json
M includes/ApiBounceHandler.php
M tests/ApiBounceHandlerTest.php
4 files changed, 22 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BounceHandler 
refs/changes/12/321412/1

diff --git a/i18n/en.json b/i18n/en.json
index d6108a7..f4dab60 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -9,6 +9,7 @@
        "apihelp-bouncehandler-example-1": "Receive a bounce email for 
processing with the content \"This is a test email\".",
        "apihelp-bouncehandler-description": "Receive a bounce email and 
process it to handle the failing recipient.",
        "apihelp-bouncehandler-param-email": "The bounced email.",
+       "apierror-bouncehandler-internalonly": "This API module is for internal 
use only.",
        "notification-bouncehandler": "{{GENDER:$1|Your}} registered email 
address is no longer valid.",
        "notification-bouncehandler-flyout": "{{GENDER:$2|Your}} registered 
email address $1 has been unsubscribed due to multiple message delivery 
failures. You can [[Special:ConfirmEmail|verify {{GENDER:$2|your}} email 
address again]].",
        "notification-link-text-change-email": "Change your email address",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 1e350fe..defb047 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -9,6 +9,7 @@
        "apihelp-bouncehandler-example-1": 
"{{doc-apihelp-example|bouncehandler}}",
        "apihelp-bouncehandler-description": 
"{{doc-apihelp-description|bouncehandler}}",
        "apihelp-bouncehandler-param-email": 
"{{doc-apihelp-param|bouncehandler|email}}",
+       "apierror-bouncehandler-internalonly": "{{doc-apierror}}",
        "notification-bouncehandler": "Title message of Echo notification to 
notify a user of his/her invalid email address. Parameters:\n* $1 is the 
username of the user whose email address was unsubscribed. Can be used for 
GENDER.",
        "notification-bouncehandler-flyout": "Flyout message of Echo 
notification to notify the user of his/her invalid email address. 
Parameters:\n* $1 is the unsubscribed email address of the user.\n* $2 is the 
username of the user whose email address was unsubscribed. Can be used for 
GENDER.",
        "notification-link-text-change-email": "Label of the link that points 
to Special:ConfirmEmail and Special:ChangeEmail wherein the users are asked to 
again verify their old email address.",
diff --git a/includes/ApiBounceHandler.php b/includes/ApiBounceHandler.php
index aea61e8..e8bfc1f 100644
--- a/includes/ApiBounceHandler.php
+++ b/includes/ApiBounceHandler.php
@@ -23,7 +23,11 @@
                }
                if ( !$inRangeIP ) {
                        wfDebugLog( 'BounceHandler', "POST received from 
restricted IP $requestIP" );
-                       $this->dieUsage( 'This API module is for internal use 
only.', 'invalid-ip' );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $this->dieWithError( 
'apierror-bouncehandler-internalonly', 'invalid-ip' );
+                       } else {
+                               $this->dieUsage( 'This API module is for 
internal use only.', 'invalid-ip' );
+                       }
                }
 
                $params = $this->extractRequestParams();
diff --git a/tests/ApiBounceHandlerTest.php b/tests/ApiBounceHandlerTest.php
index d0f6798..be596cc 100644
--- a/tests/ApiBounceHandlerTest.php
+++ b/tests/ApiBounceHandlerTest.php
@@ -77,10 +77,13 @@
         *
         * @dataProvider provideBounceEmails
         * @param $email
-        * @expectedException UsageException
-        * @expectedExceptionMessage This API module is for internal use only.
         */
        function testBounceHandlerWithBadIPPasses( $email ) {
+               $this->setExpectedException(
+                       class_exists( ApiUsageException::class ) ? 
ApiUsageException::class : UsageException::class,
+                       'This API module is for internal use only.'
+               );
+
                $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'111.111.111.111' ) );
                $this->doApiRequest( array(
                        'action' => 'bouncehandler',
@@ -90,11 +93,13 @@
 
        /**
         * Tests API request with null 'email' param
-        *
-        * @expectedException UsageException
-        * @expectedExceptionMessage The email parameter must be set
         */
        function testBounceHandlerWithNullParams() {
+               $this->setExpectedException(
+                       class_exists( ApiUsageException::class ) ? 
ApiUsageException::class : UsageException::class,
+                       'The email parameter must be set'
+               );
+
                $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'127.0.0.1' ) );
                $this->doApiRequest( array(
                        'action' => 'bouncehandler',
@@ -108,10 +113,13 @@
         *
         * @dataProvider provideBounceEmails
         * @param $email
-        * @expectedException UsageException
-        * @expectedExceptionMessage The email parameter must be set
         */
        function testBounceHandlerWithWrongParams( $email ) {
+               $this->setExpectedException(
+                       class_exists( ApiUsageException::class ) ? 
ApiUsageException::class : UsageException::class,
+                       'The email parameter must be set'
+               );
+
                $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'127.0.0.1' ) );
                $this->doApiRequest( array(
                        'action' => 'bouncehandler',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7a8deec9a8c55408f1802dfaa6c9e7e0631dc1a2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BounceHandler
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>

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

Reply via email to