diff options
-rw-r--r-- | includes/api/ApiMain.php | 18 | ||||
-rw-r--r-- | includes/api/i18n/en.json | 1 | ||||
-rw-r--r-- | includes/api/i18n/qqq.json | 1 |
3 files changed, 16 insertions, 4 deletions
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 7ea691074831..58810a91b89e 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1907,10 +1907,20 @@ class ApiMain extends ApiBase { $this->dieWithErrorOrDebug( [ 'apierror-mustbeposted', $this->mAction ] ); } - if ( $request->wasPosted() && !$request->getHeader( 'Content-Type' ) ) { - $this->addDeprecation( - 'apiwarn-deprecation-post-without-content-type', 'post-without-content-type' - ); + if ( $request->wasPosted() ) { + if ( !$request->getHeader( 'Content-Type' ) ) { + $this->addDeprecation( + 'apiwarn-deprecation-post-without-content-type', 'post-without-content-type' + ); + } + $contentLength = $request->getHeader( 'Content-Length' ); + $maxPostSize = wfShorthandToInteger( ini_get( 'post_max_size' ), 0 ); + if ( $maxPostSize && $contentLength > $maxPostSize ) { + $this->dieWithError( + [ 'apierror-http-contenttoolarge', Message::sizeParam( $maxPostSize ) ], + null, null, 413 + ); + } } // See if custom printer is used diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index ecd1dd158ca2..699a0490e440 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -1859,6 +1859,7 @@ "apierror-filenopath": "Cannot get local file path.", "apierror-filetypecannotberotated": "File type cannot be rotated.", "apierror-formatphp": "This response cannot be represented using <kbd>format=php</kbd>. See https://phabricator.wikimedia.org/T68776.", + "apierror-http-contenttoolarge": "HTTP Request Content too large. Maximum length: $1.", "apierror-imageusage-badtitle": "The title for <kbd>$1</kbd> must be a file.", "apierror-import-unknownerror": "Unknown error on import: $1.", "apierror-info-singlepagerevision": "Multiple pages or revisions were supplied, but <var>$1prop=preloadcontent</var> and <var>$1prop=editintro</var> may only be used with a single page and revision.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index 40a06bfc6d34..992f372baa46 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -1762,6 +1762,7 @@ "apierror-filenopath": "{{doc-apierror}}", "apierror-filetypecannotberotated": "{{doc-apierror}}", "apierror-formatphp": "{{doc-apierror}}", + "apierror-http-contenttoolarge": "{{doc-apierror}}\n\nParameters:\n* $1 - maximum size parameter (already formatted as \"1 KB\" or similar).", "apierror-imageusage-badtitle": "{{doc-apierror}}\n\nParameters:\n* $1 - Module name.", "apierror-import-unknownerror": "{{doc-apierror}}\n\nParameters:\n* $1 - Error message returned by the import, probably in English.", "apierror-info-singlepagerevision": "{{doc-apierror}}\n\nParameters:\n* $1 - Module parameter prefix, e.g. \"in\".", |