summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-08-12 11:43:10 +0000
committerDries Buytaert <dries@buytaert.net>2009-08-12 11:43:10 +0000
commit99ce96e5da2cdd92d5bab55ea275f25e05cdd1a4 (patch)
treeaebd34bc336cce90d568b47694b7ddd406887f68 /modules
parentda2639d6cd05daa7a29f2c754d45728bb458ca82 (diff)
downloadbrdo-99ce96e5da2cdd92d5bab55ea275f25e05cdd1a4.tar.gz
brdo-99ce96e5da2cdd92d5bab55ea275f25e05cdd1a4.tar.bz2
- Patch #459980 by Xano: rework admin/settings/performance.
Diffstat (limited to 'modules')
-rw-r--r--modules/block/block.admin.inc24
-rw-r--r--modules/block/block.module33
-rw-r--r--modules/system/system.admin.inc126
-rw-r--r--modules/system/system.js21
4 files changed, 115 insertions, 89 deletions
diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc
index cc97d5227..436ca29b3 100644
--- a/modules/block/block.admin.inc
+++ b/modules/block/block.admin.inc
@@ -7,6 +7,30 @@
*/
/**
+ * Implement hook_form_FORM_ID_alter().
+ */
+function block_form_system_performance_settings_alter(&$form, &$form_state) {
+ $disabled = count(module_implements('node_grants'));
+ $form['caching']['block_cache'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Cache blocks'),
+ '#default_value' => variable_get('block_cache', FALSE),
+ '#disabled' => $disabled,
+ '#description' => $disabled ? t('Block caching is inactive because you have enabled modules defining content access restrictions.') : NULL,
+ '#weight' => -1,
+ );
+
+ // Check if the "Who's online" block is enabled.
+ $online_block_enabled = db_query_range("SELECT 1 FROM {block} b WHERE module = 'user' AND delta = 'online' AND status = 1", array(), 0, 1)->fetchField();
+
+ // If the "Who's online" block is enabled, append some descriptive text to
+ // the end of the form description.
+ if ($online_block_enabled) {
+ $form['page_cache']['cache']['#description'] .= '<p>' . t('When caching is enabled, anonymous user sessions are only saved to the database when needed, so the "Who\'s online" block does not display the number of anonymous users.') . '</p>';
+ }
+}
+
+/**
* Menu callback for admin/structure/block.
*/
function block_admin_display($theme = NULL) {
diff --git a/modules/block/block.module b/modules/block/block.module
index 91f71211b..9d741800a 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -464,39 +464,6 @@ function block_user_validate(&$edit, &$account, $category = NULL) {
/**
* Implement hook_form_FORM_ID_alter().
*/
-function block_form_system_performance_settings_alter(&$form, &$form_state) {
-
- // Add the block cache fieldset on the performance settings page.
- $form['block_cache'] = array(
- '#type' => 'fieldset',
- '#title' => t('Block cache'),
- '#description' => t('Enabling the block cache can offer a performance increase for all users by preventing blocks from being reconstructed on each page load. If the page cache is also enabled, performance increases from enabling the block cache will mainly benefit authenticated users.'),
- '#weight' => 0,
- );
-
- $form['block_cache']['block_cache'] = array(
- '#type' => 'radios',
- '#title' => t('Block cache'),
- '#default_value' => variable_get('block_cache', CACHE_DISABLED),
- '#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_NORMAL => t('Enabled (recommended)')),
- '#disabled' => count(module_implements('node_grants')),
- '#description' => t('Note that block caching is inactive when modules defining content access restrictions are enabled.'),
- );
-
- // Check if the "Who's online" block is enabled.
- $online_block_enabled = db_query_range("SELECT 1 FROM {block} b WHERE module = 'user' AND delta = 'online' AND status = 1", array(), 0, 1)->fetchField();
-
- // If the "Who's online" block is enabled, append some descriptive text to
- // the end of the form description.
- if ($online_block_enabled) {
- $form['page_cache']['cache']['#description'] .= '<p>' . t('When caching is enabled, anonymous user sessions are only saved to the database when needed, so the "Who\'s online" block does not display the number of anonymous users.') . '</p>';
- }
-
-}
-
-/**
- * Implement hook_form_FORM_ID_alter().
- */
function block_form_system_themes_form_alter(&$form, &$form_state) {
// This function needs to fire before the theme changes are recorded in the
// database, otherwise it will populate the default list of blocks from the
diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc
index a52545286..a77472b83 100644
--- a/modules/system/system.admin.inc
+++ b/modules/system/system.admin.inc
@@ -1358,85 +1358,99 @@ function system_logging_settings() {
* @see system_settings_form()
*/
function system_performance_settings() {
+ drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
- $description = '<p>' . t("The normal page cache mode is suitable for most sites and does not cause any side effects. The aggressive page cache mode causes Drupal to skip the loading (boot) and unloading (exit) of enabled modules when serving a cached page. This results in an additional performance boost but can cause unwanted side effects.") . '</p>';
+ $form['clear_cache'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Clear cache'),
+ );
- $problem_modules = array_unique(array_merge(module_implements('boot'), module_implements('exit')));
- sort($problem_modules);
+ $form['clear_cache']['clear'] = array(
+ '#type' => 'submit',
+ '#value' => t('Clear all caches'),
+ '#submit' => array('system_clear_cache_submit'),
+ );
+ $form['caching'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Caching'),
+ );
+
+ $cache = variable_get('cache', CACHE_DISABLED);
+ $js_hide = $cache != CACHE_AGGRESSIVE ? 'js-hide' : '';
+ $problem_modules = array_unique(array_merge(module_implements('boot'), module_implements('exit')));
if (count($problem_modules) > 0) {
- $description .= '<p>' . t('<strong class="error">The following enabled modules are incompatible with aggressive page caching mode and will not function properly: %modules</strong>', array('%modules' => implode(', ', $problem_modules))) . '.</p>';
+ $module_names = array();
+ foreach ($problem_modules as $module) {
+ $info = drupal_parse_info_file(drupal_get_path('module', $module) . "/$module.info");
+ $module_names[] = $info['name'];
+ }
+ sort($module_names);
+ $message = format_plural(count($module_names), '%module may cause issues when using aggressive caching.', '%modules may cause issues when using aggressive caching.', array('%module' => $module_names[0], '%modules' => implode(', ', $module_names)));
+ $description = ' <strong id="cache-error" class="error ' . $js_hide . '">' . $message . '</strong>';
}
else {
- $description .= '<p>' . t('<strong class="ok">Currently, all enabled modules are compatible with the aggressive page caching policy.</strong> Please note, if you use aggressive page caching and enable new modules, you will need to check this setting again to ensure compatibility.') . '</p>';
+ $description = ' <strong class="' . $js_hide . '">' . t('Note: if you use aggressive page caching and enable new modules, you will need to check this setting again to ensure compatibility.') . '</strong>';
}
- $form['page_cache'] = array(
- '#type' => 'fieldset',
- '#title' => t('Page cache'),
- '#description' => t('Enabling the page cache will offer a significant performance boost. Drupal can store and send compressed cached pages requested by <em>anonymous</em> users. By caching a web page, Drupal does not have to construct the page each time it is viewed.'),
- '#weight' => -1,
- );
-
- $form['page_cache']['cache'] = array(
+ $form['caching']['cache'] = array(
'#type' => 'radios',
- '#title' => t('Page caching mode'),
- '#default_value' => variable_get('cache', CACHE_DISABLED),
- '#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_NORMAL => t('Normal (recommended for production sites, no side effects)'), CACHE_AGGRESSIVE => t('Aggressive (experts only, possible side effects)')),
- '#description' => $description
+ '#title' => t('Page cache for anonymous users'),
+ '#default_value' => $cache,
+ '#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_NORMAL => t('Normal (recommended)'), CACHE_AGGRESSIVE => t('Aggressive (possible issues)')),
+ '#description' => t('Aggressive caching prevents modules from being loaded if the requested page can be retrieved from the cache. This may cause issues if you use modules that need to be loaded every request i.e. for writing data like statistics.') . $description,
);
-
$period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
$period[0] = '<' . t('none') . '>';
- $form['page_cache']['cache_lifetime'] = array(
+ $form['caching']['cache_lifetime'] = array(
'#type' => 'select',
'#title' => t('Minimum cache lifetime'),
'#default_value' => variable_get('cache_lifetime', 0),
'#options' => $period,
- '#description' => t('On high-traffic sites, it may be necessary to enforce a minimum cache lifetime. The minimum cache lifetime is the minimum amount of time that will elapse before the cache is emptied and recreated, and is applied to both page and block caches. A larger minimum cache lifetime offers better performance, but users will not see new content for a longer period of time.')
- );
- $form['page_cache']['page_compression'] = array(
- '#type' => 'radios',
- '#title' => t('Page compression'),
- '#default_value' => variable_get('page_compression', TRUE),
- '#options' => array(t('Disabled'), t('Enabled')),
- '#description' => t("By default, Drupal compresses the pages it caches in order to save bandwidth and improve download times. This option should be disabled when using a webserver that performs compression."),
+ '#description' => t('The minimum amount of time that will elapse before the caches are recreated.')
);
- $form['bandwidth_optimizations'] = array(
+ $directory = file_directory_path();
+ $is_writable = is_dir($directory) && is_writable($directory);
+ $public_downloads = (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
+ $disabled = !$is_writable && !$public_downloads;
+ $disabled_message = '';
+ if(!$is_writable && !$public_downloads) {
+ $disabled_message = ' ' . t('<strong class="error">Please <a href="!file-system">set up</a> the files directory and set the download method to public to make these optimizations available.</strong>', array('!file-system' => url('admin/settings/file-system')));
+ }
+ elseif(!$is_writable) {
+ $disabled_message = ' ' . t('<strong class="error">Please set up the <a href="!file-system">files directory</a> to make these optimizations available.</strong>', array('!file-system' => url('admin/settings/file-system')));
+ }
+ elseif(!$public_downloads) {
+ $disabled_message = ' ' . t('<strong class="error">Please set the <a href="!file-system">download method</a> to public to make these optimizations available.</strong>', array('!file-system' => url('admin/settings/file-system')));
+ }
+ $form['bandwidth_optimization'] = array(
'#type' => 'fieldset',
- '#title' => t('Bandwidth optimizations'),
- '#description' => '<p>' . t('Drupal can automatically optimize external resources like CSS and JavaScript, which can reduce both the size and number of requests made to your website. CSS files can be aggregated and compressed into a single file, while JavaScript files are aggregated (but not compressed). These optional optimizations may reduce server load, bandwidth requirements, and page loading times.') . '</p><p>' . t('These options are disabled if you have not set up your files directory, or if your download method is set to private.') . '</p>'
+ '#title' => t('Bandwidth optimization'),
+ '#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message,
);
- $directory = file_directory_path();
- $is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
- $form['bandwidth_optimizations']['preprocess_css'] = array(
- '#type' => 'radios',
- '#title' => t('Optimize CSS files'),
+ // Do not allow Drupal to gzip pages if the server alredy does that.
+ if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === FALSE) {
+ $js_hide = $cache == CACHE_DISABLED ? ' class="js-hide"' : '';
+ $form['bandwidth_optimization']['page_compression'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Compress cached pages.'),
+ '#default_value' => variable_get('page_compression', TRUE),
+ '#prefix' => '<div id="page-compression-wrapper"' . $js_hide . '>',
+ '#suffix' => '</div>',
+ );
+ }
+ $form['bandwidth_optimization']['preprocess_css'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Aggregate and compress CSS files into one file.'),
'#default_value' => intval(variable_get('preprocess_css', 0) && $is_writable),
- '#disabled' => !$is_writable,
- '#options' => array(t('Disabled'), t('Enabled')),
- '#description' => t('This option can interfere with theme development and should only be enabled in a production environment.'),
+ '#disabled' => $disabled,
);
- $form['bandwidth_optimizations']['preprocess_js'] = array(
- '#type' => 'radios',
- '#title' => t('Optimize JavaScript files'),
+ $form['bandwidth_optimization']['preprocess_js'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Aggregate JavaScript files into one file.'),
'#default_value' => intval(variable_get('preprocess_js', 0) && $is_writable),
- '#disabled' => !$is_writable,
- '#options' => array(t('Disabled'), t('Enabled')),
- '#description' => t('This option can interfere with module development and should only be enabled in a production environment.'),
- );
-
- $form['clear_cache'] = array(
- '#type' => 'fieldset',
- '#title' => t('Clear cached data'),
- '#description' => t('Caching data improves performance, but may cause problems while troubleshooting new modules, themes, or translations, if outdated information has been cached. To refresh all cached data on your site, click the button below. <em>Warning: high-traffic sites will experience performance slowdowns while cached data is rebuilt.</em>'),
- );
-
- $form['clear_cache']['clear'] = array(
- '#type' => 'submit',
- '#value' => t('Clear cached data'),
- '#submit' => array('system_clear_cache_submit'),
+ '#disabled' => $disabled,
);
$form['#submit'][] = 'drupal_clear_css_cache';
diff --git a/modules/system/system.js b/modules/system/system.js
index a0f712aec..479ecc6ea 100644
--- a/modules/system/system.js
+++ b/modules/system/system.js
@@ -148,5 +148,26 @@ Drupal.behaviors.poweredByPreview = {
};
+ /**
+ * Show/hide settings for page caching depending on whether page caching is
+ * enabled or not.
+ */
+Drupal.behaviors.pageCache = {
+ attach: function (context, settings) {
+ $('#edit-cache-0', context).change(function () {
+ $('#page-compression-wrapper').hide();
+ $('#cache-error').hide();
+ });
+ $('#edit-cache-1', context).change(function () {
+ $('#page-compression-wrapper').show();
+ $('#cache-error').hide();
+ });
+ $('#edit-cache-2', context).change(function () {
+ $('#page-compression-wrapper').show();
+ $('#cache-error').show();
+ });
+ },
+};
+
})(jQuery);