MDL-29866 page setup improvements

incorrect PAGE init - it should be done at the very end; redirect() should not use OUTPUT before PAGE init; SITEID should be deprecated in favour of $SITE->id (this is going to cause troubles in tenant switching in CLI, cron and tests); missing "global $SITE"'; minor coding style issues; PHPDocs; it also helps with merging/testing of multitenant patch
This commit is contained in:
Petr Skoda
2011-10-21 16:35:19 +02:00
parent d21149699c
commit f0f8f9a796
3 changed files with 120 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)