From 9393fe36438ede860dd8d469032a1d6355236bea Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Wed, 5 Jan 2022 18:22:21 +0800 Subject: [PATCH] MDL-73427 core: Remove $SESSION->fromurl --- lib/moodlelib.php | 5 ----- lib/setuplib.php | 7 +------ lib/tests/setuplib_test.php | 26 -------------------------- mod/forum/post.php | 8 +------- 4 files changed, 2 insertions(+), 44 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 32e0234bf3d..cc6bd768b78 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2727,11 +2727,6 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ $SESSION->wantsurl = qualified_me(); } - $referer = get_local_referer(false); - if (!empty($referer)) { - $SESSION->fromurl = $referer; - } - // Give auth plugins an opportunity to authenticate or redirect to an external login page $authsequence = get_enabled_auth_plugins(); // Auths, in sequence. foreach($authsequence as $authname) { diff --git a/lib/setuplib.php b/lib/setuplib.php index 2af28136af9..f1ad98d70ae 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -588,12 +588,7 @@ function get_exception_info($ex) { $moreinfourl = $errordoclink . 'error/' . $modulelink . '/' . $errorcode; if (empty($link)) { - if (!empty($SESSION->fromurl)) { - $link = $SESSION->fromurl; - unset($SESSION->fromurl); - } else { - $link = $CFG->wwwroot .'/'; - } + $link = get_local_referer(false) ?: ($CFG->wwwroot . '/'); } // When printing an error the continue button should never link offsite. diff --git a/lib/tests/setuplib_test.php b/lib/tests/setuplib_test.php index 9291605e9cd..9d165b99dd7 100644 --- a/lib/tests/setuplib_test.php +++ b/lib/tests/setuplib_test.php @@ -412,32 +412,6 @@ class core_setuplib_testcase extends advanced_testcase { $exception = new moodle_exception('none', 'error', $url); $infos = $this->get_exception_info($exception); $this->assertSame($CFG->wwwroot . '/', $infos->link); - - // Internal link from fromurl. - $SESSION->fromurl = $url = $CFG->wwwroot . '/something/here?really=yes'; - $exception = new moodle_exception('none'); - $infos = $this->get_exception_info($exception); - $this->assertSame($url, $infos->link); - - // Internal HTTPS link from fromurl. - $SESSION->fromurl = $url = $httpswwwroot . '/something/here?really=yes'; - $exception = new moodle_exception('none'); - $infos = $this->get_exception_info($exception); - $this->assertSame($url, $infos->link); - - // External link from fromurl. - $SESSION->fromurl = 'http://moodle.org/something/here?really=yes'; - $exception = new moodle_exception('none'); - $infos = $this->get_exception_info($exception); - $this->assertSame($CFG->wwwroot . '/', $infos->link); - - // External HTTPS link from fromurl. - $SESSION->fromurl = 'https://moodle.org/something/here?really=yes'; - $exception = new moodle_exception('none'); - $infos = $this->get_exception_info($exception); - $this->assertSame($CFG->wwwroot . '/', $infos->link); - - $SESSION->fromurl = ''; } /** diff --git a/mod/forum/post.php b/mod/forum/post.php index 7d9e3abc288..ae162ebfa75 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -160,8 +160,6 @@ if (!empty($forum)) { ); } - $SESSION->fromurl = get_local_referer(false); - // Load up the $post variable. $post = new stdClass(); @@ -780,11 +778,7 @@ if ($mformpost->is_cancelled()) { } } else if ($mformpost->is_submitted() && !$mformpost->no_submit_button_pressed() && $fromform = $mformpost->get_data()) { - if (empty($SESSION->fromurl)) { - $errordestination = $urlfactory->get_forum_view_url_from_forum($forumentity); - } else { - $errordestination = $SESSION->fromurl; - } + $errordestination = get_local_referer(false) ?: $urlfactory->get_forum_view_url_from_forum($forumentity); $fromform->itemid = $fromform->message['itemid']; $fromform->messageformat = $fromform->message['format'];