summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Sanders <esanders@wikimedia.org>2021-12-22 15:30:49 +0000
committerEd Sanders <esanders@wikimedia.org>2021-12-22 23:32:56 +0000
commit37513f796bc0750c67528c7525056b75e72e2912 (patch)
tree67736ded69151917d82690dee8dd679dbed5cbd7
parent16bd6eaeb497ba577460775038a530e202ef3b0f (diff)
ApiSandbox: Show request data as PHP array
Change-Id: I11aa6037fcc92fd4c1b589f43996b7b2a5b49801
-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 f9324e178410..fb75ef3fdd99 100644
--- a/resources/src/mediawiki.special.apisandbox/apisandbox.js
+++ b/resources/src/mediawiki.special.apisandbox/apisandbox.js
@@ -628,7 +628,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( {
@@ -657,6 +657,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();
+ }
+ } )
} )
];