diff --git a/lib/setup.php b/lib/setup.php index 5e7587b0948..b829bcee74d 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -295,6 +295,11 @@ global $SESSION; */ global $USER; +/** + * Frontpage course record + */ +global $SITE; + /** * A central store of information about the current page we are * generating in response to the user's request. @@ -497,36 +502,6 @@ if (function_exists('register_shutdown_function')) { register_shutdown_function('moodle_request_shutdown'); } -// Defining the site -try { - $SITE = get_site(); - /** - * If $SITE global from {@link get_site()} is set then SITEID to $SITE->id, otherwise set to 1. - */ - define('SITEID', $SITE->id); - // And the 'default' course - this will usually get reset later in require_login() etc. - $COURSE = clone($SITE); -} catch (dml_exception $e) { - $SITE = null; - if (empty($CFG->version)) { - // we are just installing - /** - * @ignore - */ - define('SITEID', 1); - // And the 'default' course - $COURSE = new stdClass(); // no site created yet - $COURSE->id = 1; - } else { - throw $e; - } -} - -// define SYSCONTEXTID in config.php if you want to save some queries (after install or upgrade!) -if (!defined('SYSCONTEXTID')) { - get_system_context(); -} - // Set error reporting back to normal if ($originaldatabasedebug == -1) { $CFG->debug = DEBUG_MINIMAL; @@ -624,15 +599,6 @@ ini_set('pcre.backtrack_limit', 20971520); // 20 MB $CFG->wordlist = $CFG->libdir .'/wordlist.txt'; $CFG->moddata = 'moddata'; -// Create the $PAGE global. -if (!empty($CFG->moodlepageclass)) { - $classname = $CFG->moodlepageclass; -} else { - $classname = 'moodle_page'; -} -$PAGE = new $classname(); -unset($classname); - // A hack to get around magic_quotes_gpc being turned on // It is strongly recommended to disable "magic_quotes_gpc"! if (ini_get_bool('magic_quotes_gpc')) { @@ -678,6 +644,29 @@ if (isset($_SERVER['PHP_SELF'])) { // initialise ME's - this must be done BEFORE starting of session! initialise_fullme(); +// define SYSCONTEXTID in config.php if you want to save some queries, +// after install it must match the system context record id. +if (!defined('SYSCONTEXTID')) { + get_system_context(); +} + +// Defining the site - aka frontpage course +try { + $SITE = get_site(); +} catch (dml_exception $e) { + $SITE = null; + if (empty($CFG->version)) { + $SITE = new stdClass(); + $SITE->id = 1; + } else { + throw $e; + } +} +// And the 'default' course - this will usually get reset later in require_login() etc. +$COURSE = clone($SITE); +/** @deprecated Id of the frontpage course, use $SITE->id instead */ +define('SITEID', $SITE->id); + // init session prevention flag - this is defined on pages that do not want session if (CLI_SCRIPT) { // no sessions in CLI scripts possible @@ -760,6 +749,16 @@ if (empty($CFG->lang)) { // it is definitely too late to call this first in require_login()! moodle_setlocale(); +// Create the $PAGE global - this marks the PAGE and OUTPUT fully initialised, this MUST be done at the end of setup! +if (!empty($CFG->moodlepageclass)) { + $classname = $CFG->moodlepageclass; +} else { + $classname = 'moodle_page'; +} +$PAGE = new $classname(); +unset($classname); + + if (!empty($CFG->debugvalidators) and !empty($CFG->guestloginbutton)) { if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation if (isset($_SERVER['HTTP_USER_AGENT']) and empty($USER->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest) diff --git a/lib/setuplib.php b/lib/setuplib.php index f06f6b54744..f4c46c852c0 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -661,7 +661,7 @@ function initialise_cfg() { * setup.php. */ function initialise_fullme() { - global $CFG, $FULLME, $ME, $SCRIPT, $FULLSCRIPT, $USER; + global $CFG, $FULLME, $ME, $SCRIPT, $FULLSCRIPT; // Detect common config error. if (substr($CFG->wwwroot, -1) == '/') { @@ -673,13 +673,26 @@ function initialise_fullme() { return; } - $wwwroot = parse_url($CFG->wwwroot); - if (!isset($wwwroot['path'])) { - $wwwroot['path'] = ''; - } - $wwwroot['path'] .= '/'; - $rurl = setup_get_remote_url(); + $wwwroot = parse_url($CFG->wwwroot.'/'); + + if (empty($rurl['host'])) { + // missing host in request header, probably not a real browser, let's ignore them + + } else if (!empty($CFG->reverseproxy)) { + // $CFG->reverseproxy specifies if reverse proxy server used + // Used in load balancing scenarios. + // Do not abuse this to try to solve lan/wan access problems!!!!! + + } else { + if (($rurl['host'] !== $wwwroot['host']) or (!empty($wwwroot['port']) and $rurl['port'] != $wwwroot['port'])) { + // Explain the problem and redirect them to the right URL + if (!defined('NO_MOODLE_COOKIES')) { + define('NO_MOODLE_COOKIES', true); + } + redirect($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3); + } + } // Check that URL is under $CFG->wwwroot. if (strpos($rurl['path'], $wwwroot['path']) === 0) { @@ -703,27 +716,6 @@ function initialise_fullme() { $rurl['scheme'] = 'https'; // make moodle believe it runs on https, squid or something else it doing it } - // $CFG->reverseproxy specifies if reverse proxy server used. - // Used in load balancing scenarios. - // Do not abuse this to try to solve lan/wan access problems!!!!! - if (empty($CFG->reverseproxy)) { - if (empty($rurl['host'])) { - // missing host in request header, probably not a real browser, let's ignore them - } else if (($rurl['host'] !== $wwwroot['host']) or - (!empty($wwwroot['port']) and $rurl['port'] != $wwwroot['port'])) { - // Explain the problem and redirect them to the right URL - if (!defined('NO_MOODLE_COOKIES')) { - define('NO_MOODLE_COOKIES', true); - } - if (!isset($USER->id)) { - // MDL-27899 workaround - $USER = new stdClass(); - $USER->id = 0; - } - redirect($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3); - } - } - // hopefully this will stop all those "clever" admins trying to set up moodle // with two different addresses in intranet and Internet if (!empty($CFG->reverseproxy) && $rurl['host'] === $wwwroot['host']) { @@ -1366,6 +1358,12 @@ class bootstrap_renderer { /** * Returns nicely formatted error message in a div box. + * @static + * @param string $message error message + * @param string $moreinfourl ignored + * @param string $link ignored + * @param array $backtrace + * @param string $debuginfo * @return string */ public static function early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo = null) { @@ -1392,6 +1390,12 @@ width: 80%; -moz-border-radius: 20px; padding: 15px"> /** * This function should only be called by this class, or from exception handlers + * @static + * @param string $message error message + * @param string $moreinfourl + * @param string $link + * @param array $backtrace + * @param string $debuginfo * @return string */ public static function early_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null) { @@ -1454,17 +1458,54 @@ width: 80%; -moz-border-radius: 20px; padding: 15px"> return self::plain_page($strerror, $content); } + /** + * Early notification message + * @static + * @param $message + * @param string $classes + * @return string + */ public static function early_notification($message, $classes = 'notifyproblem') { return '
' . get_string('pageshouldredirect') . '
'; + $message = '