Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.385
diff -u -p -r1.385 theme.inc
--- includes/theme.inc	25 Sep 2007 12:43:18 -0000	1.385
+++ includes/theme.inc	3 Oct 2007 04:38:14 -0000
@@ -272,22 +272,25 @@ function _theme_process_registry(&$cache
       // Check for default _preprocess_ functions. Ensure arrayness.
       if (!isset($info['preprocess functions']) || !is_array($info['preprocess functions'])) {
         $info['preprocess functions'] = array();
-        $prefix = ($type == 'module' ? 'template' : $name);
-        // theme engines get an extra set that come before the normally named preprocess.
-        if ($type == 'theme_engine') {
-          if (function_exists($prefix .'_engine_preprocess')) {
-            $info['preprocess functions'][] = $prefix .'_engine_preprocess';
-          }
-          if (function_exists($prefix .'_engine_preprocess_'. $hook)) {
-            $info['preprocess functions'][] = $prefix .'_engine_preprocess_'. $hook;
-          }
-        }
-
-        // Let the theme engine register theme specific variable functions.
-        $prefixes = array($prefix);
-        if ($type == 'theme_engine') {
+        $prefixes = array();
+        if ($type == 'module') {
+          // Default and module preprocessors.
+          // The module list is used to intervene preprocessors not registered to itself.
+          $prefixes[] = 'template';
+          $prefixes += module_list();
+        }
+        elseif ($type == 'theme_engine') {
+          // Theme engines get an extra set that come before the normally named preprocessors.
+          // The theme engine also registers on behalf of the theme.
+          $prefixes[] = $name .'_engine';
+          $prefixes[] = $name;
           $prefixes[] = $theme;
         }
+        else {
+          // This applies to themes without theme engines.
+          $prefixes[] = $name;
+        }
+
         foreach ($prefixes as $prefix) {
           if (function_exists($prefix .'_preprocess')) {
             $info['preprocess functions'][] = $prefix .'_preprocess';
@@ -444,38 +447,45 @@ function list_theme_engines($refresh = F
  * If the implementation is a template, the arguments are converted to a
  * $variables array. This array is then modified by the theme engine (if
  * applicable) and the theme. The following functions may be used to modify
- * the $variables array:
+ * the $variables array. They are processed in this order:
  *
- * ENGINE_engine_preprocess(&$variables)
+ * - template_preprocess(&$variables)
+ *   This sets a default set of variables for all template implementations.
+ *
+ * - template_preprocess_HOOK(&$variables)
+ *   This is called for the hook; it should be implemented by the module that
+ *   registers the hook, and will always be called if the hook is a template.
+ *
+ * - MODULE_preprocess(&$variables)
+ *   This will be called for all templates; it should only be used if there
+ *   is a real need.
+ *
+ * - MODULE_preprocess_HOOK(&$variables)
+ *   This is meant to be used by modules that want to provides some extra
+ *   variables for an existing theme hook.
+ *
+ * - ENGINE_engine_preprocess(&$variables)
  *   This function should only be implemented by theme engines and exists
- *   so that the theme engine can set necessary variables. It is commonly
- *   used to set global variables such as $directory and $is_front_page.
+ *   so that the theme engine can set necessary variables.
  *
- * ENGINE_engine_preprocess_HOOK(&$variables)
+ * - ENGINE_engine_preprocess_HOOK(&$variables)
  *   This is the same as the previous function, but is called only per hook.
  *
- * ENGINE_preprocess_HOOK(&$variables)
- *
- * ENGINE_preprocess(&$variables)
- *   This is meant to be used by themes that utilize a theme engine; as it is
- *   good practice for these themes to use the theme engine's name for
- *   their functions so that they may share code. In PHPTemplate, these
- *   functions will appear in template.php
+ * - ENGINE_preprocess(&$variables)
+ *   This is meant to be used by themes that utilize a theme engine. Theme
+ *   authors must be careful when using this in sub-themes with PHPTemplate
+ *   since it can cause a fatal redeclare errors due to multiple template.php
+ *   files being used. A good practice is to use the engine name for the base
+ *   theme and the theme name for the sub-themes to minimize name collisions. 
  *
- * THEME_preprocess_HOOK(&$variables)
+ * - ENGINE_preprocess_HOOK(&$variables)
+ *   This is the same as the previous function, but is called only per hook.
  *
- * THEME_preprocess(&$variables)
+ * - THEME_preprocess(&$variables)
  *   These functions are based upon the raw theme; they should primarily be
- *   used by themes that do not use an engine or by themes that need small
- *   changes to what has already been established in the theme engine version
- *   of the function.
- *
- * template_preprocess(&$variables)
- *   This function will only be called for theme functions registered by
- *   the named module. In general it is preferred to use the following
- *   function if possible, but it may not always be the case.
+ *   used by themes that do not use an engine or by sub-themes.
  *
- * template_preprocess_HOOK(&$variables)
+ * - THEME_preprocess_HOOK(&$variables)
  *   This is the same as the previous function, but is called only per hook.
  *
  * There are two special variables that these hooks can set:
