Merge branch 'w29_MDL-40546_m26_jscache' of https://github.com/skodak/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2013-07-17 00:30:13 +02:00
2 changed files with 13 additions and 6 deletions
+5 -3
View File
@@ -42,7 +42,7 @@ if ($slashargument = min_get_slash_argument()) {
$file = '/'.min_clean_param($file, 'SAFEPATH');
} else {
$rev = min_optional_param('rev', 0, 'INT');
$rev = min_optional_param('rev', -1, 'INT');
$file = min_optional_param('jsfile', '', 'RAW'); // 'file' would collide with URL rewriting!
}
@@ -76,9 +76,11 @@ if (!$jsfiles) {
}
$etag = sha1($rev.implode(',', $jsfiles));
$candidate = $CFG->cachedir.'/js/'.$etag;
if ($rev > -1) {
// Use the caching only for meaningful revision numbers which prevents future cache poisoning.
if ($rev > 0 and $rev < (time() + 60*60)) {
$candidate = $CFG->cachedir.'/js/'.$etag;
if (file_exists($candidate)) {
if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
// we do not actually need to verify the etag value because our files
+8 -3
View File
@@ -612,12 +612,17 @@ class page_requirements_manager {
throw new coding_exception('Attempt to require a JavaScript file that does not exist.', $url);
}
}
if (!empty($CFG->cachejs) and !empty($CFG->jsrev) and $CFG->jsrev > 0 and substr($url, -3) === '.js') {
if (substr($url, -3) === '.js') {
if (empty($CFG->cachejs) or !isset($CFG->jsrev)) {
$jsrev = -1;
} else {
$jsrev = (int)$CFG->jsrev;
}
if (empty($CFG->slasharguments)) {
return new moodle_url($CFG->httpswwwroot.'/lib/javascript.php', array('rev'=>$CFG->jsrev, 'jsfile'=>$url));
return new moodle_url($CFG->httpswwwroot.'/lib/javascript.php', array('rev'=>$jsrev, 'jsfile'=>$url));
} else {
$returnurl = new moodle_url($CFG->httpswwwroot.'/lib/javascript.php');
$returnurl->set_slashargument('/'.$CFG->jsrev.$url);
$returnurl->set_slashargument('/'.$jsrev.$url);
return $returnurl;
}
} else {