jenkins-bot has submitted this change and it was merged.

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


Update for API error i18n

See Iae0e2ce3.

Change-Id: I8cb4fc65e8c1e09d7d674d0f89cc77772a0116c6
---
M i18n/en.json
M i18n/qqq.json
M includes/ApiEditMassMessageList.php
M includes/ApiMassMessage.php
M includes/content/MassMessageListContentHandler.php
M includes/job/MassMessageJob.php
M tests/phpunit/api/ApiMassMessageTest.php
7 files changed, 35 insertions(+), 5 deletions(-)

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



diff --git a/i18n/en.json b/i18n/en.json
index 902f97b..13f6756 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -124,6 +124,7 @@
        "apihelp-query+mmsites-description": "Serve autocomplete requests for 
the site field in MassMessage.",
        "apihelp-query+mmsites-param-term": "The prefix to search for.",
        "apihelp-query+mmsites-example-1": "Autocomplete \"en\"",
+       "apierror-massmessage-invalidspamlist": "The specified spamlist is 
invalid.",
        "tag-massmessage-delivery": "MassMessage delivery",
        "tag-massmessage-delivery-description": "Message delivery using 
[[:mw:Extension:MassMessage|Extension:MassMessage]]"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 4c52951..3d5afb3 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -130,6 +130,7 @@
        "apihelp-query+mmsites-description": 
"{{doc-apihelp-description|query+mmsites}}",
        "apihelp-query+mmsites-param-term": "Label of an input area. Connected 
site names will be returned if they match the provided prefix (e.g. entering 
\"meta\" may return 
\"metawiki\").\n----\n{{doc-apihelp-param|query+mmsites|term}}",
        "apihelp-query+mmsites-example-1": 
"{{doc-apihelp-example|query+mmsites}}",
+       "apierror-massmessage-invalidspamlist": "{{doc-apierror}}",
        "tag-massmessage-delivery": "Change tag for MassMessage delivery edits",
        "tag-massmessage-delivery-description": "Description for MassMessage 
delivery change tag"
 }
diff --git a/includes/ApiEditMassMessageList.php 
b/includes/ApiEditMassMessageList.php
index dd48327..d7a2e33 100644
--- a/includes/ApiEditMassMessageList.php
+++ b/includes/ApiEditMassMessageList.php
@@ -17,7 +17,11 @@
                        || !$spamlist->exists()
                        || !$spamlist->hasContentModel( 
'MassMessageListContent' )
                ) {
-                       $this->dieUsage( 'The specified spamlist is invalid', 
'invalidspamlist' );
+                       if ( is_callable( [ $this, 'dieWithError' ] ) ) {
+                               $this->dieWithError( 
'apierror-massmessage-invalidspamlist', 'invalidspamlist' );
+                       } else {
+                               $this->dieUsage( 'The specified spamlist is 
invalid', 'invalidspamlist' );
+                       }
                }
 
                /** @var MassMessageListContent $content */
diff --git a/includes/ApiMassMessage.php b/includes/ApiMassMessage.php
index 021fe0e..7a5fd6a 100644
--- a/includes/ApiMassMessage.php
+++ b/includes/ApiMassMessage.php
@@ -9,8 +9,12 @@
  */
 class ApiMassMessage extends ApiBase {
        public function execute() {
-               if ( !$this->getUser()->isAllowed( 'massmessage' ) ) {
-                       $this->dieUsageMsg( 'permissiondenied' );
+               if ( is_callable( [ $this, 'checkUserRightsAny' ] ) ) {
+                       $this->checkUserRightsAny( 'massmessage' );
+               } else {
+                       if ( !$this->getUser()->isAllowed( 'massmessage' ) ) {
+                               $this->dieUsageMsg( 'permissiondenied' );
+                       }
                }
 
                $data = $this->extractRequestParams();
diff --git a/includes/content/MassMessageListContentHandler.php 
b/includes/content/MassMessageListContentHandler.php
index f4aae01..f5439f6 100644
--- a/includes/content/MassMessageListContentHandler.php
+++ b/includes/content/MassMessageListContentHandler.php
@@ -75,6 +75,8 @@
                try {
                        $api = new ApiMain( $der, true );
                        $api->execute();
+               } catch ( ApiUsageException $e ) {
+                       return Status::wrap( $e->getStatusValue() );
                } catch ( UsageException $e ) {
                        return Status::newFatal( $context->msg( 
'massmessage-ch-apierror',
                                $e->getCodeString() ) );
diff --git a/includes/job/MassMessageJob.php b/includes/job/MassMessageJob.php
index f735b95..59e4fd7 100644
--- a/includes/job/MassMessageJob.php
+++ b/includes/job/MassMessageJob.php
@@ -309,6 +309,22 @@
                        try {
                                $api->execute();
                                break; // Continue after the while block if the 
API request succeeds
+                       } catch ( ApiUsageException $e ) {
+                               $attemptCount++;
+                               $isEditConflict = false;
+                               foreach ( $e->getStatusValue()->getErrors() as 
$error ) {
+                                       if ( ApiMessage::create( $error 
)->getApiCode() === 'editconflict' ) {
+                                               $isEditConflict = true;
+                                               break;
+                                       }
+                               }
+                               // If the failure is not caused by an edit 
conflict or if there
+                               // have been too many failures, log the error 
and continue
+                               // execution. Otherwise retry the request.
+                               if ( !$isEditConflict || $attemptCount >= 5 ) {
+                                       $this->logLocalFailure( $errorCode );
+                                       break;
+                               }
                        } catch ( UsageException $e ) {
                                $attemptCount++;
                                $errorCode = $e->getCodeString();
diff --git a/tests/phpunit/api/ApiMassMessageTest.php 
b/tests/phpunit/api/ApiMassMessageTest.php
index feb9b2f..3886783 100644
--- a/tests/phpunit/api/ApiMassMessageTest.php
+++ b/tests/phpunit/api/ApiMassMessageTest.php
@@ -56,8 +56,10 @@
         * Tests that an error is thrown properly for invalid spamlists
         */
        public function testInvalidSpamlist() {
-               $this->setExpectedException( 'UsageException',
-                       'The specified delivery list page or category does not 
exist.' );
+               $this->setExpectedException(
+                       class_exists( ApiUsageException::class ) ? 
ApiUsageException::class : UsageException::class,
+                       'The specified delivery list page or category does not 
exist.'
+               );
                $this->doApiRequestWithToken( [
                        'action' => 'massmessage',
                        'spamlist' => '<InvalidPageTitle>',

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8cb4fc65e8c1e09d7d674d0f89cc77772a0116c6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Catrope <r...@wikimedia.org>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: Wctaiwan <wctai...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to