ApiLogin: i18n for 'Aborted' reasons
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 16 May 2017 14:14:03 +0000 (10:14 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Tue, 16 May 2017 14:16:28 +0000 (10:16 -0400)
Ia6c402a4 did it for 'Failed', but overlooked 'Aborted'.

Change-Id: I3f7379af3609c30f10ea8c648f2ec840310e8d97

RELEASE-NOTES-1.30
includes/api/ApiLogin.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json

index d32db34..b24a08d 100644 (file)
@@ -46,6 +46,8 @@ production.
 * (T37247) action=parse output will be wrapped in a div with
   class="mw-parser-output" by default. This may be changed or disabled using
   the new 'wrapoutputclass' parameter.
+* When errorformat is not 'bc', abort reasons from action=login will be
+  formatted as specified by the error formatter parameters.
 
 === Action API internal changes in 1.30 ===
 * …
index 41bec35..398c8c7 100644 (file)
@@ -49,6 +49,23 @@ class ApiLogin extends ApiBase {
                }
        }
 
+       /**
+        * Format a message for the response
+        * @param Message|string|array $message
+        * @return string|array
+        */
+       private function formatMessage( $message ) {
+               $message = Message::newFromSpecifier( $message );
+               $errorFormatter = $this->getErrorFormatter();
+               if ( $errorFormatter instanceof ApiErrorFormatter_BackCompat ) {
+                       return ApiErrorFormatter::stripMarkup(
+                               $message->useDatabase( false )->inLanguage( 'en' )->text()
+                       );
+               } else {
+                       return $errorFormatter->formatMessage( $message );
+               }
+       }
+
        /**
         * Executes the log-in attempt using the parameters passed. If
         * the log-in succeeds, it attaches a cookie to the session
@@ -64,7 +81,7 @@ class ApiLogin extends ApiBase {
                if ( $this->lacksSameOriginSecurity() ) {
                        $this->getResult()->addValue( null, 'login', [
                                'result' => 'Aborted',
-                               'reason' => 'Cannot log in when the same-origin policy is not applied',
+                               'reason' => $this->formatMessage( 'api-login-fail-sameorigin' ),
                        ] );
 
                        return;
@@ -84,8 +101,10 @@ class ApiLogin extends ApiBase {
                if ( !$session->canSetUser() ) {
                        $this->getResult()->addValue( null, 'login', [
                                'result' => 'Aborted',
-                               'reason' => 'Cannot log in when using ' .
-                                       $session->getProvider()->describe( Language::factory( 'en' ) ),
+                               'reason' => $this->formatMessage( [
+                                       'api-login-fail-badsessionprovider',
+                                       $session->getProvider()->describe( $this->getErrorFormatter()->getLanguage() ),
+                               ] )
                        ] );
 
                        return;
@@ -190,25 +209,15 @@ class ApiLogin extends ApiBase {
                                break;
 
                        case 'Failed':
-                               $errorFormatter = $this->getErrorFormatter();
-                               if ( $errorFormatter instanceof ApiErrorFormatter_BackCompat ) {
-                                       $result['reason'] = ApiErrorFormatter::stripMarkup(
-                                               $message->useDatabase( false )->inLanguage( 'en' )->text()
-                                       );
-                               } else {
-                                       $result['reason'] = $errorFormatter->formatMessage( $message );
-                               }
+                               $result['reason'] = $this->formatMessage( $message );
                                break;
 
                        case 'Aborted':
-                               $result['reason'] = 'Authentication requires user interaction, ' .
-                                       'which is not supported by action=login.';
-                               if ( $this->getConfig()->get( 'EnableBotPasswords' ) ) {
-                                       $result['reason'] .= ' To be able to login with action=login, see [[Special:BotPasswords]].';
-                                       $result['reason'] .= ' To continue using main-account login, see action=clientlogin.';
-                               } else {
-                                       $result['reason'] .= ' To log in, see action=clientlogin.';
-                               }
+                               $result['reason'] = $this->formatMessage(
+                                       $this->getConfig()->get( 'EnableBotPasswords' )
+                                               ? 'api-login-fail-aborted'
+                                               : 'api-login-fail-aborted-nobotpw'
+                               );
                                break;
 
                        default:
index c3c7bd4..5f52a1e 100644 (file)
        "api-format-prettyprint-header-only-html": "This is an HTML representation intended for debugging, and is unsuitable for application use.\n\nSee the [[mw:Special:MyLanguage/API|complete documentation]], or the [[Special:ApiHelp/main|API help]] for more information.",
        "api-format-prettyprint-status": "This response would be returned with HTTP status $1 $2.",
 
+       "api-login-fail-aborted": "Authentication requires user interaction, which is not supported by <kbd>action=login</kbd>. To be able to login with <kbd>action=login</kbd>, see [[Special:BotPasswords]]. To continue using main-account login, see <kbd>[[Special:ApiHelp/clientlogin|action=clientlogin]]</kbd>.",
+       "api-login-fail-aborted-nobotpw": "Authentication requires user interaction, which is not supported by <kbd>action=login</kbd>. To log in, see <kbd>[[Special:ApiHelp/clientlogin|action=clientlogin]]</kbd>.",
+       "api-login-fail-badsessionprovider": "Cannot log in when using $1.",
+       "api-login-fail-sameorigin": "Cannot log in when the same-origin policy is not applied.",
+
        "api-pageset-param-titles": "A list of titles to work on.",
        "api-pageset-param-pageids": "A list of page IDs to work on.",
        "api-pageset-param-revids": "A list of revision IDs to work on.",
index da0b22d..672b7f0 100644 (file)
        "api-format-prettyprint-header": "{{technical}} Displayed as a header when API output is pretty-printed in HTML.\n\nParameters:\n* $1 - Format name\n* $2 - Non-pretty-printing module name",
        "api-format-prettyprint-header-only-html": "{{technical}} Displayed as a header when API output is pretty-printed in HTML, but there is no non-html module.\n\nParameters:\n* $1 - Format name",
        "api-format-prettyprint-status": "{{technical}} Displayed as a header when API pretty-printed output is used for a response that uses an unusual HTTP status code.\n\nParameters:\n* $1 - HTTP status code (integer)\n* $2 - Standard English text for the status code.",
+       "api-login-fail-aborted": "{{technical}} Displayed as an error when API login fails due to AuthManager requiring user interaction.\n\nSee also:\n* {{msg-mw|api-login-fail-aborted-nobotpw}}",
+       "api-login-fail-aborted-nobotpw": "{{technical}} Displayed as an error when API login fails due to AuthManager requiring user interaction. Used when BotPasswords is disabled.\n\nSee also:\n* {{msg-mw|api-login-fail-aborted}}",
+       "api-login-fail-badsessionprovider": "{{technical}} Displayed as an error when API login is not possible due to a session provider that doesn't support login.\n\nParameters:\n* $1 - Session type in use that makes it not possible to log in, from a message like {{msg-mw|sessionprovider-mediawiki-session-cookiesessionprovider}}.",
+       "api-login-fail-sameorigin": "{{technical}} Displayed as an error when API login is not possible because the request does not enforce the Same-Origin policy.",
        "api-pageset-param-titles": "{{doc-apihelp-param|pageset|titles|description=the \"titles\" parameter in pageset-using modules}}",
        "api-pageset-param-pageids": "{{doc-apihelp-param|pageset|pageids|description=the \"pageids\" parameter in pageset-using modules}}",
        "api-pageset-param-revids": "{{doc-apihelp-param|pageset|revids|description=the \"revids\" parameter in pageset-using modules}}",