From: Brad Jorsch Date: Tue, 16 May 2017 14:14:03 +0000 (-0400) Subject: ApiLogin: i18n for 'Aborted' reasons X-Git-Tag: 1.31.0-rc.0~3237^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=b6502d489473daeb680a8d93f7838e4ce01ad8dc;p=lhc%2Fweb%2Fwiklou.git ApiLogin: i18n for 'Aborted' reasons Ia6c402a4 did it for 'Failed', but overlooked 'Aborted'. Change-Id: I3f7379af3609c30f10ea8c648f2ec840310e8d97 --- diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30 index d32db34cf1..b24a08d8b1 100644 --- a/RELEASE-NOTES-1.30 +++ b/RELEASE-NOTES-1.30 @@ -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 === * … diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 41bec355a7..398c8c722b 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -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: diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index c3c7bd4571..5f52a1e2b2 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -1495,6 +1495,11 @@ "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 action=login. To be able to login with action=login, see [[Special:BotPasswords]]. To continue using main-account login, see [[Special:ApiHelp/clientlogin|action=clientlogin]].", + "api-login-fail-aborted-nobotpw": "Authentication requires user interaction, which is not supported by action=login. To log in, see [[Special:ApiHelp/clientlogin|action=clientlogin]].", + "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.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index da0b22d892..672b7f0918 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -1390,6 +1390,10 @@ "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}}",