diff --git a/admin/purgecaches.php b/admin/purgecaches.php index 006bb0d9768..c2247dc94ec 100644 --- a/admin/purgecaches.php +++ b/admin/purgecaches.php @@ -27,37 +27,37 @@ require_once('../config.php'); require_once($CFG->libdir.'/adminlib.php'); $confirm = optional_param('confirm', 0, PARAM_BOOL); +$returnurl = optional_param('returnurl', null, PARAM_LOCALURL); +// If we have got here as a confirmed aciton, do it. +if ($confirm && isloggedin() && confirm_sesskey()) { + require_capability('moodle/site:config', context_system::instance()); + + // Valid request. Purge, and redirect the user back to where they came from. + purge_all_caches(); + + if ($returnurl) { + $returnurl = $CFG->wwwroot . $returnurl; + } else { + $returnurl = new moodle_url('/admin/purgecaches.php'); + } + redirect($returnurl, get_string('purgecachesfinished', 'admin')); +} + +// Otherwise, show a button to actually purge the caches. admin_externalpage_setup('purgecaches'); -require_login(); -require_capability('moodle/site:config', context_system::instance()); - -if ($confirm) { - require_sesskey(); - - // Valid request. Purge, and redisplay the form so it is easy to purge again - // in the near future. - purge_all_caches(); - redirect(new moodle_url('/admin/purgecaches.php'), get_string('purgecachesfinished', 'admin')); - -} else { - // Show a confirm form. - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('purgecaches', 'admin')); - - $url = new moodle_url('/admin/purgecaches.php', array('sesskey'=>sesskey(), 'confirm'=>1)); - $button = new single_button($url, get_string('purgecaches','admin'), 'post'); - - // Cancel button takes them back to the page the were on, if possible, - // otherwise to the site home page. - $return = new moodle_url('/'); - if (isset($_SERVER['HTTP_REFERER']) and !empty($_SERVER['HTTP_REFERER'])) { - if ($_SERVER['HTTP_REFERER'] !== "$CFG->wwwroot/$CFG->admin/purgecaches.php") { - $return = $_SERVER['HTTP_REFERER']; - } - } - - echo $OUTPUT->confirm(get_string('purgecachesconfirm', 'admin'), $button, $return); - echo $OUTPUT->footer(); +$actionurl = new moodle_url('/admin/purgecaches.php', array('sesskey'=>sesskey(), 'confirm'=>1)); +if ($returnurl) { + $actionurl->param('returnurl', $returnurl); } + +echo $OUTPUT->header(); +echo $OUTPUT->heading(get_string('purgecaches', 'admin')); + +echo $OUTPUT->box_start('generalbox', 'notice'); +echo html_writer::tag('p', get_string('purgecachesconfirm', 'admin')); +echo $OUTPUT->single_button($actionurl, get_string('purgecaches', 'admin'), 'post'); +echo $OUTPUT->box_end(); + +echo $OUTPUT->footer(); diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 006bf9ab1d6..abdf989324f 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -463,7 +463,10 @@ class core_renderer extends renderer_base { $link= '' . $txt . ''; $output .= '
'; } - $output .= ''; + $purgeurl = new moodle_url('/admin/purgecaches.php', array('confirm' => 1, + 'sesskey' => sesskey(), 'returnurl' => $this->page->url->out_as_local_url(false))); + $output .= '