diff --git a/admin/settings/language.php b/admin/settings/language.php index 14770828790..c865dfbfc2f 100644 --- a/admin/settings/language.php +++ b/admin/settings/language.php @@ -8,6 +8,8 @@ if ($hassiteconfig) { $temp = new admin_settingpage('langsettings', new lang_string('languagesettings', 'admin')); $temp->add(new admin_setting_configcheckbox('autolang', new lang_string('autolang', 'admin'), new lang_string('configautolang', 'admin'), 1)); $temp->add(new admin_setting_configselect('lang', new lang_string('lang', 'admin'), new lang_string('configlang', 'admin'), current_language(), get_string_manager()->get_list_of_translations())); // $CFG->lang might be set in installer already, default en is in setup.php + $temp->add(new admin_setting_configcheckbox('autolangusercreation', new lang_string('autolangusercreation', 'admin'), + new lang_string('configautolangusercreation', 'admin'), 1)); $temp->add(new admin_setting_configcheckbox('langmenu', new lang_string('langmenu', 'admin'), new lang_string('configlangmenu', 'admin'), 1)); $temp->add(new admin_setting_langlist()); $temp->add(new admin_setting_configcheckbox('langcache', new lang_string('langcache', 'admin'), new lang_string('langcache_desc', 'admin'), 1)); diff --git a/auth/db/auth.php b/auth/db/auth.php index 13da0f4b9ea..5c0f74fe7ed 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -454,9 +454,7 @@ class auth_plugin_db extends auth_plugin_base { $user->confirmed = 1; $user->auth = $this->authtype; $user->mnethostid = $CFG->mnet_localhost_id; - if (empty($user->lang)) { - $user->lang = $CFG->lang; - } + if ($collision = $DB->get_record_select('user', "username = :username AND mnethostid = :mnethostid AND auth <> :auth", array('username'=>$user->username, 'mnethostid'=>$CFG->mnet_localhost_id, 'auth'=>$this->authtype), 'id,username,auth')) { $trace->output(get_string('auth_dbinsertuserduplicate', 'auth_db', array('username'=>$user->username, 'auth'=>$collision->auth)), 1); continue; diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index f03372f3154..aae55224582 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -949,9 +949,7 @@ class auth_plugin_ldap extends auth_plugin_base { // // The cast to int is a workaround for MDL-53959. $user->suspended = (int)$this->is_user_suspended($user); - if (empty($user->lang)) { - $user->lang = $CFG->lang; - } + if (empty($user->calendartype)) { $user->calendartype = $CFG->calendartype; } diff --git a/auth/mnet/auth.php b/auth/mnet/auth.php index 2744dcddcb6..27cf5d708a8 100644 --- a/auth/mnet/auth.php +++ b/auth/mnet/auth.php @@ -278,13 +278,7 @@ class auth_plugin_mnet extends auth_plugin_base { if (isset($remoteuser->lang)) { $remoteuser->lang = clean_param(str_replace('_utf8', '', $remoteuser->lang), PARAM_LANG); } - if (empty($remoteuser->lang)) { - if (!empty($CFG->lang)) { - $remoteuser->lang = $CFG->lang; - } else { - $remoteuser->lang = 'en'; - } - } + $firsttime = false; // get the local record for the remote user diff --git a/backup/util/dbops/restore_dbops.class.php b/backup/util/dbops/restore_dbops.class.php index a5ca4515141..e8f13823455 100644 --- a/backup/util/dbops/restore_dbops.class.php +++ b/backup/util/dbops/restore_dbops.class.php @@ -1165,7 +1165,7 @@ abstract class restore_dbops { // if user lang doesn't exist here, use site default if (!array_key_exists($user->lang, $languages)) { - $user->lang = $CFG->lang; + $user->lang = get_newuser_language(); } // if user theme isn't available on target site or they are disabled, reset theme diff --git a/lang/en/admin.php b/lang/en/admin.php index f93e14c3326..6cbb336abc4 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -78,6 +78,7 @@ $string['authpreventaccountcreation'] = 'Prevent account creation when authentic $string['authpreventaccountcreation_help'] = 'When a user authenticates, an account on the site is automatically created if it doesn\'t yet exist. If an external database, such as LDAP, is used for authentication, but you wish to restrict access to the site to users with an existing account only, then this option should be enabled. New accounts will need to be created manually or via the upload users feature. Note that this setting doesn\'t apply to MNet authentication.'; $string['authsettings'] = 'Manage authentication'; $string['autolang'] = 'Language autodetect'; +$string['autolangusercreation'] = 'Use language that is auto detected from users browser during user creation'; $string['autologinguests'] = 'Auto-login guests'; $string['searchareas'] = 'Search areas'; $string['availableto'] = 'Available to'; @@ -173,6 +174,7 @@ $string['configallowview'] = 'Select which roles a user will see, be able to fil $string['configallusersaresitestudents'] = 'For activities on the front page of the site, should ALL users be considered as students? If you answer "Yes", then any confirmed user account will be allowed to participate as a student in those activities. If you answer "No", then only users who are already a participant in at least one course will be able to take part in those front page activities. Only admins and specially assigned teachers can act as teachers for these front page activities.'; $string['configauthenticationplugins'] = 'Please choose the authentication plugins you wish to use and arrange them in order of failthrough.'; $string['configautolang'] = 'Detect default language from browser setting, if disabled site default is used.'; +$string['configautolangusercreation'] = 'Use language from users browser during user creation'; $string['configautologinguests'] = 'Should visitors be logged in as guests automatically when entering courses with guest access?'; $string['configbloglevel'] = 'This setting allows you to restrict the level to which user blogs can be viewed on this site. Note that they specify the maximum context of the VIEWER not the poster or the types of blog posts. Blogs can also be disabled completely if you don\'t want them at all.'; $string['configcalendarcustomexport'] = 'Enable custom date range export of calendar'; diff --git a/lib/classes/user.php b/lib/classes/user.php index 70132873da0..e20dd2c7a19 100644 --- a/lib/classes/user.php +++ b/lib/classes/user.php @@ -658,7 +658,7 @@ class core_user { * @return void */ protected static function fill_properties_cache() { - global $CFG; + global $CFG, $SESSION; if (self::$propertiescache !== null) { return; } @@ -694,7 +694,8 @@ class core_user { $fields['city'] = array('type' => PARAM_TEXT, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->defaultcity); $fields['country'] = array('type' => PARAM_ALPHA, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->country, 'choices' => array_merge(array('' => ''), get_string_manager()->get_list_of_countries(true, true))); - $fields['lang'] = array('type' => PARAM_LANG, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->lang, + $fields['lang'] = array('type' => PARAM_LANG, 'null' => NULL_NOT_ALLOWED, + 'default' => (!empty($CFG->autolangusercreation) && !empty($SESSION->lang)) ? $SESSION->lang : $CFG->lang, 'choices' => array_merge(array('' => ''), get_string_manager()->get_list_of_translations(false))); $fields['calendartype'] = array('type' => PARAM_PLUGIN, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->calendartype, 'choices' => array_merge(array('' => ''), \core_calendar\type_factory::get_list_of_calendar_types())); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 0283ceb904b..c15e8d6b63d 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -3991,6 +3991,16 @@ function get_user_fieldnames() { return $fieldarray; } +/** + * Returns the string of the language for the new user. + * + * @return string language for the new user + */ +function get_newuser_language() { + global $CFG, $SESSION; + return (!empty($CFG->autolangusercreation) && !empty($SESSION->lang)) ? $SESSION->lang : $CFG->lang; +} + /** * Creates a bare-bones user record * @@ -4002,7 +4012,7 @@ function get_user_fieldnames() { * @return stdClass A complete user object */ function create_user_record($username, $password, $auth = 'manual') { - global $CFG, $DB; + global $CFG, $DB, $SESSION; require_once($CFG->dirroot.'/user/profile/lib.php'); require_once($CFG->dirroot.'/user/lib.php'); @@ -4038,7 +4048,7 @@ function create_user_record($username, $password, $auth = 'manual') { // user CFG lang for user if $newuser->lang is empty // or $user->lang is not an installed language. if (empty($newuser->lang) || !get_string_manager()->translation_exists($newuser->lang)) { - $newuser->lang = $CFG->lang; + $newuser->lang = get_newuser_language(); } $newuser->confirmed = 1; $newuser->lastip = getremoteaddr(); @@ -4378,7 +4388,7 @@ function guest_user() { if ($newuser = $DB->get_record('user', array('id' => $CFG->siteguest))) { $newuser->confirmed = 1; - $newuser->lang = $CFG->lang; + $newuser->lang = get_newuser_language(); $newuser->lastip = getremoteaddr(); } @@ -5026,7 +5036,7 @@ function get_complete_user_data($field, $value, $mnethostid = null, $throwexcept } if (isguestuser($user)) { // Guest language always same as site. - $user->lang = $CFG->lang; + $user->lang = get_newuser_language(); // Name always in current language. $user->firstname = get_string('guestuser'); $user->lastname = ' '; @@ -6460,7 +6470,7 @@ function setnew_password_and_mail($user, $fasthash = false) { // We try to send the mail in language the user understands, // unfortunately the filter_string() does not support alternative langs yet // so multilang will not work properly for site->fullname. - $lang = empty($user->lang) ? $CFG->lang : $user->lang; + $lang = empty($user->lang) ? get_newuser_language() : $user->lang; $site = get_site();