Commit d2358786 authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon
Browse files

Replace minor version in URLs with an arbitrary cache version

Bug 1384481

Change-Id: Ia34c51ccae2859e3860896a5fa9fda5a4cbff1dc
parent 77a6677e
......@@ -157,7 +157,7 @@ $viewtheme = $view->get('theme');
if ($viewtheme && $THEME->basename != $viewtheme) {
$THEME = new Theme($viewtheme);
}
$headers = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">',);
$headers = array('<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'theme/views.css' ) . '">',);
// Set up skin, if the page has one
$owner = $view->get('owner');
......
......@@ -202,7 +202,7 @@ function export_submit(Pieform $form, $values) {
$smarty = smarty(
$jsfiles,
array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">'),
array('<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'theme/views.css') . '">'),
array(),
array('stylesheets' => array('style/views.css'))
);
......
......@@ -35,14 +35,14 @@ if ($USER->is_logged_in()) {
$blocktype_js = $view->get_all_blocktype_javascript();
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
$inlinejs = "addLoadEvent( function() {\n" . join("\n", $blocktype_js['initjs']) . "\n});";
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">');
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'theme/views.css') . '">');
$stylesheets = array_merge($stylesheets, $view->get_all_blocktype_css());
// include slimbox2 js and css files, if it is enabled...
if (get_config_plugin('blocktype', 'gallery', 'useslimbox2')) {
$langdir = (get_string('thisdirection', 'langconfig') == 'rtl' ? '-rtl' : '');
$stylesheets = array_merge($stylesheets, array('<script type="text/javascript" src="' . get_config('wwwroot') . 'lib/slimbox2/js/slimbox2.js?v=' . get_config('release'). '"></script>',
'<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'lib/slimbox2/css/slimbox2' . $langdir . '.css?v=' . get_config('release'). '">'
$stylesheets = array_merge($stylesheets, array('<script type="text/javascript" src="' . append_version_number(get_config('wwwroot') . 'lib/slimbox2/js/slimbox2.js') . '"></script>',
'<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'lib/slimbox2/css/slimbox2' . $langdir . '.css') . '">'
));
}
......
......@@ -3749,5 +3749,12 @@ function xmldb_core_upgrade($oldversion=0) {
set_field('view', 'locked', 0, 'type', 'grouphomepage', 'owner', 0);
}
if ($oldversion < 2014110500) {
// Adding cacheversion, as an arbitrary number appended to the end of JS & CSS files in order
// to tell cacheing software when they've been updated. (Without having to use the Mahara
// minor version for that purpose.)
// Set this to a random starting number to make minor version slightly harder to detect
set_config('cacheversion', rand(1000, 9999));
}
return $status;
}
......@@ -1743,7 +1743,7 @@ function pieform_get_headdata() {/*{{{*/
// TODO: jsdirectory should be independent of ANY form
if ($GLOBALS['_PIEFORM_REGISTRY']) {
array_unshift($htmlelements, '<script type="text/javascript" src="'
. Pieform::hsc($form->get_property('jsdirectory')) . 'pieforms.js?v=' . get_config('release'). '"></script>');
. Pieform::hsc(append_version_number($form->get_property('jsdirectory') . 'pieforms.js')) . '"></script>');
array_unshift($htmlelements, '<script type="text/javascript">pieformPath = "'
. Pieform::hsc($form->get_property('jsdirectory')) . '";</script>');
}
......
......@@ -184,10 +184,10 @@ function add_prev_next_year(inst) {
}
EOF;
$result = array(
'<link rel="stylesheet" type="text/css" media="all" href="' . $libcss . '?v=' . get_config('release'). '">',
'<link rel="stylesheet" type="text/css" media="all" href="' . $themefile . '?v=' . get_config('release'). '">',
'<script type="text/javascript" src="' . $libjs . '?v=' . get_config('release'). '"></script>',
'<script type="text/javascript" src="' . $timeaddonjs . '?v=' . get_config('release'). '"></script>',
'<link rel="stylesheet" type="text/css" media="all" href="' . append_version_number($libcss) . '">',
'<link rel="stylesheet" type="text/css" media="all" href="' . append_version_number($themefile) . '">',
'<script type="text/javascript" src="' . append_version_number($libjs) . '"></script>',
'<script type="text/javascript" src="' . append_version_number($timeaddonjs) . '"></script>',
'<script type="text/javascript">' . $extrajs . '</script>',
);
return $result;
......
......@@ -356,6 +356,7 @@ function upgrade_core($upgrade) {
set_config('version', $upgrade->to);
set_config('release', $upgrade->torelease);
set_config('series', $upgrade->toseries);
bump_cache_version();
if (!empty($upgrade->install)) {
core_postinst();
......@@ -380,6 +381,7 @@ function upgrade_local($upgrade) {
set_config('localversion', $upgrade->to);
set_config('localrelease', $upgrade->torelease);
bump_cache_version();
db_commit();
return true;
......@@ -456,6 +458,7 @@ function upgrade_plugin($upgrade) {
else {
update_record($installtable, $installed, 'name');
}
bump_cache_version();
// postinst stuff...
safe_require($plugintype, $pluginname);
......@@ -847,6 +850,8 @@ function core_install_firstcoredata_defaults() {
set_config('onlineuserssideblockmaxusers', 10);
set_config('loggedinprofileviewaccess', 1);
set_config('dropdownmenu', 0);
// Set this to a random starting number to make minor version slightly harder to detect
set_config('cacheversion', rand(1000, 9999));
// install the applications
$app = new StdClass;
......@@ -1571,3 +1576,13 @@ function install_watchlist_notification() {
$cron->dayofweek = '*';
ensure_record_exists('cron', $cron, $cron);
}
/**
* Increment the cache version number.
* This is an arbitrary number that we append to the end of static content to make sure the user
* refreshes it when we update the site.
*/
function bump_cache_version() {
set_config('cacheversion', get_config('cacheversion') + 1);
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014102900;
$config->version = 2014110500;
$config->series = '15.04';
$config->release = '15.04dev';
$config->minupgradefrom = 2009022600;
......
......@@ -2323,7 +2323,7 @@ class View {
$hrefs = array_reverse($hrefs);
foreach ($hrefs as $href) {
$cssfiles[] = '<link rel="stylesheet" type="text/css" href="' . $href . '?v=' . get_config('release'). '">';
$cssfiles[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number($href) . '">';
}
}
}
......
......@@ -467,7 +467,7 @@ EOF;
}
$smarty->assign('sitename', $sitename);
$sitelogo = $THEME->header_logo();
$sitelogo = $sitelogo . ((strpos($sitelogo, '?') === false) ? '?' : '&') . 'v=' . get_config('release');
$sitelogo = append_version_number($sitelogo);
$smarty->assign('sitelogo', $sitelogo);
$smarty->assign('sitelogo4facebook', $THEME->facebook_logo());
$smarty->assign('sitedescription4facebook', get_string('facebookdescription', 'mahara'));
......@@ -538,6 +538,7 @@ EOF;
$smarty->assign_by_ref('JAVASCRIPT', $javascript_array);
$smarty->assign('RELEASE', get_config('release'));
$smarty->assign('SERIES', get_config('series'));
$smarty->assign('CACHEVERSION', get_config('cacheversion'));
$siteclosedforupgrade = get_config('siteclosed');
if ($siteclosedforupgrade && get_config('disablelogin')) {
$smarty->assign('SITECLOSED', 'logindisabled');
......@@ -4223,20 +4224,20 @@ function append_version_number($urls) {
$formattedurls = array();
foreach ($urls as $url) {
if (preg_match('/\?/',$url)) {
$url .= '&v=' . get_config('release');
$url .= '&v=' . get_config('cacheversion');
}
else {
$url .= '?v=' . get_config('release');
$url .= '?v=' . get_config('cacheversion');
}
$formattedurls[] = $url;
}
return $formattedurls;
}
if (preg_match('/\?/',$urls)) {
$urls .= '&v=' . get_config('release');
$urls .= '&v=' . get_config('cacheversion');
}
else {
$urls .= '?v=' . get_config('release');
$urls .= '?v=' . get_config('cacheversion');
}
return $urls;
}
......
......@@ -34,12 +34,12 @@
{foreach from=$STYLESHEETLIST item=cssurl}
<link rel="stylesheet" type="text/css" href="{$cssurl}">
{/foreach}
<link rel="stylesheet" type="text/css" href="{theme_url filename='style/print.css'}?v={$RELEASE}" media="print">
<script type="text/javascript" src="{$WWWROOT}js/css.js?v={$RELEASE}"></script>
<link rel="shortcut icon" href="{$WWWROOT}favicon.ico?v={$RELEASE}" type="image/vnd.microsoft.icon">
<link rel="stylesheet" type="text/css" href="{theme_url filename='style/print.css'}?v={$CACHEVERSION}" media="print">
<script type="text/javascript" src="{$WWWROOT}js/css.js?v={$CACHEVERSION}"></script>
<link rel="shortcut icon" href="{$WWWROOT}favicon.ico?v={$CACHEVERSION}" type="image/vnd.microsoft.icon">
<link rel="image_src" href="{$sitelogo}">
<!-- Responsive design -->
<script type="text/javascript" src="{$WWWROOT}js/rd-nav.js?v={$RELEASE}"></script>
<script type="text/javascript" src="{$WWWROOT}js/rd-nav.js?v={$CACHEVERSION}"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{if $ADDITIONALHTMLHEAD}{$ADDITIONALHTMLHEAD|safe}{/if}
{if $COOKIECONSENTCODE}{$COOKIECONSENTCODE|safe}{/if}
......
......@@ -34,9 +34,9 @@
{foreach from=$STYLESHEETLIST item=cssurl}
<link rel="stylesheet" type="text/css" href="{$cssurl}">
{/foreach}
<link rel="stylesheet" type="text/css" href="{theme_url filename='style/print.css'}?v={$RELEASE}" media="print">
<script type="text/javascript" src="{$WWWROOT}js/css.js?v={$RELEASE}"></script>
<link rel="shortcut icon" href="{$WWWROOT}favicon.ico?v={$RELEASE}" type="image/vnd.microsoft.icon">
<link rel="stylesheet" type="text/css" href="{theme_url filename='style/print.css'}?v={$CACHEVERSION}" media="print">
<script type="text/javascript" src="{$WWWROOT}js/css.js?v={$CACHEVERSION}"></script>
<link rel="shortcut icon" href="{$WWWROOT}favicon.ico?v={$CACHEVERSION}" type="image/vnd.microsoft.icon">
<link rel="image_src" href="{$sitelogo}">
{if $ADDITIONALHTMLHEAD}{$ADDITIONALHTMLHEAD|safe}{/if}
{if $COOKIECONSENTCODE}{$COOKIECONSENTCODE|safe}{/if}
......
......@@ -103,13 +103,13 @@ $viewtheme = $view->get('theme');
if ($viewtheme && $THEME->basename != $viewtheme) {
$THEME = new Theme($viewtheme);
}
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">');
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'theme/views.css') . '">');
$stylesheets = array_merge($stylesheets, $view->get_all_blocktype_css());
// include slimbox2 js and css files, if it is enabled...
if (get_config_plugin('blocktype', 'gallery', 'useslimbox2')) {
$langdir = (get_string('thisdirection', 'langconfig') == 'rtl' ? '-rtl' : '');
$stylesheets = array_merge($stylesheets, array('<script type="text/javascript" src="' . get_config('wwwroot') . 'lib/slimbox2/js/slimbox2.js?v=' . get_config('release'). '"></script>',
'<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'lib/slimbox2/css/slimbox2' . $langdir . '.css?v=' . get_config('release'). '">'
$stylesheets = array_merge($stylesheets, array('<script type="text/javascript" src="' . append_version_number(get_config('wwwroot') . 'lib/slimbox2/js/slimbox2.js') . '"></script>',
'<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'lib/slimbox2/css/slimbox2' . $langdir . '.css') . '">'
));
}
......
......@@ -119,11 +119,11 @@ $viewtheme = $view->set_user_theme();
$allowedthemes = get_user_accessible_themes();
// Pull in cross-theme view stylesheet and file stylesheets
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">');
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'theme/views.css') . '">');
foreach (array_reverse($THEME->get_url('style/style.css', true, 'artefact/file')) as $sheet) {
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . $sheet . '?v=' . get_config('release'). '">';
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number($sheet) . '">';
}
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'js/jquery/jquery-ui/css/ui-lightness/jquery-ui-1.10.2.min.css?v=' . get_config('release'). '">';
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'js/jquery/jquery-ui/css/ui-lightness/jquery-ui-1.10.2.min.css') . '">';
$stylesheets = array_merge($stylesheets, $view->get_all_blocktype_css());
// Tell the user to change the view theme if the current one is no
// longer available to them.
......
......@@ -132,7 +132,7 @@ EOF;
$smarty = smarty(
array('js/preview.js', 'searchtable'),
array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">'),
array('<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'theme/views.css') . '">'),
array(),
array('stylesheets' => array('style/views.css'))
);
......
......@@ -158,7 +158,7 @@ $layoutform = array(
$layoutform = pieform($layoutform);
$javascript = array('jquery','js/jquery/jquery-ui/js/jquery-ui-1.10.2.min.js', 'js/customlayout.js','js/jquery/modernizr.custom.js');
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'js/jquery/jquery-ui/css/ui-lightness/jquery-ui-1.10.2.min.css?v=' . get_config('release'). '">';
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'js/jquery/jquery-ui/css/ui-lightness/jquery-ui-1.10.2.min.css') . '">';
$smarty = smarty($javascript, $stylesheets, array('view' => array('Row', 'removethisrow', 'rownr', 'nrrows', 'generatingpreview')), array('sidebars' => false));
......
......@@ -217,7 +217,7 @@ $viewtheme = $view->get('theme');
if ($viewtheme && $THEME->basename != $viewtheme) {
$THEME = new Theme($viewtheme);
}
$headers = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">');
$headers = array('<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'theme/views.css') . '">');
$headers = array_merge($headers, $view->get_all_blocktype_css());
// Set up skin, if the page has one
$viewskin = $view->get('skin');
......@@ -238,8 +238,8 @@ if (!$view->is_public()) {
if (get_config_plugin('blocktype', 'gallery', 'useslimbox2')) {
$langdir = (get_string('thisdirection', 'langconfig') == 'rtl' ? '-rtl' : '');
$headers = array_merge($headers, array(
'<script type="text/javascript" src="' . get_config('wwwroot') . 'lib/slimbox2/js/slimbox2.js?v=' . get_config('release'). '"></script>',
'<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'lib/slimbox2/css/slimbox2' . $langdir . '.css?v=' . get_config('release'). '">'
'<script type="text/javascript" src="' . append_version_number(get_config('wwwroot') . 'lib/slimbox2/js/slimbox2.js') . '"></script>',
'<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'lib/slimbox2/css/slimbox2' . $langdir . '.css') . '">'
));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment