Skip to content

Commit

Permalink
Merge branch 'w29_MDL-40546_m26_jscache' of https://github.com/skodak…
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 16, 2013
2 parents a980261 + ff74627 commit b8d73bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/javascript.php
Expand Up @@ -42,7 +42,7 @@
$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!
}

Expand Down Expand Up @@ -76,9 +76,11 @@
}

$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
Expand Down
11 changes: 8 additions & 3 deletions lib/outputrequirementslib.php
Expand Up @@ -612,12 +612,17 @@ protected function js_fix_url($url) {
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 {
Expand Down

0 comments on commit b8d73bd

Please sign in to comment.