Merge branch 'w42_MDL-29866_m22_setupinit' of git://github.com/skodak/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2011-10-25 16:41:11 +02:00
3 changed files with 126 additions and 74 deletions
+38 -39
View File
@@ -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)
+79 -31
View File
@@ -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']) {
@@ -1318,6 +1310,12 @@ class bootstrap_renderer {
return false;
}
/**
* Constructor - to be used by core code only.
* @param $method
* @param $arguments
* @return string
*/
public function __call($method, $arguments) {
global $OUTPUT, $PAGE;
@@ -1357,6 +1355,12 @@ class bootstrap_renderer {
/**
* Returns nicely formatted error message in a div box.
* @static
* @param string $message error message
* @param string $moreinfourl (ignored in early errors)
* @param string $link (ignored in early errors)
* @param array $backtrace
* @param string $debuginfo
* @return string
*/
public static function early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo = null) {
@@ -1383,6 +1387,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 (ignored in early errors)
* @param string $link (ignored in early errors)
* @param array $backtrace
* @param string $debuginfo extra information for developers
* @return string
*/
public static function early_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null) {
@@ -1445,17 +1455,54 @@ width: 80%; -moz-border-radius: 20px; padding: 15px">
return self::plain_page($strerror, $content);
}
/**
* Early notification message
* @static
* @param $message
* @param string $classes usually notifyproblem or notifysuccess
* @return string
*/
public static function early_notification($message, $classes = 'notifyproblem') {
return '<div class="' . $classes . '">' . $message . '</div>';
}
/**
* Page should redirect message.
* @static
* @param $encodedurl redirect url
* @return string
*/
public static function plain_redirect_message($encodedurl) {
$message = '<p>' . get_string('pageshouldredirect') . '</p><p><a href="'.
$encodedurl .'">'. get_string('continue') .'</a></p>';
$message = '<div style="margin-top: 3em; margin-left:auto; margin-right:auto; text-align:center;">' . get_string('pageshouldredirect') . '<br /><a href="'.
$encodedurl .'">'. get_string('continue') .'</a></div>';
return self::plain_page(get_string('redirect'), $message);
}
protected static function plain_page($title, $content) {
/**
* Early redirection page, used before full init of $PAGE global
* @static
* @param $encodedurl redirect url
* @param $message redirect message
* @param $delay time in seconds
* @return string redirect page
*/
public static function early_redirect_message($encodedurl, $message, $delay) {
$meta = '<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />';
$content = self::early_error_content($message, null, null, null);
$content .= self::plain_redirect_message($encodedurl);
return self::plain_page(get_string('redirect'), $content, $meta);
}
/**
* Output basic html page.
* @static
* @param $title page title
* @param $content page content
* @param string $meta meta tag
* @return string html page
*/
protected static function plain_page($title, $content, $meta = '') {
if (function_exists('get_string') && function_exists('get_html_lang')) {
$htmllang = get_html_lang();
} else {
@@ -1466,6 +1513,7 @@ width: 80%; -moz-border-radius: 20px; padding: 15px">
<html xmlns="http://www.w3.org/1999/xhtml" ' . $htmllang . '>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
'.$meta.'
<title>' . $title . '</title>
</head><body>' . $content . '</body></html>';
}
+9 -4
View File
@@ -2257,6 +2257,7 @@ function redirect($url, $message='', $delay=-1) {
// prevent debug errors - make sure context is properly initialised
if ($PAGE) {
$PAGE->set_context(null);
$PAGE->set_pagelayout('redirect'); // No header and footer needed
}
if ($url instanceof moodle_url) {
@@ -2354,10 +2355,14 @@ function redirect($url, $message='', $delay=-1) {
}
// Include a redirect message, even with a HTTP redirect, because that is recommended practice.
$PAGE->set_pagelayout('redirect'); // No header and footer needed
$CFG->docroot = false; // to prevent the link to moodle docs from being displayed on redirect page.
echo $OUTPUT->redirect_message($encodedurl, $message, $delay, $debugdisableredirect);
exit;
if ($PAGE) {
$CFG->docroot = false; // to prevent the link to moodle docs from being displayed on redirect page.
echo $OUTPUT->redirect_message($encodedurl, $message, $delay, $debugdisableredirect);
exit;
} else {
echo bootstrap_renderer::early_redirect_message($encodedurl, $message, $delay);
exit;
}
}
/**