From f0202ae9a26a1838ce4df621751bdad06efa831f Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 22 Apr 2012 17:17:27 +0200 Subject: [PATCH 1/2] MDL-30686 improve accuracy of qualified_me() by trying PAGE->url first This should help SSL proxies and returning to current page after require_login(). --- admin/tool/unittest/ex_reporter.php | 4 ++-- lib/flickrlib.php | 3 +-- lib/moodlelib.php | 19 ++++++++-------- lib/navigationlib.php | 2 +- lib/outputrenderers.php | 1 + lib/setuplib.php | 4 ++-- lib/tests/weblib_test.php | 15 ++++++++++++- lib/weblib.php | 35 ++++++++++++++++++----------- mod/choice/view.php | 2 +- mod/forum/post.php | 4 ++-- mod/forum/search.php | 2 +- mod/forum/view.php | 2 +- mod/quiz/lib.php | 1 + report/participation/index.php | 2 +- repository/filepicker.php | 2 +- user/index.php | 2 +- 16 files changed, 61 insertions(+), 39 deletions(-) diff --git a/admin/tool/unittest/ex_reporter.php b/admin/tool/unittest/ex_reporter.php index b7b296cc77a..01476d29329 100644 --- a/admin/tool/unittest/ex_reporter.php +++ b/admin/tool/unittest/ex_reporter.php @@ -147,11 +147,11 @@ class ExHtmlReporter extends HtmlReporter { * Private method. Used by printPass/Fail/Skip/Error. */ function _paintPassFail($passorfail, $message, $stacktrace = null, $debuginfo = null) { - global $FULLME, $CFG, $OUTPUT; + global $CFG, $OUTPUT; echo $OUTPUT->box_start($passorfail . ' generalbox '); - $url = $this->_htmlEntities($this->_stripParameterFromUrl($FULLME, 'path')); + $url = $this->_htmlEntities($this->_stripParameterFromUrl(qualified_me(), 'path')); echo '', $this->get_string($passorfail), ': '; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); diff --git a/lib/flickrlib.php b/lib/flickrlib.php index 534cf35dadc..79b83ebdf32 100644 --- a/lib/flickrlib.php +++ b/lib/flickrlib.php @@ -240,12 +240,11 @@ class phpFlickr { function auth ($perms = "write", $remember_uri = true) { - global $FULLME; // Redirects to Flickr's authentication piece if there is no valid token. // If remember_uri is set to false, the callback script (included) will // redirect to its default page. if ($remember_uri) { - $redirect = $FULLME; + $redirect = qualified_me(); // TODO: this is not used, why? } $api_sig = md5($this->secret . "api_key" . $this->api_key . "perms" . $perms); $url = 'http://www.flickr.com/services/auth/?api_key=' . $this->api_key . "&perms=" . $perms . '&api_sig='. $api_sig; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 90c1677f1ce..bb890e3f516 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2646,7 +2646,7 @@ function get_login_url() { * @return mixed Void, exit, and die depending on path */ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $setwantsurltome = true, $preventredirect = false) { - global $CFG, $SESSION, $USER, $FULLME, $PAGE, $SITE, $DB, $OUTPUT; + global $CFG, $SESSION, $USER, $PAGE, $SITE, $DB, $OUTPUT; // setup global $COURSE, themes, language and locale if (!empty($courseorid)) { @@ -2710,8 +2710,7 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $ } if ($setwantsurltome) { - // TODO: switch to PAGE->url - $SESSION->wantsurl = $FULLME; + $SESSION->wantsurl = qualified_me(); } if (!empty($_SERVER['HTTP_REFERER'])) { $SESSION->fromurl = $_SERVER['HTTP_REFERER']; @@ -2735,7 +2734,7 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $ $userauth = get_auth_plugin($USER->auth); if ($userauth->can_change_password() and !$preventredirect) { if ($setwantsurltome) { - $SESSION->wantsurl = $FULLME; + $SESSION->wantsurl = qualified_me(); } if ($changeurl = $userauth->change_password_url()) { //use plugin custom url @@ -2760,7 +2759,7 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $ throw new require_login_exception('User not fully set-up'); } if ($setwantsurltome) { - $SESSION->wantsurl = $FULLME; + $SESSION->wantsurl = qualified_me(); } redirect($CFG->wwwroot .'/user/edit.php?id='. $USER->id .'&course='. SITEID); } @@ -2782,7 +2781,7 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $ throw new require_login_exception('Policy not agreed'); } if ($setwantsurltome) { - $SESSION->wantsurl = $FULLME; + $SESSION->wantsurl = qualified_me(); } redirect($CFG->wwwroot .'/user/policy.php'); } else if (!empty($CFG->sitepolicyguest) and isguestuser()) { @@ -2790,7 +2789,7 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $ throw new require_login_exception('Policy not agreed'); } if ($setwantsurltome) { - $SESSION->wantsurl = $FULLME; + $SESSION->wantsurl = qualified_me(); } redirect($CFG->wwwroot .'/user/policy.php'); } @@ -2944,7 +2943,7 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $ throw new require_login_exception('Not enrolled'); } if ($setwantsurltome) { - $SESSION->wantsurl = $FULLME; + $SESSION->wantsurl = qualified_me(); } redirect($CFG->wwwroot .'/enrol/index.php?id='. $course->id); } @@ -5113,7 +5112,7 @@ function get_mailer($action='get') { */ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $attachment='', $attachname='', $usetrueaddress=true, $replyto='', $replytoname='', $wordwrapwidth=79) { - global $CFG, $FULLME; + global $CFG; if (empty($user) || empty($user->email)) { $nulluser = 'User is null or has no email'; @@ -5313,7 +5312,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a } return true; } else { - add_to_log(SITEID, 'library', 'mailer', $FULLME, 'ERROR: '. $mail->ErrorInfo); + add_to_log(SITEID, 'library', 'mailer', qualified_me(), 'ERROR: '. $mail->ErrorInfo); if (CLI_SCRIPT) { mtrace('Error: lib/moodlelib.php email_to_user(): '.$mail->ErrorInfo); } diff --git a/lib/navigationlib.php b/lib/navigationlib.php index a2974c953aa..51b6efa16ed 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -3622,7 +3622,7 @@ class settings_navigation extends navigation_node { * @return navigation_node|false */ protected function load_user_settings($courseid=SITEID) { - global $USER, $FULLME, $CFG; + global $USER, $CFG; if (isguestuser() || !isloggedin()) { return false; diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index f50ef94644b..bbcc8771745 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -471,6 +471,7 @@ class core_renderer extends renderer_base { $output .= '
'.get_string('purgecaches', 'admin').'
'; } if (!empty($CFG->debugvalidators)) { + // NOTE: this is not a nice hack, $PAGE->url is not always accurate and $FULLME neither, it is not a bug if it fails. --skodak $output .= '