diff -urpN modules/system/memorywarn.js modules/system/memorywarn.js --- modules/system/memorywarn.js 1970-01-01 01:00:00.000000000 +0100 +++ modules/system/memorywarn.js 2007-12-17 18:50:39.000000000 +0100 @@ -0,0 +1,52 @@ +Drupal.behaviors.memoryWarn = function (context) { + $('input.form-checkbox', context).each(function () { + $(this).click(function () { + var memInfo = Drupal.getMemoryInfo(); + var memUsage = Drupal.getMemoryUsage(this); + if (this.checked) { + memInfo[0] += memUsage; + } else { + memInfo[0] -= memUsage; + } + memInfo[0] = Math.round(memInfo[0] * Math.pow(10, 2)) / Math.pow(10, 2); + // warn + if (memInfo[1] - memInfo[0] < 5.0 && this.checked) { + if (!confirm(Drupal.t("Activating this module could result in Out of Memory errors.\nDo you really want to continue?"))) { + this.checked = false; + return; + } + } + Drupal.setMemoryUsage(memInfo); + }); + }); +}; + +Drupal.getMemoryInfo = function () { + var memInfo = Array(); + var memData = /([\d\.]+)[^\.\d]*([\d\.]+)/.exec($('#meminfo').html()); + memInfo[0] = parseFloat(memData[1]); + memInfo[1] = parseFloat(memData[2]); + return memInfo; +}; + +Drupal.getMemoryUsage = function (object) { + var checkboxes = $('.package input.form-checkbox').get(); + var thisRow = -1; + // search this object + for (var i = 0; i < checkboxes.length; ++i) { + if (checkboxes[i] == object) { + thisRow = i; + break; + } + } + // get the tag with the description at the found index + var memUsage = $('.package *[@title]').map(function(){ return this.title; }).get(thisRow); + if (!memUsage) return 0.0; + return parseFloat((/([\d.]+)/.exec(memUsage)[1])); +}; + +Drupal.setMemoryUsage = function (memInfo) { + var newText = String($('#meminfo').html()); + newText = newText.replace(/[\d\.]+/, memInfo[0]); + $('#meminfo').html(newText); +}; \ No newline at end of file diff -urpN modules/system/system.admin.inc modules/system/system.admin.inc --- modules/system/system.admin.inc 2007-12-17 17:48:06.000000000 +0100 +++ modules/system/system.admin.inc 2007-12-17 18:50:39.000000000 +0100 @@ -599,6 +599,7 @@ function _system_is_incompatible(&$incom * The form array. */ function system_modules($form_state = array()) { + drupal_add_js(drupal_get_path('module', 'system') .'/memorywarn.js'); drupal_rebuild_theme_registry(); node_types_rebuild(); menu_rebuild(); @@ -641,6 +642,10 @@ function system_modules($form_state = ar $form['name'][$filename] = array('#value' => $file->info['name']); $form['version'][$filename] = array('#value' => $file->info['version']); $form['description'][$filename] = array('#value' => t($file->info['description'])); + // the memory setting is optional so we have to check that it's existing + if (isset($file->info['memory'])) { + $form['memory'][$filename] = array('#value' => $file->info['memory']); + } $options[$filename] = ''; // Ensure this module is compatible with this version of core and php. if (_system_is_incompatible($incompatible_core, $files, $file) || _system_is_incompatible($incompatible_php, $files, $file)) { @@ -1750,6 +1755,24 @@ function system_sql() { } /** + * Returns information about the memory usage + */ +function system_memory_info() { + $meminf = array(); + // get the current memory usage of the PHP parser, transform + // it in a Megabyte unit and round it + $meminf['in_use'] = round(memory_get_usage() / 1024 / 1024, 2); + $meminf['limit'] = floatval(ini_get('memory_limit')); + // if there are less than 5 MB of Memory remaining, set the warn CSS class + if ($meminf['limit'] - $meminf['in_use'] < 5.0) { + $meminf['state'] = 'error'; + } else { + $meminf['state'] = 'status'; + } + return $meminf; +} + +/** * Default page callback for batches. */ function system_batch_page() { @@ -1992,13 +2015,26 @@ function theme_system_modules($form) { } ksort($packages); - // Display packages. $output = ''; + // Display memory usage + $meminf = system_memory_info(); + $info = ''; + if ($meminf['state'] == 'error') { + $info = t('Drupals memory usage is too high. Please deactivate some modules or raise your memory limit to prevent Out of Memory errors.'); + } + $output .= '
'. t('Memory usage: @mem_in_use of @mem_limit MB. @info', array('@mem_in_use' => $meminf['in_use'], '@mem_limit' => $meminf['limit'], '@info' => $info)) .'
'; + + // Display packages. foreach ($packages as $package => $modules) { $rows = array(); foreach ($modules as $key => $module) { $row = array(); $description = drupal_render($form['description'][$key]); + $memory_info = ''; + if (isset($form['memory'][$key])) { + $memory_info = t('Estimated memory required: @memory MB', array('@memory' => $form['memory'][$key]['#value'])); + unset($form['memory'][$key]); + } if (isset($form['status']['#incompatible_modules_core'][$key])) { unset($form['status'][$key]); $status = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of Drupal core')); @@ -2030,7 +2066,7 @@ function theme_system_modules($form) { } $row[] = drupal_render($form['version'][$key]); - $row[] = array('data' => $description, 'class' => 'description'); + $row[] = array('data' => $description, 'class' => 'description', 'title' => $memory_info); $rows[] = $row; } $fieldset = array(