diff --git a/admin/roles/permissions.php b/admin/roles/permissions.php index 3670a8680233f..01ddbaa8ad6f9 100644 --- a/admin/roles/permissions.php +++ b/admin/roles/permissions.php @@ -60,7 +60,7 @@ if ($context->contextlevel == CONTEXT_USER and $USER->id != $context->instanceid) { $PAGE->navigation->extend_for_user($user); - $PAGE->set_context(context_course::instance($course->id)); + $PAGE->set_context(context_user::instance($user->id)); } else { $PAGE->set_context($context); } diff --git a/badges/mybackpack.php b/badges/mybackpack.php index 875d025b1d39e..c6bb7e8c8308b 100644 --- a/badges/mybackpack.php +++ b/badges/mybackpack.php @@ -49,7 +49,7 @@ $title = get_string('mybackpack', 'badges'); $PAGE->set_title($title); -$PAGE->set_heading($title); +$PAGE->set_heading(fullname($USER)); $PAGE->set_pagelayout('mydashboard'); $backpack = $DB->get_record('badge_backpack', array('userid' => $USER->id)); @@ -131,5 +131,6 @@ } echo $OUTPUT->header(); +echo $OUTPUT->heading($title); $form->display(); echo $OUTPUT->footer(); diff --git a/badges/mybadges.php b/badges/mybadges.php index a1454dab59b47..e7c73615795d1 100644 --- a/badges/mybadges.php +++ b/badges/mybadges.php @@ -88,7 +88,7 @@ $title = get_string('mybadges', 'badges'); $PAGE->set_title($title); -$PAGE->set_heading($title); +$PAGE->set_heading(fullname($USER)); $PAGE->set_pagelayout('mydashboard'); // Include JS files for backpack support. diff --git a/badges/preferences.php b/badges/preferences.php index edb771883a03d..a35337d6b96e6 100644 --- a/badges/preferences.php +++ b/badges/preferences.php @@ -30,7 +30,7 @@ $url = new moodle_url('/badges/preferences.php'); require_login(); -$PAGE->set_context(context_system::instance()); +$PAGE->set_context(context_user::instance($USER->id)); $PAGE->set_url($url); $PAGE->set_pagelayout('standard'); @@ -55,7 +55,7 @@ $title = "$strbadges: $strpreferences"; $PAGE->set_title($title); -$PAGE->set_heading($title); +$PAGE->set_heading(fullname($USER)); echo $OUTPUT->header(); echo $OUTPUT->heading("$strbadges: $strpreferences", 2); diff --git a/blog/edit.php b/blog/edit.php index c3052f796d511..783a2bddb5160 100644 --- a/blog/edit.php +++ b/blog/edit.php @@ -48,9 +48,9 @@ $id = null; } -// Blogs are always in system context. $sitecontext = context_system::instance(); -$PAGE->set_context($sitecontext); +$usercontext = context_user::instance($USER->id); +$PAGE->set_context($usercontext); require_login($courseid); @@ -142,10 +142,10 @@ } } else if ($action == 'add') { $PAGE->set_title("$SITE->shortname: $strblogs: " . get_string('addnewentry', 'blog')); - $PAGE->set_heading($SITE->shortname); + $PAGE->set_heading(fullname($USER)); } else if ($action == 'edit') { $PAGE->set_title("$SITE->shortname: $strblogs: " . get_string('editentry', 'blog')); - $PAGE->set_heading($SITE->shortname); + $PAGE->set_heading(fullname($USER)); } if (!empty($entry->id)) { diff --git a/blog/external_blog_edit.php b/blog/external_blog_edit.php index 0aa122bd8b09a..069ef9615f588 100644 --- a/blog/external_blog_edit.php +++ b/blog/external_blog_edit.php @@ -44,7 +44,7 @@ $url->param('id', $id); } $PAGE->set_url($url); -$PAGE->set_context($context); +$PAGE->set_context(context_user::instance($USER->id)); $PAGE->set_pagelayout('admin'); $returnurl = new moodle_url('/blog/external_blogs.php'); @@ -125,7 +125,7 @@ redirect($returnurl); } -$PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname); +$PAGE->set_heading(fullname($USER)); $PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs"); echo $OUTPUT->header(); diff --git a/blog/external_blogs.php b/blog/external_blogs.php index 800c85c6a31cd..4b0d408cbce15 100644 --- a/blog/external_blogs.php +++ b/blog/external_blogs.php @@ -29,7 +29,7 @@ require_login(); $context = context_system::instance(); -$PAGE->set_context($context); +$PAGE->set_context(context_user::instance($USER->id)); $PAGE->set_url(new moodle_url('/blog/external_blogs.php')); require_capability('moodle/blog:manageexternal', $context); @@ -61,7 +61,7 @@ $blogs = $DB->get_records('blog_external', array('userid' => $USER->id)); -$PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname); +$PAGE->set_heading(fullname($USER)); $PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs"); $PAGE->set_pagelayout('standard'); diff --git a/blog/index.php b/blog/index.php index 4c58f3451e7d0..0c9a7f60e5d8a 100644 --- a/blog/index.php +++ b/blog/index.php @@ -57,9 +57,14 @@ } } +if (isset($userid)) { + $context = context_user::instance($userid); +} else { + $context = context_system::instance(); +} +$PAGE->set_context($context); + $sitecontext = context_system::instance(); -// Blogs are always in system context. -$PAGE->set_context($sitecontext); // Check basic permissions. if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) { @@ -225,9 +230,11 @@ blog_rss_add_http_header($rsscontext, $rsstitle, $filtertype, $thingid, $tagid); } } +if (isset($userid)) { + $PAGE->set_heading(fullname($user)); +} echo $OUTPUT->header(); - echo $OUTPUT->heading($blogheaders['heading'], 2); $bloglisting = new blog_listing($blogheaders['filters']); diff --git a/blog/preferences.php b/blog/preferences.php index 59aea44dfacba..e0608d01781b1 100644 --- a/blog/preferences.php +++ b/blog/preferences.php @@ -55,7 +55,8 @@ $PAGE->set_pagelayout('admin'); $sitecontext = context_system::instance(); -$PAGE->set_context($sitecontext); +$usercontext = context_user::instance($USER->id); +$PAGE->set_context($usercontext); require_login($courseid); if (empty($CFG->enableblogs)) { @@ -90,7 +91,7 @@ $title = "$site->shortname: $strblogs : $strpreferences"; $PAGE->set_title($title); -$PAGE->set_heading($title); +$PAGE->set_heading(fullname($USER)); echo $OUTPUT->header(); diff --git a/grade/report/overview/index.php b/grade/report/overview/index.php index c8c11ed2857b7..0721d286e6f95 100644 --- a/grade/report/overview/index.php +++ b/grade/report/overview/index.php @@ -40,7 +40,6 @@ $context = context_course::instance($course->id); $systemcontext = context_system::instance(); $personalcontext = null; -$PAGE->set_context($context); // If we are accessing the page from a site context then ignore this check. if ($courseid != SITEID) { @@ -57,6 +56,12 @@ $personalcontext = context_user::instance($userid); } +if (isset($personalcontext)) { + $PAGE->set_context($personalcontext); +} else { + $PAGE->set_context($context); +} + $access = false; if (has_capability('moodle/grade:viewall', $systemcontext)) { // Ok - can view all course grades. @@ -154,9 +159,9 @@ // Display a standard page. if ($courseid == SITEID) { $PAGE->set_pagelayout('standard'); - $header = get_string('mygrades', 'grades'). ' - '.fullname($report->user); + $header = get_string('mygrades', 'grades') . ' - ' . fullname($report->user); $PAGE->set_title($header); - $PAGE->set_heading($header); + $PAGE->set_heading(fullname($report->user)); if ($USER->id != $report->user->id) { $PAGE->navigation->extend_for_user($report->user); diff --git a/login/change_password.php b/login/change_password.php index 0dfa342e53954..d36475e4c6b70 100644 --- a/login/change_password.php +++ b/login/change_password.php @@ -134,7 +134,7 @@ $fullname = fullname($USER, true); $PAGE->set_title($strpasswordchanged); - $PAGE->set_heading($COURSE->fullname); + $PAGE->set_heading(fullname($USER)); echo $OUTPUT->header(); notice($strpasswordchanged, new moodle_url($PAGE->url, array('return'=>1))); @@ -151,7 +151,7 @@ $fullname = fullname($USER, true); $PAGE->set_title($strchangepassword); -$PAGE->set_heading($COURSE->fullname); +$PAGE->set_heading($fullname); echo $OUTPUT->header(); if (get_user_preferences('auth_forcepasswordchange')) { diff --git a/message/edit.php b/message/edit.php index 7b73ec2686df2..c4172df43e490 100644 --- a/message/edit.php +++ b/message/edit.php @@ -164,7 +164,7 @@ /// Display page header $strmessaging = get_string('messaging', 'message'); $PAGE->set_title($strmessaging); -$PAGE->set_heading($strmessaging); +$PAGE->set_heading(fullname($USER)); // Grab the renderer $renderer = $PAGE->get_renderer('core', 'message'); diff --git a/message/index.php b/message/index.php index 1b458ded91412..56070bbf8cffc 100644 --- a/message/index.php +++ b/message/index.php @@ -125,8 +125,9 @@ $PAGE->set_pagelayout('incourse'); } else { $PAGE->set_pagelayout('standard'); - $PAGE->set_context(context_user::instance($user1->id)); } +// Page context should always be set to user. +$PAGE->set_context(context_user::instance($user1->id)); if (!empty($user1->id) && $user1->id != $USER->id) { $PAGE->navigation->extend_for_user($user1); } @@ -194,11 +195,10 @@ $user2fullname = fullname($user2); $PAGE->set_title("$strmessages: $user2fullname"); - $PAGE->set_heading("$strmessages: $user2fullname"); } else { $PAGE->set_title("{$SITE->shortname}: $strmessages"); - $PAGE->set_heading("{$SITE->shortname}: $strmessages"); } +$PAGE->set_heading(fullname($USER)); //now the page contents echo $OUTPUT->header(); diff --git a/mod/forum/classes/event/user_report_viewed.php b/mod/forum/classes/event/user_report_viewed.php index 711ea10edda6e..a03fe6152ceee 100644 --- a/mod/forum/classes/event/user_report_viewed.php +++ b/mod/forum/classes/event/user_report_viewed.php @@ -119,11 +119,12 @@ protected function validate_data() { { case CONTEXT_COURSE: case CONTEXT_SYSTEM: + case CONTEXT_USER: // OK, expected context level. break; default: // Unexpected contextlevel. - throw new \coding_exception('Context level must be either CONTEXT_SYSTEM or CONTEXT_COURSE.'); + throw new \coding_exception('Context level must be either CONTEXT_SYSTEM, CONTEXT_COURSE or CONTEXT_USER.'); } } diff --git a/mod/forum/tests/events_test.php b/mod/forum/tests/events_test.php index 22edf3bc9ea2f..607371901e69d 100644 --- a/mod/forum/tests/events_test.php +++ b/mod/forum/tests/events_test.php @@ -1040,7 +1040,8 @@ public function test_user_report_viewed_contextlevel_validation() { 'relateduserid' => $user->id, ); - $this->setExpectedException('coding_exception', 'Context level must be either CONTEXT_SYSTEM or CONTEXT_COURSE.'); + $this->setExpectedException('coding_exception', + 'Context level must be either CONTEXT_SYSTEM, CONTEXT_COURSE or CONTEXT_USER.'); \mod_forum\event\user_report_viewed::create($params); } diff --git a/mod/forum/user.php b/mod/forum/user.php index 87aba79caaf66..c4bcaa0e9e96d 100644 --- a/mod/forum/user.php +++ b/mod/forum/user.php @@ -108,14 +108,13 @@ // We are going to search for all of the users posts in all courses! // a general require login here as we arn't actually within any course. require_login(); - $PAGE->set_context(context_system::instance()); + $PAGE->set_context(context_user::instance($user->id)); // Now we need to get all of the courses to search. // All courses where the user has posted within a forum will be returned. $courses = forum_get_courses_user_posted_in($user, $discussionsonly); } - $params = array( 'context' => $PAGE->context, 'relateduserid' => $user->id, @@ -202,7 +201,11 @@ // Display a page letting the user know that there's nothing to display; $PAGE->set_title($pagetitle); - $PAGE->set_heading($pageheading); + if ($isspecificcourse) { + $PAGE->set_heading($pageheading); + } else { + $PAGE->set_heading(fullname($user)); + } echo $OUTPUT->header(); echo $OUTPUT->heading($pagetitle); echo $OUTPUT->notification($notification); @@ -323,7 +326,8 @@ } $PAGE->set_title($pagetitle); -$PAGE->set_heading($pagetitle); +$PAGE->set_heading($pageheading); + $PAGE->navigation->extend_for_user($user); $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed. diff --git a/my/index.php b/my/index.php index 07a808a13c52c..676dd2229bbef 100644 --- a/my/index.php +++ b/my/index.php @@ -64,7 +64,7 @@ $userid = $USER->id; // Owner of the page $context = context_user::instance($USER->id); $PAGE->set_blocks_editing_capability('moodle/my:manageblocks'); - $header = "$SITE->shortname: $strmymoodle"; + $header = fullname($USER); } // Get the My Moodle page info. Should always return something unless the database is broken. @@ -72,10 +72,6 @@ print_error('mymoodlesetup'); } -if (!$currentpage->userid) { - $context = context_system::instance(); // So we even see non-sticky blocks -} - // Start setting up the page $params = array(); $PAGE->set_context($context); @@ -109,17 +105,6 @@ } } else if ($edit !== null) { // Editing state was specified $USER->editing = $edit; // Change editing state - if (!$currentpage->userid && $edit) { - // If we are viewing a system page as ordinary user, and the user turns - // editing on, copy the system pages as new user pages, and get the - // new page record - if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PRIVATE)) { - print_error('mymoodlesetup'); - } - $context = context_user::instance($USER->id); - $PAGE->set_context($context); - $PAGE->set_subpage($currentpage->id); - } } else { // Editing state is in session if ($currentpage->userid) { // It's a page we can edit, so load from session if (!empty($USER->editing)) { @@ -127,7 +112,16 @@ } else { $edit = 0; } - } else { // It's a system page and they are not allowed to edit system pages + } else { + // For the page to display properly with the user context header the page blocks need to + // be copied over to the user context. + if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PRIVATE)) { + print_error('mymoodlesetup'); + } + $context = context_user::instance($USER->id); + $PAGE->set_context($context); + $PAGE->set_subpage($currentpage->id); + // It's a system page and they are not allowed to edit system pages $USER->editing = $edit = 0; // Disable editing completely, just to be safe } } @@ -158,12 +152,6 @@ $USER->editing = $edit = 0; } -// HACK WARNING! This loads up all this page's blocks in the system context -if ($currentpage->userid == 0) { - $CFG->blockmanagerclass = 'my_syspage_block_manager'; -} - - echo $OUTPUT->header(); echo $OUTPUT->custom_block_region('content'); diff --git a/notes/index.php b/notes/index.php index abab4e95c0a8e..8e8d84625a9f6 100644 --- a/notes/index.php +++ b/notes/index.php @@ -104,7 +104,7 @@ $PAGE->set_pagelayout('incourse'); $PAGE->set_title($course->shortname . ': ' . $strnotes); -$PAGE->set_heading($course->fullname); +$PAGE->set_heading(fullname($USER)); echo $OUTPUT->header(); if ($userid) { diff --git a/report/log/user.php b/report/log/user.php index c339e6ceb4f74..7e94953bf345b 100644 --- a/report/log/user.php +++ b/report/log/user.php @@ -43,6 +43,10 @@ $coursecontext = context_course::instance($course->id); $personalcontext = context_user::instance($user->id); +if ($courseid == SITEID) { + $PAGE->set_context($personalcontext); +} + if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) { //TODO: do not require parents to be enrolled in courses - this is a hack! @@ -71,7 +75,11 @@ $PAGE->navigation->extend_for_user($user); $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed. $PAGE->set_title("$course->shortname: $stractivityreport"); -$PAGE->set_heading($course->fullname); +if ($courseid == SITEID) { + $PAGE->set_heading(fullname($user)); +} else { + $PAGE->set_heading($course->fullname); +} // Trigger a user logs viewed event. $event = \report_log\event\user_report_viewed::create(array('context' => $coursecontext, 'relateduserid' => $userid, diff --git a/report/outline/user.php b/report/outline/user.php index ed4ac77a1f039..227ab97ab4fce 100644 --- a/report/outline/user.php +++ b/report/outline/user.php @@ -41,6 +41,10 @@ $coursecontext = context_course::instance($course->id); $personalcontext = context_user::instance($user->id); +if ($courseid == SITEID) { + $PAGE->set_context($personalcontext); +} + if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) { //TODO: do not require parents to be enrolled in courses - this is a hack! @@ -62,7 +66,11 @@ $PAGE->navigation->extend_for_user($user); $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed. $PAGE->set_title("$course->shortname: $stractivityreport"); -$PAGE->set_heading($course->fullname); +if ($courseid == SITEID) { + $PAGE->set_heading(fullname($user)); +} else { + $PAGE->set_heading($course->fullname); +} // Trigger a report viewed event. $event = \report_outline\event\report_viewed::create(array('context' => context_course::instance($course->id), diff --git a/report/usersessions/user.php b/report/usersessions/user.php index 7af5d936e9af0..7c911973bd4b6 100644 --- a/report/usersessions/user.php +++ b/report/usersessions/user.php @@ -47,6 +47,7 @@ $PAGE->set_url('/report/usersessions/user.php'); $PAGE->set_context($context); $PAGE->set_title(get_string('navigationlink', 'report_usersessions')); +$PAGE->set_heading(fullname($USER)); $PAGE->set_pagelayout('admin'); if ($delete and confirm_sesskey()) { diff --git a/user/edit.php b/user/edit.php index 0b1ce5df4d0dd..3966c1f960fe7 100644 --- a/user/edit.php +++ b/user/edit.php @@ -298,7 +298,7 @@ $userfullname = fullname($user, true); $PAGE->set_title("$course->shortname: $streditmyprofile"); -$PAGE->set_heading($course->fullname); +$PAGE->set_heading($userfullname); echo $OUTPUT->header(); echo $OUTPUT->heading($userfullname); diff --git a/user/editadvanced.php b/user/editadvanced.php index d0136b44eb80b..5e6c486bffe89 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -310,9 +310,9 @@ if ($user->id == -1) { echo $OUTPUT->header(); } else { - $PAGE->set_heading($SITE->fullname); - echo $OUTPUT->header(); $userfullname = fullname($user, true); + $PAGE->set_heading($userfullname); + echo $OUTPUT->header(); echo $OUTPUT->heading($userfullname); } } else if (!empty($USER->newadminuser)) { @@ -334,7 +334,7 @@ $userfullname = fullname($user, true); $PAGE->set_title("$course->shortname: $streditmyprofile"); - $PAGE->set_heading($course->fullname); + $PAGE->set_heading($userfullname); echo $OUTPUT->header(); echo $OUTPUT->heading($userfullname); diff --git a/user/files.php b/user/files.php index 00d1ebada6fbc..0417b0360cf9e 100644 --- a/user/files.php +++ b/user/files.php @@ -47,7 +47,7 @@ $PAGE->set_url('/user/files.php'); $PAGE->set_context($context); $PAGE->set_title($title); -$PAGE->set_heading($title); +$PAGE->set_heading(fullname($USER)); $PAGE->set_pagelayout('mydashboard'); $PAGE->set_pagetype('user-files'); diff --git a/user/preferences.php b/user/preferences.php index d65676e21ab2a..c53de77dffe8f 100644 --- a/user/preferences.php +++ b/user/preferences.php @@ -48,17 +48,13 @@ $PAGE->set_url('/user/preferences.php', array('userid' => $userid)); $PAGE->set_pagelayout('admin'); $PAGE->set_pagetype('user-preferences'); +$PAGE->set_title(fullname($user)); +$PAGE->set_heading(fullname($user)); if (!$currentuser) { - $PAGE->set_title(fullname($user)); - $PAGE->set_heading(fullname($user)); - $PAGE->navigation->extend_for_user($user); $settings = $PAGE->settingsnav->get('userviewingsettings' . $user->id); } else { - $PAGE->set_title(get_string('preferences')); - $PAGE->set_heading(get_string('preferences')); - $settings = $PAGE->settingsnav->get('usercurrentsettings'); } diff --git a/user/profile.php b/user/profile.php index ca6fea150443d..a57918511a351 100644 --- a/user/profile.php +++ b/user/profile.php @@ -85,7 +85,7 @@ $struser = get_string('user'); $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_heading($struser); $PAGE->set_url('/user/profile.php', array('id' => $userid)); $PAGE->navbar->add($struser); echo $OUTPUT->header(); @@ -99,10 +99,6 @@ print_error('mymoodlesetup'); } -if (!$currentpage->userid) { - $context = context_system::instance(); // A trick so that we even see non-sticky blocks. -} - $PAGE->set_context($context); $PAGE->set_pagelayout('mypublic'); $PAGE->set_pagetype('user-profile'); @@ -144,7 +140,7 @@ $PAGE->blocks->add_region('content'); $PAGE->set_subpage($currentpage->id); $PAGE->set_title(fullname($user).": $strpublicprofile"); -$PAGE->set_heading(fullname($user).": $strpublicprofile"); +$PAGE->set_heading(fullname($user)); if (!$currentuser) { $PAGE->navigation->extend_for_user($user); @@ -170,16 +166,6 @@ } } else if ($edit !== null) { // Editing state was specified. $USER->editing = $edit; // Change editing state. - if (!$currentpage->userid && $edit) { - // If we are viewing a system page as ordinary user, and the user turns - // editing on, copy the system pages as new user pages, and get the - // new page record. - if (!$currentpage = my_copy_page($userid, MY_PAGE_PUBLIC, 'user-profile')) { - print_error('mymoodlesetup'); - } - $PAGE->set_context($usercontext); - $PAGE->set_subpage($currentpage->id); - } } else { // Editing state is in session. if ($currentpage->userid) { // It's a page we can edit, so load from session. if (!empty($USER->editing)) { @@ -187,7 +173,15 @@ } else { $edit = 0; } - } else { // It's a system page and they are not allowed to edit system pages. + } else { + // For the page to display properly with the user context header the page blocks need to + // be copied over to the user context. + if (!$currentpage = my_copy_page($userid, MY_PAGE_PUBLIC, 'user-profile')) { + print_error('mymoodlesetup'); + } + $PAGE->set_context($usercontext); + $PAGE->set_subpage($currentpage->id); + // It's a system page and they are not allowed to edit system pages. $USER->editing = $edit = 0; // Disable editing completely, just to be safe. } } @@ -219,11 +213,6 @@ $USER->editing = $edit = 0; } -// HACK WARNING! This loads up all this page's blocks in the system context. -if ($currentpage->userid == 0) { - $CFG->blockmanagerclass = 'my_syspage_block_manager'; -} - // Trigger a user profile viewed event. profile_view($user, $usercontext);