diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index cd0eb8117fe..70821059329 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -8473,30 +8473,6 @@ function moodle_request_shutdown() {
}
}
-/**
- * This function is called when output is started. This is a chance for Moodle core
- * to check things like whether the messages popup should be shown.
- */
-function output_starting_hook() {
- global $CFG, $PAGE;
-
- // If maintenance mode is on, change the page header.
- if (!empty($CFG->maintenance_enabled)) {
- $PAGE->set_button('' . get_string('maintenancemode', 'admin') .
- ' ' . $PAGE->button);
-
- $title = $PAGE->title;
- if ($title) {
- $title .= ' - ';
- }
- $PAGE->set_title($title . get_string('maintenancemode', 'admin'));
- }
-
- // Show the messaging popup, if there are messages.
- message_popup_window();
-}
-
/**
* If new messages are waiting for the current user, then load the
* JavaScript required to pop up the messaging window.
diff --git a/lib/outputlib.php b/lib/outputlib.php
index 2381dbe70ea..3809989d8cf 100644
--- a/lib/outputlib.php
+++ b/lib/outputlib.php
@@ -1823,7 +1823,6 @@ class moodle_core_renderer extends moodle_renderer_base {
// TODO remove $navigation and $menu arguments - replace with $PAGE->navigation
global $USER, $CFG;
- output_starting_hook();
$this->page->set_state(moodle_page::STATE_PRINTING_HEADER);
// Find the appropriate page template, based on $this->page->generaltype.
diff --git a/lib/pagelib.php b/lib/pagelib.php
index 7c1a822ab39..5beed216063 100644
--- a/lib/pagelib.php
+++ b/lib/pagelib.php
@@ -853,7 +853,7 @@ class moodle_page {
* state. This is our last change to initialise things.
*/
protected function starting_output() {
- global $SITE, $CFG;
+ global $CFG;
$this->initialise_standard_body_classes();
@@ -861,6 +861,22 @@ class moodle_page {
$this->blocks->load_blocks();
}
+ // If maintenance mode is on, change the page header.
+ if (!empty($CFG->maintenance_enabled)) {
+ $this->set_button('' . get_string('maintenancemode', 'admin') .
+ ' ' . $this->button);
+
+ $title = $this->title;
+ if ($title) {
+ $title .= ' - ';
+ }
+ $this->set_title($title . get_string('maintenancemode', 'admin'));
+ }
+
+ // Show the messaging popup, if there are messages.
+ message_popup_window();
+
// Add any stylesheets required using the horrible legacy mechanism.
if (!empty($CFG->stylesheets)) {
debugging('Some code on this page is using the horrible legacy mechanism $CFG->stylesheets to include links to ' .