Merge "Handle missing namespace prefix in XML dumps more gracefully"
[lhc/web/wiklou.git] / includes / api / ApiLogin.php
index 6ac261d..d64aeb7 100644 (file)
@@ -70,13 +70,7 @@ class ApiLogin extends ApiBase {
                        return;
                }
 
-               try {
-                       $this->requirePostedParameters( [ 'password', 'token' ] );
-               } catch ( UsageException $ex ) {
-                       // Make this a warning for now, upgrade to an error in 1.29.
-                       $this->setWarning( $ex->getMessage() );
-                       $this->logFeatureUsage( 'login-params-in-query-string' );
-               }
+               $this->requirePostedParameters( [ 'password', 'token' ] );
 
                $params = $this->extractRequestParams();
 
@@ -146,15 +140,10 @@ class ApiLogin extends ApiBase {
                        switch ( $res->status ) {
                                case AuthenticationResponse::PASS:
                                        if ( $this->getConfig()->get( 'EnableBotPasswords' ) ) {
-                                               $warn = 'Main-account login via action=login is deprecated and may stop working ' .
-                                                       'without warning.';
-                                               $warn .= ' To continue login with action=login, see [[Special:BotPasswords]].';
-                                               $warn .= ' To safely continue using main-account login, see action=clientlogin.';
+                                               $this->addDeprecation( 'apiwarn-deprecation-login-botpw', 'main-account-login' );
                                        } else {
-                                               $warn = 'Login via action=login is deprecated and may stop working without warning.';
-                                               $warn .= ' To safely log in, see action=clientlogin.';
+                                               $this->addDeprecation( 'apiwarn-deprecation-login-nobotpw', 'main-account-login' );
                                        }
-                                       $this->setWarning( $warn );
                                        $authRes = 'Success';
                                        $loginType = 'AuthManager';
                                        break;
@@ -194,21 +183,26 @@ class ApiLogin extends ApiBase {
 
                        case 'NeedToken':
                                $result['token'] = $token->toString();
-                               $this->setWarning( 'Fetching a token via action=login is deprecated. ' .
-                                  'Use action=query&meta=tokens&type=login instead.' );
-                               $this->logFeatureUsage( 'action=login&!lgtoken' );
+                               $this->addDeprecation( 'apiwarn-deprecation-login-token', 'action=login&!lgtoken' );
                                break;
 
                        case 'WrongToken':
                                break;
 
                        case 'Failed':
-                               $result['reason'] = $message->useDatabase( 'false' )->inLanguage( 'en' )->text();
+                               $errorFormatter = $this->getErrorFormatter();
+                               if ( $errorFormatter instanceof ApiErrorFormatter_BackCompat ) {
+                                       $result['reason'] = ApiErrorFormatter::stripMarkup(
+                                               $message->useDatabase( false )->inLanguage( 'en' )->text()
+                                       );
+                               } else {
+                                       $result['reason'] = $errorFormatter->formatMessage( $message );
+                               }
                                break;
 
                        case 'Aborted':
                                $result['reason'] = 'Authentication requires user interaction, ' .
-                                  'which is not supported by action=login.';
+                                       '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.';