MDL-52781 core_user: replace direct PARAM_ usages.
authorSimey Lameze <simey@moodle.com>
Mon, 11 Apr 2016 04:16:09 +0000 (12:16 +0800)
committerSimey Lameze <simey@moodle.com>
Thu, 21 Apr 2016 07:24:36 +0000 (15:24 +0800)
This commit replace as much as possible of clean_param and PARAM_ usages related to user object.
Also few unit tests has been changed to match the new validation

16 files changed:
admin/tool/uploaduser/index.php
admin/tool/uploaduser/user_form.php
admin/webservice/testclient_forms.php
auth/ldap/tests/plugin_test.php
lib/testing/tests/generator_test.php
lib/tests/datalib_test.php
login/index.php
login/signup_form.php
user/editadvanced_form.php
user/editlib.php
user/externallib.php
user/forum_form.php
user/language.php
user/language_form.php
user/lib.php
user/tests/externallib_test.php

index b053388..0916d50 100644 (file)
@@ -280,7 +280,7 @@ if ($formdata = $mform2->is_cancelled()) {
         // normalize username
         $originalusername = $user->username;
         if ($standardusernames) {
         // normalize username
         $originalusername = $user->username;
         if ($standardusernames) {
-            $user->username = clean_param($user->username, PARAM_USERNAME);
+            $user->username = core_user::clean_field($user->username, 'username');
         }
 
         // make sure we really have username
         }
 
         // make sure we really have username
@@ -295,7 +295,7 @@ if ($formdata = $mform2->is_cancelled()) {
             continue;
         }
 
             continue;
         }
 
-        if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
+        if ($user->username !== core_user::clean_field($user->username, 'username')) {
             $upt->track('status', get_string('invalidusername', 'error', 'username'), 'error');
             $upt->track('username', $errorstr, 'error');
             $userserrors++;
             $upt->track('status', get_string('invalidusername', 'error', 'username'), 'error');
             $upt->track('username', $errorstr, 'error');
             $userserrors++;
@@ -443,7 +443,7 @@ if ($formdata = $mform2->is_cancelled()) {
             }
 
             if ($standardusernames) {
             }
 
             if ($standardusernames) {
-                $oldusername = clean_param($user->oldusername, PARAM_USERNAME);
+                $oldusername = core_user::clean_field($user->oldusername, 'username');
             } else {
                 $oldusername = $user->oldusername;
             }
             } else {
                 $oldusername = $user->oldusername;
             }
