From cc359566fe264e2aa86c53ea31184f6cb8f5d0b7 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 19 Oct 2011 13:24:11 +0100 Subject: [PATCH] MDL-29474 admin index/plugins/environment pages: all ouptut code -> renderer. --- admin/cli/upgrade.php | 3 +- admin/environment.php | 75 ++---- admin/index.php | 198 ++++----------- admin/plugins.php | 8 +- admin/renderer.php | 532 ++++++++++++++++++++++++++++++++++++++++- lib/environmentlib.php | 197 +-------------- lib/installlib.php | 3 +- 7 files changed, 607 insertions(+), 409 deletions(-) diff --git a/admin/cli/upgrade.php b/admin/cli/upgrade.php index c3e630b176b..6f49cc1a1a9 100644 --- a/admin/cli/upgrade.php +++ b/admin/cli/upgrade.php @@ -94,7 +94,8 @@ $oldversion = "$CFG->release ($CFG->version)"; $newversion = "$release ($version)"; // test environment first -if (!check_moodle_environment(normalize_version($release), $environment_results, false, ENV_SELECT_RELEASE)) { +list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); +if (!$envstatus) { $errors = environment_get_errors($environment_results); cli_heading(get_string('environment', 'admin')); foreach ($errors as $error) { diff --git a/admin/environment.php b/admin/environment.php index bb83bbb796e..1fc732ea064 100644 --- a/admin/environment.php +++ b/admin/environment.php @@ -32,30 +32,15 @@ require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/environmentlib.php'); require_once($CFG->libdir.'/componentlib.class.php'); -admin_externalpage_setup('environment'); - // Parameters $action = optional_param('action', '', PARAM_ACTION); $version = optional_param('version', '', PARAM_FILE); // - -// Get some strings -$stradmin = get_string('administration'); -$stradminhelpenvironment = get_string("adminhelpenvironment"); -$strenvironment = get_string('environment', 'admin'); -$strerror = get_string('error'); -$strmoodleversion = get_string('moodleversion'); -$strupdate = get_string('updatecomponent', 'admin'); -$strupwards = get_string('upwards', 'admin'); -$strmisc = get_string('miscellaneous'); - -// Print the header stuff -echo $OUTPUT->header(); - -// Print the component download link -echo ''; - -echo $OUTPUT->heading($strenvironment); +$extraurlparams = array(); +if ($version) { + $extraurlparams['version'] = $version; +} +admin_externalpage_setup('environment', '', $extraurlparams); // Handle the 'updatecomponent' action if ($action == 'updatecomponent' && confirm_sesskey()) { @@ -68,28 +53,27 @@ if ($action == 'updatecomponent' && confirm_sesskey()) { case COMPONENT_ERROR: if ($cd->get_error() == 'remotedownloaderror') { $a = new stdClass(); - $a->url = 'http://download.moodle.org/environment/environment.zip'; - $a->dest= $CFG->dataroot.'/'; - echo $OUTPUT->box(get_string($cd->get_error(), 'error', $a), 'errorbox'); + $a->url = 'http://download.moodle.org/environment/environment.zip'; + $a->dest = $CFG->dataroot . '/'; + print_error($cd->get_error(), 'error', $PAGE->url, $a); + die(); + } else { - echo $OUTPUT->box(get_string($cd->get_error(), 'error'), 'errorbox'); + print_error($cd->get_error(), 'error', $PAGE->url); + die(); } - break; + case COMPONENT_UPTODATE: - echo $OUTPUT->box(get_string($cd->get_error(), 'error')); - break; + redirect($PAGE->url, get_string($cd->get_error(), 'error')); + die; + case COMPONENT_INSTALLED: - echo $OUTPUT->box(get_string('componentinstalled', 'admin')); - break; + redirect($PAGE->url, get_string('componentinstalled', 'admin')); + die; } } } -// Start of main box -echo $OUTPUT->box_start(); - -echo "
".$stradminhelpenvironment."

