summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>2021-12-23 12:31:50 +0000
committerGerrit Code Review <gerrit@wikimedia.org>2021-12-23 12:31:50 +0000
commit95fe8522bee580847200f928068dcac327b53518 (patch)
treeabe034de94e68a36e6e49098ed7f0236c61a21e7
parente6f92bf97c4fc967372f24e879d526fed351f12e (diff)
parent37513f796bc0750c67528c7525056b75e72e2912 (diff)
Merge "ApiSandbox: Show request data as PHP array"
-rw-r--r--languages/i18n/en.json2
-rw-r--r--languages/i18n/qqq.json10
-rw-r--r--resources/Resources.php2
-rw-r--r--resources/src/mediawiki.special.apisandbox/apisandbox.js27
4 files changed, 36 insertions, 5 deletions
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index 8842a267e4b7..535d22630858 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -2234,6 +2234,8 @@
"apisandbox-request-url-label": "Request URL:",
"apisandbox-request-format-json-label": "JSON",
"apisandbox-request-json-label": "Request JSON:",
+ "apisandbox-request-format-php-label": "PHP array",
+ "apisandbox-request-php-label": "Request PHP array:",
"apisandbox-request-time": "Request time: {{PLURAL:$1|$1 ms}}",
"apisandbox-results-fixtoken": "Correct token and resubmit",
"apisandbox-results-fixtoken-fail": "Failed to fetch \"$1\" token.",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index 3da82866816f..54cb2d9602db 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -2460,10 +2460,12 @@
"apisandbox-results-error": "Displayed as an error message from JavaScript when the request failed.\n\nParameters:\n* $1 - Error message",
"apisandbox-results-login-suppressed": "Displayed as a warning when a request was processed as a logged-out user to avoid Same-Origin security bypass.",
"apisandbox-request-selectformat-label": "Label for the format selector on the results page.",
- "apisandbox-request-format-url-label": "Label for the menu item to select URL format.\n\nSee also:\n* {{msg-mw|apisandbox-request-selectformat-label}}\n* {{msg-mw|apisandbox-request-url-label}}",
- "apisandbox-request-url-label": "Label for the text field displaying the URL used to make this request.\n\nSee also:\n* {{msg-mw|apisandbox-request-format-url-label}}",
- "apisandbox-request-format-json-label": "Label for the menu item to select JSON format.\n\nSee also:\n* {{msg-mw|apisandbox-request-selectformat-label}}\n* {{msg-mw|apisandbox-request-json-label}}",
- "apisandbox-request-json-label": "Label for text field display the request parameters as JSON.\n\nSee also:\n* {{msg-mw|apisandbox-request-format-json-label}}",
+ "apisandbox-request-format-url-label": "Label for the menu item to select URL format.\n\nSee also:\n* {{msg-mw|apisandbox-request-selectformat-label}}\n* {{msg-mw|apisandbox-request-url-label}}\n* {{msg-mw|apisandbox-request-php-label}}",
+ "apisandbox-request-url-label": "Label for the text field displaying the URL used to make this request.\n\nSee also:\n* {{msg-mw|apisandbox-request-format-url-label}}\n* {{msg-mw|apisandbox-request-format-php-label}}",
+ "apisandbox-request-format-json-label": "Label for the menu item to select JSON format.\n\nSee also:\n* {{msg-mw|apisandbox-request-selectformat-label}}\n* {{msg-mw|apisandbox-request-json-label}}\n* {{msg-mw|apisandbox-request-php-label}}",
+ "apisandbox-request-json-label": "Label for text field display the request parameters as JSON.\n\nSee also:\n* {{msg-mw|apisandbox-request-format-json-label}}\n* {{msg-mw|apisandbox-request-format-php-label}}",
+ "apisandbox-request-format-php-label": "Label for the menu item to select PHP array format.\n\nSee also:\n* {{msg-mw|apisandbox-request-selectformat-label}}\n* {{msg-mw|apisandbox-request-json-label}}\n* {{msg-mw|apisandbox-request-url-label}}",
+ "apisandbox-request-php-label": "Label for text field display the request parameters a PHP array.\n\nSee also:\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-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",
diff --git a/resources/Resources.php b/resources/Resources.php
index fee9693246bd..71d60e1a91af 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1989,6 +1989,8 @@ return [
'apisandbox-request-url-label',
'apisandbox-request-format-json-label',
'apisandbox-request-json-label',
+ 'apisandbox-request-format-php-label',
+ 'apisandbox-request-php-label',
'apisandbox-request-time',
'apisandbox-results-fixtoken',
'apisandbox-results-fixtoken-fail',
diff --git a/resources/src/mediawiki.special.apisandbox/apisandbox.js b/resources/src/mediawiki.special.apisandbox/apisandbox.js
index b0e5f0dfb62f..c8b192ba5936 100644
--- a/resources/src/mediawiki.special.apisandbox/apisandbox.js
+++ b/resources/src/mediawiki.special.apisandbox/apisandbox.js
@@ -623,7 +623,7 @@
* @return {OO.ui.MenuOptionWidget[]} Each item's data should be an OO.ui.FieldLayout
*/
formatRequest: function ( displayParams, rawParams ) {
- var jsonLayout,
+ var jsonLayout, phpLayout,
apiUrl = new mw.Uri( mw.util.wikiScript( 'api' ) ).toString(),
items = [
new OO.ui.MenuOptionWidget( {
@@ -652,6 +652,31 @@
jsonLayout.textInput.updatePosition();
}
} )
+ } ),
+ new OO.ui.MenuOptionWidget( {
+ label: Util.parseMsg( 'apisandbox-request-format-php-label' ),
+ data: phpLayout = new mw.widgets.CopyTextLayout( {
+ label: Util.parseMsg( 'apisandbox-request-php-label' ),
+ copyText: '[\n' +
+ Object.keys( displayParams ).map( function ( param ) {
+ // displayParams is a diction or strings or numbers
+ return '\t' + JSON.stringify( param ) + ' => ' + JSON.stringify( displayParams[ param ] );
+ } ).join( ',\n' ) +
+ '\n]',
+ multiline: true,
+ textInput: {
+ classes: [ 'mw-apisandbox-textInputCode' ],
+ autosize: true,
+ maxRows: 6
+ }
+ } ).on( 'toggle', function ( visible ) {
+ if ( visible ) {
+ // Call updatePosition instead of adjustSize
+ // because the latter has weird caching
+ // behavior and the former bypasses it.
+ phpLayout.textInput.updatePosition();
+ }
+ } )
} )
];