@@ -597,7 +597,7 @@ if ($formdata = $mform2->is_cancelled()) {
                             if (empty($user->lang)) {
                                 // Do not change to not-set value.
                                 continue;
                             if (empty($user->lang)) {
                                 // Do not change to not-set value.
                                 continue;
-                            } else if (clean_param($user->lang, PARAM_LANG) === '') {
+                            } else if (core_user::clean_field($user->lang, 'lang') === '') {
                                 $upt->track('status', get_string('cannotfindlang', 'error', $user->lang), 'warning');
                                 continue;
                             }
                                 $upt->track('status', get_string('cannotfindlang', 'error', $user->lang), 'warning');
                                 continue;
                             }
@@ -774,7 +774,7 @@ if ($formdata = $mform2->is_cancelled()) {
 
             if (empty($user->lang)) {
                 $user->lang = '';
 
             if (empty($user->lang)) {
                 $user->lang = '';
-            } else if (clean_param($user->lang, PARAM_LANG) === '') {
+            } else if (core_user::clean_field($user->lang, 'lang') === '') {
                 $upt->track('status', get_string('cannotfindlang', 'error', $user->lang), 'warning');
                 $user->lang = '';
             }
                 $upt->track('status', get_string('cannotfindlang', 'error', $user->lang), 'warning');
                 $user->lang = '';
             }
@@ -1177,7 +1177,7 @@ while ($linenum <= $previewrows and $fields = $cir->next()) {
     $rowcols['status'] = array();
 
     if (isset($rowcols['username'])) {
     $rowcols['status'] = array();
 
     if (isset($rowcols['username'])) {
-        $stdusername = clean_param($rowcols['username'], PARAM_USERNAME);
+        $stdusername = core_user::clean_field($rowcols['username'], 'username');
         if ($rowcols['username'] !== $stdusername) {
             $rowcols['status'][] = get_string('invalidusernameupload');
         }
         if ($rowcols['username'] !== $stdusername) {
             $rowcols['status'][] = get_string('invalidusernameupload');
         }
index 218392e..dfd2123 100644 (file)
@@ -226,28 +226,28 @@ class admin_uploaduser_form2 extends moodleform {
 
         $choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse'));
         $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
 
         $choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse'));
         $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
-        $mform->setDefault('maildisplay', $CFG->defaultpreference_maildisplay);
+        $mform->setDefault('maildisplay', core_user::get_property_default('maildisplay'));
 
         $choices = array(0 => get_string('textformat'), 1 => get_string('htmlformat'));
         $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
 
         $choices = array(0 => get_string('textformat'), 1 => get_string('htmlformat'));
         $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
-        $mform->setDefault('mailformat', $CFG->defaultpreference_mailformat);
+        $mform->setDefault('mailformat', core_user::get_property_default('mailformat'));
         $mform->setAdvanced('mailformat');
 
         $choices = array(0 => get_string('emaildigestoff'), 1 => get_string('emaildigestcomplete'), 2 => get_string('emaildigestsubjects'));
         $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
         $mform->setAdvanced('mailformat');
 
         $choices = array(0 => get_string('emaildigestoff'), 1 => get_string('emaildigestcomplete'), 2 => get_string('emaildigestsubjects'));
         $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
-        $mform->setDefault('maildigest', $CFG->defaultpreference_maildigest);
+        $mform->setDefault('maildigest', core_user::get_property_default('maildigest'));
         $mform->setAdvanced('maildigest');
 
         $choices = array(1 => get_string('autosubscribeyes'), 0 => get_string('autosubscribeno'));
         $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
         $mform->setAdvanced('maildigest');
 
         $choices = array(1 => get_string('autosubscribeyes'), 0 => get_string('autosubscribeno'));
         $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
-        $mform->setDefault('autosubscribe', $CFG->defaultpreference_autosubscribe);
+        $mform->setDefault('autosubscribe', core_user::get_property_default('autosubscribe'));
 
         $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="25"');
         $mform->setType('city', PARAM_TEXT);
         if (empty($CFG->defaultcity)) {
             $mform->setDefault('city', $templateuser->city);
         } else {
 
         $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="25"');
         $mform->setType('city', PARAM_TEXT);
         if (empty($CFG->defaultcity)) {
             $mform->setDefault('city', $templateuser->city);
         } else {
-            $mform->setDefault('city', $CFG->defaultcity);
+            $mform->setDefault('city', core_user::get_property_default('city'));
         }
 
         $choices = get_string_manager()->get_list_of_countries();
         }
 
         $choices = get_string_manager()->get_list_of_countries();
@@ -256,7 +256,7 @@ class admin_uploaduser_form2 extends moodleform {
         if (empty($CFG->country)) {
             $mform->setDefault('country', $templateuser->country);
         } else {
         if (empty($CFG->country)) {
             $mform->setDefault('country', $templateuser->country);
         } else {
-            $mform->setDefault('country', $CFG->country);
+            $mform->setDefault('country', core_user::get_property_default('country'));
         }
         $mform->setAdvanced('country');
 
         }
         $mform->setAdvanced('country');
 
index ab88e23..cc958c2 100644 (file)
@@ -41,28 +41,28 @@ class moodle_user_create_users_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_SAFEDIR);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
 
         /// specific to the create users function
         $mform->addElement('text', 'username', 'username');
 
         /// specific to the create users function
         $mform->addElement('text', 'username', 'username');
-        $mform->setType('username', PARAM_USERNAME);
+        $mform->setType('username', core_user::get_property_type('username'));
         $mform->addElement('text', 'password', 'password');
         $mform->addElement('text', 'password', 'password');
-        $mform->setType('password', PARAM_RAW);
+        $mform->setType('password', core_user::get_property_type('password'));
         $mform->addElement('text', 'firstname', 'firstname');
         $mform->addElement('text', 'firstname', 'firstname');
-        $mform->setType('firstname', PARAM_RAW);
+        $mform->setType('firstname', core_user::get_property_type('firstname'));
         $mform->addElement('text', 'lastname', 'lastname');
         $mform->addElement('text', 'lastname', 'lastname');
-        $mform->setType('lastname', PARAM_RAW);
+        $mform->setType('lastname', core_user::get_property_type('lastname'));
         $mform->addElement('text', 'email', 'email');
         $mform->addElement('text', 'email', 'email');
-        $mform->setType('email', PARAM_EMAIL);
+        $mform->setType('email', core_user::get_property_type('email'));
 
         $mform->addElement('text', 'customfieldtype', 'customfieldtype');
         $mform->setType('customfieldtype', PARAM_RAW);
 
         $mform->addElement('text', 'customfieldtype', 'customfieldtype');
         $mform->setType('customfieldtype', PARAM_RAW);
@@ -125,31 +125,31 @@ class moodle_user_update_users_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
 
         /// specific to the create users function
         $mform->addElement('text', 'id', 'id');
         $mform->addRule('id', get_string('required'), 'required', null, 'client');
 
         /// specific to the create users function
         $mform->addElement('text', 'id', 'id');
         $mform->addRule('id', get_string('required'), 'required', null, 'client');
-        $mform->setType('id', PARAM_INT);
+        $mform->setType('id', core_user::get_property_type('id'));
         $mform->addElement('text', 'username', 'username');
         $mform->addElement('text', 'username', 'username');
-        $mform->setType('username', PARAM_USERNAME);
+        $mform->setType('username', core_user::get_property_type('username'));
         $mform->addElement('text', 'password', 'password');
         $mform->addElement('text', 'password', 'password');
-        $mform->setType('password', PARAM_RAW);
+        $mform->setType('password', core_user::get_property_type('password'));
         $mform->addElement('text', 'firstname', 'firstname');
         $mform->addElement('text', 'firstname', 'firstname');
-        $mform->setType('firstname', PARAM_RAW);
+        $mform->setType('firstname', core_user::get_property_type('firstname'));
         $mform->addElement('text', 'lastname', 'lastname');
         $mform->addElement('text', 'lastname', 'lastname');
-        $mform->setType('lastname', PARAM_RAW);
+        $mform->setType('lastname', core_user::get_property_type('lastname'));
         $mform->addElement('text', 'email', 'email');
         $mform->addElement('text', 'email', 'email');
-        $mform->setType('email', PARAM_EMAIL);
+        $mform->setType('email', core_user::get_property_type('email'));
 
 
         $mform->addElement('text', 'customfieldtype', 'customfieldtype');
 
 
         $mform->addElement('text', 'customfieldtype', 'customfieldtype');
@@ -219,23 +219,23 @@ class moodle_user_delete_users_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
 
         /// beginning of specific code to the create users function
         $mform->addElement('text', 'userids[0]', 'userids[0]');
         $mform->addElement('text', 'userids[1]', 'userids[1]');
         $mform->addElement('text', 'userids[2]', 'userids[2]');
         $mform->addElement('text', 'userids[3]', 'userids[3]');
 
         /// beginning of specific code to the create users function
         $mform->addElement('text', 'userids[0]', 'userids[0]');
         $mform->addElement('text', 'userids[1]', 'userids[1]');
         $mform->addElement('text', 'userids[2]', 'userids[2]');
         $mform->addElement('text', 'userids[3]', 'userids[3]');
-        $mform->setType('userids', PARAM_INT);
+        $mform->setType('userids', core_user::get_property_type('id'));
         /// end of specific code to the create users function
 
         $mform->addElement('hidden', 'function');
         /// end of specific code to the create users function
 
         $mform->addElement('hidden', 'function');
@@ -291,23 +291,23 @@ class moodle_user_get_users_by_id_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
 
         /// beginning of specific code to the create users function
         $mform->addElement('text', 'userids[0]', 'userids[0]');
         $mform->addElement('text', 'userids[1]', 'userids[1]');
         $mform->addElement('text', 'userids[2]', 'userids[2]');
         $mform->addElement('text', 'userids[3]', 'userids[3]');
 
         /// beginning of specific code to the create users function
         $mform->addElement('text', 'userids[0]', 'userids[0]');
         $mform->addElement('text', 'userids[1]', 'userids[1]');
         $mform->addElement('text', 'userids[2]', 'userids[2]');
         $mform->addElement('text', 'userids[3]', 'userids[3]');
-        $mform->setType('userids', PARAM_INT);
+        $mform->setType('userids', core_user::get_property_type('id'));
         /// end of specific code to the create users function
 
         $mform->addElement('hidden', 'function');
         /// end of specific code to the create users function
 
         $mform->addElement('hidden', 'function');
@@ -364,16 +364,16 @@ class moodle_group_create_groups_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
 
         $mform->addElement('text', 'courseid', 'courseid');
         $mform->setType('courseid', PARAM_INT);
 
         $mform->addElement('text', 'courseid', 'courseid');
         $mform->setType('courseid', PARAM_INT);
@@ -430,16 +430,16 @@ class moodle_group_get_groups_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
         $mform->addElement('text', 'groupids[0]', 'groupids[0]');
         $mform->addElement('text', 'groupids[1]', 'groupids[1]');
         $mform->addElement('text', 'groupids[2]', 'groupids[2]');
         $mform->addElement('text', 'groupids[0]', 'groupids[0]');
         $mform->addElement('text', 'groupids[1]', 'groupids[1]');
         $mform->addElement('text', 'groupids[2]', 'groupids[2]');
@@ -493,16 +493,16 @@ class moodle_group_get_course_groups_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
         $mform->addElement('text', 'courseid', 'courseid');
 
         $mform->addElement('hidden', 'function');
         $mform->addElement('text', 'courseid', 'courseid');
 
         $mform->addElement('hidden', 'function');
@@ -546,16 +546,16 @@ class moodle_group_delete_groups_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
         $mform->addElement('text', 'groupids[0]', 'groupids[0]');
         $mform->addElement('text', 'groupids[1]', 'groupids[1]');
         $mform->addElement('text', 'groupids[2]', 'groupids[2]');
         $mform->addElement('text', 'groupids[0]', 'groupids[0]');
         $mform->addElement('text', 'groupids[1]', 'groupids[1]');
         $mform->addElement('text', 'groupids[2]', 'groupids[2]');
@@ -611,16 +611,16 @@ class moodle_group_get_groupmembers_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
         $mform->addElement('text', 'groupids[0]', 'groupids[0]');
         $mform->addElement('text', 'groupids[1]', 'groupids[1]');
         $mform->addElement('text', 'groupids[2]', 'groupids[2]');
         $mform->addElement('text', 'groupids[0]', 'groupids[0]');
         $mform->addElement('text', 'groupids[1]', 'groupids[1]');
         $mform->addElement('text', 'groupids[2]', 'groupids[2]');
@@ -674,21 +674,21 @@ class moodle_group_add_groupmembers_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_SAFEDIR);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
         $mform->addElement('text', 'userid[0]', 'userid[0]');
         $mform->addElement('text', 'groupid[0]', 'groupid[0]');
         $mform->addElement('text', 'userid[1]', 'userid[1]');
         $mform->addElement('text', 'groupid[1]', 'groupid[1]');
         $mform->addElement('text', 'userid[0]', 'userid[0]');
         $mform->addElement('text', 'groupid[0]', 'groupid[0]');
         $mform->addElement('text', 'userid[1]', 'userid[1]');
         $mform->addElement('text', 'groupid[1]', 'groupid[1]');
-        $mform->setType('userid', PARAM_INT);
+        $mform->setType('userid', core_user::get_property_type('id'));
         $mform->setType('groupids', PARAM_INT);
 
         $mform->addElement('hidden', 'function');
         $mform->setType('groupids', PARAM_INT);
 
         $mform->addElement('hidden', 'function');
@@ -738,16 +738,16 @@ class moodle_group_delete_groupmembers_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
         $mform->addElement('text', 'userid[0]', 'userid[0]');
         $mform->addElement('text', 'groupid[0]', 'groupid[0]');
         $mform->addElement('text', 'userid[1]', 'userid[1]');
         $mform->addElement('text', 'userid[0]', 'userid[0]');
         $mform->addElement('text', 'groupid[0]', 'groupid[0]');
         $mform->addElement('text', 'userid[1]', 'userid[1]');
@@ -812,16 +812,16 @@ class core_course_create_categories_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
         $mform->addElement('text', 'name[0]', 'name[0]');
         $mform->addElement('text', 'parent[0]', 'parent[0]');
         $mform->addElement('text', 'idnumber[0]', 'idnumber[0]');
         $mform->addElement('text', 'name[0]', 'name[0]');
         $mform->addElement('text', 'parent[0]', 'parent[0]');
         $mform->addElement('text', 'idnumber[0]', 'idnumber[0]');
@@ -830,10 +830,10 @@ class core_course_create_categories_form extends moodleform {
         $mform->addElement('text', 'parent[1]', 'parent[1]');
         $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
         $mform->addElement('text', 'description[1]', 'description[1]');
         $mform->addElement('text', 'parent[1]', 'parent[1]');
         $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
         $mform->addElement('text', 'description[1]', 'description[1]');
-        $mform->setType('name', PARAM_TEXT);
-        $mform->setType('parent', PARAM_INT);
-        $mform->setType('idnumber', PARAM_RAW);
-        $mform->setType('description', PARAM_TEXT);
+        $mform->setType('name', core_user::get_property_type('firstname'));
+        $mform->setType('parent', core_user::get_property_type('id'));
+        $mform->setType('idnumber', core_user::get_property_type('idnumber'));
+        $mform->setType('description', core_user::get_property_type('description'));
 
         $mform->addElement('hidden', 'function');
         $mform->setType('function', PARAM_PLUGIN);
 
         $mform->addElement('hidden', 'function');
         $mform->setType('function', PARAM_PLUGIN);
@@ -896,23 +896,23 @@ class core_course_delete_categories_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
         $mform->addElement('text', 'id[0]', 'id[0]');
         $mform->addElement('text', 'newparent[0]', 'newparent[0]');
         $mform->addElement('text', 'recursive[0]', 'recursive[0]');
         $mform->addElement('text', 'id[1]', 'id[1]');
         $mform->addElement('text', 'newparent[1]', 'newparent[1]');
         $mform->addElement('text', 'recursive[1]', 'recursive[1]');
         $mform->addElement('text', 'id[0]', 'id[0]');
         $mform->addElement('text', 'newparent[0]', 'newparent[0]');
         $mform->addElement('text', 'recursive[0]', 'recursive[0]');
         $mform->addElement('text', 'id[1]', 'id[1]');
         $mform->addElement('text', 'newparent[1]', 'newparent[1]');
         $mform->addElement('text', 'recursive[1]', 'recursive[1]');
-        $mform->setType('id', PARAM_INT);
+        $mform->setType('id', core_user::get_property_type('id'));
         $mform->setType('newparent', PARAM_INT);
         $mform->setType('recursive', PARAM_BOOL);
 
         $mform->setType('newparent', PARAM_INT);
         $mform->setType('recursive', PARAM_BOOL);
 
@@ -984,16 +984,16 @@ class core_course_update_categories_form extends moodleform {
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
         $data = $this->_customdata;
         if ($data['authmethod'] == 'simple') {
             $mform->addElement('text', 'wsusername', 'wsusername');
-            $mform->setType('wsusername', PARAM_USERNAME);
+            $mform->setType('wsusername', core_user::get_property_type('username'));
             $mform->addElement('text', 'wspassword', 'wspassword');
             $mform->addElement('text', 'wspassword', 'wspassword');
-            $mform->setType('wspassword', PARAM_RAW);
+            $mform->setType('wspassword', core_user::get_property_type('password'));
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
         } else if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
 
         $mform->addElement('hidden', 'authmethod', $data['authmethod']);
-        $mform->setType('authmethod', PARAM_ALPHA);
+        $mform->setType('authmethod', core_user::get_property_type('auth'));
         $mform->addElement('text', 'id[0]', 'id[0]');
         $mform->addElement('text', 'name[0]', 'name[0]');
         $mform->addElement('text', 'parent[0]', 'parent[0]');
         $mform->addElement('text', 'id[0]', 'id[0]');
         $mform->addElement('text', 'name[0]', 'name[0]');
         $mform->addElement('text', 'parent[0]', 'parent[0]');
@@ -1004,11 +1004,11 @@ class core_course_update_categories_form extends moodleform {
         $mform->addElement('text', 'parent[1]', 'parent[1]');
         $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
         $mform->addElement('text', 'description[1]', 'description[1]');
         $mform->addElement('text', 'parent[1]', 'parent[1]');
         $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
         $mform->addElement('text', 'description[1]', 'description[1]');
-        $mform->setType('id', PARAM_INT);
-        $mform->setType('name', PARAM_TEXT);
+        $mform->setType('id', core_user::get_property_type('id'));
+        $mform->setType('name', core_user::get_property_type('firstname'));
         $mform->setType('parent', PARAM_INT);
         $mform->setType('parent', PARAM_INT);
-        $mform->setType('idnumber', PARAM_RAW);
-        $mform->setType('description', PARAM_TEXT);
+        $mform->setType('idnumber', core_user::get_property_type('idnumber'));
+        $mform->setType('description', core_user::get_property_type('description'));
 
         $mform->addElement('hidden', 'function');
         $mform->setType('function', PARAM_PLUGIN);
 
         $mform->addElement('hidden', 'function');
         $mform->setType('function', PARAM_PLUGIN);
index ba82adc..dff1485 100644 (file)
@@ -365,7 +365,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
             'email' => 'usersignuptest1@example.com',
             'description' => 'This is a description for user 1',
             'city' => 'Perth',
             'email' => 'usersignuptest1@example.com',
             'description' => 'This is a description for user 1',
             'city' => 'Perth',
-            'country' => 'au',
+            'country' => 'AU',
             'mnethostid' => $CFG->mnet_localhost_id,
             'auth' => 'ldap'
             );
             'mnethostid' => $CFG->mnet_localhost_id,
             'auth' => 'ldap'
             );
index 0c55fab..c80d600 100644 (file)
@@ -64,8 +64,8 @@ class core_test_generator_testcase extends advanced_testcase {
         $this->setCurrentTimeStart();
         $user = $generator->create_user();
         $this->assertEquals($count + 1, $DB->count_records('user'));
         $this->setCurrentTimeStart();
         $user = $generator->create_user();
         $this->assertEquals($count + 1, $DB->count_records('user'));
-        $this->assertSame($user->username, clean_param($user->username, PARAM_USERNAME));
-        $this->assertSame($user->email, clean_param($user->email, PARAM_EMAIL));
+        $this->assertSame($user->username, core_user::clean_field($user->username, 'username'));
+        $this->assertSame($user->email, core_user::clean_field($user->email, 'email'));
         $this->assertSame(AUTH_PASSWORD_NOT_CACHED, $user->password);
         $this->assertNotEmpty($user->firstnamephonetic);
         $this->assertNotEmpty($user->lastnamephonetic);
         $this->assertSame(AUTH_PASSWORD_NOT_CACHED, $user->password);
         $this->assertNotEmpty($user->firstnamephonetic);
         $this->assertNotEmpty($user->lastnamephonetic);
index 0a4a6b7..b334a3f 100644 (file)
@@ -71,7 +71,7 @@ class core_datalib_testcase extends advanced_testcase {
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
-            'country' => 'au'
+            'country' => 'AU'
             );
         $user1 = self::getDataGenerator()->create_user($user1);
         $user2 = array(
             );
         $user1 = self::getDataGenerator()->create_user($user1);
         $user2 = array(
@@ -94,7 +94,7 @@ class core_datalib_testcase extends advanced_testcase {
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
-            'country' => 'au'
+            'country' => 'AU'
             );
         $user2 = self::getDataGenerator()->create_user($user2);
 
             );
         $user2 = self::getDataGenerator()->create_user($user2);
 
index b223b73..b277f89 100644 (file)
@@ -137,7 +137,7 @@ if ($frm and isset($frm->username)) {                             // Login WITH
     $frm->username = trim(core_text::strtolower($frm->username));
 
     if (is_enabled_auth('none') ) {
     $frm->username = trim(core_text::strtolower($frm->username));
 
     if (is_enabled_auth('none') ) {
-        if ($frm->username !== clean_param($frm->username, PARAM_USERNAME)) {
+        if ($frm->username !== core_user::clean_field($frm->username, 'username')) {
             $errormsg = get_string('username').': '.get_string("invalidusername");
             $errorcode = 2;
             $user = null;
             $errormsg = get_string('username').': '.get_string("invalidusername");
             $errorcode = 2;
             $user = null;
@@ -312,6 +312,7 @@ if (!isset($frm) or !is_object($frm)) {
 
 if (empty($frm->username) && $authsequence[0] != 'shibboleth') {  // See bug 5184
     if (!empty($_GET["username"])) {
 
 if (empty($frm->username) && $authsequence[0] != 'shibboleth') {  // See bug 5184
     if (!empty($_GET["username"])) {
+        // we do not want data from _POST here
         $frm->username = clean_param($_GET["username"], PARAM_RAW); // we do not want data from _POST here
     } else {
         $frm->username = get_moodle_cookie();
         $frm->username = clean_param($_GET["username"], PARAM_RAW); // we do not want data from _POST here
     } else {
         $frm->username = get_moodle_cookie();
index 45966f6..6bb97ce 100644 (file)
@@ -40,30 +40,30 @@ class login_signup_form extends moodleform {
 
 
         $mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"');
 
 
         $mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"');
-        $mform->setType('username', PARAM_NOTAGS);
+        $mform->setType('username', core_user::get_property_type('username'));
         $mform->addRule('username', get_string('missingusername'), 'required', null, 'client');
 
         if (!empty($CFG->passwordpolicy)){
             $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
         }
         $mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"');
         $mform->addRule('username', get_string('missingusername'), 'required', null, 'client');
 
         if (!empty($CFG->passwordpolicy)){
             $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
         }
         $mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"');
-        $mform->setType('password', PARAM_RAW);
+        $mform->setType('password', core_user::get_property_type('password'));
         $mform->addRule('password', get_string('missingpassword'), 'required', null, 'client');
 
         $mform->addElement('header', 'supplyinfo', get_string('supplyinfo'),'');
 
         $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25"');
         $mform->addRule('password', get_string('missingpassword'), 'required', null, 'client');
 
         $mform->addElement('header', 'supplyinfo', get_string('supplyinfo'),'');
 
         $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25"');
-        $mform->setType('email', PARAM_RAW_TRIMMED);
+        $mform->setType('email', core_user::get_property_type('email'));
         $mform->addRule('email', get_string('missingemail'), 'required', null, 'client');
 
         $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"');
         $mform->addRule('email', get_string('missingemail'), 'required', null, 'client');
 
         $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"');
-        $mform->setType('email2', PARAM_RAW_TRIMMED);
+        $mform->setType('email2', core_user::get_property_type('email'));
         $mform->addRule('email2', get_string('missingemail'), 'required', null, 'client');
 
         $namefields = useredit_get_required_name_fields();
         foreach ($namefields as $field) {
             $mform->addElement('text', $field, get_string($field), 'maxlength="100" size="30"');
         $mform->addRule('email2', get_string('missingemail'), 'required', null, 'client');
 
         $namefields = useredit_get_required_name_fields();
         foreach ($namefields as $field) {
             $mform->addElement('text', $field, get_string($field), 'maxlength="100" size="30"');
-            $mform->setType($field, PARAM_NOTAGS);
+            $mform->setType($field, core_user::get_property_type('firstname'));
             $stringid = 'missing' . $field;
             if (!get_string_manager()->string_exists($stringid, 'moodle')) {
                 $stringid = 'required';
             $stringid = 'missing' . $field;
             if (!get_string_manager()->string_exists($stringid, 'moodle')) {
                 $stringid = 'required';
@@ -72,7 +72,7 @@ class login_signup_form extends moodleform {
         }
 
         $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="20"');
         }
 
         $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="20"');
-        $mform->setType('city', PARAM_TEXT);
+        $mform->setType('city', core_user::get_property_type('city'));
         if (!empty($CFG->defaultcity)) {
             $mform->setDefault('city', $CFG->defaultcity);
         }
         if (!empty($CFG->defaultcity)) {
             $mform->setDefault('city', $CFG->defaultcity);
         }
@@ -132,7 +132,7 @@ class login_signup_form extends moodleform {
             if ($data['username'] !== core_text::strtolower($data['username'])) {
                 $errors['username'] = get_string('usernamelowercase');
             } else {
             if ($data['username'] !== core_text::strtolower($data['username'])) {
                 $errors['username'] = get_string('usernamelowercase');
             } else {
-                if ($data['username'] !== clean_param($data['username'], PARAM_USERNAME)) {
+                if ($data['username'] !== core_user::clean_field($data['username'], 'username')) {
                     $errors['username'] = get_string('invalidusername');
                 }
 
                     $errors['username'] = get_string('invalidusername');
                 }
 
index b689923..e12b7fd 100644 (file)
@@ -60,7 +60,7 @@ class user_editadvanced_form extends moodleform {
 
         // Add some extra hidden fields.
         $mform->addElement('hidden', 'id');
 
         // Add some extra hidden fields.
         $mform->addElement('hidden', 'id');
-        $mform->setType('id', PARAM_INT);
+        $mform->setType('id', core_user::get_property_type('id'));
         $mform->addElement('hidden', 'course', $COURSE->id);
         $mform->setType('course', PARAM_INT);
 
         $mform->addElement('hidden', 'course', $COURSE->id);
         $mform->setType('course', PARAM_INT);
 
@@ -69,7 +69,7 @@ class user_editadvanced_form extends moodleform {
 
         $mform->addElement('text', 'username', get_string('username'), 'size="20"');
         $mform->addRule('username', $strrequired, 'required', null, 'client');
 
         $mform->addElement('text', 'username', get_string('username'), 'size="20"');
         $mform->addRule('username', $strrequired, 'required', null, 'client');
-        $mform->setType('username', PARAM_RAW);
+        $mform->setType('username', core_user::get_property_type('username'));
 
         $auths = core_component::get_plugin_list('auth');
         $enabled = get_string('pluginenabled', 'core_plugin');
 
         $auths = core_component::get_plugin_list('auth');
         $enabled = get_string('pluginenabled', 'core_plugin');
@@ -107,7 +107,7 @@ class user_editadvanced_form extends moodleform {
         }
         $mform->addElement('passwordunmask', 'newpassword', get_string('newpassword'), 'size="20"');
         $mform->addHelpButton('newpassword', 'newpassword');
         }
         $mform->addElement('passwordunmask', 'newpassword', get_string('newpassword'), 'size="20"');
         $mform->addHelpButton('newpassword', 'newpassword');
-        $mform->setType('newpassword', PARAM_RAW);
+        $mform->setType('newpassword', core_user::get_property_type('password'));
         $mform->disabledIf('newpassword', 'createpassword', 'checked');
 
         $mform->disabledIf('newpassword', 'auth', 'in', $cannotchangepass);
         $mform->disabledIf('newpassword', 'createpassword', 'checked');
 
         $mform->disabledIf('newpassword', 'auth', 'in', $cannotchangepass);
@@ -259,7 +259,7 @@ class user_editadvanced_form extends moodleform {
             if ($usernew->username !== core_text::strtolower($usernew->username)) {
                 $err['username'] = get_string('usernamelowercase');
             } else {
             if ($usernew->username !== core_text::strtolower($usernew->username)) {
                 $err['username'] = get_string('usernamelowercase');
             } else {
-                if ($usernew->username !== clean_param($usernew->username, PARAM_USERNAME)) {
+                if ($usernew->username !== core_user::clean_field($usernew->username, 'username')) {
                     $err['username'] = get_string('invalidusername');
                 }
             }
                     $err['username'] = get_string('invalidusername');
                 }
             }
index 7c8388b..3cf9ed5 100644 (file)
@@ -322,7 +322,7 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
     $choices['1'] = get_string('emaildisplayyes');
     $choices['2'] = get_string('emaildisplaycourse');
     $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
     $choices['1'] = get_string('emaildisplayyes');
     $choices['2'] = get_string('emaildisplaycourse');
     $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
-    $mform->setDefault('maildisplay', $CFG->defaultpreference_maildisplay);
+    $mform->setDefault('maildisplay', core_user::get_property_default('maildisplay'));
 
     $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
     $mform->setType('city', PARAM_TEXT);
 
     $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
     $mform->setType('city', PARAM_TEXT);
@@ -334,14 +334,14 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
     $choices = array('' => get_string('selectacountry') . '...') + $choices;
     $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
     if (!empty($CFG->country)) {
     $choices = array('' => get_string('selectacountry') . '...') + $choices;
     $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
     if (!empty($CFG->country)) {
-        $mform->setDefault('country', $CFG->country);
+        $mform->setDefault('country', core_user::get_property_default('country'));
     }
 
     if (isset($CFG->forcetimezone) and $CFG->forcetimezone != 99) {
         $choices = core_date::get_list_of_timezones($CFG->forcetimezone);
         $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
         $mform->addElement('hidden', 'timezone');
     }
 
     if (isset($CFG->forcetimezone) and $CFG->forcetimezone != 99) {
         $choices = core_date::get_list_of_timezones($CFG->forcetimezone);
         $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
         $mform->addElement('hidden', 'timezone');
-        $mform->setType('timezone', PARAM_TIMEZONE);
+        $mform->setType('timezone', core_user::get_property_type('timezone'));
     } else {
         $choices = core_date::get_list_of_timezones($user->timezone, true);
         $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
     } else {
         $choices = core_date::get_list_of_timezones($user->timezone, true);
         $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
@@ -413,40 +413,40 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
     $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
 
     $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
     $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
 
     $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
-    $mform->setType('url', PARAM_URL);
+    $mform->setType('url', core_user::get_property_type('url'));
 
     $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
 
     $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
-    $mform->setType('icq', PARAM_NOTAGS);
+    $mform->setType('icq', core_user::get_property_type('icq'));
 
     $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
 
     $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
-    $mform->setType('skype', PARAM_NOTAGS);
+    $mform->setType('skype', core_user::get_property_type('skype'));
 
     $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
 
     $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
-    $mform->setType('aim', PARAM_NOTAGS);
+    $mform->setType('aim', core_user::get_property_type('aim'));
 
     $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
 
     $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
-    $mform->setType('yahoo', PARAM_NOTAGS);
+    $mform->setType('yahoo', core_user::get_property_type('yahoo'));
 
     $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
 
     $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
-    $mform->setType('msn', PARAM_NOTAGS);
+    $mform->setType('msn', core_user::get_property_type('msn'));
 
     $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
 
     $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
-    $mform->setType('idnumber', PARAM_NOTAGS);
+    $mform->setType('idnumber', core_user::get_property_type('idnumber'));
 
     $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="255" size="25"');
 
     $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="255" size="25"');
-    $mform->setType('institution', PARAM_TEXT);
+    $mform->setType('institution', core_user::get_property_type('institution'));
 
     $mform->addElement('text', 'department', get_string('department'), 'maxlength="255" size="25"');
 
     $mform->addElement('text', 'department', get_string('department'), 'maxlength="255" size="25"');
-    $mform->setType('department', PARAM_TEXT);
+    $mform->setType('department', core_user::get_property_type('department'));
 
     $mform->addElement('text', 'phone1', get_string('phone1'), 'maxlength="20" size="25"');
 
     $mform->addElement('text', 'phone1', get_string('phone1'), 'maxlength="20" size="25"');
-    $mform->setType('phone1', PARAM_NOTAGS);
+    $mform->setType('phone1', core_user::get_property_type('phone1'));
 
     $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
 
     $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
-    $mform->setType('phone2', PARAM_NOTAGS);
+    $mform->setType('phone2', core_user::get_property_type('phone2'));
 
     $mform->addElement('text', 'address', get_string('address'), 'maxlength="255" size="25"');
 
     $mform->addElement('text', 'address', get_string('address'), 'maxlength="255" size="25"');
-    $mform->setType('address', PARAM_TEXT);
+    $mform->setType('address', core_user::get_property_type('address'));
 }
 
 /**
 }
 
 /**
index a1b0cb6..8fb8df5 100644 (file)
@@ -51,53 +51,53 @@ class core_user_external extends external_api {
                     new external_single_structure(
                         array(
                             'username' =>
                     new external_single_structure(
                         array(
                             'username' =>
-                                new external_value(PARAM_USERNAME, 'Username policy is defined in Moodle security config.'),
+                                new external_value(core_user::get_property_type('username'), 'Username policy is defined in Moodle security config.'),
                             'password' =>
                             'password' =>
-                                new external_value(PARAM_RAW, 'Plain text password consisting of any characters', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('password'), 'Plain text password consisting of any characters', VALUE_OPTIONAL),
                             'createpassword' =>
                                 new external_value(PARAM_BOOL, 'True if password should be created and mailed to user.',
                                     VALUE_OPTIONAL),
                             'firstname' =>
                             'createpassword' =>
                                 new external_value(PARAM_BOOL, 'True if password should be created and mailed to user.',
                                     VALUE_OPTIONAL),
                             'firstname' =>
-                                new external_value(PARAM_NOTAGS, 'The first name(s) of the user'),
+                                new external_value(core_user::get_property_type('firstname'), 'The first name(s) of the user'),
                             'lastname' =>
                             'lastname' =>
-                                new external_value(PARAM_NOTAGS, 'The family name of the user'),
+                                new external_value(core_user::get_property_type('lastname'), 'The family name of the user'),
                             'email' =>
                             'email' =>
-                                new external_value(PARAM_EMAIL, 'A valid and unique email address'),
+                                new external_value(core_user::get_property_type('email'), 'A valid and unique email address'),
                             'auth' =>
                             'auth' =>
-                                new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_DEFAULT,
-                                    'manual', NULL_NOT_ALLOWED),
+                                new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, imap, etc', VALUE_DEFAULT,
+                                    'manual', core_user::get_property_null('auth')),
                             'idnumber' =>
                             'idnumber' =>
-                                new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution',
+                                new external_value(core_user::get_property_type('idnumber'), 'An arbitrary ID code number perhaps from the institution',
                                     VALUE_DEFAULT, ''),
                             'lang' =>
                                     VALUE_DEFAULT, ''),
                             'lang' =>
-                                new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_DEFAULT,
-                                    $CFG->lang, NULL_NOT_ALLOWED),
+                                new external_value(core_user::get_property_type('lang'), 'Language code such as "en", must exist on server', VALUE_DEFAULT,
+                                    core_user::get_property_default('lang'), core_user::get_property_null('lang')),
                             'calendartype' =>
                             'calendartype' =>
-                                new external_value(PARAM_PLUGIN, 'Calendar type such as "gregorian", must exist on server',
+                                new external_value(core_user::get_property_type('calendartype'), 'Calendar type such as "gregorian", must exist on server',
                                     VALUE_DEFAULT, $CFG->calendartype, VALUE_OPTIONAL),
                             'theme' =>
                                     VALUE_DEFAULT, $CFG->calendartype, VALUE_OPTIONAL),
                             'theme' =>
-                                new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server',
+                                new external_value(core_user::get_property_type('theme'), 'Theme name such as "standard", must exist on server',
                                     VALUE_OPTIONAL),
                             'timezone' =>
                                     VALUE_OPTIONAL),
                             'timezone' =>
-                                new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default',
+                                new external_value(core_user::get_property_type('timezone'), 'Timezone code such as Australia/Perth, or 99 for default',
                                     VALUE_OPTIONAL),
                             'mailformat' =>
                                     VALUE_OPTIONAL),
                             'mailformat' =>
-                                new external_value(PARAM_INT, 'Mail format code is 0 for plain text, 1 for HTML etc',
+                                new external_value(core_user::get_property_type('mailformat'), 'Mail format code is 0 for plain text, 1 for HTML etc',
                                     VALUE_OPTIONAL),
                             'description' =>
                                     VALUE_OPTIONAL),
                             'description' =>
-                                new external_value(PARAM_TEXT, 'User profile description, no HTML', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('description'), 'User profile description, no HTML', VALUE_OPTIONAL),
                             'city' =>
                             'city' =>
-                                new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('city'), 'Home city of the user', VALUE_OPTIONAL),
                             'country' =>
                             'country' =>
-                                new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('country'), 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
                             'firstnamephonetic' =>
                             'firstnamephonetic' =>
-                                new external_value(PARAM_NOTAGS, 'The first name(s) phonetically of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('firstnamephonetic'), 'The first name(s) phonetically of the user', VALUE_OPTIONAL),
                             'lastnamephonetic' =>
                             'lastnamephonetic' =>
-                                new external_value(PARAM_NOTAGS, 'The family name phonetically of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('lastnamephonetic'), 'The family name phonetically of the user', VALUE_OPTIONAL),
                             'middlename' =>
                             'middlename' =>
-                                new external_value(PARAM_NOTAGS, 'The middle name of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('middlename'), 'The middle name of the user', VALUE_OPTIONAL),
                             'alternatename' =>
                             'alternatename' =>
-                                new external_value(PARAM_NOTAGS, 'The alternate name of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('alternatename'), 'The alternate name of the user', VALUE_OPTIONAL),
                             'preferences' => new external_multiple_structure(
                                 new external_single_structure(
                                     array(
                             'preferences' => new external_multiple_structure(
                                 new external_single_structure(
                                     array(
@@ -252,8 +252,8 @@ class core_user_external extends external_api {
         return new external_multiple_structure(
             new external_single_structure(
                 array(
         return new external_multiple_structure(
             new external_single_structure(
                 array(
-                    'id'       => new external_value(PARAM_INT, 'user id'),
-                    'username' => new external_value(PARAM_USERNAME, 'user name'),
+                    'id'       => new external_value(core_user::get_property_type('id'), 'user id'),
+                    'username' => new external_value(core_user::get_property_type('username'), 'user name'),
                 )
             )
         );
                 )
             )
         );
@@ -269,7 +269,7 @@ class core_user_external extends external_api {
     public static function delete_users_parameters() {
         return new external_function_parameters(
             array(
     public static function delete_users_parameters() {
         return new external_function_parameters(
             array(
-                'userids' => new external_multiple_structure(new external_value(PARAM_INT, 'user ID')),
+                'userids' => new external_multiple_structure(new external_value(core_user::get_property_type('id'), 'user ID')),
             )
         );
     }
             )
         );
     }
@@ -336,56 +336,56 @@ class core_user_external extends external_api {
                     new external_single_structure(
                         array(
                             'id' =>
                     new external_single_structure(
                         array(
                             'id' =>
-                                new external_value(PARAM_INT, 'ID of the user'),
+                                new external_value(core_user::get_property_type('id'), 'ID of the user'),
                             'username' =>
                             'username' =>
-                                new external_value(PARAM_USERNAME, 'Username policy is defined in Moodle security config.',
+                                new external_value(core_user::get_property_type('username'), 'Username policy is defined in Moodle security config.',
                                     VALUE_OPTIONAL, '', NULL_NOT_ALLOWED),
                             'password' =>
                                     VALUE_OPTIONAL, '', NULL_NOT_ALLOWED),
                             'password' =>
-                                new external_value(PARAM_RAW, 'Plain text password consisting of any characters', VALUE_OPTIONAL,
+                                new external_value(core_user::get_property_type('password'), 'Plain text password consisting of any characters', VALUE_OPTIONAL,
                                     '', NULL_NOT_ALLOWED),
                             'firstname' =>
                                     '', NULL_NOT_ALLOWED),
                             'firstname' =>
-                                new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL, '',
+                                new external_value(core_user::get_property_type('firstname'), 'The first name(s) of the user', VALUE_OPTIONAL, '',
                                     NULL_NOT_ALLOWED),
                             'lastname' =>
                                     NULL_NOT_ALLOWED),
                             'lastname' =>
-                                new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('lastname'), 'The family name of the user', VALUE_OPTIONAL),
                             'email' =>
                             'email' =>
-                                new external_value(PARAM_EMAIL, 'A valid and unique email address', VALUE_OPTIONAL, '',
+                                new external_value(core_user::get_property_type('email'), 'A valid and unique email address', VALUE_OPTIONAL, '',
                                     NULL_NOT_ALLOWED),
                             'auth' =>
                                     NULL_NOT_ALLOWED),
                             'auth' =>
-                                new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL, '',
+                                new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL, '',
                                     NULL_NOT_ALLOWED),
                             'idnumber' =>
                                     NULL_NOT_ALLOWED),
                             'idnumber' =>
-                                new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution',
+                                new external_value(core_user::get_property_type('idnumber'), 'An arbitrary ID code number perhaps from the institution',
                                     VALUE_OPTIONAL),
                             'lang' =>
                                     VALUE_OPTIONAL),
                             'lang' =>
-                                new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server',
+                                new external_value(core_user::get_property_type('lang'), 'Language code such as "en", must exist on server',
                                     VALUE_OPTIONAL, '', NULL_NOT_ALLOWED),
                             'calendartype' =>
                                     VALUE_OPTIONAL, '', NULL_NOT_ALLOWED),
                             'calendartype' =>
-                                new external_value(PARAM_PLUGIN, 'Calendar type such as "gregorian", must exist on server',
+                                new external_value(core_user::get_property_type('calendartype'), 'Calendar type such as "gregorian", must exist on server',
                                     VALUE_OPTIONAL, '', NULL_NOT_ALLOWED),
                             'theme' =>
                                     VALUE_OPTIONAL, '', NULL_NOT_ALLOWED),
                             'theme' =>
-                                new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server',
+                                new external_value(core_user::get_property_type('theme'), 'Theme name such as "standard", must exist on server',
                                     VALUE_OPTIONAL),
                             'timezone' =>
                                     VALUE_OPTIONAL),
                             'timezone' =>
-                                new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default',
+                                new external_value(core_user::get_property_type('timezone'), 'Timezone code such as Australia/Perth, or 99 for default',
                                     VALUE_OPTIONAL),
                             'mailformat' =>
                                     VALUE_OPTIONAL),
                             'mailformat' =>
-                                new external_value(PARAM_INT, 'Mail format code is 0 for plain text, 1 for HTML etc',
+                                new external_value(core_user::get_property_type('mailformat'), 'Mail format code is 0 for plain text, 1 for HTML etc',
                                     VALUE_OPTIONAL),
                             'description' =>
                                     VALUE_OPTIONAL),
                             'description' =>
-                                new external_value(PARAM_TEXT, 'User profile description, no HTML', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('description'), 'User profile description, no HTML', VALUE_OPTIONAL),
                             'city' =>
                             'city' =>
-                                new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('city'), 'Home city of the user', VALUE_OPTIONAL),
                             'country' =>
                             'country' =>
-                                new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('country'), 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
                             'firstnamephonetic' =>
                             'firstnamephonetic' =>
-                                new external_value(PARAM_NOTAGS, 'The first name(s) phonetically of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('firstnamephonetic'), 'The first name(s) phonetically of the user', VALUE_OPTIONAL),
                             'lastnamephonetic' =>
                             'lastnamephonetic' =>
-                                new external_value(PARAM_NOTAGS, 'The family name phonetically of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('lastnamephonetic'), 'The family name phonetically of the user', VALUE_OPTIONAL),
                             'middlename' =>
                             'middlename' =>
-                                new external_value(PARAM_NOTAGS, 'The middle name of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('middlename'), 'The middle name of the user', VALUE_OPTIONAL),
                             'alternatename' =>
                             'alternatename' =>
-                                new external_value(PARAM_NOTAGS, 'The alternate name of the user', VALUE_OPTIONAL),
+                                new external_value(core_user::get_property_type('alternatename'), 'The alternate name of the user', VALUE_OPTIONAL),
                             'customfields' => new external_multiple_structure(
                                 new external_single_structure(
                                     array(
                             'customfields' => new external_multiple_structure(
                                 new external_single_structure(
                                     array(
@@ -507,16 +507,16 @@ class core_user_external extends external_api {
 
         switch ($field) {
             case 'id':
 
         switch ($field) {
             case 'id':
-                $paramtype = PARAM_INT;
+                $paramtype = core_user::get_property_type('id');
                 break;
             case 'idnumber':
                 break;
             case 'idnumber':
-                $paramtype = PARAM_RAW;
+                $paramtype = core_user::get_property_type('idnumber');
                 break;
             case 'username':
                 break;
             case 'username':
-                $paramtype = PARAM_RAW;
+                $paramtype = core_user::get_property_type('username');
                 break;
             case 'email':
                 break;
             case 'email':
-                $paramtype = PARAM_EMAIL;
+                $paramtype = core_user::get_property_type('email');
                 break;
             default:
                 throw new coding_exception('invalid field parameter',
                 break;
             default:
                 throw new coding_exception('invalid field parameter',
@@ -638,24 +638,24 @@ class core_user_external extends external_api {
             $paramtype = PARAM_RAW;
             switch ($criteria['key']) {
                 case 'id':
             $paramtype = PARAM_RAW;
             switch ($criteria['key']) {
                 case 'id':
-                    $paramtype = PARAM_INT;
+                    $paramtype = core_user::get_property_type('id');
                     break;
                 case 'idnumber':
                     break;
                 case 'idnumber':
-                    $paramtype = PARAM_RAW;
+                    $paramtype = core_user::get_property_type('idnumber');
                     break;
                 case 'username':
                     break;
                 case 'username':
-                    $paramtype = PARAM_RAW;
+                    $paramtype = core_user::get_property_type('username');
                     break;
                 case 'email':
                     // We use PARAM_RAW to allow searches with %.
                     break;
                 case 'email':
                     // We use PARAM_RAW to allow searches with %.
-                    $paramtype = PARAM_RAW;
+                    $paramtype = core_user::get_property_type('email');
                     break;
                 case 'auth':
                     break;
                 case 'auth':
-                    $paramtype = PARAM_AUTH;
+                    $paramtype = core_user::get_property_type('auth');
                     break;
                 case 'lastname':
                 case 'firstname':
                     break;
                 case 'lastname':
                 case 'firstname':
-                    $paramtype = PARAM_TEXT;
+                    $paramtype = core_user::get_property_type('firstname');
                     break;
                 default:
                     // Send back a warning that this search key is not supported in this version.
                     break;
                 default:
                     // Send back a warning that this search key is not supported in this version.
@@ -752,7 +752,9 @@ class core_user_external extends external_api {
     public static function get_users_by_id_parameters() {
         return new external_function_parameters(
             array(
     public static function get_users_by_id_parameters() {
         return new external_function_parameters(
             array(
-                'userids' => new external_multiple_structure(new external_value(PARAM_INT, 'user ID')),
+                'userids' => new external_multiple_structure(
+                    new external_value(core_user::get_property_type('id'), 'user ID')
+                ),
             )
         );
     }
             )
         );
     }
@@ -857,7 +859,7 @@ class core_user_external extends external_api {
                 'userlist' => new external_multiple_structure(
                     new external_single_structure(
                         array(
                 'userlist' => new external_multiple_structure(
                     new external_single_structure(
                         array(
-                            'userid'    => new external_value(PARAM_INT, 'userid'),
+                            'userid'    => new external_value(core_user::get_property_type('id'), 'userid'),
                             'courseid'    => new external_value(PARAM_INT, 'courseid'),
                         )
                     )
                             'courseid'    => new external_value(PARAM_INT, 'courseid'),
                         )
                     )
@@ -977,38 +979,38 @@ class core_user_external extends external_api {
      */
     public static function user_description($additionalfields = array()) {
         $userfields = array(
      */
     public static function user_description($additionalfields = array()) {
         $userfields = array(
-            'id'    => new external_value(PARAM_INT, 'ID of the user'),
-            'username'    => new external_value(PARAM_RAW, 'The username', VALUE_OPTIONAL),
-            'firstname'   => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL),
-            'lastname'    => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL),
-            'fullname'    => new external_value(PARAM_NOTAGS, 'The fullname of the user'),
-            'email'       => new external_value(PARAM_TEXT, 'An email address - allow email as root@localhost', VALUE_OPTIONAL),
-            'address'     => new external_value(PARAM_TEXT, 'Postal address', VALUE_OPTIONAL),
-            'phone1'      => new external_value(PARAM_NOTAGS, 'Phone 1', VALUE_OPTIONAL),
-            'phone2'      => new external_value(PARAM_NOTAGS, 'Phone 2', VALUE_OPTIONAL),
-            'icq'         => new external_value(PARAM_NOTAGS, 'icq number', VALUE_OPTIONAL),
-            'skype'       => new external_value(PARAM_NOTAGS, 'skype id', VALUE_OPTIONAL),
-            'yahoo'       => new external_value(PARAM_NOTAGS, 'yahoo id', VALUE_OPTIONAL),
-            'aim'         => new external_value(PARAM_NOTAGS, 'aim id', VALUE_OPTIONAL),
-            'msn'         => new external_value(PARAM_NOTAGS, 'msn number', VALUE_OPTIONAL),
-            'department'  => new external_value(PARAM_TEXT, 'department', VALUE_OPTIONAL),
-            'institution' => new external_value(PARAM_TEXT, 'institution', VALUE_OPTIONAL),
-            'idnumber'    => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL),
+            'id'    => new external_value(core_user::get_property_type('id'), 'ID of the user'),
+            'username'    => new external_value(core_user::get_property_type('username'), 'The username', VALUE_OPTIONAL),
+            'firstname'   => new external_value(core_user::get_property_type('firstname'), 'The first name(s) of the user', VALUE_OPTIONAL),
+            'lastname'    => new external_value(core_user::get_property_type('lastname'), 'The family name of the user', VALUE_OPTIONAL),
+            'fullname'    => new external_value(core_user::get_property_type('firstname'), 'The fullname of the user'),
+            'email'       => new external_value(core_user::get_property_type('email'), 'An email address - allow email as root@localhost', VALUE_OPTIONAL),
+            'address'     => new external_value(core_user::get_property_type('address'), 'Postal address', VALUE_OPTIONAL),
+            'phone1'      => new external_value(core_user::get_property_type('phone1'), 'Phone 1', VALUE_OPTIONAL),
+            'phone2'      => new external_value(core_user::get_property_type('phone2'), 'Phone 2', VALUE_OPTIONAL),
+            'icq'         => new external_value(core_user::get_property_type('icq'), 'icq number', VALUE_OPTIONAL),
+            'skype'       => new external_value(core_user::get_property_type('skype'), 'skype id', VALUE_OPTIONAL),
+            'yahoo'       => new external_value(core_user::get_property_type('yahoo'), 'yahoo id', VALUE_OPTIONAL),
+            'aim'         => new external_value(core_user::get_property_type('aim'), 'aim id', VALUE_OPTIONAL),
+            'msn'         => new external_value(core_user::get_property_type('msn'), 'msn number', VALUE_OPTIONAL),
+            'department'  => new external_value(core_user::get_property_type('department'), 'department', VALUE_OPTIONAL),
+            'institution' => new external_value(core_user::get_property_type('institution'), 'institution', VALUE_OPTIONAL),
+            'idnumber'    => new external_value(core_user::get_property_type('idnumber'), 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL),
             'interests'   => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL),
             'interests'   => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL),
-            'firstaccess' => new external_value(PARAM_INT, 'first access to the site (0 if never)', VALUE_OPTIONAL),
-            'lastaccess'  => new external_value(PARAM_INT, 'last access to the site (0 if never)', VALUE_OPTIONAL),
-            'auth'        => new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL),
-            'confirmed'   => new external_value(PARAM_INT, 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL),
-            'lang'        => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_OPTIONAL),
-            'calendartype' => new external_value(PARAM_PLUGIN, 'Calendar type such as "gregorian", must exist on server', VALUE_OPTIONAL),
-            'theme'       => new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL),
-            'timezone'    => new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL),
-            'mailformat'  => new external_value(PARAM_INT, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL),
-            'description' => new external_value(PARAM_RAW, 'User profile description', VALUE_OPTIONAL),
-            'descriptionformat' => new external_format_value('description', VALUE_OPTIONAL),
-            'city'        => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
-            'url'         => new external_value(PARAM_URL, 'URL of the user', VALUE_OPTIONAL),
-            'country'     => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
+            'firstaccess' => new external_value(core_user::get_property_type('firstaccess'), 'first access to the site (0 if never)', VALUE_OPTIONAL),
+            'lastaccess'  => new external_value(core_user::get_property_type('lastaccess'), 'last access to the site (0 if never)', VALUE_OPTIONAL),
+            'auth'        => new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL),
+            'confirmed'   => new external_value(core_user::get_property_type('confirmed'), 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL),
+            'lang'        => new external_value(core_user::get_property_type('lang'), 'Language code such as "en", must exist on server', VALUE_OPTIONAL),
+            'calendartype' => new external_value(core_user::get_property_type('calendartype'), 'Calendar type such as "gregorian", must exist on server', VALUE_OPTIONAL),
+            'theme'       => new external_value(core_user::get_property_type('theme'), 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL),
+            'timezone'    => new external_value(core_user::get_property_type('timezone'), 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL),
+            'mailformat'  => new external_value(core_user::get_property_type('mailformat'), 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL),
+            'description' => new external_value(core_user::get_property_type('description'), 'User profile description', VALUE_OPTIONAL),
+            'descriptionformat' => new external_format_value(core_user::get_property_type('descriptionformat'), VALUE_OPTIONAL),
+            'city'        => new external_value(core_user::get_property_type('city'), 'Home city of the user', VALUE_OPTIONAL),
+            'url'         => new external_value(core_user::get_property_type('url'), 'URL of the user', VALUE_OPTIONAL),
+            'country'     => new external_value(core_user::get_property_type('country'), 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
             'profileimageurlsmall' => new external_value(PARAM_URL, 'User image profile URL - small version'),
             'profileimageurl' => new external_value(PARAM_URL, 'User image profile URL - big version'),
             'customfields' => new external_multiple_structure(
             'profileimageurlsmall' => new external_value(PARAM_URL, 'User image profile URL - small version'),
             'profileimageurl' => new external_value(PARAM_URL, 'User image profile URL - big version'),
             'customfields' => new external_multiple_structure(
index 4809a61..49fb5c5 100644 (file)
@@ -52,21 +52,21 @@ class user_edit_forum_form extends moodleform {
         $choices['1'] = get_string('emaildigestcomplete');
         $choices['2'] = get_string('emaildigestsubjects');
         $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
         $choices['1'] = get_string('emaildigestcomplete');
         $choices['2'] = get_string('emaildigestsubjects');
         $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
-        $mform->setDefault('maildigest', $CFG->defaultpreference_maildigest);
+        $mform->setDefault('maildigest', core_user::get_property_default('maildigest'));
         $mform->addHelpButton('maildigest', 'emaildigest');
 
         $choices = array();
         $choices['1'] = get_string('autosubscribeyes');
         $choices['0'] = get_string('autosubscribeno');
         $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
         $mform->addHelpButton('maildigest', 'emaildigest');
 
         $choices = array();
         $choices['1'] = get_string('autosubscribeyes');
         $choices['0'] = get_string('autosubscribeno');
         $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
-        $mform->setDefault('autosubscribe', $CFG->defaultpreference_autosubscribe);
+        $mform->setDefault('autosubscribe', core_user::get_property_default('autosubscribe'));
 
         if (!empty($CFG->forum_trackreadposts)) {
             $choices = array();
             $choices['0'] = get_string('trackforumsno');
             $choices['1'] = get_string('trackforumsyes');
             $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
 
         if (!empty($CFG->forum_trackreadposts)) {
             $choices = array();
             $choices['0'] = get_string('trackforumsno');
             $choices['1'] = get_string('trackforumsyes');
             $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
-            $mform->setDefault('trackforums', $CFG->defaultpreference_trackforums);
+            $mform->setDefault('trackforums', core_user::get_property_default('trackforums'));
         }
 
         // Add some extra hidden fields.
         }
 
         // Add some extra hidden fields.
index 14b3981..ef2b09f 100644 (file)
@@ -46,7 +46,7 @@ if ($languageform->is_cancelled()) {
     $lang = $data->lang;
     // If the specified language does not exist, use the site default.
     if (!get_string_manager()->translation_exists($lang, false)) {
     $lang = $data->lang;
     // If the specified language does not exist, use the site default.
     if (!get_string_manager()->translation_exists($lang, false)) {
-        $lang = $CFG->lang;
+        $lang = core_user::get_property_default('lang');
     }
 
     $user->lang = $lang;
     }
 
     $user->lang = $lang;
index 3c9a548..4dab6be 100644 (file)
@@ -58,7 +58,7 @@ class user_edit_language_form extends moodleform {
         $mform->setType('course', PARAM_INT);
 
         $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
         $mform->setType('course', PARAM_INT);
 
         $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
-        $mform->setDefault('lang', $CFG->lang);
+        $mform->setDefault('lang', core_user::get_property_default('lang'));
 
         $this->add_action_buttons(true, get_string('savechanges'));
     }
 
         $this->add_action_buttons(true, get_string('savechanges'));
     }
@@ -77,7 +77,7 @@ class user_edit_language_form extends moodleform {
             // Check lang exists.
             if (!get_string_manager()->translation_exists($lang, false)) {
                 $langel =& $mform->getElement('lang');
             // Check lang exists.
             if (!get_string_manager()->translation_exists($lang, false)) {
                 $langel =& $mform->getElement('lang');
-                $langel->setValue($CFG->lang);
+                $langel->setValue(core_user::get_property_default('lang'));
             }
         }
 
             }
         }
 
index 91008f6..4ecf3b4 100644 (file)
@@ -34,7 +34,7 @@
  * @return int id of the newly created user
  */
 function user_create_user($user, $updatepassword = true, $triggerevent = true) {
  * @return int id of the newly created user
  */
 function user_create_user($user, $updatepassword = true, $triggerevent = true) {
-    global $CFG, $DB;
+    global $DB;
 
     // Set the timecreate field to the current time.
     if (!is_object($user)) {
 
     // Set the timecreate field to the current time.
     if (!is_object($user)) {
@@ -64,26 +64,25 @@ function user_create_user($user, $updatepassword = true, $triggerevent = true) {
 
     // Apply default values for user preferences that are stored in users table.
     if (!isset($user->calendartype)) {
 
     // Apply default values for user preferences that are stored in users table.
     if (!isset($user->calendartype)) {
-        $user->calendartype = $CFG->calendartype;
+        $user->calendartype = core_user::get_property_default('calendartype');
     }
     }
-
     if (!isset($user->maildisplay)) {
     if (!isset($user->maildisplay)) {
-        $user->maildisplay = $CFG->defaultpreference_maildisplay;
+        $user->maildisplay = core_user::get_property_default('maildisplay');
     }
     if (!isset($user->mailformat)) {
     }
     if (!isset($user->mailformat)) {
-        $user->mailformat = $CFG->defaultpreference_mailformat;
+        $user->mailformat = core_user::get_property_default('mailformat');
     }
     if (!isset($user->maildigest)) {
     }
     if (!isset($user->maildigest)) {
-        $user->maildigest = $CFG->defaultpreference_maildigest;
+        $user->maildigest = core_user::get_property_default('maildigest');
     }
     if (!isset($user->autosubscribe)) {
     }
     if (!isset($user->autosubscribe)) {
-        $user->autosubscribe = $CFG->defaultpreference_autosubscribe;
+        $user->autosubscribe = core_user::get_property_default('autosubscribe');
     }
     if (!isset($user->trackforums)) {
     }
     if (!isset($user->trackforums)) {
-        $user->trackforums = $CFG->defaultpreference_trackforums;
+        $user->trackforums = core_user::get_property_default('trackforums');
     }
     if (!isset($user->lang)) {
     }
     if (!isset($user->lang)) {
-        $user->lang = $CFG->lang;
+        $user->lang = core_user::get_property_default('lang');
     }
 
     $user->timecreated = time();
     }
 
     $user->timecreated = time();
index 6172453..7b79bf1 100644 (file)
@@ -64,7 +64,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
-            'country' => 'au'
+            'country' => 'AU'
             );
 
         $user1 = self::getDataGenerator()->create_user($user1);
             );
 
         $user1 = self::getDataGenerator()->create_user($user1);
@@ -222,7 +222,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
-            'country' => 'au'
+            'country' => 'AU'
             );
         $user1 = self::getDataGenerator()->create_user($user1);
         if (!empty($CFG->usetags)) {
             );
         $user1 = self::getDataGenerator()->create_user($user1);
         if (!empty($CFG->usetags)) {
@@ -383,7 +383,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
-            'country' => 'au'
+            'country' => 'AU'
         );
         $return->user1 = self::getDataGenerator()->create_user($return->user1);
         if (!empty($CFG->usetags)) {
         );
         $return->user1 = self::getDataGenerator()->create_user($return->user1);
         if (!empty($CFG->usetags)) {
@@ -494,7 +494,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
             'email' => 'usertest1@example.com',
             'description' => 'This is a description for user 1',
             'city' => 'Perth',
             'email' => 'usertest1@example.com',
             'description' => 'This is a description for user 1',
             'city' => 'Perth',
-            'country' => 'au'
+            'country' => 'AU'
             );
 
         $context = context_system::instance();
             );
 
         $context = context_system::instance();
@@ -586,7 +586,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
             'descriptionformat' => FORMAT_MOODLE,
             'city' => 'Perth',
             'url' => 'http://moodle.org',
-            'country' => 'au'
+            'country' => 'AU'
             );
         $user1 = self::getDataGenerator()->create_user($user1);
         if (!empty($CFG->usetags)) {
             );
         $user1 = self::getDataGenerator()->create_user($user1);
         if (!empty($CFG->usetags)) {
@@ -672,7 +672,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
             'email' => 'usertest1@example.com',
             'description' => 'This is a description for user 1',
             'city' => 'Perth',
             'email' => 'usertest1@example.com',
             'description' => 'This is a description for user 1',
             'city' => 'Perth',
-            'country' => 'au'
+            'country' => 'AU'
             );
 
         $context = context_system::instance();
             );
 
         $context = context_system::instance();