ApiSandbox: Use POST when we have long URL

Bug: T406283
Change-Id: Ibb2a1813b29f521d665ce7cedf551fdaa35061fa
(cherry picked from commit 95c93b9371194cc9c9954ca8c5f2005ef094d7b1)
This commit is contained in:
Ammarpad 2025-11-08 00:33:18 +01:00 committed by Reedy
parent 048f9ebd15
commit c183e4f127
4 changed files with 13 additions and 2 deletions

View file

@ -2140,6 +2140,7 @@
"apisandbox-request-php-label": "Request PHP array:",
"apisandbox-request-time": "Request time: {{PLURAL:$1|$1 ms}}",
"apisandbox-request-post": "This request must be sent using the HTTP POST method.",
"apisandbox-request-post2": "Due to the size of the payload, this request has been sent using the HTTP POST method.",
"apisandbox-request-formdata": "This request must be sent as a file upload (i.e. using <code>multipart/form-data</code>).",
"apisandbox-results-fixtoken": "Correct token and resubmit",
"apisandbox-results-fixtoken-fail": "Failed to fetch \"$1\" token.",

View file

@ -2413,6 +2413,7 @@
"apisandbox-request-php-label": "Label for text field display the request parameters a PHP array.\n\nShould be similar to {{msg-mw|Apisandbox-request-json-label}}.\n\nSee also:\n* {{msg-mw|Apisandbox-request-format-php-label}}\n* {{msg-mw|apisandbox-request-format-json-label}}\n* {{msg-mw|apisandbox-request-format-url-label}}",
"apisandbox-request-time": "Label and value for displaying the time taken by the request.\n\nParameters:\n* $1 - Time taken in milliseconds",
"apisandbox-request-post": "Label shown below request parameters on [[Special:ApiSandbox]].\n\nSee also:\n* {{msg-mw|api-help-flag-mustbeposted}}\n* {{msg-mw|apierror-mustbeposted}}",
"apisandbox-request-post2": "Label shown below request parameters on [[Special:ApiSandbox]].\n\nSee also:\n* {{msg-mw|apisandbox-request-post}}",
"apisandbox-request-formdata": "Label shown below request parameters on [[Special:ApiSandbox]].\n\nSee also:\n* {{msg-mw|apihelp-import-extended-description}}\n* {{msg-mw|apihelp-upload-extended-description}}\n* {{msg-mw|apierror-badupload}}",
"apisandbox-results-fixtoken": "JavaScript button label",
"apisandbox-results-fixtoken-fail": "Displayed as an error message from JavaScript when a CSRF token could not be fetched.\n\nParameters:\n* $1 - Token type",

View file

@ -2117,6 +2117,7 @@ return [
'apisandbox-request-php-label',
'apisandbox-request-time',
'apisandbox-request-post',
'apisandbox-request-post2',
'apisandbox-request-formdata',
'apisandbox-results-fixtoken',
'apisandbox-results-fixtoken-fail',

View file

@ -888,7 +888,8 @@
* The form fields will be updated to match.
*/
sendRequest: function ( params ) {
let method = 'get';
let method = 'get',
infoMessage;
const paramsAreForced = !!params,
deferreds = [],
displayParams = {},
@ -919,6 +920,7 @@
checkPage.getQueryParams( params, displayParams, ajaxOptions );
if ( checkPage.paramInfo.mustbeposted !== undefined ) {
method = 'post';
infoMessage = mw.message( 'apisandbox-request-post' ).parseDom();
}
const subpages = checkPage.getSubpages();
// eslint-disable-next-line no-loop-func
@ -1004,6 +1006,12 @@
const query = $.param( displayParams );
// Force POST if we have huge payload (T406283)
if ( method !== 'post' && query.length > 7500 ) {
method = 'post';
infoMessage = mw.message( 'apisandbox-request-post2' ).parseDom();
}
const formatItems = Util.formatRequest( displayParams, params, method, ajaxOptions );
// Force a 'fm' format with wrappedhtml=1, if available
@ -1061,7 +1069,7 @@
if ( method === 'post' ) {
page.$element.append( new OO.ui.LabelWidget( {
label: mw.message( 'apisandbox-request-post' ).parseDom(),
label: infoMessage,
classes: [ 'oo-ui-inline-help' ]
} ).$element );
}