X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiLogin.php;h=398c8c722b7d49d8558854f1d0b223cce3ab6d77;hb=b6502d489473daeb680a8d93f7838e4ce01ad8dc;hp=6cf1fad30cd8827f6d23b2da8e4ce43f75d1a859;hpb=5b1dcdc344f5d251120a161637bcb89e01b0f6a4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 6cf1fad30c..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,20 +81,13 @@ 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; } - try { - $this->requirePostedParameters( [ 'password', 'token' ] ); - } catch ( ApiUsageException $ex ) { - // Make this a warning for now, upgrade to an error in 1.29. - foreach ( $ex->getStatusValue()->getErrors() as $error ) { - $this->addDeprecation( $error, 'login-params-in-query-string' ); - } - } + $this->requirePostedParameters( [ 'password', 'token' ] ); $params = $this->extractRequestParams(); @@ -91,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; @@ -197,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: @@ -257,6 +259,7 @@ class ApiLogin extends ApiBase { 'token' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => false, // for BC + ApiBase::PARAM_SENSITIVE => true, ApiBase::PARAM_HELP_MSG => [ 'api-help-param-token', 'login' ], ], ]; @@ -272,7 +275,7 @@ class ApiLogin extends ApiBase { } public function getHelpUrls() { - return 'https://www.mediawiki.org/wiki/API:Login'; + return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Login'; } /**