Index: module.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/module.inc,v retrieving revision 1.98 diff -u -p -r1.98 module.inc --- module.inc 4 Feb 2007 21:20:50 -0000 1.98 +++ module.inc 7 Feb 2007 15:23:31 -0000 @@ -45,38 +45,58 @@ function module_iterate($function, $argu * modules. */ function module_list($refresh = FALSE, $bootstrap = TRUE, $sort = FALSE, $fixed_list = NULL) { - static $list, $sorted_list; + if ($fixed_list) { + return _module_list_fixed($sort, $fixed_list); + } + + if ($bootstrap) { + return _module_list_bootstrap ($refresh, $sort); + } + + return _module_list ($refresh, $sort); +} + +function _module_list_fixed($sort, $fixed_list) { + $list = array(); + foreach ($fixed_list as $name => $module) { + drupal_get_filename('module', $name, $module['filename']); + $list[$name] = $name; + } + if ($sort) { + ksort ($list); + } + return $list; +} - if ($refresh || $fixed_list) { +function _module_list_bootstrap($refresh, $sort) { + static $list = array(), $sorted_list; + + if ($refresh || empty($list)) { unset($sorted_list); - $list = array(); - if ($fixed_list) { - foreach ($fixed_list as $name => $module) { - drupal_get_filename('module', $name, $module['filename']); - $list[$name] = $name; - } - } - else { - if ($bootstrap) { - $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC"); - } - else { - $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC"); - } - while ($module = db_fetch_object($result)) { - if (file_exists($module->filename)) { - // Determine the current throttle status and see if the module should be - // loaded based on server load. We have to directly access the throttle - // variables, since throttle.module may not be loaded yet. - $throttle = ($module->throttle && variable_get('throttle_level', 0) > 0); - if (!$throttle) { - drupal_get_filename('module', $module->name, $module->filename); - $list[$module->name] = $module->name; - } - } - } + $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC"); + $list = _module_list_db_result($result); + } + + if ($sort) { + if (!isset($sorted_list)) { + $sorted_list = $list; + ksort($sorted_list); } + return $sorted_list; } + + return $list; +} + +function _module_list($refresh, $sort) { + static $list = array(), $sorted_list; + + if ($refresh || empty($list)) { + unset($sorted_list); + $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC"); + $list = _module_list_db_result($result); + } + if ($sort) { if (!isset($sorted_list)) { $sorted_list = $list; @@ -84,6 +104,24 @@ function module_list($refresh = FALSE, $ } return $sorted_list; } + + return $list; +} + +function _module_list_db_result($result) { + $list = array(); + while ($module = db_fetch_object($result)) { + if (file_exists($module->filename)) { + // Determine the current throttle status and see if the module should be + // loaded based on server load. We have to directly access the throttle + // variables, since throttle.module may not be loaded yet. + $throttle = ($module->throttle && variable_get('throttle_level', 0) > 0); + if (!$throttle) { + drupal_get_filename('module', $module->name, $module->filename); + $list[$module->name] = $module->name; + } + } + } return $list; }