From 4373103084527e9ca33cc98e388d5e7b2fba39a3 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Thu, 26 Jul 2012 11:38:02 +0800 Subject: [PATCH] MDL-34460 Librairies: Replaced deprecated get_context_instance() --- rss/file.php | 2 +- tag/coursetags_add.php | 2 +- tag/coursetags_edit.php | 4 ++-- tag/coursetags_more.php | 6 +++--- tag/coursetagslib.php | 2 +- tag/edit.php | 2 +- tag/edit_form.php | 2 +- tag/index.php | 2 +- tag/lib.php | 2 +- tag/locallib.php | 8 ++++---- tag/manage.php | 4 ++-- tag/search.php | 4 ++-- theme/mymobile/renderers.php | 10 +++++----- user/addnote.php | 2 +- user/edit.php | 10 +++++----- user/edit_form.php | 4 ++-- user/editadvanced.php | 12 ++++++------ user/editadvanced_form.php | 2 +- user/editlib.php | 2 +- user/emailupdate.php | 2 +- user/externallib.php | 10 +++++----- user/files.php | 2 +- user/filters/courserole.php | 2 +- user/filters/globalrole.php | 2 +- user/groupaddnote.php | 2 +- user/index.php | 14 +++++++------- user/lib.php | 12 ++++++------ user/managetoken.php | 2 +- user/messageselect.php | 6 +++--- user/pix.php | 2 +- user/policy.php | 2 +- user/portfolio.php | 2 +- user/portfoliologs.php | 2 +- user/profile.php | 10 +++++----- user/profile/field/checkbox/field.class.php | 2 +- user/profile/field/menu/field.class.php | 2 +- user/profile/lib.php | 12 ++++++------ user/profilesys.php | 2 +- user/renderer.php | 2 +- user/repository.php | 2 +- user/selector/lib.php | 6 +++--- user/selector/search.php | 2 +- user/view.php | 8 ++++---- userpix/index.php | 2 +- webservice/externallib.php | 2 +- webservice/lib.php | 12 ++++++------ webservice/upload.php | 2 +- webservice/wsdoc.php | 2 +- 48 files changed, 106 insertions(+), 106 deletions(-) diff --git a/rss/file.php b/rss/file.php index fdc4958e6756c..b9896db3781b0 100644 --- a/rss/file.php +++ b/rss/file.php @@ -85,7 +85,7 @@ foreach ($modinfo->instances[$componentname] as $modinstanceid=>$cm) { if ($modinstanceid==$instanceid) { - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id, IGNORE_MISSING); break; } } diff --git a/tag/coursetags_add.php b/tag/coursetags_add.php index 969dda3e3ac89..2ad1777220283 100644 --- a/tag/coursetags_add.php +++ b/tag/coursetags_add.php @@ -28,7 +28,7 @@ require_login(); -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); require_capability('moodle/tag:create', $systemcontext); if (empty($CFG->usetags)) { diff --git a/tag/coursetags_edit.php b/tag/coursetags_edit.php index 8dbc285dffae1..53e6be651866b 100644 --- a/tag/coursetags_edit.php +++ b/tag/coursetags_edit.php @@ -59,7 +59,7 @@ } // Permissions -$sitecontext = get_context_instance(CONTEXT_SYSTEM); +$sitecontext = context_system::instance(); require_login($course); $canedit = has_capability('moodle/tag:create', $sitecontext); @@ -85,7 +85,7 @@ // The title and breadcrumb $title = get_string('edittitle', $tagslang); $coursefullname = format_string($course->fullname); -$courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))); +$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $PAGE->navbar->add($title); $PAGE->set_title($title); $PAGE->set_heading($course->fullname); diff --git a/tag/coursetags_more.php b/tag/coursetags_more.php index 60b18207be118..61c3ccd333115 100644 --- a/tag/coursetags_more.php +++ b/tag/coursetags_more.php @@ -65,7 +65,7 @@ } if ($courseid) { - $PAGE->set_context(get_context_instance(CONTEXT_COURSE, $courseid)); + $PAGE->set_context(context_course::instance($courseid)); } else { $PAGE->set_context(get_system_context()); } @@ -86,7 +86,7 @@ // The title and breadcrumb if ($courseid) { - $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid))); + $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($courseid))); $PAGE->navbar->add($courseshortname, new moodle_url('/course/view.php', array('id'=>$courseid))); } $PAGE->navbar->add($title); @@ -183,7 +183,7 @@ } } if ($courseid) { - $fullname = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))); + $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id))); if ($show == 'course') { $link1 .= ' | '.get_string('moreshowcoursetags', $tagslang, $fullname).''; } else { diff --git a/tag/coursetagslib.php b/tag/coursetagslib.php index 5b5557aa5e48a..7d36b473642a4 100644 --- a/tag/coursetagslib.php +++ b/tag/coursetagslib.php @@ -232,7 +232,7 @@ function coursetag_print_cloud($tagcloud, $return=false, $max_size=180, $min_siz $step = ($max_size - $min_size)/($spread); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $can_manage_tags = has_capability('moodle/tag:manage', $systemcontext); //prints the tag cloud diff --git a/tag/edit.php b/tag/edit.php index b71c72f2be059..3629ed0315ca6 100644 --- a/tag/edit.php +++ b/tag/edit.php @@ -36,7 +36,7 @@ } //Editing a tag requires moodle/tag:edit capability -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); require_capability('moodle/tag:edit', $systemcontext); if ($tag_name) { diff --git a/tag/edit_form.php b/tag/edit_form.php index 972836755a7fb..9c62a4a6d0559 100644 --- a/tag/edit_form.php +++ b/tag/edit_form.php @@ -51,7 +51,7 @@ function definition () { $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); if (has_capability('moodle/tag:manage', $systemcontext)) { $mform->addElement('text', 'rawname', get_string('name', 'tag'), diff --git a/tag/index.php b/tag/index.php index 7e957826964e8..dbf3009a9c15c 100644 --- a/tag/index.php +++ b/tag/index.php @@ -41,7 +41,7 @@ $userpage = optional_param('userpage', 0, PARAM_INT); // which page to show $perpage = optional_param('perpage', 24, PARAM_INT); -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); if ($tagname) { $tag = tag_get('name', $tagname, '*'); diff --git a/tag/lib.php b/tag/lib.php index cdbe37fb9048a..d2a6f66500ece 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -600,7 +600,7 @@ function tag_delete($tagids) { } $success = true; - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); foreach ($tagids as $tagid) { if (is_null($tagid)) { // can happen if tag doesn't exists continue; diff --git a/tag/locallib.php b/tag/locallib.php index fb7f9a9f7300a..81afc01928f04 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -39,7 +39,7 @@ function tag_print_cloud($nr_of_tags=150, $return=false) { global $CFG, $DB; - $can_manage_tags = has_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM)); + $can_manage_tags = has_capability('moodle/tag:manage', context_system::instance()); if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid @@ -146,7 +146,7 @@ function tag_print_description_box($tag_object, $return=false) { $options = new stdClass(); $options->para = false; $options->overflowdiv = true; - $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', get_context_instance(CONTEXT_SYSTEM)->id, 'tag', 'description', $tag_object->id); + $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', context_system::instance()->id, 'tag', 'description', $tag_object->id); $output .= format_text($tag_object->description, $tag_object->descriptionformat, $options); } @@ -190,7 +190,7 @@ function tag_print_management_box($tag_object, $return=false) { if (!isguestuser()) { $output .= $OUTPUT->box_start('box','tag-management-box'); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $links = array(); // Add a link for users to add/remove this from their interests @@ -356,7 +356,7 @@ function tag_print_tagged_users_table($tag_object, $limitfrom='', $limitnum='', function tag_print_user_box($user, $return=false) { global $CFG, $OUTPUT; - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $usercontext = context_user::instance($user->id); $profilelink = ''; if ($usercontext and (has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($user->id))) { diff --git a/tag/manage.php b/tag/manage.php index e0edeb94bf546..2a886d3c7aa16 100644 --- a/tag/manage.php +++ b/tag/manage.php @@ -41,7 +41,7 @@ print_error('tagsaredisabled', 'tag'); } -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); require_capability('moodle/tag:manage', $systemcontext); $params = array(); @@ -151,7 +151,7 @@ // tag exists, change the type tag_type_set($new_otag_id, 'official'); } else { - require_capability('moodle/tag:create', get_context_instance(CONTEXT_SYSTEM)); + require_capability('moodle/tag:create', context_system::instance()); tag_add($new_otag, 'official'); } $notice .= get_string('addedotag', 'tag', $new_otag) .' '; diff --git a/tag/search.php b/tag/search.php index 7ebcfbf3e99ff..422d4e1bc7ca0 100644 --- a/tag/search.php +++ b/tag/search.php @@ -47,10 +47,10 @@ $params['perpage'] = $perpage; } $PAGE->set_url(new moodle_url('/tag/search.php', $params)); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); $PAGE->set_pagelayout('standard'); -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); $manage_link = ' '; $PAGE->set_title(get_string('tags', 'tag')); diff --git a/theme/mymobile/renderers.php b/theme/mymobile/renderers.php index 2b340d9521267..b6b49cf273a69 100644 --- a/theme/mymobile/renderers.php +++ b/theme/mymobile/renderers.php @@ -44,7 +44,7 @@ class theme_mymobile_renderer extends plugin_renderer_base { */ public function settings_tree(settings_navigation $navigation) { $content = $this->navigation_node($navigation, array('class' => 'settings')); - if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('moodle/site:config', context_system::instance())) { // TODO: Work out whether something is missing from here. } return $content; @@ -326,7 +326,7 @@ public function login_info() { // $course->id is not defined during installation return ''; } else if (isloggedin()) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $fullname = fullname($USER, true); // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page) @@ -364,7 +364,7 @@ public function login_info() { } else { $loggedinas .= get_string('failedloginattemptsall', '', $count); } - if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) { + if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', context_system::instance())) { $loggedinas .= ' ('.get_string('logs').')'; } $loggedinas .= ''; @@ -405,7 +405,7 @@ public function login_info_footer() { // $course->id is not defined during installation return ''; } else if (isloggedin()) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $fullname = fullname($USER, true); // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page) @@ -447,7 +447,7 @@ public function login_info_footer() { } else { $loggedinas .= get_string('failedloginattemptsall', '', $count); } - if (has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('report/log:view', context_system::instance())) { $loggedinas .= ' ('.get_string('logs').')'; } $loggedinas .= ''; diff --git a/user/addnote.php b/user/addnote.php index 1b899822686f8..e64957b4ecc90 100644 --- a/user/addnote.php +++ b/user/addnote.php @@ -37,7 +37,7 @@ print_error('invalidcourseid'); } -$context = get_context_instance(CONTEXT_COURSE, $id); +$context = context_course::instance($id); require_login($course); // to create notes the current user needs a capability diff --git a/user/edit.php b/user/edit.php index aa88131d5fa94..207093c23ddc6 100644 --- a/user/edit.php +++ b/user/edit.php @@ -97,12 +97,12 @@ } if ($course->id == SITEID) { - $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context + $coursecontext = context_system::instance(); // SYSTEM context } else { - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context + $coursecontext = context_course::instance($course->id); // Course context } -$systemcontext = get_context_instance(CONTEXT_SYSTEM); -$personalcontext = get_context_instance(CONTEXT_USER, $user->id); +$systemcontext = context_system::instance(); +$personalcontext = context_user::instance($user->id); // check access control if ($user->id == $USER->id) { @@ -244,7 +244,7 @@ $a = new stdClass(); $a->url = $CFG->wwwroot . '/user/emailupdate.php?key=' . $usernew->preference_newemailkey . '&id=' . $user->id; - $a->site = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID))); + $a->site = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID))); $a->fullname = fullname($user, true); $emailupdatemessage = get_string('emailupdatemessage', 'auth', $a); diff --git a/user/edit_form.php b/user/edit_form.php index b077a0c2143f3..cec4d5dfd684a 100644 --- a/user/edit_form.php +++ b/user/edit_form.php @@ -83,7 +83,7 @@ function definition_after_data() { // print picture if (!empty($CFG->gdversion)) { - $context = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST); + $context = context_user::instance($user->id, MUST_EXIST); $fs = get_file_storage(); $hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg')); if (!empty($user->picture) && $hasuploadedpicture) { @@ -147,7 +147,7 @@ function validation($usernew, $files) { $errors['email'] = get_string('toomanybounces'); } - if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', context_system::instance())) { $errorstr = email_is_not_allowed($usernew->email); if ($errorstr !== false) { $errors['email'] = $errorstr; diff --git a/user/editadvanced.php b/user/editadvanced.php index cdf03bd86e7bf..10c0faa0b4855 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -49,11 +49,11 @@ } if ($course->id == SITEID) { - $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context + $coursecontext = context_system::instance(); // SYSTEM context } else { - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context + $coursecontext = context_course::instance($course->id); // Course context } -$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = context_system::instance(); if ($id == -1) { // creating new user @@ -68,7 +68,7 @@ // editing existing user require_capability('moodle/user:update', $systemcontext); $user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST); - $PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id)); + $PAGE->set_context(context_user::instance($user->id)); if ($user->id == $USER->id) { if ($course->id != SITEID && $node = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE)) { $node->make_active(); @@ -112,7 +112,7 @@ } if ($user->id !== -1) { - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $usercontext = context_user::instance($user->id); $editoroptions = array( 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, @@ -203,7 +203,7 @@ $usercreated = false; } - $usercontext = get_context_instance(CONTEXT_USER, $usernew->id); + $usercontext = context_user::instance($usernew->id); //update preferences useredit_update_user_preference($usernew); diff --git a/user/editadvanced_form.php b/user/editadvanced_form.php index dbe6d829cab7a..04a63d718e03b 100644 --- a/user/editadvanced_form.php +++ b/user/editadvanced_form.php @@ -130,7 +130,7 @@ function definition_after_data() { // print picture if (!empty($CFG->gdversion) and empty($USER->newadminuser)) { if ($user) { - $context = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST); + $context = context_user::instance($user->id, MUST_EXIST); $fs = get_file_storage(); $hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg')); if (!empty($user->picture) && $hasuploadedpicture) { diff --git a/user/editlib.php b/user/editlib.php index 4c2a317fa34ee..d2250fbbfc3e7 100644 --- a/user/editlib.php +++ b/user/editlib.php @@ -46,7 +46,7 @@ function useredit_update_picture(stdClass $usernew, moodleform $userform, $filem global $CFG, $DB; require_once("$CFG->libdir/gdlib.php"); - $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST); + $context = context_user::instance($usernew->id, MUST_EXIST); $user = $DB->get_record('user', array('id'=>$usernew->id), 'id, picture', MUST_EXIST); $newpicture = $user->picture; diff --git a/user/emailupdate.php b/user/emailupdate.php index 602aa16401791..0aee6c8758481 100644 --- a/user/emailupdate.php +++ b/user/emailupdate.php @@ -31,7 +31,7 @@ $id = required_param('id', PARAM_INT); $PAGE->set_url('/user/emailupdate.php', array('id'=>$id, 'key'=>$key)); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); if (!$user = $DB->get_record('user', array('id' => $id))) { print_error('invaliduserid'); diff --git a/user/externallib.php b/user/externallib.php index 47b2663a6633a..49987cb938eda 100644 --- a/user/externallib.php +++ b/user/externallib.php @@ -100,7 +100,7 @@ public static function create_users($users) { require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function // Ensure the current user is allowed to run this function - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); self::validate_context($context); require_capability('moodle/user:create', $context); @@ -226,7 +226,7 @@ public static function delete_users($userids) { require_once($CFG->dirroot."/user/lib.php"); // Ensure the current user is allowed to run this function - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); require_capability('moodle/user:delete', $context); self::validate_context($context); @@ -324,7 +324,7 @@ public static function update_users($users) { require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function // Ensure the current user is allowed to run this function - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); require_capability('moodle/user:update', $context); self::validate_context($context); @@ -413,7 +413,7 @@ public static function get_users_by_id($userids) { continue; } context_instance_preload($user); - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $usercontext = context_user::instance($user->id, IGNORE_MISSING); self::validate_context($usercontext); $currentuser = ($user->id == $USER->id); @@ -576,7 +576,7 @@ public static function get_course_user_profiles($userlist) { } context_instance_preload($user); $course = $courses[$courseids[$user->id]]; - $context = get_context_instance(CONTEXT_COURSE, $courseids[$user->id]); + $context = context_course::instance($courseids[$user->id], IGNORE_MISSING); self::validate_context($context); if ($userarray = user_get_user_details($user, $course)) { $result[] = $userarray; diff --git a/user/files.php b/user/files.php index 54f7962c75aa2..973bbf5773c16 100644 --- a/user/files.php +++ b/user/files.php @@ -38,7 +38,7 @@ $returnurl = new moodle_url('/user/files.php'); } -$context = get_context_instance(CONTEXT_USER, $USER->id); +$context = context_user::instance($USER->id); require_capability('moodle/user:manageownfiles', $context); $title = get_string('myfiles'); diff --git a/user/filters/courserole.php b/user/filters/courserole.php index a38fe415c6fd4..0247bcc4f9900 100644 --- a/user/filters/courserole.php +++ b/user/filters/courserole.php @@ -21,7 +21,7 @@ function user_filter_courserole($name, $label, $advanced) { * @return array of availble roles */ function get_roles() { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); $roles = array(0=> get_string('anyrole','filters')) + get_default_enrol_roles($context); return $roles; } diff --git a/user/filters/globalrole.php b/user/filters/globalrole.php index 2721fdb9a0b91..2e9635ecbe25c 100644 --- a/user/filters/globalrole.php +++ b/user/filters/globalrole.php @@ -22,7 +22,7 @@ function user_filter_globalrole($name, $label, $advanced) { * @return array of availble roles */ function get_roles() { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); $roles = array(0=> get_string('anyrole','filters')) + get_assignable_roles($context); return $roles; } diff --git a/user/groupaddnote.php b/user/groupaddnote.php index 26649da10baf9..67dc9b39c2cc6 100644 --- a/user/groupaddnote.php +++ b/user/groupaddnote.php @@ -44,7 +44,7 @@ print_error('invalidcourseid'); } -$context = get_context_instance(CONTEXT_COURSE, $id); +$context = context_course::instance($id); require_login($course); // to create notes the current user needs a capability diff --git a/user/index.php b/user/index.php index c73e42b02a6f5..e850bdc9a90e9 100644 --- a/user/index.php +++ b/user/index.php @@ -41,7 +41,7 @@ $course = $DB->get_record('course', array('id'=>$context->instanceid), '*', MUST_EXIST); } else { $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); - $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); + $context = context_course::instance($course->id, MUST_EXIST); } // not needed anymore unset($contextid); @@ -49,10 +49,10 @@ require_login($course); - $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = context_system::instance(); $isfrontpage = ($course->id == SITEID); - $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID); + $frontpagectx = context_course::instance(SITEID); if ($isfrontpage) { $PAGE->set_pagelayout('admin'); @@ -190,7 +190,7 @@ $courselist = array(); $popupurl = new moodle_url('/user/index.php?roleid='.$roleid.'&sifirst=&silast='); foreach ($mycourses as $mycourse) { - $coursecontext = get_context_instance(CONTEXT_COURSE, $mycourse->id); + $coursecontext = context_course::instance($mycourse->id); $courselist[$mycourse->id] = format_string($mycourse->shortname, true, array('context' => $coursecontext)); } if (has_capability('moodle/site:viewparticipants', $systemcontext)) { @@ -579,8 +579,8 @@ context_instance_preload($user); - $context = get_context_instance(CONTEXT_COURSE, $course->id); - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $context = context_course::instance($course->id); + $usercontext = context_user::instance($user->id); $countries = get_string_manager()->get_list_of_countries(); @@ -719,7 +719,7 @@ } } - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $usercontext = context_user::instance($user->id); if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext))) { $profilelink = ''.fullname($user).''; diff --git a/user/lib.php b/user/lib.php index 9a497d2b9f2ec..8c84656a66a05 100644 --- a/user/lib.php +++ b/user/lib.php @@ -70,7 +70,7 @@ function user_create_user($user) { $newuser = $DB->get_record('user', array('id' => $newuserid)); // create USER context for this user - get_context_instance(CONTEXT_USER, $newuserid); + context_user::instance($newuserid); // update user password if necessary if (isset($userpassword)) { @@ -225,11 +225,11 @@ function user_get_user_details($user, $course = null, array $userfields = array( } if (!empty($course)) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); - $usercontext = get_context_instance(CONTEXT_USER, $user->id); + $context = context_course::instance($course->id); + $usercontext = context_user::instance($user->id); $canviewdetailscap = (has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext)); } else { - $context = get_context_instance(CONTEXT_USER, $user->id); + $context = context_user::instance($user->id); $usercontext = $context; $canviewdetailscap = has_capability('moodle/user:viewdetails', $usercontext); } @@ -448,10 +448,10 @@ function user_get_user_details($user, $course = null, array $userfields = array( if ($mycourses = enrol_get_users_courses($user->id, true)) { foreach ($mycourses as $mycourse) { if ($mycourse->category) { - $coursecontext = get_context_instance(CONTEXT_COURSE, $mycourse->id); + $coursecontext = context_course::instance($mycourse->id); $enrolledcourse = array(); $enrolledcourse['id'] = $mycourse->id; - $enrolledcourse['fullname'] = format_string($mycourse->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $mycourse->id))); + $enrolledcourse['fullname'] = format_string($mycourse->fullname, true, array('context' => context_course::instance($mycourse->id))); $enrolledcourse['shortname'] = format_string($mycourse->shortname, true, array('context' => $coursecontext)); $enrolledcourses[] = $enrolledcourse; } diff --git a/user/managetoken.php b/user/managetoken.php index c8f47b2af88c8..1342f129d48b7 100644 --- a/user/managetoken.php +++ b/user/managetoken.php @@ -29,7 +29,7 @@ require_login(); require_sesskey(); -$usercontext = get_context_instance(CONTEXT_USER, $USER->id); +$usercontext = context_user::instance($USER->id); $PAGE->set_context($usercontext); $PAGE->set_url('/user/managetoken.php'); diff --git a/user/messageselect.php b/user/messageselect.php index d54d26d413332..db354bf965d51 100644 --- a/user/messageselect.php +++ b/user/messageselect.php @@ -58,7 +58,7 @@ $url->param('deluser', $deluser); } $PAGE->set_url($url); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); @@ -66,8 +66,8 @@ require_login(); -$coursecontext = get_context_instance(CONTEXT_COURSE, $id); // Course context -$systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context +$coursecontext = context_course::instance($id); // Course context +$systemcontext = context_system::instance(); // SYSTEM context require_capability('moodle/course:bulkmessaging', $coursecontext); if (empty($SESSION->emailto)) { diff --git a/user/pix.php b/user/pix.php index b4b4cc1100b1d..1e354ed0c6597 100644 --- a/user/pix.php +++ b/user/pix.php @@ -42,7 +42,7 @@ } else { $image = 'f2'; } - if ($usercontext = get_context_instance(CONTEXT_USER, $userid)) { + if ($usercontext = context_user::instance($userid, IGNORE_MISSING)) { $url = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', $image); redirect($url); } diff --git a/user/policy.php b/user/policy.php index 46a2f2bb20fb3..0f5168fe35261 100644 --- a/user/policy.php +++ b/user/policy.php @@ -66,7 +66,7 @@ $strpolicyagreement = get_string('policyagreement'); $strpolicyagreementclick = get_string('policyagreementclick'); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); $PAGE->set_title($strpolicyagreement); $PAGE->set_heading($SITE->fullname); $PAGE->navbar->add($strpolicyagreement); diff --git a/user/portfolio.php b/user/portfolio.php index c91e04e628d25..653131e365db7 100644 --- a/user/portfolio.php +++ b/user/portfolio.php @@ -58,7 +58,7 @@ require_login($course, false); $PAGE->set_url($url); -$PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id)); +$PAGE->set_context(context_user::instance($user->id)); $PAGE->set_title("$course->fullname: $fullname: $strportfolios"); $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('standard'); diff --git a/user/portfoliologs.php b/user/portfoliologs.php index 1690b1f63814c..d9f60355ebd67 100644 --- a/user/portfoliologs.php +++ b/user/portfoliologs.php @@ -60,7 +60,7 @@ $PAGE->set_url($url); $PAGE->set_title("$course->fullname: $fullname: $strportfolios"); $PAGE->set_heading($course->fullname); -$PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id)); +$PAGE->set_context(context_user::instance($user->id)); $PAGE->set_pagelayout('standard'); echo $OUTPUT->header(); diff --git a/user/profile.php b/user/profile.php index 9dafdd9d35a2a..979319dcd88e4 100644 --- a/user/profile.php +++ b/user/profile.php @@ -59,7 +59,7 @@ $user = $DB->get_record('user', array('id' => $userid)); if ($user->deleted) { - $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); + $PAGE->set_context(context_system::instance()); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('userdeleted')); echo $OUTPUT->footer(); @@ -67,7 +67,7 @@ } $currentuser = ($user->id == $USER->id); -$context = $usercontext = get_context_instance(CONTEXT_USER, $userid, MUST_EXIST); +$context = $usercontext = context_user::instance($userid, MUST_EXIST); if (!$currentuser && !empty($CFG->forceloginforprofiles) && @@ -76,7 +76,7 @@ // Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366) $struser = get_string('user'); - $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); + $PAGE->set_context(context_system::instance()); $PAGE->set_title("$SITE->shortname: $struser"); // Do not leak the name $PAGE->set_heading("$SITE->shortname: $struser"); $PAGE->set_url('/user/profile.php', array('id'=>$userid)); @@ -93,7 +93,7 @@ } if (!$currentpage->userid) { - $context = get_context_instance(CONTEXT_SYSTEM); // A trick so that we even see non-sticky blocks + $context = context_system::instance(); // A trick so that we even see non-sticky blocks } $PAGE->set_context($context); @@ -306,7 +306,7 @@ if ($mycourse->category) { $class = ''; if ($mycourse->visible == 0) { - $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id); + $ccontext = context_course::instance($mycourse->id); if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) { continue; } diff --git a/user/profile/field/checkbox/field.class.php b/user/profile/field/checkbox/field.class.php index 6602556d02927..142ce254842f4 100644 --- a/user/profile/field/checkbox/field.class.php +++ b/user/profile/field/checkbox/field.class.php @@ -29,7 +29,7 @@ function edit_field_add($mform) { $checkbox->setChecked(true); } $mform->setType($this->inputname, PARAM_BOOL); - if ($this->is_required() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + if ($this->is_required() and !has_capability('moodle/user:update', context_system::instance())) { $mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client'); } } diff --git a/user/profile/field/menu/field.class.php b/user/profile/field/menu/field.class.php index 36b711acc8f7d..c0b8694134beb 100644 --- a/user/profile/field/menu/field.class.php +++ b/user/profile/field/menu/field.class.php @@ -80,7 +80,7 @@ function edit_field_set_locked($mform) { if (!$mform->elementExists($this->inputname)) { return; } - if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + if ($this->is_locked() and !has_capability('moodle/user:update', context_system::instance())) { $mform->hardFreeze($this->inputname); $mform->setConstant($this->inputname, $this->datakey); } diff --git a/user/profile/lib.php b/user/profile/lib.php index fd30d581180c2..4c193e4131d88 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -67,7 +67,7 @@ function display_data() { function edit_field($mform) { if ($this->field->visible != PROFILE_VISIBLE_NONE - or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + or has_capability('moodle/user:update', context_system::instance())) { $this->edit_field_add($mform); $this->edit_field_set_default($mform); @@ -85,7 +85,7 @@ function edit_field($mform) { function edit_after_data($mform) { if ($this->field->visible != PROFILE_VISIBLE_NONE - or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + or has_capability('moodle/user:update', context_system::instance())) { $this->edit_field_set_locked($mform); return true; } @@ -183,7 +183,7 @@ function edit_field_set_locked($mform) { if (!$mform->elementExists($this->inputname)) { return; } - if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { + if ($this->is_locked() and !has_capability('moodle/user:update', context_system::instance())) { $mform->hardFreeze($this->inputname); $mform->setConstant($this->inputname, $this->data); } @@ -283,11 +283,11 @@ function is_visible() { return true; } else { return has_capability('moodle/user:viewalldetails', - get_context_instance(CONTEXT_USER, $this->userid)); + context_user::instance($this->userid)); } default: return has_capability('moodle/user:viewalldetails', - get_context_instance(CONTEXT_USER, $this->userid)); + context_user::instance($this->userid)); } } @@ -359,7 +359,7 @@ function profile_definition($mform, $userid = 0) { global $CFG, $DB; // if user is "admin" fields are displayed regardless - $update = has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM)); + $update = has_capability('moodle/user:update', context_system::instance()); if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) { foreach ($categories as $category) { diff --git a/user/profilesys.php b/user/profilesys.php index 79740ef311e8c..fc3e467346e4e 100644 --- a/user/profilesys.php +++ b/user/profilesys.php @@ -37,7 +37,7 @@ require_login(); -$context = get_context_instance(CONTEXT_SYSTEM); +$context = context_system::instance(); require_capability('moodle/my:configsyspages', $context); $PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); $header = "$SITE->shortname: ".get_string('publicprofile')." (".get_string('myprofile', 'admin').")"; diff --git a/user/renderer.php b/user/renderer.php index 09f30d73895eb..70319c630b74e 100644 --- a/user/renderer.php +++ b/user/renderer.php @@ -84,7 +84,7 @@ class user_files_tree implements renderable { public $dir; public function __construct() { global $USER; - $this->context = get_context_instance(CONTEXT_USER, $USER->id); + $this->context = context_user::instance($USER->id); $fs = get_file_storage(); $this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0); } diff --git a/user/repository.php b/user/repository.php index 23ed84f160b58..daa6de058f415 100644 --- a/user/repository.php +++ b/user/repository.php @@ -46,7 +46,7 @@ $pluginstr = get_string('plugin', 'repository'); require_login($course, false); -$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$coursecontext = context_course::instance($course->id, MUST_EXIST); $link = new moodle_url('/user/view.php', array('id'=>$user->id)); $PAGE->navbar->add($fullname, $link); diff --git a/user/selector/lib.php b/user/selector/lib.php index 35f40658d774c..9aa40edf03f2b 100644 --- a/user/selector/lib.php +++ b/user/selector/lib.php @@ -98,7 +98,7 @@ public function __construct($name, $options = array()) { if (isset($options['accesscontext'])) { $this->accesscontext = $options['accesscontext']; } else { - $this->accesscontext = get_context_instance(CONTEXT_SYSTEM); + $this->accesscontext = context_system::instance(); } if (isset($options['extrafields'])) { @@ -676,7 +676,7 @@ abstract class groups_user_selector_base extends user_selector_base { */ public function __construct($name, $options) { global $CFG; - $options['accesscontext'] = get_context_instance(CONTEXT_COURSE, $options['courseid']); + $options['accesscontext'] = context_course::instance($options['courseid']); parent::__construct($name, $options); $this->groupid = $options['groupid']; $this->courseid = $options['courseid']; @@ -809,7 +809,7 @@ public function find_users($search) { global $DB; // Get list of allowed roles. - $context = get_context_instance(CONTEXT_COURSE, $this->courseid); + $context = context_course::instance($this->courseid); if ($validroleids = groups_get_possible_roles($context)) { list($roleids, $roleparams) = $DB->get_in_or_equal($validroleids, SQL_PARAMS_NAMED, 'r'); } else { diff --git a/user/selector/search.php b/user/selector/search.php index fcaf74ec3bbbe..341ebf5b22669 100644 --- a/user/selector/search.php +++ b/user/selector/search.php @@ -26,7 +26,7 @@ require_once(dirname(__FILE__) . '/../../config.php'); require_once($CFG->dirroot . '/user/selector/lib.php'); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); $PAGE->set_url('/user/selector/search.php'); // In developer debug mode, when there is a debug=1 in the URL send as plain text diff --git a/user/view.php b/user/view.php index 68d36ac33cf2f..4c4c8da2b9964 100644 --- a/user/view.php +++ b/user/view.php @@ -46,9 +46,9 @@ $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); $currentuser = ($user->id == $USER->id); -$systemcontext = get_context_instance(CONTEXT_SYSTEM); -$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); -$usercontext = get_context_instance(CONTEXT_USER, $user->id, IGNORE_MISSING); +$systemcontext = context_system::instance(); +$coursecontext = context_course::instance($course->id); +$usercontext = context_user::instance($user->id, IGNORE_MISSING); // Require login first if (isguestuser($user)) { @@ -288,7 +288,7 @@ $courselisting = ''; foreach ($mycourses as $mycourse) { if ($mycourse->category) { - $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);; + $ccontext = context_course::instance($mycourse->id);; $cfullname = format_string($mycourse->fullname, true, array('context' => $ccontext)); if ($mycourse->id != $course->id){ $class = ''; diff --git a/userpix/index.php b/userpix/index.php index 652df70401f0b..515957116ad24 100644 --- a/userpix/index.php +++ b/userpix/index.php @@ -13,7 +13,7 @@ require_login(); /// Remove the following three lines if you want everyone to access it -$syscontext = get_context_instance(CONTEXT_SYSTEM); +$syscontext = context_system::instance(); require_capability('moodle/site:config', $syscontext); $title = get_string("users"); diff --git a/webservice/externallib.php b/webservice/externallib.php index 7b006d6e1b19b..4effcde1d493e 100644 --- a/webservice/externallib.php +++ b/webservice/externallib.php @@ -71,7 +71,7 @@ public function get_site_info($serviceshortnames = array()) { array('serviceshortnames'=>$serviceshortnames)); $profileimageurl = moodle_url::make_pluginfile_url( - get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'icon', NULL, '/', 'f1'); + context_user::instance($USER->id)->id, 'user', 'icon', NULL, '/', 'f1'); //site information $siteinfo = array( diff --git a/webservice/lib.php b/webservice/lib.php index 4fac2e9722a36..111ae75ec6f81 100644 --- a/webservice/lib.php +++ b/webservice/lib.php @@ -102,7 +102,7 @@ public function authenticate_user($token) { } //Non admin can not authenticate if maintenance mode - $hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM), $user); + $hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user); if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) { //this is usually temporary, client want to implement code logic => moodle_exception throw new moodle_exception('sitemaintenance', 'admin'); @@ -116,7 +116,7 @@ public function authenticate_user($token) { } //check if there is any required system capability - if ($service->requiredcapability and !has_capability($service->requiredcapability, get_context_instance(CONTEXT_SYSTEM), $user)) { + if ($service->requiredcapability and !has_capability($service->requiredcapability, context_system::instance(), $user)) { throw new webservice_access_exception('The capability ' . $service->requiredcapability . ' is required.'); } @@ -262,7 +262,7 @@ public function generate_user_ws_tokens($userid) { global $CFG, $DB; // generate a token for non admin if web service are enable and the user has the capability to create a token - if (!is_siteadmin() && has_capability('moodle/webservice:createtoken', get_context_instance(CONTEXT_SYSTEM), $userid) && !empty($CFG->enablewebservices)) { + if (!is_siteadmin() && has_capability('moodle/webservice:createtoken', context_system::instance(), $userid) && !empty($CFG->enablewebservices)) { // for every service than the user is authorised on, create a token (if it doesn't already exist) // get all services which are set to all user (no restricted to specific users) @@ -298,7 +298,7 @@ public function generate_user_ws_tokens($userid) { $newtoken->userid = $userid; $newtoken->externalserviceid = $serviceid; // TODO MDL-31190 find a way to get the context - UPDATE FOLLOWING LINE - $newtoken->contextid = get_context_instance(CONTEXT_SYSTEM)->id; + $newtoken->contextid = context_system::instance()->id; $newtoken->creatorid = $userid; $newtoken->timecreated = time(); @@ -835,7 +835,7 @@ protected function authenticate_user() { throw new webservice_access_exception('The web service authentication plugin is missing.'); } - $this->restricted_context = get_context_instance(CONTEXT_SYSTEM); + $this->restricted_context = context_system::instance(); if (!$this->username) { throw new moodle_exception('missingusername', 'webservice'); @@ -860,7 +860,7 @@ protected function authenticate_user() { } //Non admin can not authenticate if maintenance mode - $hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM), $user); + $hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user); if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) { throw new moodle_exception('sitemaintenance', 'admin'); } diff --git a/webservice/upload.php b/webservice/upload.php index 5e2f6cc0f2f2b..9c01869e00490 100644 --- a/webservice/upload.php +++ b/webservice/upload.php @@ -51,7 +51,7 @@ $authenticationinfo = $webservicelib->authenticate_user($token); // check the user can manage his own files (can upload) -$context = get_context_instance(CONTEXT_USER, $USER->id); +$context = context_user::instance($USER->id); require_capability('moodle/user:manageownfiles', $context); $fs = get_file_storage(); diff --git a/webservice/wsdoc.php b/webservice/wsdoc.php index a0206c2dbaed7..01b71c034c9ee 100644 --- a/webservice/wsdoc.php +++ b/webservice/wsdoc.php @@ -29,7 +29,7 @@ require_login(); require_sesskey(); -$usercontext = get_context_instance(CONTEXT_USER, $USER->id); +$usercontext = context_user::instance($USER->id); $tokenid = required_param('id', PARAM_INT); // PAGE settings