Skip to content

Commit

Permalink
Merge branch 'w18_MDL-30686_m23_guessurl' of git://github.com/skodak/…
Browse files Browse the repository at this point in the history
…moodle
  • Loading branch information
danpoltawski committed May 1, 2012
2 parents 35a1c03 + bd319d1 commit 6b445cb
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 39 deletions.
4 changes: 2 additions & 2 deletions admin/tool/unittest/ex_reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ function paintException($exception) {
* 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 '<b class="', $passorfail, '">', $this->get_string($passorfail), '</b>: ';
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
Expand Down
3 changes: 1 addition & 2 deletions lib/flickrlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,11 @@ function getFriendlyGeodata($lat, $lon) {

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;
Expand Down
19 changes: 9 additions & 10 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2655,7 +2655,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)) {
Expand Down Expand Up @@ -2719,8 +2719,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'];
Expand All @@ -2744,7 +2743,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
Expand All @@ -2769,7 +2768,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 .'&amp;course='. SITEID);
}
Expand All @@ -2791,15 +2790,15 @@ 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()) {
if ($preventredirect) {
throw new require_login_exception('Policy not agreed');
}
if ($setwantsurltome) {
$SESSION->wantsurl = $FULLME;
$SESSION->wantsurl = qualified_me();
}
redirect($CFG->wwwroot .'/user/policy.php');
}
Expand Down Expand Up @@ -2953,7 +2952,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);
}
Expand Down Expand Up @@ -5122,7 +5121,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';
Expand Down Expand Up @@ -5322,7 +5321,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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3622,7 +3622,7 @@ protected function load_module_settings() {
* @return navigation_node|false
*/
protected function load_user_settings($courseid=SITEID) {
global $USER, $FULLME, $CFG;
global $USER, $CFG;

if (isguestuser() || !isloggedin()) {
return false;
Expand Down
1 change: 1 addition & 0 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ public function standard_footer_html() {
$output .= '<div class="purgecaches"><a href="'.$CFG->wwwroot.'/admin/purgecaches.php?confirm=1&amp;sesskey='.sesskey().'">'.get_string('purgecaches', 'admin').'</a></div>';
}
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 .= '<div class="validators"><ul>
<li><a href="http://validator.w3.org/check?verbose=1&amp;ss=1&amp;uri=' . urlencode(qualified_me()) . '">Validate HTML</a></li>
<li><a href="http://www.contentquality.com/mynewtester/cynthia.exe?rptmode=-1&amp;url1=' . urlencode(qualified_me()) . '">Section 508 Check</a></li>
Expand Down
4 changes: 2 additions & 2 deletions lib/setuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ function __construct($debuginfo = NULL) {
* @return void -does not return. Terminates execution!
*/
function default_exception_handler($ex) {
global $CFG, $DB, $OUTPUT, $USER, $FULLME, $SESSION;
global $CFG, $DB, $OUTPUT, $USER, $FULLME, $SESSION, $PAGE;

// detect active db transactions, rollback and log as error
abort_all_db_transactions();

if (($ex instanceof required_capability_exception) && !CLI_SCRIPT && !AJAX_SCRIPT && !empty($CFG->autologinguests) && !empty($USER->autologinguest)) {
$SESSION->wantsurl = $FULLME;
$SESSION->wantsurl = qualified_me();
redirect(get_login_url());
}

Expand Down
15 changes: 14 additions & 1 deletion lib/tests/weblib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
defined('MOODLE_INTERNAL') || die();


class web_testcase extends basic_testcase {
class web_testcase extends advanced_testcase {

function test_format_string() {
global $CFG;
Expand Down Expand Up @@ -184,4 +184,17 @@ public function test_clean_text() {
$this->assertEquals('lala xx', clean_text($text, FORMAT_MOODLE));
$this->assertEquals('lala xx', clean_text($text, FORMAT_HTML));
}

public function test_qualified_me() {
global $PAGE, $FULLME, $CFG;
$this->resetAfterTest();

$PAGE = new moodle_page();

$FULLME = $CFG->wwwroot.'/course/view.php?id=1&xx=yy';
$this->assertEquals($FULLME, qualified_me());

$PAGE->set_url('/course/view.php', array('id'=>1));
$this->assertEquals($CFG->wwwroot.'/course/view.php?id=1', qualified_me());
}
}
35 changes: 22 additions & 13 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ function get_referer($stripquery=true) {
* server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.)
* <b>NOTE:</b> This function returns false if the global variables needed are not set.
*
* @global string
* @return mixed String, or false if the global variables needed are not set
*/
function me() {
Expand All @@ -196,22 +195,32 @@ function me() {
}

/**
* Returns the name of the current script, WITH the full URL.
*
* This function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME
* return different things depending on a lot of things like your OS, Web
* server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.
* <b>NOTE:</b> This function returns false if the global variables needed are not set.
* Guesses the full URL of the current script.
*
* Like {@link me()} but returns a full URL
* @see me()
* This function is using $PAGE->url, but may fall back to $FULLME which
* is constructed from PHP_SELF and REQUEST_URI or SCRIPT_NAME
*
* @global string
* @return mixed String, or false if the global variables needed are not set
* @return mixed full page URL string or false if unknown
*/
function qualified_me() {
global $FULLME;
return $FULLME;
global $FULLME, $PAGE, $CFG;

if (isset($PAGE) and $PAGE->has_set_url()) {
// this is the only recommended way to find out current page
return $PAGE->url->out(false);

} else {
if ($FULLME === null) {
// CLI script most probably
return false;
}
if (!empty($CFG->sslproxy)) {
// return only https links when using SSL proxy
return preg_replace('/^http:/', 'https:', $FULLME, 1);
} else {
return $FULLME;
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion mod/choice/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
get_login_url(), new moodle_url('/course/view.php', array('id'=>$course->id)));
} else if (!is_enrolled($context)) {
// Only people enrolled can make a choice
$SESSION->wantsurl = $FULLME;
$SESSION->wantsurl = qualified_me();
$SESSION->enrolcancel = (!empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : '';

$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
Expand Down
4 changes: 2 additions & 2 deletions mod/forum/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
if (!isguestuser()) {
if (!is_enrolled($coursecontext)) {
if (enrol_selfenrol_available($course->id)) {
$SESSION->wantsurl = $FULLME;
$SESSION->wantsurl = qualified_me();
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id, get_string('youneedtoenrol'));
}
Expand Down Expand Up @@ -181,7 +181,7 @@
if (! forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) {
if (!isguestuser()) {
if (!is_enrolled($coursecontext)) { // User is a guest here!
$SESSION->wantsurl = $FULLME;
$SESSION->wantsurl = qualified_me();
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id, get_string('youneedtoenrol'));
}
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}

$PAGE->set_pagelayout('standard');
$PAGE->set_url($FULLME);
$PAGE->set_url($FULLME); //TODO: this is very sloppy --skodak

if (empty($search)) { // Check the other parameters instead
if (!empty($words)) {
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
}

$SESSION->fromdiscussion = $FULLME; // Return here if we post or set subscription etc
$SESSION->fromdiscussion = qualified_me(); // Return here if we post or set subscription etc


/// Print settings and things across the top
Expand Down
1 change: 1 addition & 0 deletions mod/quiz/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ function quiz_grade_item_update($quiz, $grades = null) {
if (!empty($gradebook_grades->items)) {
$grade_item = $gradebook_grades->items[0];
if ($grade_item->locked) {
// NOTE: this is an extremely nasty hack! It is not a bug if this confirmation fails badly. --skodak
$confirm_regrade = optional_param('confirm_regrade', 0, PARAM_INT);
if (!$confirm_regrade) {
$message = get_string('gradeitemislocked', 'grades');
Expand Down
2 changes: 1 addition & 1 deletion report/participation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
echo '<form action="'.$CFG->wwwroot.'/user/action_redir.php" method="post" id="studentsform">'."\n";
echo '<div>'."\n";
echo '<input type="hidden" name="id" value="'.$id.'" />'."\n";
echo '<input type="hidden" name="returnto" value="'. s($FULLME) .'" />'."\n";
echo '<input type="hidden" name="returnto" value="'. s($PAGE->url) .'" />'."\n";
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'."\n";

foreach ($users as $u) {
Expand Down
2 changes: 1 addition & 1 deletion repository/filepicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@

case 'confirm':
echo $OUTPUT->header();
echo '<div><a href="'.me().'">'.get_string('back', 'repository').'</a></div>';
echo '<div><a href="'.s($PAGE->url(false)).'">'.get_string('back', 'repository').'</a></div>';
echo '<img src="'.$thumbnail.'" />';
echo '<form method="post">';
echo '<table>';
Expand Down
2 changes: 1 addition & 1 deletion user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
echo '<form action="action_redir.php" method="post" id="participantsform">';
echo '<div>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="returnto" value="'.s(me()).'" />';
echo '<input type="hidden" name="returnto" value="'.s($PAGE->url->out(false)).'" />';
}

if ($mode === MODE_USERDETAILS) { // Print simple listing
Expand Down

0 comments on commit 6b445cb

Please sign in to comment.