From 6e8be422daafef68cb6adb4f7a6507959cdedc0f Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Sat, 9 Mar 2013 06:57:07 -0400 Subject: [PATCH] Set lang in api createaccount regardless of $wgLoginLanguageSelector $wgLoginLanguageSelector is related to how the interface of special:userlogin works. It doesn't make sense to listen to it in the api module Also throw error if invalid lang code is specified (for sanity) Change-Id: Ibf72fd5a318cadc450b3b579757ee8145864a27a --- includes/api/ApiCreateAccount.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/includes/api/ApiCreateAccount.php b/includes/api/ApiCreateAccount.php index 55c60cce2e..1eb1aa5cb8 100644 --- a/includes/api/ApiCreateAccount.php +++ b/includes/api/ApiCreateAccount.php @@ -54,6 +54,10 @@ class ApiCreateAccount extends ApiBase { $this->dieUsageMsg( 'noemail' ); } + if ( $params['language'] && !Language::isSupportedLanguage( $params['language'] ) ) { + $this->dieUsage( 'Invalid language parameter', 'langinvalid' ); + } + $context = new DerivativeContext( $this->getContext() ); $context->setRequest( new DerivativeRequest( $this->getContext()->getRequest(), @@ -80,12 +84,10 @@ class ApiCreateAccount extends ApiBase { $result = array(); if( $status->isGood() ) { // Success! + global $wgEmailAuthentication; $user = $status->getValue(); - // If we showed up language selection links, and one was in use, be - // smart (and sensible) and save that language as the user's preference - global $wgLoginLanguageSelector, $wgEmailAuthentication; - if( $wgLoginLanguageSelector && $params['language'] ) { + if( $params['language'] ) { $user->setOption( 'language', $params['language'] ); } @@ -275,6 +277,10 @@ class ApiCreateAccount extends ApiBase { 'code' => 'aborted', 'info' => 'Account creation aborted by hook (info may vary)' ); + $errors[] = array( + 'code' => 'langinvalid', + 'info' => 'Invalid language parameter' + ); // 'passwordtooshort' has parameters. :( global $wgMinimalPasswordLength; -- 2.20.1