"; - // Get current Moodle version $current_version = $CFG->release; @@ -111,24 +95,15 @@ if ($contents = load_environment_xml()) { } } // Add 'upwards' to the last element - $versions[$env_version] = $env_version.' '.$strupwards; + $versions[$env_version] = $env_version.' '.get_string('upwards', 'admin'); } else { - $versions = array('error' => $strerror); + $versions = array('error' => get_string('error')); } } -// Print form and popup menu -echo '
'; -$select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null); -$select->label = $strmoodleversion; -echo $OUTPUT->render($select); -echo '
'; +// Get the results of the environment check. +list($envstatus, $environment_results) = check_moodle_environment($version); -// End of main box -echo $OUTPUT->box_end(); - -// Gather and show results -$status = check_moodle_environment($version, $environment_results); - -// Print footer -echo $OUTPUT->footer(); +// Display the page. +$output = $PAGE->get_renderer('core', 'admin'); +echo $output->environment_check_page($versions, $version, $envstatus, $environment_results); diff --git a/admin/index.php b/admin/index.php index 1a4d727e9d9..631f7890162 100644 --- a/admin/index.php +++ b/admin/index.php @@ -103,6 +103,11 @@ if (!$version or !$release) { print_error('withoutversion', 'debug'); // without version, stop } +if (!isset($maturity)) { + // Fallback for now. Should probably be removed in the future. + $maturity = MATURITY_STABLE; +} + // Turn off xmlstrictheaders during upgrade. $origxmlstrictheaders = !empty($CFG->xmlstrictheaders); $CFG->xmlstrictheaders = false; @@ -121,66 +126,39 @@ if (!core_tables_exist()) { if (empty($agreelicense)) { $strlicense = get_string('license'); + $PAGE->navbar->add($strlicense); $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); $PAGE->set_heading($strinstallation); $PAGE->set_cacheable(false); + $output = $PAGE->get_renderer('core', 'admin'); - echo $output->header(); - echo $output->heading('Moodle - Modular Object-Oriented Dynamic Learning Environment'); - echo $output->heading(get_string('copyrightnotice')); - $copyrightnotice = text_to_html(get_string('gpl3')); - $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack - echo $output->box($copyrightnotice, 'copyrightnotice'); - echo '
'; - $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get'); - echo $output->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License"); - echo $output->footer(); + echo $output->install_licence_page(); die; } if (empty($confirmrelease)) { + require_once($CFG->libdir.'/environmentlib.php'); + list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); $strcurrentrelease = get_string('currentrelease'); + $PAGE->navbar->add($strcurrentrelease); $PAGE->set_title($strinstallation); $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); $PAGE->set_cacheable(false); + $output = $PAGE->get_renderer('core', 'admin'); - echo $output->header(); - echo $output->heading("Moodle $release"); - - if (isset($maturity)) { - // main version.php declares moodle code maturity - if ($maturity < MATURITY_STABLE) { - $maturitylevel = get_string('maturity'.$maturity, 'admin'); - echo $output->box( - $output->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) . - $output->container($output->doc_link('admin/versions', get_string('morehelp'))), - 'generalbox maturitywarning'); - } - } - - $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases'); - $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack - echo $output->box($releasenoteslink, 'generalbox releasenoteslink'); - - require_once($CFG->libdir.'/environmentlib.php'); - if (!check_moodle_environment(normalize_version($release), $environment_results, true, ENV_SELECT_RELEASE)) { - echo $output->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang))); - } else { - echo $output->notification(get_string('environmentok', 'admin'), 'notifysuccess'); - echo $output->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang))); - } - - echo $output->footer(); + echo $output->install_environment_page($maturity, $envstatus, $environment_results); die; } $strdatabasesetup = get_string('databasesetup'); upgrade_init_javascript(); + $PAGE->navbar->add($strdatabasesetup); $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); $PAGE->set_heading($strinstallation); $PAGE->set_cacheable(false); + $output = $PAGE->get_renderer('core', 'admin'); echo $output->header(); @@ -210,79 +188,45 @@ if ($version > $CFG->version) { // upgrade $PAGE->set_pagelayout('maintenance'); $PAGE->set_popup_notification_allowed(false); - $a->oldversion = "$CFG->release ($CFG->version)"; - $a->newversion = "$release ($version)"; - $strdatabasechecking = get_string('databasechecking', '', $a); - if (empty($confirmupgrade)) { + $a->oldversion = "$CFG->release ($CFG->version)"; + $a->newversion = "$release ($version)"; + $strdatabasechecking = get_string('databasechecking', '', $a); + $PAGE->set_title($stradministration); $PAGE->set_heading($strdatabasechecking); $PAGE->set_cacheable(false); + $output = $PAGE->get_renderer('core', 'admin'); - echo $output->header(); - if (isset($maturity)) { - // main version.php declares moodle code maturity - if ($maturity < MATURITY_STABLE) { - $maturitylevel = get_string('maturity'.$maturity, 'admin'); - echo $output->box( - $output->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) . - $output->container($output->doc_link('admin/versions', get_string('morehelp'))), - 'generalbox maturitywarning'); -} - } - $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1)); - $cancelurl = new moodle_url('index.php'); - echo $output->confirm(get_string('upgradesure', 'admin', $a->newversion), $continueurl, $cancelurl); - echo $output->footer(); + echo $output->upgrade_confirm_page($a->newversion, $maturity); exit; } else if (empty($confirmrelease)){ + require_once($CFG->libdir.'/environmentlib.php'); + list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE); $strcurrentrelease = get_string('currentrelease'); + $PAGE->navbar->add($strcurrentrelease); $PAGE->set_title($strcurrentrelease); $PAGE->set_heading($strcurrentrelease); $PAGE->set_cacheable(false); + $output = $PAGE->get_renderer('core', 'admin'); - echo $output->header(); - echo $output->heading("Moodle $release"); - $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases'); - $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack - echo $output->box($releasenoteslink); - - require_once($CFG->libdir.'/environmentlib.php'); - if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) { - echo $output->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1)); - } else { - echo $output->notification(get_string('environmentok', 'admin'), 'notifysuccess'); - if (empty($CFG->skiplangupgrade) and current_language() !== 'en') { - echo $output->box_start('generalbox', 'notice'); - print_string('langpackwillbeupdated', 'admin'); - echo $output->box_end(); - } - echo $output->continue_button('index.php?confirmupgrade=1&confirmrelease=1'); - } - - echo $output->footer(); + echo $this->upgrade_environment_page($release, $envstatus, $environment_results); die; - } elseif (empty($confirmplugins)) { + } else if (empty($confirmplugins)) { $strplugincheck = get_string('plugincheck'); + $PAGE->navbar->add($strplugincheck); $PAGE->set_title($strplugincheck); $PAGE->set_heading($strplugincheck); $PAGE->set_cacheable(false); - $output = $PAGE->get_renderer('core', 'admin'); - echo $output->header(); - echo $output->box_start('generalbox'); - echo $output->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice'); - echo $output->plugins_check(plugin_manager::instance(), array('full' => $showallplugins)); - echo $output->box_end(); - echo $output->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1, 'confirmrelease' => 1)); - $button = new single_button(new moodle_url('index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1)), get_string('upgradestart', 'admin'), 'get'); - $button->class = 'continuebutton'; - echo $output->render($button); - echo $output->footer(); + $output = $PAGE->get_renderer('core', 'admin'); + echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $showallplugins, + new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)), + new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1))); die(); } else { @@ -303,25 +247,19 @@ if (moodle_needs_upgrading()) { if (!$PAGE->headerprinted) { // means core upgrade or installation was not already done if (!$confirmplugins) { + $strplugincheck = get_string('plugincheck'); + $PAGE->set_pagelayout('maintenance'); $PAGE->set_popup_notification_allowed(false); - $strplugincheck = get_string('plugincheck'); $PAGE->navbar->add($strplugincheck); $PAGE->set_title($strplugincheck); $PAGE->set_heading($strplugincheck); $PAGE->set_cacheable(false); - $output = $PAGE->get_renderer('core', 'admin'); - echo $output->header(); - echo $output->box_start('generalbox'); - echo $output->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice'); - echo $output->plugins_check(plugin_manager::instance(), array('full' => $showallplugins)); - echo $output->box_end(); - echo $output->upgrade_reload(new moodle_url('/admin/index.php')); - $button = new single_button(new moodle_url('index.php', array('confirmplugincheck'=>1)), get_string('upgradestart', 'admin'), 'get'); - $button->class = 'continuebutton'; - echo $output->render($button); - echo $output->footer(); + $output = $PAGE->get_renderer('core', 'admin'); + echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $showallplugins, + new moodle_url('/admin/index.php'), + new moodle_url('/admin/index.php', array('confirmplugincheck'=>1))); die(); } } @@ -416,58 +354,14 @@ if (any_new_admin_settings($adminroot)){ // Everything should now be set up, and the user is an admin // Print default admin page with notifications. -admin_externalpage_setup('adminnotifications'); -echo $OUTPUT->header(); +$errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED'); -// Unstable code warning -if (isset($maturity)) { - if ($maturity < MATURITY_STABLE) { - $maturitylevel = get_string('maturity'.$maturity, 'admin'); - echo $OUTPUT->box( - get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' . - $OUTPUT->doc_link('admin/versions', get_string('morehelp')), - 'generalbox adminwarning maturityinfo'); - } -} - -if ($insecuredataroot == INSECURE_DATAROOT_WARNING) { - echo $OUTPUT->box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'generalbox adminwarning'); -} else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) { - echo $OUTPUT->box(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'generalbox adminerror'); - -} - -if (defined('WARN_DISPLAY_ERRORS_ENABLED')) { - echo $OUTPUT->box(get_string('displayerrorswarning', 'admin'), 'generalbox adminwarning'); -} - -// If no recently cron run $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}'); -if (time() - $lastcron > 3600 * 24) { - $helpbutton = $OUTPUT->help_icon('cron', 'admin'); - echo $OUTPUT->box(get_string('cronwarning', 'admin').' '.$helpbutton, 'generalbox adminwarning'); -} - -// diagnose DB, especially the sloppy MyISAM tables -$diagnose = $DB->diagnose(); -if ($diagnose !== NULL) { - echo $OUTPUT->box($diagnose, 'generalbox adminwarning'); -} - -// Alert if we are currently in maintenance mode -if (!empty($CFG->maintenance_enabled)) { - echo $OUTPUT->box(get_string('sitemaintenancewarning2', 'admin', "$CFG->wwwroot/$CFG->admin/settings.php?section=maintenancemode"), 'generalbox adminwarning'); -} - -////////////////////////////////////////////////////////////////////////////////////////////////// -//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE /// -$copyrighttext = 'Moodle '. - ''.$CFG->release.'
'. - 'Copyright © 1999 onwards, Martin Dougiamas
'. - 'and many other contributors.
'. - 'GNU Public License'; -echo $OUTPUT->box($copyrighttext, 'copyright'); -////////////////////////////////////////////////////////////////////////////////////////////////// - -echo $OUTPUT->footer(); +$cronoverdue = ($lastcron < time() - 3600 * 24); +$dbproblems = $DB->diagnose(); +$maintenancemode = !empty($CFG->maintenance_enabled); +admin_externalpage_setup('adminnotifications'); +$output = $PAGE->get_renderer('core', 'admin'); +echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, + $cronoverdue, $dbproblems, $maintenancemode); diff --git a/admin/plugins.php b/admin/plugins.php index 786adceaa7a..02049307993 100644 --- a/admin/plugins.php +++ b/admin/plugins.php @@ -31,10 +31,4 @@ require_once($CFG->libdir . '/pluginlib.php'); require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); admin_externalpage_setup('pluginsoverview'); $output = $PAGE->get_renderer('core', 'admin'); - -echo $output->header(); -echo $output->heading(get_string('pluginsoverview', 'core_admin')); -echo $output->box_start('generalbox'); -echo $output->plugins_control_panel(plugin_manager::instance()); -echo $output->box_end(); -echo $output->footer(); +echo $output->plugin_management_page(plugin_manager::instance()); diff --git a/admin/renderer.php b/admin/renderer.php index 8baee9dfc83..c90c4130ce0 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -32,6 +32,354 @@ require_once($CFG->libdir . '/pluginlib.php'); */ class core_admin_renderer extends plugin_renderer_base { + /** + * Display the 'Do you acknowledge the terms of the GPL' page. The first page + * during install. + * @return string HTML to output. + */ + public function install_licence_page() { + global $CFG; + $output = ''; + + $copyrightnotice = text_to_html(get_string('gpl3')); + $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack + + $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get'); + + $output .= $this->header(); + $output .= $this->heading('Moodle - Modular Object-Oriented Dynamic Learning Environment'); + $output .= $this->heading(get_string('copyrightnotice')); + $output .= $this->box($copyrightnotice, 'copyrightnotice'); + $output .= html_writer::empty_tag('br'); + $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License"); + $output .= $this->footer(); + + return $output; + } + + /** + * Display the 'environment check' page that is displayed during install. + * @return string HTML to output. + */ + public function install_environment_page($maturity, $envstatus, $environment_results) { + global $CFG; + $output = ''; + + $output .= $this->header(); + $output .= $this->maturity_warning($maturity); + $output .= $this->heading("Moodle $release"); + $output .= $this->release_notes_link(); + + $output .= $this->environment_check_table($envstatus, $environment_results); + + if (!$envstatus) { + $output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang))); + } else { + $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess'); + $output .= $this->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang))); + } + + $output .= $this->footer(); + return $output; + } + + /** + * Display the 'You are about to upgrade Moodle' page. The first page + * during upgrade. + * @return string HTML to output. + */ + public function upgrade_confirm_page($strnewversion, $maturity) { + $output = ''; + + $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1)); + $cancelurl = new moodle_url('index.php'); + + $output .= $this->header(); + $output .= $this->maturity_warning($maturity); + $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl); + $output .= $this->footer(); + + return $output; + } + + /** + * Display the environment page during the upgrade process. + * @return string HTML to output. + */ + public function upgrade_environment_page($release, $envstatus, $environment_results) { + global $CFG; + $output = ''; + + $output .= $this->header(); + $output .= $this->heading("Moodle $release"); + $output .= $this->release_notes_link(); + $output .= $this->environment_check_table($envstatus, $environment_results); + + if (!$envstatus) { + $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1)); + + } else { + echo $output->notification(get_string('environmentok', 'admin'), 'notifysuccess'); + + if (empty($CFG->skiplangupgrade) and current_language() !== 'en') { + $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice'); + } + + $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1))); + } + + $output .= $this->footer(); + + return $output; + } + + /** + * Display the upgrade page that lists all the plugins that require attention. + * @return string HTML to output. + */ + public function upgrade_plugin_check_page($pluginman, $showallplugins, $reloadurl, $continueurl) { + $output = ''; + + $output .= $this->header(); + $output .= $this->box_start('generalbox'); + $output .= $this->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice'); + $output .= $this->plugins_check_table($pluginman, array('full' => $showallplugins)); + $output .= $this->box_end(); + $output .= $this->upgrade_reload($reloadurl); + + $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get'); + $button->class = 'continuebutton'; + $output .= $this->render($button); + + $output .= $this->footer(); + + return $output; + } + + /** + * Display the admin notifications page. + * @return string HTML to output. + */ + public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, + $cronoverdue, $dbproblems, $maintenancemode) { + $output = ''; + + $output .= $this->header(); + $output .= $this->maturity_info($maturity); + $output .= $this->insecure_dataroot_warning($insecuredataroot); + $output .= $this->display_errors_warning($errorsdisplayed); + $output .= $this->cron_overdue_warning($errorsdisplayed); + $output .= $this->db_problems($dbproblems); + $output .= $this->maintenance_mode_warning($maintenancemode); + + ////////////////////////////////////////////////////////////////////////////////////////////////// + //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE /// + $output .= $this->moodle_copyright(); + ////////////////////////////////////////////////////////////////////////////////////////////////// + + $output .= $this->footer(); + + return $output; + } + + /** + * Display the plugin management page (admin/plugins.php). + * @return string HTML to output. + */ + public function plugin_management_page($pluginman) { + $output = ''; + + $output .= $this->header(); + $output .= $this->heading(get_string('pluginsoverview', 'core_admin')); + $output .= $this->box_start('generalbox'); + $output .= $this->plugins_control_panel($pluginman); + $output .= $this->box_end(); + $output .= $this->footer(); + + return $output; + } + + /** + * Display the plugin management page (admin/environment.php). + * @return string HTML to output. + */ + public function environment_check_page($versions, $version, $envstatus, $environment_results) { + $output = ''; + $output .= $this->header(); + + // Print the component download link + $output .= html_writer::tag('div', html_writer::link( + new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())), + get_string('updatecomponent', 'admin')), + array('class' => 'reportlink')); + + // Heading. + $output .= $this->heading(get_string('environment', 'admin')); + + // Box with info and a menu to choose the version. + $output .= $this->box_start(); + $output .= html_writer::tag('div', get_string('adminhelpenvironment')); + $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null); + $select->label = get_string('moodleversion'); + $output .= $this->render($select); + $output .= $this->box_end(); + + // The results + $output .= $this->environment_check_table($envstatus, $environment_results); + + $output .= $this->footer(); + return $output; + } + + /** + * Output a warning message, of the type that appears on the admin notifications page. + * @param string $message the message to display. + * @return string HTML to output. + */ + protected function warning($message, $type = 'warning') { + return $this->box($message, 'generalbox admin' . $type); + } + + /** + * Render an appropriate message if dataroot is insecure. + * @return string HTML to output. + */ + protected function insecure_dataroot_warning($insecuredataroot) { + global $CFG; + + if ($insecuredataroot == INSECURE_DATAROOT_WARNING) { + return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot)); + + } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) { + return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error'); + + } else { + return ''; + } + } + + /** + * Render an appropriate message if dataroot is insecure. + * @return string HTML to output. + */ + protected function display_errors_warning($errorsdisplayed) { + if (!$errorsdisplayed) { + return ''; + } + + return $this->warning(get_string('displayerrorswarning', 'admin')); + } + + /** + * Render an appropriate message if cron has not been run recently. + * @return string HTML to output. + */ + public function cron_overdue_warning($cronoverdue) { + if (!$cronoverdue) { + return ''; + } + + return $this->warning(get_string('cronwarning', 'admin') . ' ' . + $this->help_icon('cron', 'admin')); + } + + /** + * Render an appropriate message if there are any problems with the DB set-up. + * @return string HTML to output. + */ + public function db_problems($dbproblems) { + if (!$dbproblems) { + return ''; + } + + return $this->warning($dbproblems); + } + + /** + * Render an appropriate message if the site in in maintenance mode. + * @return string HTML to output. + */ + public function maintenance_mode_warning($maintenancemode) { + if (!$maintenancemode) { + return ''; + } + + return $this->warning(get_string('sitemaintenancewarning2', 'admin', + new moodle_url('/admin/settings.php', array('section' => 'maintenancemode')))); + } + + /** + * Display a warning about installing development code if necesary. + * @return string HTML to output. + */ + protected function maturity_warning($maturity) { + if ($maturity == MATURITY_STABLE) { + return ''; // No worries. + } + + $maturitylevel = get_string('maturity' . $maturity, 'admin'); + return $this->box( + $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) . + $this->container($this->doc_link('admin/versions', get_string('morehelp'))), + 'generalbox maturitywarning'); + } + + /** + * Output the copyright notice. + * @return string HTML to output. + */ + protected function moodle_copyright() { + global $CFG; + + ////////////////////////////////////////////////////////////////////////////////////////////////// + //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE /// + $copyrighttext = 'Moodle '. + ''.$CFG->release.'
'. + 'Copyright © 1999 onwards, Martin Dougiamas
'. + 'and many other contributors.
'. + 'GNU Public License'; + ////////////////////////////////////////////////////////////////////////////////////////////////// + + return $this->box($copyrighttext, 'copyright'); + } + + /** + * Display a warning about installing development code if necesary. + * @param string HTML to output. + */ + protected function maturity_info($maturity) { + if ($maturity == MATURITY_STABLE) { + return ''; // No worries. + } + + $maturitylevel = get_string('maturity' . $maturity, 'admin'); + return $this->box( + get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' . + $this->doc_link('admin/versions', get_string('morehelp')), + 'generalbox adminwarning maturityinfo'); + } + + /** + * Display a link to the release notes. + * @param string HTML to output. + */ + protected function release_notes_link() { + $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases'); + $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack + return $this->box($releasenoteslink, 'generalbox releasenoteslink'); + } + + /** + * Display the reload link that appears on several upgrade/install pages. + */ + function upgrade_reload($url) { + return html_writer::empty_tag('br') . + html_writer::tag('div', + html_writer::link($url, $this->pix_icon('i/reload', '') . + get_string('reload'), array('title' => get_string('reload'))), + array('class' => 'continuebutton')) . html_writer::empty_tag('br'); + } + /** * Displays all known plugins and information about their installation or upgrade * @@ -43,7 +391,7 @@ class core_admin_renderer extends plugin_renderer_base { * @param array $options rendering options * @return string HTML code */ - public function plugins_check(plugin_manager $pluginman, array $options = null) { + public function plugins_check_table(plugin_manager $pluginman, array $options = null) { global $CFG; $plugininfo = $pluginman->get_plugins(); @@ -356,13 +704,181 @@ class core_admin_renderer extends plugin_renderer_base { } /** - * @global object + * This function will render one beautiful table with all the environmental + * configuration and how it suits Moodle needs. + * + * @param boolean $result final result of the check (true/false) + * @param array $environment_results array of results gathered + * @return string HTML to output. */ - function upgrade_reload($url) { - return html_writer::empty_tag('br') . - html_writer::tag('div', - html_writer::link($url, $this->pix_icon('i/reload', '') . - get_string('reload'), array('title' => get_string('reload'))), - array('class' => 'continuebutton')) . html_writer::empty_tag('br'); + public function environment_check_table($result, $environment_results) { + global $CFG; + + // Table headers + $servertable = new html_table();//table for server checks + $servertable->head = array( + get_string('name'), + get_string('info'), + get_string('report'), + get_string('status'), + ); + $servertable->align = array('center', 'center', 'left', 'center'); + $servertable->wrap = array('nowrap', '', '', 'nowrap'); + $servertable->size = array('10', 10, '100%', '10'); + $servertable->attributes['class'] = 'environmenttable generaltable'; + + $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array()); + + $othertable = new html_table();//table for custom checks + $othertable->head = array( + get_string('info'), + get_string('report'), + get_string('status'), + ); + $othertable->align = array('center', 'left', 'center'); + $othertable->wrap = array('', '', 'nowrap'); + $othertable->size = array(10, '100%', '10'); + $othertable->attributes['class'] = 'environmenttable generaltable'; + + $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array()); + + // Iterate over each environment_result + $continue = true; + foreach ($environment_results as $environment_result) { + $errorline = false; + $warningline = false; + $stringtouse = ''; + if ($continue) { + $type = $environment_result->getPart(); + $info = $environment_result->getInfo(); + $status = $environment_result->getStatus(); + $error_code = $environment_result->getErrorCode(); + // Process Report field + $rec = new stdClass(); + // Something has gone wrong at parsing time + if ($error_code) { + $stringtouse = 'environmentxmlerror'; + $rec->error_code = $error_code; + $status = get_string('error'); + $errorline = true; + $continue = false; + } + + if ($continue) { + if ($rec->needed = $environment_result->getNeededVersion()) { + // We are comparing versions + $rec->current = $environment_result->getCurrentVersion(); + if ($environment_result->getLevel() == 'required') { + $stringtouse = 'environmentrequireversion'; + } else { + $stringtouse = 'environmentrecommendversion'; + } + + } else if ($environment_result->getPart() == 'custom_check') { + // We are checking installed & enabled things + if ($environment_result->getLevel() == 'required') { + $stringtouse = 'environmentrequirecustomcheck'; + } else { + $stringtouse = 'environmentrecommendcustomcheck'; + } + + } else if ($environment_result->getPart() == 'php_setting') { + if ($status) { + $stringtouse = 'environmentsettingok'; + } else if ($environment_result->getLevel() == 'required') { + $stringtouse = 'environmentmustfixsetting'; + } else { + $stringtouse = 'environmentshouldfixsetting'; + } + + } else { + if ($environment_result->getLevel() == 'required') { + $stringtouse = 'environmentrequireinstall'; + } else { + $stringtouse = 'environmentrecommendinstall'; + } + } + + // Calculate the status value + if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning) + $status = get_string('bypassed'); + $warningline = true; + } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error) + $status = get_string('restricted'); + $errorline = true; + } else { + if ($status) { //Handle ok result (ok) + $status = get_string('ok'); + } else { + if ($environment_result->getLevel() == 'optional') {//Handle check result (warning) + $status = get_string('check'); + $warningline = true; + } else { //Handle error result (error) + $status = get_string('check'); + $errorline = true; + } + } + } + } + + // Build the text + $linkparts = array(); + $linkparts[] = 'admin/environment'; + $linkparts[] = $type; + if (!empty($info)){ + $linkparts[] = $info; + } + if (empty($CFG->docroot)) { + $report = get_string($stringtouse, 'admin', $rec); + } else { + $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec)); + } + + // Format error or warning line + if ($errorline || $warningline) { + $messagetype = $errorline? 'error':'warn'; + } else { + $messagetype = 'ok'; + } + $status = ''.$status.''; + // Here we'll store all the feedback found + $feedbacktext = ''; + // Append the feedback if there is some + $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype); + //Append the bypass if there is some + $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn'); + //Append the restrict if there is some + $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error'); + + $report .= $feedbacktext; + + // Add the row to the table + if ($environment_result->getPart() == 'custom_check'){ + $otherdata[$messagetype][] = array ($info, $report, $status); + } else { + $serverdata[$messagetype][] = array ($type, $info, $report, $status); + } + } + } + + //put errors first in + $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']); + $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']); + + // Print table + $output = ''; + $output .= $this->heading(get_string('serverchecks', 'admin')); + $output .= html_writer::table($servertable); + if (count($othertable->data)){ + $output .= $this->heading(get_string('customcheck', 'admin')); + $output .= html_writer::table($othertable); + } + + // Finally, if any error has happened, print the summary box + if (!$result) { + $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox'); + } + + return $output; } } diff --git a/lib/environmentlib.php b/lib/environmentlib.php index f530b043604..ee925afda38 100644 --- a/lib/environmentlib.php +++ b/lib/environmentlib.php @@ -80,23 +80,19 @@ defined('MOODLE_INTERNAL') || die(); define('ENV_SELECT_RELEASE', 2); /** - * This function will perform the whole check, returning - * true or false as final result. Also, he full array of - * environment_result will be returned in the parameter list. - * The function looks for the best version to compare and - * everything. This is the only function that should be called - * ever from the rest of Moodle. + * This function checks all the requirements defined in environment.xml. * * @staticvar bool $result * @staticvar array $env_results * @staticvar bool $cache_exists + * * @param string $version version to check. - * @param array $environment_results results array of results checked. - * @param boolean $print_table true/false, whether to print the table or just return results array * @param int $env_select one of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use. Default ENV_SELECT_NEWER (BC) - * @return boolean true/false, depending of results + * @return array with two elements. The first element true/false, depending on + * on whether the check passed. The second element is an array of environment_results + * objects that has detailed information about the checks and which ones passed. */ -function check_moodle_environment($version, &$environment_results, $print_table=true, $env_select=ENV_SELECT_NEWER) { +function check_moodle_environment($version, $env_select = ENV_SELECT_NEWER) { $status = true; @@ -140,186 +136,7 @@ function check_moodle_environment($version, &$environment_results, $print_table= $cache_exists = true; } ///End of cache block -/// If we have decided to print all the information, just do it - if ($print_table) { - print_moodle_environment($result && $status, $environment_results); - } - return ($result && $status); -} - -/** - * This function will print one beautiful table with all the environmental - * configuration and how it suits Moodle needs. - * - * @global object - * @param boolean $result final result of the check (true/false) - * @param array $environment_results array of results gathered - * @return void - */ -function print_moodle_environment($result, $environment_results) { - global $CFG, $OUTPUT; - -/// Get some strings - $strname = get_string('name'); - $strinfo = get_string('info'); - $strreport = get_string('report'); - $strstatus = get_string('status'); - $strok = get_string('ok'); - $strerror = get_string('error'); - $strcheck = get_string('check'); - $strbypassed = get_string('bypassed'); - $strrestricted = get_string('restricted'); - $strenvironmenterrortodo = get_string('environmenterrortodo', 'admin'); -/// Table headers - $servertable = new html_table();//table for server checks - $servertable->head = array ($strname, $strinfo, $strreport, $strstatus); - $servertable->align = array ('center', 'center', 'left', 'center'); - $servertable->wrap = array ('nowrap', '', '', 'nowrap'); - $servertable->size = array ('10', 10, '100%', '10'); - $servertable->attributes['class'] = 'environmenttable generaltable'; - - $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array()); - - $othertable = new html_table();//table for custom checks - $othertable->head = array ($strinfo, $strreport, $strstatus); - $othertable->align = array ('center', 'left', 'center'); - $othertable->wrap = array ('', '', 'nowrap'); - $othertable->size = array (10, '100%', '10'); - $othertable->attributes['class'] = 'environmenttable generaltable'; - - $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array()); - -/// Iterate over each environment_result - $continue = true; - foreach ($environment_results as $environment_result) { - $errorline = false; - $warningline = false; - $stringtouse = ''; - if ($continue) { - $type = $environment_result->getPart(); - $info = $environment_result->getInfo(); - $status = $environment_result->getStatus(); - $error_code = $environment_result->getErrorCode(); - /// Process Report field - $rec = new stdClass(); - /// Something has gone wrong at parsing time - if ($error_code) { - $stringtouse = 'environmentxmlerror'; - $rec->error_code = $error_code; - $status = $strerror; - $errorline = true; - $continue = false; - } - - if ($continue) { - /// We are comparing versions - if ($rec->needed = $environment_result->getNeededVersion()) { - $rec->current = $environment_result->getCurrentVersion(); - if ($environment_result->getLevel() == 'required') { - $stringtouse = 'environmentrequireversion'; - } else { - $stringtouse = 'environmentrecommendversion'; - } - /// We are checking installed & enabled things - } else if ($environment_result->getPart() == 'custom_check') { - if ($environment_result->getLevel() == 'required') { - $stringtouse = 'environmentrequirecustomcheck'; - } else { - $stringtouse = 'environmentrecommendcustomcheck'; - } - } else if ($environment_result->getPart() == 'php_setting') { - if ($status) { - $stringtouse = 'environmentsettingok'; - } else if ($environment_result->getLevel() == 'required') { - $stringtouse = 'environmentmustfixsetting'; - } else { - $stringtouse = 'environmentshouldfixsetting'; - } - } else { - if ($environment_result->getLevel() == 'required') { - $stringtouse = 'environmentrequireinstall'; - } else { - $stringtouse = 'environmentrecommendinstall'; - } - } - /// Calculate the status value - if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning) - $status = $strbypassed; - $warningline = true; - } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error) - $status = $strrestricted; - $errorline = true; - } else { - if ($status) { //Handle ok result (ok) - $status = $strok; - } else { - if ($environment_result->getLevel() == 'optional') {//Handle check result (warning) - $status = $strcheck; - $warningline = true; - } else { //Handle error result (error) - $status = $strcheck; - $errorline = true; - } - } - } - } - - /// Build the text - $linkparts = array(); - $linkparts[] = 'admin/environment'; - $linkparts[] = $type; - if (!empty($info)){ - $linkparts[] = $info; - } - if (empty($CFG->docroot)) { - $report = get_string($stringtouse, 'admin', $rec); - } else { - $report = $OUTPUT->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec)); - } - - - /// Format error or warning line - if ($errorline || $warningline) { - $messagetype = $errorline? 'error':'warn'; - } else { - $messagetype = 'ok'; - } - $status = ''.$status.''; - /// Here we'll store all the feedback found - $feedbacktext = ''; - ///Append the feedback if there is some - $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype); - ///Append the bypass if there is some - $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn'); - ///Append the restrict if there is some - $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error'); - - $report .= $feedbacktext; - /// Add the row to the table - - if ($environment_result->getPart() == 'custom_check'){ - $otherdata[$messagetype][] = array ($info, $report, $status); - } else { - $serverdata[$messagetype][] = array ($type, $info, $report, $status); - } - } - } - //put errors first in - $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']); - $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']); - -/// Print table - echo $OUTPUT->heading(get_string('serverchecks', 'admin')); - echo html_writer::table($servertable); - if (count($othertable->data)){ - echo $OUTPUT->heading(get_string('customcheck', 'admin')); - echo html_writer::table($othertable); - } - -/// Finally, if any error has happened, print the summary box - if (!$result) { - echo $OUTPUT->box($strenvironmenterrortodo, 'environmentbox errorbox'); - } + return array($result && $status, $environment_results); } diff --git a/lib/installlib.php b/lib/installlib.php index a4ebab407f0..c6cb423c187 100644 --- a/lib/installlib.php +++ b/lib/installlib.php @@ -404,7 +404,8 @@ function install_cli_database(array $options, $interactive) { } // test environment first - if (!check_moodle_environment(normalize_version($release), $environment_results, false, ENV_SELECT_RELEASE)) { + list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); + if (!$envstatus) { $errors = environment_get_errors($environment_results); cli_heading(get_string('environment', 'admin')); foreach ($errors as $error) {