Merge branch 'w18_MDL-30686_m23_guessurl' of git://github.com/skodak/moodle

This commit is contained in:
Dan Poltawski
2012-05-01 11:27:16 +08:00
16 changed files with 61 additions and 39 deletions
+2 -2
View File
@@ -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 '<b class="', $passorfail, '">', $this->get_string($passorfail), '</b>: ';
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
+1 -2
View File
@@ -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;
+9 -10
View File
@@ -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)) {
@@ -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'];
@@ -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
@@ -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);
}
@@ -2791,7 +2790,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()) {
@@ -2799,7 +2798,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');
}
@@ -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);
}
@@ -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';
@@ -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);
}
+1 -1
View File
@@ -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;
+1
View File
@@ -471,6 +471,7 @@ class core_renderer extends renderer_base {
$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>
+2 -2
View File
@@ -338,13 +338,13 @@ class file_serving_exception extends moodle_exception {
* @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());
}
+14 -1
View File
@@ -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;
@@ -184,4 +184,17 @@ class web_testcase extends basic_testcase {
$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());
}
}
+22 -13
View File
@@ -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() {
@@ -196,22 +195,32 @@ function me() {
}
/**
* Returns the name of the current script, WITH the full URL.
* Guesses the full URL of the current script.
*
* 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.
* This function is using $PAGE->url, but may fall back to $FULLME which
* is constructed from PHP_SELF and REQUEST_URI or SCRIPT_NAME
*
* Like {@link me()} but returns a full URL
* @see me()
*
* @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;
}
}
}
/**
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -113,7 +113,7 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
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'));
}
@@ -181,7 +181,7 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
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'));
}
+1 -1
View File
@@ -64,7 +64,7 @@ if ($timetorestrict) {
}
$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)) {
+1 -1
View File
@@ -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
+1
View File
@@ -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');
+1 -1
View File
@@ -283,7 +283,7 @@ if (!empty($instanceid) && !empty($roleid)) {
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) {
+1 -1
View File
@@ -316,7 +316,7 @@ case 'download':
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>';
+1 -1
View File
@@ -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