jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/321446 )

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


Update for API error i18n

See Iae0e2ce3.

Change-Id: I9598a94cafbc6f74f9100159bee7d7465770c418
---
M i18n/en.json
M i18n/qqq.json
M includes/ApiParsoidBatch.php
3 files changed, 91 insertions(+), 25 deletions(-)

Approvals:
  Gergő Tisza: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index 6487e77..3978512 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -6,5 +6,13 @@
        },
        "parsoidbatchapi-desc": "Batch API for Parsoid",
        "apihelp-parsoid-batch-description": "",
-       "apihelp-parsoid-batch-param-batch": ""
+       "apihelp-parsoid-batch-param-batch": "",
+       "apierror-parsoid-batch-notallowed": "Client IP address not in 
ParsoidBatchAPI_AllowedIPs.",
+       "apierror-parsoid-batch-invalidbatch": "Invalid batch, must be array.",
+       "apierror-parsoid-batch-batchtoolarge": "Batch too large, limit is 
500.",
+       "apierror-parsoid-batch-invalidaction": "Invalid action in item index 
$1.",
+       "apierror-parsoid-batch-texttoobig": "Input text exceeds maximum 
article size.",
+       "apierror-parsoid-batch-invalidtitle": "Invalid title ($1).",
+       "apierror-parsoid-batch-mustbescalar": "The <var>$1</var> parameter 
must be a scalar.",
+       "apierror-parsoid-batch-mustbearray": "The <var>$1</var> parameter must 
be an array."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 6f27ba4..eeb6531 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -6,5 +6,13 @@
        },
        "parsoidbatchapi-desc": 
"{{desc|name=ParsoidBatchAPI|url=https://www.mediawiki.org/wiki/Extension:ParsoidBatchAPI}}";,
        "apihelp-parsoid-batch-description": 
"{{doc-apihelp-description|parsoid-batch}}",
-       "apihelp-parsoid-batch-param-batch": 
"{{doc-apihelp-param|parsoid-batch|batch}}"
+       "apihelp-parsoid-batch-param-batch": 
"{{doc-apihelp-param|parsoid-batch|batch}}",
+       "apierror-parsoid-batch-batchtoolarge": "{{doc-apierror}}",
+       "apierror-parsoid-batch-invalidaction": 
"{{doc-apierror}}\n\nParameters:\n* $1 - Item index",
+       "apierror-parsoid-batch-invalidbatch": "{{doc-apierror}}",
+       "apierror-parsoid-batch-invalidtitle": 
"{{doc-apierror}}\n\nParameters:\n* $1 - Item index",
+       "apierror-parsoid-batch-mustbearray": 
"{{doc-apierror}}\n\nParameters:\n* $1 - Parameter name",
+       "apierror-parsoid-batch-mustbescalar": 
"{{doc-apierror}}\n\nParameters:\n* $1 - Parameter name",
+       "apierror-parsoid-batch-notallowed": "{{doc-apierror}}",
+       "apierror-parsoid-batch-texttoobig": "{{doc-apierror}}"
 }
diff --git a/includes/ApiParsoidBatch.php b/includes/ApiParsoidBatch.php
index 9045d84..f7d05f7 100644
--- a/includes/ApiParsoidBatch.php
+++ b/includes/ApiParsoidBatch.php
@@ -8,17 +8,29 @@
                $config = $context->getConfig();
                $ipset = new IPSet( $config->get( 'ParsoidBatchAPI_AllowedIPs' 
) );
                if ( !$ipset->match( $context->getRequest()->getIP() ) ) {
-                       $this->dieUsage( "Client IP address not in 
ParsoidBatchAPI_AllowedIPs",
-                               'not_allowed' );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $this->dieWithError( 
'apierror-parsoid-batch-notallowed', 'not_allowed' );
+                       } else {
+                               $this->dieUsage( "Client IP address not in 
ParsoidBatchAPI_AllowedIPs",
+                                       'not_allowed' );
+                       }
                }
 
                // Parameter validation
                $batch = json_decode( $params['batch'], true );
                if ( !is_array( $batch ) ) {
-                       $this->dieUsage( "Invalid batch, must be array", 
'invalid_batch' );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $this->dieWithError( 
'apierror-parsoid-batch-invalidbatch', 'invalid_batch' );
+                       } else {
+                               $this->dieUsage( "Invalid batch, must be 
array", 'invalid_batch' );
+                       }
                }
                if ( count( $batch ) > 500 ) {
-                       $this->dieUsage( "Batch too large, limit is 500", 
'batch_too_large' );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $this->dieWithError( 
'apierror-parsoid-batch-batchtoolarge', 'batch_too_large' );
+                       } else {
+                               $this->dieUsage( "Batch too large, limit is 
500", 'batch_too_large' );
+                       }
                }
                wfIncrStats( 'ParsoidBatchAPI.batches' );
                wfIncrStats( 'ParsoidBatchAPI.items', count( $batch ) );
@@ -49,11 +61,21 @@
                                        $filenames[] = 
