Merge "ApiSandbox: Indicate when login is suppressed"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 20 Jun 2017 21:02:30 +0000 (21:02 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 20 Jun 2017 21:02:30 +0000 (21:02 +0000)
includes/api/ApiMain.php
languages/i18n/en.json
languages/i18n/qqq.json
resources/Resources.php
resources/src/mediawiki.special/mediawiki.special.apisandbox.js

index 00f976e..d7586e0 100644 (file)
@@ -236,6 +236,7 @@ class ApiMain extends ApiBase {
                                wfDebug( "API: stripping user credentials when the same-origin policy is not applied\n" );
                                $wgUser = new User();
                                $this->getContext()->setUser( $wgUser );
+                               $request->response()->header( 'MediaWiki-Login-Suppressed: true' );
                        }
                }
 
@@ -778,7 +779,8 @@ class ApiMain extends ApiBase {
 
                        if ( !$preflight ) {
                                $response->header(
-                                       'Access-Control-Expose-Headers: MediaWiki-API-Error, Retry-After, X-Database-Lag'
+                                       'Access-Control-Expose-Headers: MediaWiki-API-Error, Retry-After, X-Database-Lag, '
+                                       . 'MediaWiki-Login-Suppressed'
                                );
                        }
                }
index 2590c62..145cf2f 100644 (file)
        "apisandbox-sending-request": "Sending API request...",
        "apisandbox-loading-results": "Receiving API results...",
        "apisandbox-results-error": "An error occurred while loading the API query response: $1.",
+       "apisandbox-results-login-suppressed": "This request has been processed as a logged-out user as it could be used to bypass browser Same-Origin security. Note that the API sandbox's automatic token handling does not work properly with such requests, please fill them in manually.",
        "apisandbox-request-selectformat-label": "Show request data as:",
        "apisandbox-request-format-url-label": "URL query string",
        "apisandbox-request-url-label": "Request URL:",
index fad105d..ed99c41 100644 (file)
        "apisandbox-sending-request": "JavaScript message displayed while the request is being sent.",
        "apisandbox-loading-results": "JavaScript message displayed while the response is being read.",
        "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}}",
index 864f93e..ef33111 100644 (file)
@@ -1920,6 +1920,7 @@ return [
                        'apisandbox-sending-request',
                        'apisandbox-loading-results',
                        'apisandbox-results-error',
+                       'apisandbox-results-login-suppressed',
                        'apisandbox-request-selectformat-label',
                        'apisandbox-request-format-url-label',
                        'apisandbox-request-url-label',
index c32f953..ff6a80c 100644 (file)
                                        } )
                                        .then( function ( data, jqXHR ) {
                                                var m, loadTime, button, clear,
-                                                       ct = jqXHR.getResponseHeader( 'Content-Type' );
+                                                       ct = jqXHR.getResponseHeader( 'Content-Type' ),
+                                                       loginSuppressed = jqXHR.getResponseHeader( 'MediaWiki-Login-Suppressed' ) || 'false';
 
                                                $result.empty();
+                                               if ( loginSuppressed !== 'false' ) {
+                                                       $( '<div>' )
+                                                               .addClass( 'warning' )
+                                                               .append( Util.parseMsg( 'apisandbox-results-login-suppressed' ) )
+                                                               .appendTo( $result );
+                                               }
                                                if ( /^text\/mediawiki-api-prettyprint-wrapped(?:;|$)/.test( ct ) ) {
                                                        data = JSON.parse( data );
                                                        if ( data.modules.length ) {