$batch[$itemIndex]['filename'] = $title->getDBkey();
                                }
                        } else {
-                               $this->dieUsage( "Invalid action in item index 
$itemIndex", 'invalid_action' );
+                               if ( is_callable( array( $this, 'dieWithError' 
) ) ) {
+                                       $this->dieWithError(
+                                               [ 
'apierror-parsoid-batch-invalidaction', wfEscapeWikiText( $itemIndex ) ], 
'invalid_action'
+                                       );
+                               } else {
+                                       $this->dieUsage( "Invalid action in 
item index $itemIndex", 'invalid_action' );
+                               }
                        }
                }
                if ( $size > 1024 * $config->get( 'MaxArticleSize' ) ) {
-                       $this->dieUsage( "Input text exceeds maximum article 
size", 'text_too_big' );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $this->dieWithError( 
'apierror-parsoid-batch-texttoobig', 'text_too_big' );
+                       } else {
+                               $this->dieUsage( "Input text exceeds maximum 
article size", 'text_too_big' );
+                       }
                }
 
                // Now do the thing
@@ -70,7 +92,13 @@
                        if ( $action === 'parse' || $action === 'preprocess' ) {
                                $title = Title::newFromText( 
$itemParams['title'] );
                                if ( !$title ) {
-                                       $this->dieUsage( "Invalid title 
($itemIndex)", 'invalid_title' );
+                                       if ( is_callable( array( $this, 
'dieWithError' ) ) ) {
+                                               $this->dieWithError(
+                                                       [ 
'apierror-parsoid-batch-invalidtitle', wfEscapeWikiText( $itemIndex ) ], 
'invalid_title'
+                                               );
+                                       } else {
+                                               $this->dieUsage( "Invalid title 
($itemIndex)", 'invalid_title' );
+                                       }
                                }
                                $text = $itemParams['text'];
                                $revid = isset( $itemParams['revid'] ) ? 
intval( $itemParams['revid'] ) : false;
@@ -101,35 +129,57 @@
 
        protected function assertScalar( array $array, $key ) {
                if ( !isset( $array[$key] ) ) {
-                       $this->dieUsage(
-                               "The $key parameter is required",
-                               "missing_$key" );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $eKey = wfEscapeWikiText( $key ); // Might be 
user-supplied via txopts
+                               $this->dieWithError( array( 
'apierror-missingparam', $eKey ), "missing_$eKey" );
+                       } else {
+                               $this->dieUsage(
+                                       "The $key parameter is required",
+                                       "missing_$key" );
+                       }
                }
                if ( !is_scalar( $array[$key] ) ) {
-                       $this->dieUsage(
-                               "The $key parameter must be a scalar",
-                               "invalid_$key" );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $eKey = wfEscapeWikiText( $key ); // Might be 
user-supplied via txopts
+                               $this->dieWithError( array( 
'apierror-parsoid-batch-mustbescalar', $eKey ), "invalid_$eKey" );
+                       } else {
+                               $this->dieUsage(
+                                       "The $key parameter must be a scalar",
+                                       "invalid_$key" );
+                       }
                }
        }
 
        protected function assertScalarOrMissing( array $array, $key ) {
                if ( isset( $array[$key] ) && !is_scalar( $array[$key] ) ) {
-                       $this->dieUsage(
-                               "The $key parameter must be a scalar",
-                               "invalid_$key" );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $this->dieWithError( array( 
'apierror-parsoid-batch-mustbescalar', $key ), "invalid_$key" );
+                       } else {
+                               $this->dieUsage(
+                                       "The $key parameter must be a scalar",
+                                       "invalid_$key" );
+                       }
                }
        }
 
        protected function assertArray( array $array, $key ) {
                if ( !isset( $array[$key] ) ) {
-                       $this->dieUsage(
-                               "The $key parameter is required",
-                               "missing_$key" );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $this->dieWithError( array( 
'apierror-missingparam', $key ), "missing_$key" );
+                       } else {
+                               $this->dieUsage(
+                                       "The $key parameter is required",
+                                       "missing_$key" );
+                       }
                }
                if ( !is_array( $array[$key] ) ) {
-                       $this->dieUsage(
-                               "The $key parameter must be an array",
-                               "invalid_$key" );
+                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                               $this->dieWithError( array( 
'apierror-parsoid-batch-mustbearray', $key ), "invalid_$key" );
+                       } else {
+                               $this->dieUsage(
+                                       "The $key parameter must be an array",
+                                       "invalid_$key" );
+                       }
                }
        }
 
@@ -241,7 +291,7 @@
                                }
 
                                // Proposed MediaTransformOutput serialization 
method for T51896 etc.
-                               if ( is_callable( [ $mto, 'getAPIData' ] ) ) {
+                               if ( is_callable( array( $mto, 'getAPIData' ) ) 
) {
                                        $result['thumbdata'] = 
$mto->getAPIData();
                                }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9598a94cafbc6f74f9100159bee7d7465770c418
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/ParsoidBatchAPI
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
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